From c62710625979ff1dcfae22a70703ad5a4c19f76c Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Sat, 19 Jun 2021 06:00:33 +0900 Subject: [PATCH] split form_test --- spec/form/check_box_spec.cr | 46 ++++++++++++++++++ spec/form/field_spec.cr | 28 +++++++++++ spec/form/radio_button_spec.cr | 74 +++++++++++++++++++++++++++++ spec/form_spec.cr | 87 ---------------------------------- 4 files changed, 148 insertions(+), 87 deletions(-) create mode 100644 spec/form/check_box_spec.cr create mode 100644 spec/form/field_spec.cr create mode 100644 spec/form/radio_button_spec.cr diff --git a/spec/form/check_box_spec.cr b/spec/form/check_box_spec.cr new file mode 100644 index 0000000..7f227b2 --- /dev/null +++ b/spec/form/check_box_spec.cr @@ -0,0 +1,46 @@ +require "../spec_helper" + +WebMock.stub(:get, "example.com/form/check_box").to_return(body: +<<-BODY + + + page_title + + +
+ +
+ + +BODY +) + +describe "Form Fields CheckBox" do + agent = Mechanize.new + page = agent.get("http://example.com/form/check_box") + form = page.forms[0] + checkbox = form.checkboxes.first + + it "returns checkbox status" do + checkbox.checked?.should eq true + end + + it "can change check status" do + checkbox.checked?.should eq true + checkbox.uncheck + checkbox.checked?.should eq false + checkbox.check + checkbox.checked?.should eq true + # #click reverses check status + checkbox.click + checkbox.checked?.should eq false + checkbox.click + checkbox.checked?.should eq true + end + + it "doesn't included in request data if checkbox isn't checked" do + form.request_data.should contain("remember_me=on") + checkbox.uncheck + form.request_data.should_not contain("remember_me=") + end +end diff --git a/spec/form/field_spec.cr b/spec/form/field_spec.cr new file mode 100644 index 0000000..7079e52 --- /dev/null +++ b/spec/form/field_spec.cr @@ -0,0 +1,28 @@ +require "../spec_helper" + +WebMock.stub(:get, "example.com/form/fields").to_return(body: +<<-BODY + + + page_title + + +
+ + +
+ + +BODY +) + +describe "Form Fields" do + agent = Mechanize.new + page = agent.get("http://example.com/form/fields") + form = page.forms[0] + it "returns field attribute" do + field = form.fields.first + field.type.should eq "text" + field.name.should eq "name" + end +end diff --git a/spec/form/radio_button_spec.cr b/spec/form/radio_button_spec.cr new file mode 100644 index 0000000..02bc7ef --- /dev/null +++ b/spec/form/radio_button_spec.cr @@ -0,0 +1,74 @@ +require "../spec_helper.cr" + +WebMock.stub(:get, "example.com/form/radio_button").to_return(body: +<<-BODY + + + page_title + + +
+ + + +
+ + +BODY +) + +describe "Form Fields RadioButton" do + agent = Mechanize.new + page = agent.get("http://example.com/form/radio_button") + form = page.forms[0] + + radiobuttons = form.radiobuttons + radiobuttons.size.should eq 3 + + it "returns radiobutton check status" do + radiobuttons.map(&.checked?).should eq [false,false,false] + end + + it "can change check status" do + radiobutton = radiobuttons.first + radiobutton.checked?.should eq false + radiobutton.check + radiobutton.checked?.should eq true + radiobutton.uncheck + radiobutton.checked?.should eq false + # #click reverses check status + radiobutton.click + radiobutton.checked?.should eq true + radiobutton.click + radiobutton.checked?.should eq false + end + + it "check status is exclusive" do + radiobuttons[0].check + radiobuttons[0].checked.should eq true + radiobuttons[1].checked.should eq false + radiobuttons[1].check + radiobuttons[1].checked.should eq true + radiobuttons[0].checked.should eq false + end + + it "doesn't included in request data if checkbox isn't checked" do + radiobuttons[0].check + form.request_data.should contain "contact=email" + radiobuttons[0].uncheck + form.request_data.should_not contain "contact" + end + + it "can be found by radiobutton_with method" do + radiobutton = form.radiobutton_with("contact") + radiobutton.value.should eq "email" + end + + it "can be found by radiobuttons_with method" do + radiobuttons = form.radiobuttons_with("contact") + radiobuttons.size.should eq 3 + radiobuttons[0].value.should eq "email" + radiobuttons[1].value.should eq "phone" + radiobuttons[2].value.should eq "mail" + end +end diff --git a/spec/form_spec.cr b/spec/form_spec.cr index 15c2b8a..ce29a40 100644 --- a/spec/form_spec.cr +++ b/spec/form_spec.cr @@ -36,91 +36,4 @@ describe "Mechanize Form test" do it "includes fields" do form.fields.size.should eq 2 end - - context "Form Fields" do - it "returns field attribute" do - field = form.fields.first - field.type.should eq "text" - field.name.should eq "name" - end - end - - context "Form Fields CheckBox" do - checkbox = form.checkboxes.first - - it "returns checkbox status" do - checkbox.checked?.should eq true - end - - it "can change check status" do - checkbox.checked?.should eq true - checkbox.uncheck - checkbox.checked?.should eq false - checkbox.check - checkbox.checked?.should eq true - # #click reverses check status - checkbox.click - checkbox.checked?.should eq false - checkbox.click - checkbox.checked?.should eq true - end - - it "doesn't included in request data if checkbox isn't checked" do - form.request_data.should contain("remember_me=on") - checkbox.uncheck - form.request_data.should_not contain("remember_me=") - end - end - - context "Form Fields RadioButton" do - radiobuttons = form.radiobuttons - radiobuttons.size.should eq 3 - - it "returns radiobutton check status" do - radiobuttons.map(&.checked?).should eq [false,false,false] - end - - it "can change check status" do - radiobutton = radiobuttons.first - radiobutton.checked?.should eq false - radiobutton.check - radiobutton.checked?.should eq true - radiobutton.uncheck - radiobutton.checked?.should eq false - # #click reverses check status - radiobutton.click - radiobutton.checked?.should eq true - radiobutton.click - radiobutton.checked?.should eq false - end - - it "check status is exclusive" do - radiobuttons[0].check - radiobuttons[0].checked.should eq true - radiobuttons[1].checked.should eq false - radiobuttons[1].check - radiobuttons[1].checked.should eq true - radiobuttons[0].checked.should eq false - end - - it "doesn't included in request data if checkbox isn't checked" do - radiobuttons[0].check - form.request_data.should contain "contact=email" - radiobuttons[0].uncheck - form.request_data.should_not contain "contact" - end - - it "can be found by radiobutton_with method" do - radiobutton = form.radiobutton_with("contact") - radiobutton.value.should eq "email" - end - - it "can be found by radiobuttons_with method" do - radiobuttons = form.radiobuttons_with("contact") - radiobuttons.size.should eq 3 - radiobuttons[0].value.should eq "email" - radiobuttons[1].value.should eq "phone" - radiobuttons[2].value.should eq "mail" - end - end end