diff --git a/lib/capybara/queries/text_query.rb b/lib/capybara/queries/text_query.rb index af1d1ff5..a1bf6797 100644 --- a/lib/capybara/queries/text_query.rb +++ b/lib/capybara/queries/text_query.rb @@ -70,7 +70,7 @@ module Capybara invisible_text = text(@node, :all) invisible_count = invisible_text.scan(@search_regexp).size if invisible_count != @count - details_message << ". it was found #{invisible_count} #{Capybara::Helpers.declension("time", "times", invisible_count)} including non-visible text" + details_message << "it was found #{invisible_count} #{Capybara::Helpers.declension("time", "times", invisible_count)} including non-visible text" end rescue # An error getting the non-visible text (if element goes out of scope) should not affect the response diff --git a/lib/capybara/spec/session/assert_text.rb b/lib/capybara/spec/session/assert_text.rb index 8cef1e18..7bd2a01c 100644 --- a/lib/capybara/spec/session/assert_text.rb +++ b/lib/capybara/spec/session/assert_text.rb @@ -52,6 +52,14 @@ Capybara::SpecHelper.spec '#assert_text' do end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search/) end + it "should raise error with helpful message if requested text is present but invisible and with incorrect case", requires: [:js] do + @session.visit('/with_html') + el = @session.find(:css, '#uppercase') + expect do + el.assert_text('text here') + end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search and it was found 1 time including non-visible text/) + end + it "should raise the correct error if requested text is missing but contains regex special characters" do @session.visit('/with_html') expect do diff --git a/lib/capybara/spec/views/with_html.erb b/lib/capybara/spec/views/with_html.erb index e8da0b3d..94d0256e 100644 --- a/lib/capybara/spec/views/with_html.erb +++ b/lib/capybara/spec/views/with_html.erb @@ -122,6 +122,10 @@ banana Blank href +
+ text here +
+
Ancestor