From 0aeee9f8f0e46d602524724defca966e6f9013a7 Mon Sep 17 00:00:00 2001 From: Jo Liss Date: Thu, 19 Jul 2012 17:03:35 +0200 Subject: [PATCH] Accept non-string parameters to has_text, notably nil and numbers This is mostly for compatibility with Capybara 1.1.2. --- lib/capybara/node/matchers.rb | 2 +- lib/capybara/spec/session/has_text_spec.rb | 11 +++++++++++ lib/capybara/spec/views/with_html.erb | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index f7ceee944..672ec1b13 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -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 ## diff --git a/lib/capybara/spec/session/has_text_spec.rb b/lib/capybara/spec/session/has_text_spec.rb index ac4a3e132..5d47e4f2b 100644 --- a/lib/capybara/spec/session/has_text_spec.rb +++ b/lib/capybara/spec/session/has_text_spec.rb @@ -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 diff --git a/lib/capybara/spec/views/with_html.erb b/lib/capybara/spec/views/with_html.erb index 707957900..3586ad5ab 100644 --- a/lib/capybara/spec/views/with_html.erb +++ b/lib/capybara/spec/views/with_html.erb @@ -72,6 +72,10 @@ banana visible link +
+ Number 42 +
+