Class: Dommy::Rails::RSpec::Matchers::HaveHtmlLink

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

Instance Method Summary collapse

Constructor Details

#initialize(text, href:, count:) ⇒ HaveHtmlLink

Returns a new instance of HaveHtmlLink.



699
700
701
702
703
# File 'lib/dommy/rails/rspec/matchers.rb', line 699

def initialize(text, href:, count:)
  @text = text
  @href = href
  @count = count
end

Instance Method Details

#descriptionObject



717
718
719
# File 'lib/dommy/rails/rspec/matchers.rb', line 717

def description
  "have HTML link"
end

#does_not_match?(mail) ⇒ Boolean

Returns:

  • (Boolean)


713
714
715
# File 'lib/dommy/rails/rspec/matchers.rb', line 713

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

#failure_messageObject



721
722
723
724
725
# File 'lib/dommy/rails/rspec/matchers.rb', line 721

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

  "expected mail HTML to contain link, found #{@matched.size}"
end

#failure_message_when_negatedObject



727
728
729
# File 'lib/dommy/rails/rspec/matchers.rb', line 727

def failure_message_when_negated
  "expected mail HTML not to contain link"
end

#matches?(mail) ⇒ Boolean

Returns:

  • (Boolean)


705
706
707
708
709
710
711
# File 'lib/dommy/rails/rspec/matchers.rb', line 705

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

  @matched = Dommy::Rails::PageInspector.links(@document, text: @text, href: @href)
  Dommy::Internal::DomMatching.count_matches?(@matched.size, @count)
end