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

    Parameters:

    • type (:all, :visible)

      Whether to check for only visible or all text. If this parameter is missing or nil then we use the value of ignore_hidden_elements, which defaults to true, corresponding to :visible.

    • text (String, Regexp)

      The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.

    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

    Parameters:

    • text (String, Regexp)

      The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.

    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

Returns:

  • (true)

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