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:
parent
d18787de65
commit
df300e9fbe
2 changed files with 16 additions and 4 deletions
|
@ -113,8 +113,8 @@ module Capybara
|
||||||
|
|
||||||
def have_button(button, options={})
|
def have_button(button, options={})
|
||||||
HaveMatcher.new(:button, button, options) do |page, matcher|
|
HaveMatcher.new(:button, button, options) do |page, matcher|
|
||||||
buttons = page.all(:xpath, './/button | .//input[(type="submit") or (type="image") or (type="button")]')
|
buttons = page.all(:xpath, './/button | .//input[(@type="submit") or (@type="image") or (@type="button")]')
|
||||||
labels = buttons.map { |button| %("#{button.text}") }.join(', ')
|
labels = buttons.map { |button| %("#{button[:value] or button.text}") }.join(', ')
|
||||||
%(expected there to be a button #{matcher.locator.inspect}, other buttons: #{labels})
|
%(expected there to be a button #{matcher.locator.inspect}, other buttons: #{labels})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -269,6 +269,20 @@ describe Capybara::RSpecMatchers do
|
||||||
describe "have_link matcher"
|
describe "have_link matcher"
|
||||||
|
|
||||||
describe "have_button matcher" do
|
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>' }
|
let(:html) { '<button>A button</button><button>Another button</button>' }
|
||||||
|
|
||||||
it "passes if there is such a button" do
|
it "passes if there is such a button" do
|
||||||
|
@ -282,8 +296,6 @@ describe Capybara::RSpecMatchers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "have_no_button matcher"
|
|
||||||
describe "have_field matcher"
|
|
||||||
describe "have_checked_field matcher"
|
describe "have_checked_field matcher"
|
||||||
describe "have_unchecked_field matcher"
|
describe "have_unchecked_field matcher"
|
||||||
describe "have_select matcher"
|
describe "have_select matcher"
|
||||||
|
|
Loading…
Add table
Reference in a new issue