Permalink
Browse files

Accept non-string parameters to has_text, notably nil and numbers

This is mostly for compatibility with Capybara 1.1.2.
  • Loading branch information...
joliss committed Jul 19, 2012
1 parent 5c7515c commit 0aeee9f8f0e46d602524724defca966e6f9013a7
@@ -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
##
@@ -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
@@ -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>

0 comments on commit 0aeee9f

Please sign in to comment.