Skip to content

Commit

Permalink
Merge pull request teamcapybara#762 from joliss/has-text-nil
Browse files Browse the repository at this point in the history
Accept non-string parameters to has_text, notably nil and numbers
  • Loading branch information
jnicklas committed Jul 19, 2012
2 parents 5c7515c + 0aeee9f commit dca0c59
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/capybara/node/matchers.rb
Expand Up @@ -472,7 +472,7 @@ def ==(other)
# @return [String] Normalized text
#
def normalize_whitespace(text)
text.is_a?(Regexp) ? text : text.gsub(/\s+/, ' ').strip
text.is_a?(Regexp) ? text : text.to_s.gsub(/\s+/, ' ').strip
end

##
Expand Down
11 changes: 11 additions & 0 deletions lib/capybara/spec/session/has_text_spec.rb
Expand Up @@ -83,6 +83,17 @@
@session.visit('/with_html')
@session.should_not have_text('.orem')
end

it "should accept non-string parameters" do
@session.visit('/with_html')
@session.should have_text(42)
end

it "should be true when passed nil" do
# Historical behavior; no particular reason other than compatibility.
@session.visit('/with_html')
@session.should have_text(nil)
end
end

describe '#has_no_text?' do
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/spec/views/with_html.erb
Expand Up @@ -72,6 +72,10 @@ banana</textarea>
<a id="visible" class="visibility">visible link</a>
</div>

<div>
Number 42
</div>

<ul>
<li id="john_monkey">Monkey John</li>
<li id="paul_monkey">Monkey Paul</li>
Expand Down

0 comments on commit dca0c59

Please sign in to comment.