diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb
index 565634f9..5cb113d1 100644
--- a/lib/capybara/rspec/matchers.rb
+++ b/lib/capybara/rspec/matchers.rb
@@ -113,8 +113,8 @@ module Capybara
def have_button(button, options={})
HaveMatcher.new(:button, button, options) do |page, matcher|
- buttons = page.all(:xpath, './/button | .//input[(type="submit") or (type="image") or (type="button")]')
- labels = buttons.map { |button| %("#{button.text}") }.join(', ')
+ buttons = page.all(:xpath, './/button | .//input[(@type="submit") or (@type="image") or (@type="button")]')
+ labels = buttons.map { |button| %("#{button[:value] or button.text}") }.join(', ')
%(expected there to be a button #{matcher.locator.inspect}, other buttons: #{labels})
end
end
diff --git a/spec/rspec/matchers_spec.rb b/spec/rspec/matchers_spec.rb
index 837b4cfc..8aa8246d 100644
--- a/spec/rspec/matchers_spec.rb
+++ b/spec/rspec/matchers_spec.rb
@@ -269,6 +269,20 @@ describe Capybara::RSpecMatchers do
describe "have_link matcher"
describe "have_button matcher" do
+ let(:html) { '' }
+
+ it "passes if there is such a button" do
+ html.should have_button('A button')
+ end
+
+ it "fails if there is no such button" do
+ expect do
+ html.should have_button('No such Button')
+ end.to raise_error(/expected there to be a button "No such Button", other buttons: "A button", "Another button"/)
+ end
+ end
+
+ describe "have_field matcher" do
let(:html) { '' }
it "passes if there is such a button" do
@@ -282,8 +296,6 @@ describe Capybara::RSpecMatchers do
end
end
- describe "have_no_button matcher"
- describe "have_field matcher"
describe "have_checked_field matcher"
describe "have_unchecked_field matcher"
describe "have_select matcher"