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
23
24
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 20

def activate
  doubles_by_method_name.each do |_method_name, double|
    double.activate
  end
end

#calls_by_method_nameObject



32
33
34
35
36
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 32

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



38
39
40
41
42
43
44
45
46
# File 'lib/shoulda/matchers/doublespeak/double_collection.rb', line 38

def calls_to(method_name)
  double = doubles_by_method_name[method_name]

  if double
    double.calls
  else
    []
  end
end

#deactivateObject



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

def deactivate
  doubles_by_method_name.each do |_method_name, double|
    double.deactivate
  end
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