1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Better errors for button matcher

This commit is contained in:
Jonas Nicklas 2011-02-13 17:46:22 +01:00
parent d18787de65
commit df300e9fbe
2 changed files with 16 additions and 4 deletions

View file

@ -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

View file

@ -269,6 +269,20 @@ describe Capybara::RSpecMatchers do
describe "have_link matcher"
describe "have_button matcher" do
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
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) { '<button>A button</button><button>Another button</button>' }
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"