RR::DoubleInjection is the binding of an subject and a method. A double_injection has 0 to many Double objects. Each Double has Argument Expectations and Times called Expectations.
RR::DoubleInjection#bind injects a method that acts as a dispatcher that dispatches to the matching Double when the method is called.
# File lib/rr/injections/double_injection.rb, line 112 def bind if subject_has_method_defined?(method_name) bind_method_with_alias else Injections::MethodMissingInjection.find_or_create(subject_class) Injections::SingletonMethodAddedInjection.find_or_create(subject_class) bind_method_that_self_destructs_and_delegates_to_method_missing end self end
# File lib/rr/injections/double_injection.rb, line 140 def bind_method id = BoundObjects.size BoundObjects[id] = subject_class subject_class.class_eval( def #{method_name}(*args, &block) arguments = MethodArguments.new(args, block) obj = ::RR::Injections::DoubleInjection::BoundObjects[#{id}] RR::Injections::DoubleInjection.dispatch_method(self, obj, :#{method_name}, arguments.arguments, arguments.block) end, __FILE__, __LINE__ + 1) self end
# File lib/rr/injections/double_injection.rb, line 125 def bind_method_that_self_destructs_and_delegates_to_method_missing id = BoundObjects.size BoundObjects[id] = subject_class subject_class.class_eval( def #{method_name}(*args, &block) ::RR::Injections::DoubleInjection::BoundObjects[#{id}].class_eval do remove_method(:#{method_name}) end method_missing(:#{method_name}, *args, &block) end, __FILE__, __LINE__ + 1) self end
# File lib/rr/injections/double_injection.rb, line 34 def dispatch_method(subject, subject_class, method_name, arguments, block) subject_eigenclass = (class << subject; self; end) if ( exists?(subject_class, method_name) && (subject_class == subject_eigenclass) || !subject.is_a?(Class) ) find(subject_class, method_name.to_sym).dispatch_method(subject, arguments, block) else new(subject_class, method_name.to_sym).dispatch_original_method(subject, arguments, block) end end
# File lib/rr/injections/double_injection.rb, line 200 def dispatch_method_delegates_to_dispatch_original_method @dispatch_method_delegates_to_dispatch_original_method = true yield ensure @dispatch_method_delegates_to_dispatch_original_method = nil end
# File lib/rr/injections/double_injection.rb, line 187 def dispatch_original_method(subject, args, block) dispatch = MethodDispatches::MethodDispatch.new(self, subject, args, block) dispatch.call_original_method end
# File lib/rr/injections/double_injection.rb, line 26 def exists?(subject_class, method_name) !!find(subject_class, method_name) end
# File lib/rr/injections/double_injection.rb, line 30 def exists_by_subject?(subject, method_name) exists?((class << subject; self; end), method_name) end
# File lib/rr/injections/double_injection.rb, line 18 def find(subject_class, method_name) instances[subject_class] && instances[subject_class][method_name.to_sym] end
# File lib/rr/injections/double_injection.rb, line 22 def find_by_subject(subject, method_name) find(class << subject; self; end, method_name) end
# File lib/rr/injections/double_injection.rb, line 8 def find_or_create(subject_class, method_name) instances[subject_class][method_name.to_sym] ||= begin new(subject_class, method_name.to_sym).bind end end
# File lib/rr/injections/double_injection.rb, line 14 def find_or_create_by_subject(subject, method_name) find_or_create(class << subject; self; end, method_name) end
# File lib/rr/injections/double_injection.rb, line 83 def instances @instances ||= HashWithObjectIdKey.new do |hash, subject_class| hash.set_with_object_id(subject_class, {}) end end
# File lib/rr/injections/double_injection.rb, line 196 def original_method_alias_name "__rr__original_#{@method_name}" end
# File lib/rr/injections/double_injection.rb, line 46 def reset instances.each do |subject_class, method_double_map| SingletonMethodAddedInjection.find(subject_class) && SingletonMethodAddedInjection.find(subject_class).reset method_double_map.keys.each do |method_name| reset_double(subject_class, method_name) end Injections::DoubleInjection.instances.delete(subject_class) if Injections::DoubleInjection.instances.has_key?(subject_class) end end
Resets the DoubleInjection for the passed in subject and method_name.
# File lib/rr/injections/double_injection.rb, line 77 def reset_double(subject_class, method_name) double_injection = Injections::DoubleInjection.instances[subject_class].delete(method_name) double_injection.reset Injections::DoubleInjection.instances.delete(subject_class) if Injections::DoubleInjection.instances[subject_class].empty? end
# File lib/rr/injections/double_injection.rb, line 192 def subject_has_original_method_missing? class_instance_method_defined(subject_class, MethodDispatches::MethodMissingDispatch.original_method_missing_alias_name) end
# File lib/rr/injections/double_injection.rb, line 56 def verify(*subjects) subject_classes = subjects.empty? ? Injections::DoubleInjection.instances.keys : subjects.map {|subject| class << subject; self; end} subject_classes.each do |subject_class| instances.include?(subject_class) && instances[subject_class].keys.each do |method_name| verify_double(subject_class, method_name) end && instances.delete(subject_class) end end
Verifies the DoubleInjection for the passed in subject and method_name.
# File lib/rr/injections/double_injection.rb, line 70 def verify_double(subject_class, method_name) Injections::DoubleInjection.find(subject_class, method_name).verify ensure reset_double subject_class, method_name end
Generated with the Darkfish Rdoc Generator 2.