add checkbox_with method
This commit is contained in:
parent
8fa89fab2d
commit
b4c5e33037
@ -8,7 +8,8 @@ WebMock.stub(:get, "example.com/form/check_box").to_return(body:
|
||||
</head>
|
||||
<body>
|
||||
<form action="post_path" method="post" name="sample_form">
|
||||
<input type="checkbox" id="remember_me" name="remember_me" checked>
|
||||
<input type="checkbox" class="some_checkbox" id="remember_me" name="remember_me" checked>
|
||||
<input type="checkbox" class="some_checkbox" id="forget_me" name="forget_me">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@ -19,13 +20,14 @@ 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 = form.checkboxes.first
|
||||
checkbox.checked?.should eq true
|
||||
end
|
||||
|
||||
it "can change check status" do
|
||||
checkbox = form.checkboxes.first
|
||||
checkbox.checked?.should eq true
|
||||
checkbox.uncheck
|
||||
checkbox.checked?.should eq false
|
||||
@ -39,8 +41,21 @@ describe "Form Fields CheckBox" do
|
||||
end
|
||||
|
||||
it "doesn't included in request data if checkbox isn't checked" do
|
||||
checkbox = form.checkboxes.first
|
||||
form.request_data.should contain("remember_me=on")
|
||||
checkbox.uncheck
|
||||
form.request_data.should_not contain("remember_me=")
|
||||
end
|
||||
|
||||
it "can be found by checkbox_with method" do
|
||||
checkbox = form.checkbox_with("remember_me")
|
||||
checkbox.name.should eq "remember_me"
|
||||
end
|
||||
|
||||
it "can be found by checkboxes_with method" 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
|
||||
|
@ -49,6 +49,7 @@ class MechanizeCr::Form
|
||||
|
||||
elements_with "field"
|
||||
elements_with "radiobutton"
|
||||
elements_with "checkbox", "checkboxes"
|
||||
|
||||
private def parse
|
||||
@node.css("input").not_nil!.each do |html_node|
|
||||
|
@ -1,6 +1,6 @@
|
||||
module MechanzeCr::ElementMatcher
|
||||
macro elements_with(singular)
|
||||
{% plural = "#{singular.id}s" %}
|
||||
macro elements_with(singular, plural="")
|
||||
{% plural = "#{singular.id}s" if plural.empty? %}
|
||||
def {{plural.id}}_with(criteria)
|
||||
{{plural.id}}_with(criteria){}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user