Sha256: f8354f287ded24f2570f7104f790b4742a35aee8c49e4c10f56416117fb46123

Contents?: true

Size: 927 Bytes

Versions: 3

Compression:

Stored size: 927 Bytes

Contents

require 'muack/mock'
require 'muack/stub'

module Muack
  module Proxy
    def __mock_block_call defi, actual_args, actual_block
      # handle block call in injected method, since we need to call origin
      defi # but we still want to know which defi gets dispatched!
    end

    def __mock_inject_mock_method target, defi
      mock = self # remember the context
      target.__send__(:define_method, defi.msg){|*actual_args, &actual_block|
        d = mock.__mock_dispatch(defi.msg, actual_args, actual_block)

        ret = if d.original_method
                __send__(d.original_method, *actual_args, &actual_block)
              else
                super(*actual_args, &actual_block)
              end

        if d.block
          d.block.call(ret)
        else
          ret
        end
      }
    end
  end

  class MockProxy < Mock
    include Proxy
  end

  class StubProxy < Stub
    include Proxy
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
muack-0.5.2 lib/muack/proxy.rb
muack-0.5.1 lib/muack/proxy.rb
muack-0.5.0 lib/muack/proxy.rb