Class: FlexMock::ExpectationRecorder

Inherits:
Object
  • Object
show all
Defined in:
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

Constructor Details

#initializeExpectationRecorder

Initialize the recorder.



314
315
316
# File 'lib/flexmock/expectation.rb', line 314

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.



319
320
321
322
# File 'lib/flexmock/expectation.rb', line 319

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).



327
328
329
330
331
332
# File 'lib/flexmock/expectation.rb', line 327

def apply(mock)
  obj = mock
  @expectations.each do |sym, args, block|
    obj = obj.send(sym, *args, &block)
  end
end