Class: Crspec::Matchers::YieldControlMatcher

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, #initialize, #or

Constructor Details

This class inherits a constructor from Crspec::Matchers::BaseMatcher

Instance Method Details

#failure_messageObject



652
653
654
# File 'lib/crspec/matchers.rb', line 652

def failure_message
  "Expected block to yield control, but it did not"
end

#failure_message_when_negatedObject



656
657
658
# File 'lib/crspec/matchers.rb', line 656

def failure_message_when_negated
  "Expected block not to yield control, but it yielded #{@yielded} time(s)"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


645
646
647
648
649
650
# File 'lib/crspec/matchers.rb', line 645

def matches?(block)
  @yielded = 0
  probe = ->(*) { @yielded += 1 }
  block.call(probe)
  @yielded.positive?
end