From e7b72c72ecd30194148b1baa6ffb970a62b85287 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Thu, 8 Aug 2013 19:05:38 -0400 Subject: [PATCH] Allows passing options through has_button? to has_selector? This enables assertions on the presence of disabled buttons by doing: assert has_button?('Button text', :disabled => true) in a similar way to: find_field("Disabled Checkbox", :disabled => true) --- lib/capybara/node/matchers.rb | 8 +++---- lib/capybara/rspec/matchers.rb | 4 ++-- lib/capybara/spec/session/has_button_spec.rb | 24 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index 5836f056..55f5f112 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -280,8 +280,8 @@ module Capybara # @param [String] locator The text, value or id of a button to check for # @return [Boolean] Whether it exists # - def has_button?(locator) - has_selector?(:button, locator) + def has_button?(locator, options={}) + has_selector?(:button, locator, options) end ## @@ -292,8 +292,8 @@ module Capybara # @param [String] locator The text, value or id of a button to check for # @return [Boolean] Whether it doesn't exist # - def has_no_button?(locator) - has_no_selector?(:button, locator) + def has_no_button?(locator, options={}) + has_no_selector?(:button, locator, options) end ## diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index 4267accc..964c0d31 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -126,8 +126,8 @@ module Capybara HaveSelector.new(:link, locator, options) end - def have_button(locator) - HaveSelector.new(:button, locator) + def have_button(locator, options={}) + HaveSelector.new(:button, locator, options) end def have_field(locator, options={}) diff --git a/lib/capybara/spec/session/has_button_spec.rb b/lib/capybara/spec/session/has_button_spec.rb index d1ba42b8..8c5338e2 100644 --- a/lib/capybara/spec/session/has_button_spec.rb +++ b/lib/capybara/spec/session/has_button_spec.rb @@ -9,9 +9,21 @@ Capybara::SpecHelper.spec '#has_button?' do @session.should have_button(:'crap321') end + it "should be true for disabled buttons if :disabled => true" do + @session.should have_button('Disabled button', :disabled => true) + end + it "should be false if the given button is not on the page" do @session.should_not have_button('monkey') end + + it "should be false for disabled buttons by default" do + @session.should_not have_button('Disabled button') + end + + it "should be false for disabled buttons if :disabled => false" do + @session.should_not have_button('Disabled button', :disabled => false) + end end Capybara::SpecHelper.spec '#has_no_button?' do @@ -24,7 +36,19 @@ Capybara::SpecHelper.spec '#has_no_button?' do @session.should_not have_no_button('crap321') end + it "should be true for disabled buttons if :disabled => true" do + @session.should_not have_no_button('Disabled button', :disabled => true) + end + it "should be false if the given button is not on the page" do @session.should have_no_button('monkey') end + + it "should be false for disabled buttons by default" do + @session.should have_no_button('Disabled button') + end + + it "should be false for disabled buttons if :disabled => false" do + @session.should have_no_button('Disabled button', :disabled => false) + end end