class Shoulda::Matchers::Doublespeak::DoubleCollection

@private

Attributes

doubles_by_method_name[R]
klass[R]
world[R]

Public Class Methods

new(world, klass) click to toggle source
# File lib/shoulda/matchers/doublespeak/double_collection.rb, line 6
def initialize(world, klass)
  @world = world
  @klass = klass
  @doubles_by_method_name = {}
end

Public Instance Methods

activate() click to toggle source
# 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_name() click to toggle source
# 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) click to toggle source
# 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
deactivate() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/shoulda/matchers/doublespeak/double_collection.rb, line 12
def register_stub(method_name)
  register_double(method_name, :stub)
end

Protected Instance Methods

register_double(method_name, implementation_type) click to toggle source
# File lib/shoulda/matchers/doublespeak/double_collection.rb, line 52
def register_double(method_name, implementation_type)
  doubles_by_method_name.fetch(method_name) do
    implementation =
      DoubleImplementationRegistry.find(implementation_type)
    double = Double.new(world, klass, method_name, implementation)
    doubles_by_method_name[method_name] = double
    double
  end
end