Class: Mocha::Expectation
- Inherits:
-
Object
- Object
- Mocha::Expectation
- Defined in:
- lib/debugger/test/mocha_extensions.rb
Instance Method Summary collapse
-
#calls(&block) ⇒ Object
Allows to specify a block to execute when expectation will be matched.
- #invoke_with_calls(arguments, &block) ⇒ Object (also: #invoke)
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.('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 |