Class: Gimme::TestDouble

Inherits:
BlankSlate show all
Defined in:
lib/gimme/test_double.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cls = nil) ⇒ TestDouble

Returns a new instance of TestDouble.



14
15
16
17
18
# File 'lib/gimme/test_double.rb', line 14

def initialize(cls=nil)
  @cls = cls
  @stubbings = {}
  @invocations = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/gimme/test_double.rb', line 20

def method_missing(sym, *args, &block)
  sym = ResolvesMethods.new(self.cls,sym,args).resolve(false)

  @invocations[sym] ||= {}
  @stubbings[sym] ||= {}

  @invocations[sym][args] = 1 + (@invocations[sym][args]||0)

  InvokesSatisfiedStubbing.new(@stubbings).invoke(sym, args)
end

Instance Attribute Details

#clsObject

Returns the value of attribute cls.



10
11
12
# File 'lib/gimme/test_double.rb', line 10

def cls
  @cls
end

#invocationsObject (readonly)

Returns the value of attribute invocations.



12
13
14
# File 'lib/gimme/test_double.rb', line 12

def invocations
  @invocations
end

#stubbingsObject

Returns the value of attribute stubbings.



11
12
13
# File 'lib/gimme/test_double.rb', line 11

def stubbings
  @stubbings
end