Permalink
Browse files

Fix error messages for has_text when argument is non-string

Follow-up fix to #762.
  • Loading branch information...
1 parent b2767a8 commit 2b030c7c3e3fc4a8105a477ed7a13dce9cef0ef4 @joliss joliss committed Aug 1, 2012
Showing with 14 additions and 3 deletions.
  1. +8 −3 lib/capybara/rspec/matchers.rb
  2. +6 −0 spec/rspec/matchers_spec.rb
View
11 lib/capybara/rspec/matchers.rb
@@ -48,15 +48,15 @@ def does_not_match?(actual)
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 @@ def wrap(actual)
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)
View
6 spec/rspec/matchers_spec.rb
@@ -324,6 +324,12 @@
"<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

0 comments on commit 2b030c7

Please sign in to comment.