Sha256: a9e8c31e01db390c0e73f7f5fd2ff3a397aeca26728bc1372df6db34a2c80274

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module Orchestra
  class Recording
    class Playback < BasicObject
      attr :mocks

      def initialize mocks
        @mocks = mocks
      end

      def respond_to? meth
        mocks.has_key? meth
      end

      def self.build service_recording
        factory = Factory.new
        factory.build service_recording
      end

      class Factory
        attr :klass, :mocks

        def initialize
          @klass = Class.new Playback
          @mocks = Hash.new do |hsh, meth| hsh[meth] = {} end
        end

        def build service_recording
          record = method :<<
          service_recording.each &record
          klass.new mocks
        end

        def << record
          method = record[:method].to_sym
          unless klass.instance_methods.include? method
            klass.send :define_method, method do |*args| mocks[method][args] end
          end
          mocks[method][record[:input]] = record[:output]
        end

        def singleton
          singleton = class << instance ; self end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ntl-orchestra-0.9.5 lib/orchestra/recording/playback.rb
ntl-orchestra-0.9.4 lib/orchestra/recording/playback.rb
ntl-orchestra-0.9.3 lib/orchestra/recording/playback.rb