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

RSpec matchers use Capybara's selectors' error messages

This commit is contained in:
Jonas Nicklas 2011-02-04 16:56:27 +01:00
parent 95e3df506a
commit 2adf7c6638
2 changed files with 25 additions and 1 deletions

View file

@ -13,7 +13,11 @@ module Capybara
end
failure_message_for_should do |actual|
"expected #{normalized[:selector].name} #{normalized[:locator].inspect} to return something from:\n#{actual.inspect}"
if normalized[:selector].failure_message
normalized[:selector].failure_message.call(wrap(actual))
else
"expected #{normalized[:selector].name} #{normalized[:locator].inspect} to return something from:\n#{actual.inspect}"
end
end
failure_message_for_should_not do |actual|

View file

@ -136,6 +136,16 @@ describe Capybara::RSpecMatchers do
"<h1>Text</h1>".should have_selector('//h2')
end.to raise_error(%r(expected xpath "//h2" to return something))
end
it "fails with the selector's failure_message if set" do
Capybara.add_selector(:monkey) do
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
failure_message { |node| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
end
expect do
'<h1 id="monkey_paul">Monkey John</h1>'.should have_selector(:monkey, 14)
end.to raise_error("Monkey John")
end
end
context "with should_not" do
@ -166,6 +176,16 @@ describe Capybara::RSpecMatchers do
page.should have_selector("//h1[@id='doesnotexist']")
end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
end
it "fails with the selector's failure_message if set" do
Capybara.add_selector(:monkey) do
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
failure_message { |node| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
end
expect do
page.should have_selector(:monkey, 14)
end.to raise_error("Monkey John, Monkey Paul")
end
end
context "with should_not" do