diff --git a/History.md b/History.md index 7b288b53..a3c9a65b 100644 --- a/History.md +++ b/History.md @@ -3,7 +3,7 @@ Release date: unreleased ### Added -* text predicates and matchers (`has_text?`, `has_content?`, `assert_text`, etc) now support a `collapse_ws` option +* text predicates and matchers (`has_text?`, `has_content?`, `assert_text`, etc) now support a `normalize_ws` option ### Fixed diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index 91d6c86d..4ed2c5bd 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -632,7 +632,7 @@ module Capybara # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument # @option options [Boolean] :exact (Capybara.exact_text) Whether text must be an exact match or just substring - # @option options [Boolean] :collapse_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space + # @option options [Boolean] :nomalize_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space # @overload $0(text, **options) # @param [String, Regexp] text The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it. # @option options [Integer] :count (nil) Number of times the text is expected to occur @@ -641,7 +641,7 @@ module Capybara # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument # @option options [Boolean] :exact (Capybara.exact_text) Whether text must be an exact match or just substring - # @option options [Boolean] :collapse_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space + # @option options [Boolean] :normalize_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time # @return [true] # diff --git a/lib/capybara/queries/text_query.rb b/lib/capybara/queries/text_query.rb index 6df01f8e..c5938cf8 100644 --- a/lib/capybara/queries/text_query.rb +++ b/lib/capybara/queries/text_query.rb @@ -24,7 +24,7 @@ module Capybara def resolve_for(node) @node = node @actual_text = text(node, @type) - @actual_text.gsub!(/[[:space:]]+/, ' ').strip! if options[:collapse_ws] + @actual_text.gsub!(/[[:space:]]+/, ' ').strip! if options[:normalize_ws] @count = @actual_text.scan(@search_regexp).size end @@ -84,7 +84,7 @@ module Capybara end def valid_keys - COUNT_KEYS + %i[wait exact collapse_ws] + COUNT_KEYS + %i[wait exact normalize_ws] end def check_visible_text? diff --git a/lib/capybara/spec/session/assert_text_spec.rb b/lib/capybara/spec/session/assert_text_spec.rb index d92e81b7..c9ab2f99 100644 --- a/lib/capybara/spec/session/assert_text_spec.rb +++ b/lib/capybara/spec/session/assert_text_spec.rb @@ -12,7 +12,7 @@ Capybara::SpecHelper.spec '#assert_text' do it 'should support collapsing whitespace' do @session.visit('/with_html') - expect(@session.assert_text('text with whitespace', collapse_ws: true)).to eq(true) + expect(@session.assert_text('text with whitespace', normalize_ws: true)).to eq(true) end it 'should take scopes into account' do diff --git a/lib/capybara/spec/session/has_text_spec.rb b/lib/capybara/spec/session/has_text_spec.rb index 105e1dbd..7c48dece 100644 --- a/lib/capybara/spec/session/has_text_spec.rb +++ b/lib/capybara/spec/session/has_text_spec.rb @@ -36,7 +36,7 @@ Capybara::SpecHelper.spec '#has_text?' do it 'should search whitespace collapsed text' do @session.visit('/with_html') - expect(@session).to have_text('text with whitespace', collapse_ws: true) + expect(@session).to have_text('text with whitespace', normalize_ws: true) end it 'should be false if the given text is not on the page' do