diff --git a/lib/webcat/driver/rack_test_driver.rb b/lib/webcat/driver/rack_test_driver.rb index 75dfe319..13b0a0ef 100644 --- a/lib/webcat/driver/rack_test_driver.rb +++ b/lib/webcat/driver/rack_test_driver.rb @@ -19,7 +19,11 @@ class Webcat::Driver::RackTest session.html.xpath("//input[@name='#{self[:name]}']").each { |node| node.remove_attribute("checked") } node['checked'] = 'checked' elsif tag_name == 'input' and type == 'checkbox' - node['checked'] = 'checked' + if value + node['checked'] = 'checked' + else + node.remove_attribute('checked') + end elsif tag_name == "textarea" node.content = value.to_s end diff --git a/lib/webcat/session.rb b/lib/webcat/session.rb index a239ee80..a71ef703 100644 --- a/lib/webcat/session.rb +++ b/lib/webcat/session.rb @@ -44,6 +44,10 @@ class Webcat::Session def check(locator) find_field(locator, :checkbox).set(true) end + + def uncheck(locator) + find_field(locator, :checkbox).set(false) + end def body driver.body diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 2e0ba8e4..9375bf7c 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -224,7 +224,25 @@ shared_examples_for "session" do end describe "#uncheck" do - + before do + @session.visit('/form') + end + + it "should uncheck a checkbox by id" do + pending "Culerity doesn't seem to uncheck this" if @session.mode == :culerity + @session.uncheck("form_pets_hamster") + @session.click_button('awesome') + YAML.load(@session.body)['pets'].should include('dog') + YAML.load(@session.body)['pets'].should_not include('hamster') + end + + it "should uncheck a checkbox by label" do + pending "Culerity doesn't seem to uncheck this" if @session.mode == :culerity + @session.uncheck("Hamster") + @session.click_button('awesome') + YAML.load(@session.body)['pets'].should include('dog') + YAML.load(@session.body)['pets'].should_not include('hamster') + end end describe "#select" do