Class: Dommy::Rails::RSpec::Matchers::HaveHtmlText

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/rails/rspec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HaveHtmlText

Returns a new instance of HaveHtmlText.



733
734
735
# File 'lib/dommy/rails/rspec/matchers.rb', line 733

def initialize(text)
  @text = text
end

Instance Method Details

#descriptionObject



749
750
751
# File 'lib/dommy/rails/rspec/matchers.rb', line 749

def description
  "have HTML text #{@text.inspect}"
end

#does_not_match?(mail) ⇒ Boolean

Returns:

  • (Boolean)


745
746
747
# File 'lib/dommy/rails/rspec/matchers.rb', line 745

def does_not_match?(mail)
  !matches?(mail)
end

#failure_messageObject



753
754
755
756
757
# File 'lib/dommy/rails/rspec/matchers.rb', line 753

def failure_message
  return "expected mail to have an HTML part" unless @document

  "expected mail HTML to include #{@text.inspect}, got #{@actual.inspect}"
end

#failure_message_when_negatedObject



759
760
761
# File 'lib/dommy/rails/rspec/matchers.rb', line 759

def failure_message_when_negated
  "expected mail HTML not to include #{@text.inspect}"
end

#matches?(mail) ⇒ Boolean

Returns:

  • (Boolean)


737
738
739
740
741
742
743
# File 'lib/dommy/rails/rspec/matchers.rb', line 737

def matches?(mail)
  @document = Dommy::Rails::MailPart.html_document(mail)
  return false unless @document

  @actual = Dommy::Internal::DomMatching.text_of(@document)
  Dommy::Internal::DomMatching.text_matches?(@actual, @text)
end