Class: Capybara::Queries::TextQuery Private
- Defined in:
- lib/capybara/queries/text_query.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary
Constants inherited from BaseQuery
Instance Attribute Summary
Attributes inherited from BaseQuery
Instance Method Summary collapse
- #failure_message ⇒ Object private
-
#initialize(*args) ⇒ TextQuery
constructor
private
A new instance of TextQuery.
- #negative_failure_message ⇒ Object private
- #resolve_for(node) ⇒ Object private
Methods inherited from BaseQuery
Constructor Details
#initialize(*args) ⇒ TextQuery
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TextQuery.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/capybara/queries/text_query.rb', line 5 def initialize(*args) @type = args.shift if args.first.is_a?(Symbol) || args.first.nil? @expected_text, @options = args unless @expected_text.is_a?(Regexp) @expected_text = Capybara::Helpers.normalize_whitespace(@expected_text) end @search_regexp = Capybara::Helpers.to_regexp(@expected_text) @options ||= {} assert_valid_keys # this is needed to not break existing tests that may use keys supported by `Query` but not supported by `TextQuery` # can be removed in next minor version (> 2.4) invalid_keys = @options.keys - (COUNT_KEYS + [:wait]) unless invalid_keys.empty? invalid_names = invalid_keys.map(&:inspect).join(", ") valid_names = valid_keys.map(&:inspect).join(", ") warn "invalid keys #{invalid_names}, should be one of #{valid_names}" end end |
Instance Method Details
#failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/capybara/queries/text_query.rb', line 30 def description = if @expected_text.is_a?(Regexp) "text matching #{@expected_text.inspect}" else "text #{@expected_text.inspect}" end = Capybara::Helpers.(description, @options) unless (COUNT_KEYS & @options.keys).empty? << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}" end << " in #{@actual_text.inspect}" end |
#negative_failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/capybara/queries/text_query.rb', line 45 def .sub(/(to find)/, 'not \1') end |
#resolve_for(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 |
# File 'lib/capybara/queries/text_query.rb', line 25 def resolve_for(node) @actual_text = Capybara::Helpers.normalize_whitespace(node.text(@type)) @count = @actual_text.scan(@search_regexp).size end |