Class: Capybara::Queries::TextQuery

### Home Classes Methods

### In Files

- lib/capybara/queries/text_query.rb

### Parent

Capybara::Queries::BaseQuery

### Methods

- ::new
- #failure_message
- #negative_failure_message
- #resolve_for

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::Queries::TextQuery

### Public Class Methods

new(*args) click to toggle source

    # 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

### Public Instance Methods

failure_message() click to toggle source

    # File lib/capybara/queries/text_query.rb, line 30
    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_message() click to toggle source

    # File lib/capybara/queries/text_query.rb, line 45
    def negative_failure_message
      failure_message.sub(/(to find)/, 'not \1')
    end

resolve_for(node) click to toggle source

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.