Class: Dommy::Rails::RSpec::Matchers::HaveTurboFrame

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

Instance Method Summary collapse

Constructor Details

#initialize(id, text:, count:) ⇒ HaveTurboFrame

Returns a new instance of HaveTurboFrame.



360
361
362
363
364
# File 'lib/dommy/rails/rspec/matchers.rb', line 360

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

Instance Method Details

#descriptionObject



377
378
379
# File 'lib/dommy/rails/rspec/matchers.rb', line 377

def description
  "have turbo-frame#{@id ? " ##{@id}" : ""}"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/dommy/rails/rspec/matchers.rb', line 373

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

#failure_messageObject



381
382
383
# File 'lib/dommy/rails/rspec/matchers.rb', line 381

def failure_message
  "expected to find turbo-frame#{@id ? " ##{@id}" : ""}, found #{@matched.size}"
end

#failure_message_when_negatedObject



385
386
387
# File 'lib/dommy/rails/rspec/matchers.rb', line 385

def failure_message_when_negated
  "expected not to find turbo-frame#{@id ? " ##{@id}" : ""}, found #{@matched.size}"
end

#matches?(actual, &block) ⇒ Boolean

Returns:

  • (Boolean)


366
367
368
369
370
371
# File 'lib/dommy/rails/rspec/matchers.rb', line 366

def matches?(actual, &block)
  @matched = Dommy::Rails::PageInspector.turbo_frames(MatchTarget.document(actual), @id, text: @text)
  ok = Dommy::Internal::DomMatching.count_matches?(@matched.size, @count)
  block.call(@matched.first) if ok && block && @matched.any?
  ok
end