Class: Mocha::Expectation

Inherits:
Object
  • Object
show all
Defined in:
lib/debugger/test/mocha_extensions.rb

Instance Method Summary collapse

Instance Method Details

#calls(&block) ⇒ Object

Allows to specify a block to execute when expectation will be matched. This way, we can specify dynamic values to return or just make some side effects

Example:

foo.expects(:bar).with('bla').calls { 2 + 3 }
foo.bar('bla') # => 5


12
13
14
15
16
# File 'lib/debugger/test/mocha_extensions.rb', line 12

def calls(&block)
  @calls ||= Call.new
  @calls += Call.new(block)
  self
end

#invoke_with_calls(arguments, &block) ⇒ Object Also known as: invoke



18
19
20
# File 'lib/debugger/test/mocha_extensions.rb', line 18

def invoke_with_calls(arguments, &block)
  invoke_without_calls(&block) || (@calls.next(arguments, &block) if @calls)
end