Class: FlexMock::ExpectationRecorder
- Defined in:
- lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb
Overview
An expectation recorder records any expectations received and plays them back on demand. This is used to collect the expectations in the blockless version of the new_instances call.
Instance Method Summary collapse
-
#apply(mock) ⇒ Object
Apply the recorded messages to the given object in a chaining fashion (i.e. the result of the previous call is used as the target of the next call).
-
#initialize ⇒ ExpectationRecorder
constructor
Initialize the recorder.
-
#method_missing(sym, *args, &block) ⇒ Object
Save any incoming messages to be played back later.
Constructor Details
#initialize ⇒ ExpectationRecorder
Initialize the recorder.
456 457 458 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 456 def initialize @expectations = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Save any incoming messages to be played back later.
461 462 463 464 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 461 def method_missing(sym, *args, &block) @expectations << [sym, args, block] self end |
Instance Method Details
#apply(mock) ⇒ Object
Apply the recorded messages to the given object in a chaining fashion (i.e. the result of the previous call is used as the target of the next call).
469 470 471 472 473 474 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 469 def apply(mock) obj = mock @expectations.each do |sym, args, block| obj = obj.send(sym, *args, &block) end end |