Class: Crspec::Matchers::YieldSuccessiveArgsMatcher

Inherits:
BaseMatcher
  • Object
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(*expected_args) ⇒ YieldSuccessiveArgsMatcher

Returns a new instance of YieldSuccessiveArgsMatcher.



688
689
690
691
# File 'lib/crspec/matchers.rb', line 688

def initialize(*expected_args)
  super(expected_args)
  @expected_args = expected_args
end

Instance Method Details

#failure_messageObject



702
703
704
# File 'lib/crspec/matchers.rb', line 702

def failure_message
  "Expected block to yield successive args #{@expected_args.inspect}, got #{@yielded.inspect}"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


693
694
695
696
697
698
699
700
# File 'lib/crspec/matchers.rb', line 693

def matches?(block)
  @yielded = []
  probe = ->(*args) { @yielded << (args.size == 1 ? args.first : args) }
  block.call(probe)
  return false unless @yielded.size == @expected_args.size

  @expected_args.zip(@yielded).all? { |e, a| e == a || e === a }
end