Class: Capybara::Queries::TextQuery Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseQuery
|
|
Instance Chain:
self,
BaseQuery
|
|
Inherits: |
Capybara::Queries::BaseQuery
|
Defined in: | lib/capybara/queries/text_query.rb |
Constant Summary
BaseQuery
- Inherited
Class Method Summary
- .new(type = nil, expected_text, session_options:, **options) ⇒ TextQuery constructor Internal use only
BaseQuery
- Inherited
Instance Attribute Summary
- #check_case_insensitive? ⇒ Boolean readonly private Internal use only
- #check_visible_text? ⇒ Boolean readonly private Internal use only
- #exact? ⇒ Boolean readonly private Internal use only
BaseQuery
- Inherited
#expects_none? | Checks if a count of 0 is valid for the query Returns false if query does not have any count options specified. |
#options, #session_options, #session_options=, #count_specified? |
Instance Method Summary
- #description Internal use only
- #failure_message Internal use only
- #negative_failure_message Internal use only
- #resolve_for(node) Internal use only
- #build_message(report_on_invisible) private Internal use only
- #case_insensitive_message private Internal use only
- #default_type private Internal use only
- #invisible_message private Internal use only
- #text(node: @node, query_type: @type) private Internal use only
- #valid_keys private Internal use only
- #valid_types private Internal use only
BaseQuery
- Inherited
#failure_message | Generates a failure message from the query description and count options. |
#matches_count? | Checks if the given count matches the query count options. |
#negative_failure_message, #wait, #assert_valid_keys, #count_message, #occurrences |
Constructor Details
.new(type = nil, expected_text, session_options:, **options) ⇒ TextQuery
# File 'lib/capybara/queries/text_query.rb', line 7
def initialize(type = nil, expected_text, session_options:, ** ) # rubocop:disable Style/OptionalArguments @type = type.nil? ? default_type : type raise ArgumentError, "#{@type} is not a valid type for a text query" unless valid_types.include?(@type) @options = super(@options) self. = if expected_text.nil? && !exact? warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. ' \ "Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}" end @expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s @search_regexp = Capybara::Helpers.to_regexp(@expected_text, exact: exact?) assert_valid_keys end
Instance Attribute Details
#check_case_insensitive? ⇒ Boolean
(readonly, private)
# File 'lib/capybara/queries/text_query.rb', line 102
def check_case_insensitive? !@expected_text.is_a?(Regexp) end
#check_visible_text? ⇒ Boolean
(readonly, private)
# File 'lib/capybara/queries/text_query.rb', line 98
def check_visible_text? @type == :visible end
#exact? ⇒ Boolean
(readonly, private)
# File 'lib/capybara/queries/text_query.rb', line 51
def exact? .fetch(:exact, .exact_text) end
Instance Method Details
#build_message(report_on_invisible) (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 55
def (report_on_invisible) = +'' unless (COUNT_KEYS & @options.keys).empty? << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}" end << " in #{@actual_text.inspect}" = [] << if @node && check_case_insensitive? << if @node && check_visible_text? && report_on_invisible .compact! << ". (However, #{ .join(' and ')}.)" unless .empty? end
#case_insensitive_message (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 71
def insensitive_regexp = Capybara::Helpers.to_regexp(@expected_text, options: Regexp::IGNORECASE) insensitive_count = @actual_text.scan(insensitive_regexp).size return if insensitive_count == @count "it was found #{occurrences insensitive_count} using a case insensitive search" end
#default_type (private)
[ GitHub ]#description
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 41
def description if @expected_text.is_a?(Regexp) "text matching #{@expected_text.inspect}" else "#{'exact ' if exact?}text #{@expected_text.inspect}" end end
#failure_message
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 33
def super << (true) end
#invisible_message (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 79
def invisible_text = text(query_type: :all) invisible_count = invisible_text.scan(@search_regexp).size return if invisible_count == @count "it was found #{occurrences invisible_count} including non-visible text" rescue StandardError # An error getting the non-visible text (if element goes out of scope) should not affect the response nil end
#negative_failure_message
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 37
def super << (false) end
#resolve_for(node)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 27
def resolve_for(node) @node = node @actual_text = text @count = @actual_text.scan(@search_regexp).size end
#text(node: @node, query_type: @type) (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 106
def text(node: @node, query_type: @type) normalize_ws = .fetch(:normalize_ws, .default_normalize_ws) node.text(query_type, normalize_ws: normalize_ws) end
#valid_keys (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 90
def valid_keys COUNT_KEYS + %i[wait exact normalize_ws] end
#valid_types (private)
[ GitHub ]# File 'lib/capybara/queries/text_query.rb', line 94
def valid_types %i[all visible] end