Class: Shoulda::Matchers::Doublespeak::DoubleCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/doublespeak/double_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(world, klass) ⇒ DoubleCollection

Returns a new instance of DoubleCollection.



6
7
8
9
10
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 6

def initialize(world, klass)
  @world = world
  @klass = klass
  @doubles_by_method_name = {}
end

Instance Method Details

#activateObject



20
21
22
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 20

def activate
  doubles_by_method_name.each_value(&:activate)
end

#calls_by_method_nameObject



28
29
30
31
32
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 28

def calls_by_method_name
  doubles_by_method_name.inject({}) do |hash, (method_name, double)|
    hash.merge method_name => double.calls.map(&:args)
  end
end

#calls_to(method_name) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 34

def calls_to(method_name)
  double = doubles_by_method_name[method_name]

  if double
    double.calls
  else
    []
  end
end

#deactivateObject



24
25
26
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 24

def deactivate
  doubles_by_method_name.each_value(&:deactivate)
end

#register_proxy(method_name) ⇒ Object



16
17
18
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 16

def register_proxy(method_name)
  register_double(method_name, :proxy)
end

#register_stub(method_name) ⇒ Object



12
13
14
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 12

def register_stub(method_name)
  register_double(method_name, :stub)
end