Sha256: 2f3a2039729b53b0d2167006bfb493db0d519a8ebfad7b846e81cd06d647f7b0

Contents?: true

Size: 1.08 KB

Versions: 23

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

#---
# Copyright 2003-2013 by Jim Weirich (jim.weirich@gmail.com).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#+++

class FlexMock

  # 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.
  #
  class ExpectationRecorder

    # Initialize the recorder.
    def initialize
      @expectations = []
    end

    # Save any incoming messages to be played back later.
    def method_missing(sym, *args, &block)
      @expectations << [sym, args, block]
      self
    end

    # 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).
    def apply(mock)
      obj = mock
      @expectations.each do |sym, args, block|
        obj = obj.send(sym, *args, &block)
      end
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
flexmock-2.4.2 lib/flexmock/expectation_recorder.rb
flexmock-2.4.1 lib/flexmock/expectation_recorder.rb
flexmock-2.4.0 lib/flexmock/expectation_recorder.rb
flexmock-2.3.8 lib/flexmock/expectation_recorder.rb
flexmock-2.3.6 lib/flexmock/expectation_recorder.rb
flexmock-2.3.5 lib/flexmock/expectation_recorder.rb
flexmock-2.3.4 lib/flexmock/expectation_recorder.rb
flexmock-2.3.3 lib/flexmock/expectation_recorder.rb
flexmock-2.3.2 lib/flexmock/expectation_recorder.rb
flexmock-2.3.1 lib/flexmock/expectation_recorder.rb
flexmock-2.3.0 lib/flexmock/expectation_recorder.rb
flexmock-2.2.1 lib/flexmock/expectation_recorder.rb
flexmock-2.2.0 lib/flexmock/expectation_recorder.rb
flexmock-2.1.0 lib/flexmock/expectation_recorder.rb
flexmock-2.0.6 lib/flexmock/expectation_recorder.rb
flexmock-2.0.5 lib/flexmock/expectation_recorder.rb
flexmock-2.0.4 lib/flexmock/expectation_recorder.rb
flexmock-2.0.3 lib/flexmock/expectation_recorder.rb
flexmock-2.0.2 lib/flexmock/expectation_recorder.rb
flexmock-2.0.1 lib/flexmock/expectation_recorder.rb