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

Instance Method Summary collapse

Methods inherited from BaseQuery

#wait

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
# File 'lib/capybara/queries/text_query.rb', line 5

def initialize(*args)
  @type = (args.first.is_a?(Symbol) || args.first.nil?) ? args.shift : 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
end

Instance Method Details

#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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capybara/queries/text_query.rb', line 21

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

  message = Capybara::Helpers.failure_message(description, @options)
  unless (COUNT_KEYS & @options.keys).empty?
    message << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}"
  end
  message << " in #{@actual_text.inspect}"
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.



36
37
38
# File 'lib/capybara/queries/text_query.rb', line 36

def negative_failure_message
  failure_message.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.



16
17
18
19
# File 'lib/capybara/queries/text_query.rb', line 16

def resolve_for(node)
  @actual_text = Capybara::Helpers.normalize_whitespace(node.text(@type))
  @count = @actual_text.scan(@search_regexp).size
end