Skip to content

Commit

Permalink
Fix error messages for has_text when argument is non-string
Browse files Browse the repository at this point in the history
Follow-up fix to #762.
  • Loading branch information
joliss committed Aug 1, 2012
1 parent b2767a8 commit 2b030c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/capybara/rspec/matchers.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/matchers_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2b030c7

Please sign in to comment.