Class: RSpecHTML::Matchers::MatchText

Inherits:
Object
  • Object
show all
Includes:
Countable, Base
Defined in:
lib/rspec_html/matchers/match_text.rb

Overview

Matches text or regex within a given DOM element (strips HTML tags and compares text content only).

Instance Attribute Summary

Attributes included from Base

#rspec_actual

Instance Method Summary collapse

Methods included from Countable

#at_least, #at_most, #once, #times, #twice

Methods included from Base

#description, #failure_message, included, #initialize, #pluralize, #reconstituted, #save_actual

Instance Method Details

#match(actual, expected_count:, expected_count_type:) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rspec_html/matchers/match_text.rb', line 12

def match(actual, expected_count:, expected_count_type:)
  raise_argument_error unless actual.is_a?(RSpecHTML::Element)
  @expected_count = expected_count
  @expected_count_type = expected_count_type
  @rspec_actual = actual&.text
  return regexp_match?(actual) || regexp_siblings_match?(actual) if @expected.is_a?(Regexp)

  string_match?(actual) || string_siblings_match?(actual)
end