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.



483
484
485
# File 'lib/flexmock/expectation.rb', line 483

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.



488
489
490
491
# File 'lib/flexmock/expectation.rb', line 488

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



496
497
498
499
500
501
# File 'lib/flexmock/expectation.rb', line 496

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