Merge pull request #1940 from andyklimczak/fix-non-visible-error

Fix non-visible text error message
This commit is contained in:
Thomas Walpole 2017-11-22 08:57:36 -08:00 committed by GitHub
commit 53a8f5717e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -70,7 +70,7 @@ module Capybara
invisible_text = text(@node, :all) invisible_text = text(@node, :all)
invisible_count = invisible_text.scan(@search_regexp).size invisible_count = invisible_text.scan(@search_regexp).size
if invisible_count != @count 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 end
rescue rescue
# An error getting the non-visible text (if element goes out of scope) should not affect the response # An error getting the non-visible text (if element goes out of scope) should not affect the response

View File

@ -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.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search/)
end 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 it "should raise the correct error if requested text is missing but contains regex special characters" do
@session.visit('/with_html') @session.visit('/with_html')
expect do expect do

View File

@ -122,6 +122,10 @@ banana</textarea>
<a id="link_blank_href" href="">Blank href</a> <a id="link_blank_href" href="">Blank href</a>
</div> </div>
<div id="uppercase" style="text-transform: uppercase;">
text here
</div>
<div id="ancestor3"> <div id="ancestor3">
Ancestor Ancestor
<div id="ancestor2"> <div id="ancestor2">