Class: QED::Mock

Inherits:
Module show all
Defined in:
lib/qed/doubles/mock.rb

Overview

Mock

Defined Under Namespace

Classes: Delegator, Setter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMock

Returns a new instance of Mock.



8
9
10
11
# File 'lib/qed/doubles/mock.rb', line 8

def initialize
  super()
  @table = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

TODO: Ruby has retry, but I need continue!



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qed/doubles/mock.rb', line 17

def method_missing(meth, *args, &block)
  table     = @table
  interface = [meth, args, block_given?]

  table[interface] = nil

  define_method(meth) do |*args|
    result = super
    result.assert == table[interface]
    return result
  end

  Setter.new(table, interface)
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



6
7
8
# File 'lib/qed/doubles/mock.rb', line 6

def object
  @object
end

Instance Method Details

#__table__Object



14
# File 'lib/qed/doubles/mock.rb', line 14

def __table__ ; @table ; end