Class: Crspec::Matchers::YieldWithArgsMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::YieldWithArgsMatcher
- Defined in:
- lib/crspec/matchers.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*expected_args) ⇒ YieldWithArgsMatcher
constructor
A new instance of YieldWithArgsMatcher.
- #matches?(block) ⇒ Boolean
Methods inherited from BaseMatcher
#and, #failure_message_when_negated, #or
Constructor Details
#initialize(*expected_args) ⇒ YieldWithArgsMatcher
Returns a new instance of YieldWithArgsMatcher.
662 663 664 665 |
# File 'lib/crspec/matchers.rb', line 662 def initialize(*expected_args) super(expected_args) @expected_args = expected_args end |
Instance Method Details
#failure_message ⇒ Object
678 679 680 681 682 683 684 |
# File 'lib/crspec/matchers.rb', line 678 def if @yielded_args.nil? "Expected block to yield with args #{@expected_args.inspect}, but it did not yield" else "Expected block to yield with args #{@expected_args.inspect}, got #{@yielded_args.inspect}" end end |
#matches?(block) ⇒ Boolean
667 668 669 670 671 672 673 674 675 676 |
# File 'lib/crspec/matchers.rb', line 667 def matches?(block) @yielded_args = nil probe = ->(*args) { @yielded_args = args } block.call(probe) return false if @yielded_args.nil? return true if @expected_args.empty? return false unless @yielded_args.size == @expected_args.size @expected_args.zip(@yielded_args).all? { |e, a| e == a || e === a } end |