class Spy::Nest
This class manages all the Constant Mutations for a given Module
def add(spy)
-
(self)
-
Parameters:
-
spy
(Constant
) --
def add(spy) if @constant_spies[spy.constant_name] raise AlreadyStubbedError, "#{spy.constant_name} has already been stubbed" else @constant_spies[spy.constant_name] = spy end self end
def all
-
(Hash
-)
def all @all ||= {} end
def fetch(base_module)
-
(Nest)
-
Parameters:
-
base_module
(Module
) --
def fetch(base_module) all[base_module.name] ||= self.new(base_module) end
def get(constant_name)
-
(Constant, nil)
-
Parameters:
-
constant_name
(Symbol
) --
def get(constant_name) @constant_spies[constant_name] end
def get(base_module)
-
(Nil, Nest)
-
Parameters:
-
base_module
(Module
) --
def get(base_module) all[base_module.name] end
def hooked?(constant_name)
-
(Boolean)
-
Parameters:
-
constant_name
(Symbol
) --
def hooked?(constant_name) !!get(constant_name) end
def hooked_constants
-
(Array)
-
def hooked_constants @constant_spies.keys end
def initialize(base_module)
def initialize(base_module) raise ArgumentError, "#{base_module} is not a kind of Module" unless base_module.is_a?(Module) @base_module = base_module @constant_spies = {} end
def remove(spy)
-
(self)
-
Parameters:
-
spy
(Constant
) --
def remove(spy) if @constant_spies[spy.constant_name] == spy @constant_spies.delete(spy.constant_name) else raise NoSpyError, "#{spy.constant_name} was not stubbed on #{base_module.name}" end self end