From 5eb538d7304c828e6bea01ff9af6757f1127d4e6 Mon Sep 17 00:00:00 2001 From: Andy Klimczak Date: Tue, 21 Nov 2017 21:19:16 -0500 Subject: [PATCH] Fix non-visible text error message - Remove extra period in the invisible text details message - Add error validation test that requires :js for when text is changed by `text-transform` css - When asserting on text that is changed via css in a test that requires :js, the test must assert how the text exactly looks on the page, not just in HTML - Discrepancy between pure html and actual output on page - In this case, the text is found using case insensitive text and including non-visible text - When those two error detail messages (case insensitive and non-visible) are concatenated, the error looks off because of the prepended period. - Remove the prepended period so that the error looks correct --- lib/capybara/queries/text_query.rb | 2 +- lib/capybara/spec/session/assert_text.rb | 8 ++++++++ lib/capybara/spec/views/with_html.erb | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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