Class: Crspec::Matchers::AllMatcher

Inherits:
BaseMatcher show all
Defined in:
lib/crspec/matchers.rb

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected

Instance Method Summary collapse

Methods inherited from BaseMatcher

#and, #failure_message_when_negated, #or

Constructor Details

#initialize(inner) ⇒ AllMatcher

Returns a new instance of AllMatcher.



482
483
484
485
# File 'lib/crspec/matchers.rb', line 482

def initialize(inner)
  super()
  @inner = inner
end

Instance Method Details

#failure_messageObject



500
501
502
# File 'lib/crspec/matchers.rb', line 500

def failure_message
  "Expected all elements to match, but element at index #{@failed_index} failed: #{@failed_message}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/crspec/matchers.rb', line 487

def matches?(actual)
  @actual = actual
  @failed_index = nil
  actual.each_with_index do |item, idx|
    next if @inner.matches?(item)

    @failed_index = idx
    @failed_message = @inner.failure_message
    return false
  end
  true
end