Class: Dommy::Rails::RSpec::Matchers::HaveLink

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HaveLink.



331
332
333
334
335
# File 'lib/dommy/rails/rspec/matchers.rb', line 331

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

Instance Method Details

#descriptionObject



346
347
348
# File 'lib/dommy/rails/rspec/matchers.rb', line 346

def description
  "have link"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


342
343
344
# File 'lib/dommy/rails/rspec/matchers.rb', line 342

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

#failure_messageObject



350
351
352
# File 'lib/dommy/rails/rspec/matchers.rb', line 350

def failure_message
  "expected to find link, found #{@matched.size}"
end

#failure_message_when_negatedObject



354
355
356
# File 'lib/dommy/rails/rspec/matchers.rb', line 354

def failure_message_when_negated
  "expected not to find link, found #{@matched.size}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


337
338
339
340
# File 'lib/dommy/rails/rspec/matchers.rb', line 337

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