mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix error messages for has_text when argument is non-string
Follow-up fix to #762.
This commit is contained in:
parent
b2767a8413
commit
2b030c7c3e
2 changed files with 14 additions and 3 deletions
|
@ -48,15 +48,15 @@ module Capybara
|
|||
end
|
||||
|
||||
def failure_message_for_should
|
||||
"expected there to be text #{text.inspect} in #{@actual.text.inspect}"
|
||||
"expected there to be text #{format(text)} in #{format(@actual.text)}"
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
"expected there not to be text #{text.inspect} in #{@actual.text.inspect}"
|
||||
"expected there not to be text #{format(text)} in #{format(@actual.text)}"
|
||||
end
|
||||
|
||||
def description
|
||||
"have text #{text.inspect}"
|
||||
"have text #{format(text)}"
|
||||
end
|
||||
|
||||
def wrap(actual)
|
||||
|
@ -66,6 +66,11 @@ module Capybara
|
|||
Capybara.string(actual.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def format(text)
|
||||
text = Capybara::Helpers.normalize_whitespace(text) unless text.is_a? Regexp
|
||||
text.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def have_selector(*args)
|
||||
|
|
|
@ -324,6 +324,12 @@ describe Capybara::RSpecMatchers do
|
|||
"<h1>Text</h1>".should have_text('No such Text')
|
||||
end.to raise_error(/expected there to be text "No such Text" in "Text"/)
|
||||
end
|
||||
|
||||
it "casts has_text? argument to string" do
|
||||
expect do
|
||||
"<h1>Text</h1>".should have_text(:cast_me)
|
||||
end.to raise_error(/expected there to be text "cast_me" in "Text"/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with should_not" do
|
||||
|
|
Loading…
Reference in a new issue