Method: Capybara::Node::Matchers#assert_text

Defined in:
lib/capybara/node/matchers.rb

#assert_text(type, text, **options) ⇒ true #assert_text(text, **options) ⇒ true

Asserts that the page or current node has the given text content, ignoring any HTML tags.

Overloads:

  • #assert_text(type, text, **options) ⇒ true

    Options Hash (**options):

    • :count (Integer) — default: nil

      Number of times the text is expected to occur

    • :minimum (Integer) — default: nil

      Minimum number of times the text is expected to occur

    • :maximum (Integer) — default: nil

      Maximum number of times the text is expected to occur

    • :between (Range) — default: nil

      Range of times that is expected to contain number of times text occurs

    • :wait (Numeric)

      Maximum time that Capybara will wait for text to eq/match given string/regexp argument. Defaults to default_max_wait_time.

    • :exact (Boolean)

      Whether text must be an exact match or just substring. Defaults to exact_text.

    • :normalize_ws (Boolean) — default: false

      When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space

  • #assert_text(text, **options) ⇒ true

    Options Hash (**options):

    • :count (Integer) — default: nil

      Number of times the text is expected to occur

    • :minimum (Integer) — default: nil

      Minimum number of times the text is expected to occur

    • :maximum (Integer) — default: nil

      Maximum number of times the text is expected to occur

    • :between (Range) — default: nil

      Range of times that is expected to contain number of times text occurs

    • :wait (Numeric)

      Maximum time that Capybara will wait for text to eq/match given string/regexp argument. Defaults to default_max_wait_time.

    • :exact (Boolean)

      Whether text must be an exact match or just substring. Defaults to exact_text.

    • :normalize_ws (Boolean) — default: false

      When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space

Raises:



700
701
702
703
704
705
706
# File 'lib/capybara/node/matchers.rb', line 700

def assert_text(type_or_text, *args, **opts)
  _verify_text(type_or_text, *args, **opts) do |count, query|
    unless query.matches_count?(count) && (count.positive? || query.expects_none?)
      raise Capybara::ExpectationNotMet, query.failure_message
    end
  end
end