Skip to content

Commit

Permalink
Better errors for button matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Feb 13, 2011
1 parent d18787d commit df300e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/capybara/rspec/matchers.rb
Expand Up @@ -113,8 +113,8 @@ def have_content(text)

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
Expand Down
16 changes: 14 additions & 2 deletions spec/rspec/matchers_spec.rb
Expand Up @@ -269,6 +269,20 @@
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
Expand All @@ -282,8 +296,6 @@
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"
Expand Down

0 comments on commit df300e9

Please sign in to comment.