Class: FlexMock::ExpectationRecorder
- Defined in:
- lib/flexmock/expectation_recorder.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.
21 22 23 |
# File 'lib/flexmock/expectation_recorder.rb', line 21 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.
26 27 28 29 |
# File 'lib/flexmock/expectation_recorder.rb', line 26 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).
34 35 36 37 38 39 |
# File 'lib/flexmock/expectation_recorder.rb', line 34 def apply(mock) obj = mock @expectations.each do |sym, args, block| obj = obj.send(sym, *args, &block) end end |