Class: Capybara::Queries::TextQuery Private

Inherits:
BaseQuery
  • Object
show all
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

BaseQuery::COUNT_KEYS

Instance Attribute Summary

Attributes inherited from BaseQuery

#options, #session_options

Instance Method Summary collapse

Methods inherited from BaseQuery

#expects_none?, #matches_count?, #wait, wait

Constructor Details

#initialize(type = nil, expected_text, session_options:, **options) ⇒ 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.

rubocop:disable Style/OptionalArguments



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/capybara/queries/text_query.rb', line 7

def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments
  @type = type
  @type = Capybara.ignore_hidden_elements || Capybara.visible_text_only ? :visible : :all if @type.nil?
  @expected_text = expected_text
  @options = options
  super(@options)
  self.session_options = session_options
  unless @expected_text.is_a?(Regexp)
    @expected_text = Capybara::Helpers.normalize_whitespace(@expected_text)
  end
  @search_regexp = Capybara::Helpers.to_regexp(@expected_text, nil, exact?)
  assert_valid_keys
end

Instance Method Details

#descriptionObject

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.



35
36
37
38
39
40
41
# File 'lib/capybara/queries/text_query.rb', line 35

def description
  if @expected_text.is_a?(Regexp)
    "text matching #{@expected_text.inspect}"
  else
    "#{"exact " if exact?}text #{@expected_text.inspect}"
  end
end

#failure_messageObject

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.



27
28
29
# File 'lib/capybara/queries/text_query.rb', line 27

def failure_message
  super << build_message(true)
end

#negative_failure_messageObject

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.



31
32
33
# File 'lib/capybara/queries/text_query.rb', line 31

def negative_failure_message
  super << build_message(false)
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.



21
22
23
24
25
# File 'lib/capybara/queries/text_query.rb', line 21

def resolve_for(node)
  @node = node
  @actual_text = text(node, @type)
  @count = @actual_text.scan(@search_regexp).size
end