Class: Crspec::Matchers::YieldSuccessiveArgsMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::YieldSuccessiveArgsMatcher
- Defined in:
- lib/crspec/matchers.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*expected_args) ⇒ YieldSuccessiveArgsMatcher
constructor
A new instance of YieldSuccessiveArgsMatcher.
- #matches?(block) ⇒ Boolean
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_message ⇒ Object
702 703 704 |
# File 'lib/crspec/matchers.rb', line 702 def "Expected block to yield successive args #{@expected_args.inspect}, got #{@yielded.inspect}" end |
#matches?(block) ⇒ 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 |