diff --git a/spec/form/button_spec.cr b/spec/form/button_spec.cr index 41fee83..644f684 100644 --- a/spec/form/button_spec.cr +++ b/spec/form/button_spec.cr @@ -26,8 +26,13 @@ describe "Form Fields CheckBox" do form.buttons.size.should eq 2 end - it "can be found by button_with method" do + it "can be found by button_with method, argument type: Hash" do button2 = form.button_with({"class" => "sndButton"}) button2.value.should eq "sndButtonValue" end + + it "can be found by button_with method, argument type: NamedTuple" do + button2 = form.button_with({class: "sndButton"}) + button2.value.should eq "sndButtonValue" + end end diff --git a/spec/form/check_box_spec.cr b/spec/form/check_box_spec.cr index 714ec04..d9a251a 100644 --- a/spec/form/check_box_spec.cr +++ b/spec/form/check_box_spec.cr @@ -52,10 +52,17 @@ describe "Form Fields CheckBox" do checkbox.name.should eq "remember_me" end - it "can be found by checkboxes_with method" do + it "can be found by checkboxes_with method, argument type: Hash" do checkboxes = form.checkboxes_with({"class" => "some_checkbox"}) checkboxes.size.should eq 2 checkboxes[0].name.should eq "remember_me" checkboxes[1].name.should eq "forget_me" end + + it "can be found by checkboxes_with method, argument type: NamedTuple" do + checkboxes = form.checkboxes_with({class: "some_checkbox"}) + checkboxes.size.should eq 2 + checkboxes[0].name.should eq "remember_me" + checkboxes[1].name.should eq "forget_me" + end end diff --git a/spec/form/field_spec.cr b/spec/form/field_spec.cr index caa35c5..e761206 100644 --- a/spec/form/field_spec.cr +++ b/spec/form/field_spec.cr @@ -47,9 +47,17 @@ describe "Form Fields" do email_field.name.should eq "email" end - it "can be found by fields_with method" do + it "can be found by fields_with method, argument type: Hash" do name_fields = form.fields_with("name") name_fields.size.should eq 2 name_fields[0].name.should eq "name" end + + it "can be found by fields_with method, argument type: NamedTuple" do + name_field = form.field_with("name") + name_field.name.should eq "name" + + email_field = form.field_with({id: "emailID"}) + email_field.name.should eq "email" + end end diff --git a/spec/form/radio_button_spec.cr b/spec/form/radio_button_spec.cr index 02bc7ef..e800f77 100644 --- a/spec/form/radio_button_spec.cr +++ b/spec/form/radio_button_spec.cr @@ -71,4 +71,14 @@ describe "Form Fields RadioButton" do radiobuttons[1].value.should eq "phone" radiobuttons[2].value.should eq "mail" end + + it "can be found by radiobutton_with method, argument type: Hash" do + radiobutton = form.radiobutton_with({"id": "contactChoice1"}) + radiobutton.value.should eq "email" + end + + it "can be found by radiobutton_with method, argument type: NamedTuple" do + radiobutton = form.radiobutton_with({id: "contactChoice1"}) + radiobutton.value.should eq "email" + end end diff --git a/spec/page_spec.cr b/spec/page_spec.cr index b49f4c9..329d32e 100644 --- a/spec/page_spec.cr +++ b/spec/page_spec.cr @@ -32,10 +32,17 @@ describe "Mechanize Page test" do page.forms.first.name.should eq "sample_form" end - it "can detect form by using form_with method" do + it "can detect form by using form_with method, argument type: Hash" do agent = Mechanize.new page = agent.get("http://example.com/form") form = page.form_with({"name" => "sample_form" }) form.name.should eq "sample_form" end + + it "can detect form by using form_with method, argument type: NamedTuple" do + agent = Mechanize.new + page = agent.get("http://example.com/form") + form = page.form_with({name: "sample_form" }) + form.name.should eq "sample_form" + end end diff --git a/src/mechanize/utils/element_matcher.cr b/src/mechanize/utils/element_matcher.cr index fcbb8ae..72fd902 100644 --- a/src/mechanize/utils/element_matcher.cr +++ b/src/mechanize/utils/element_matcher.cr @@ -6,6 +6,9 @@ module MechanzeCr::ElementMatcher end def {{plural.id}}_with(criteria, &block) + if criteria.is_a?(NamedTuple) + criteria = criteria.to_h + end if criteria.is_a?(String) criteria = {"name" => criteria} else