Class Index [+]

Quicksearch

RR::Injections::DoubleInjection

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.

Constants

MethodArguments

Attributes

subject_class[R]
method_name[R]
doubles[R]

Public Class Methods

create(subject, method_name) click to toggle source
    # File lib/rr/injections/double_injection.rb, line 8
 8:         def create(subject, method_name)
 9:           instances[subject][method_name.to_sym] ||= begin
10:             new(subject, method_name.to_sym, (class << subject; self; end)).bind
11:           end
12:         end
exists?(subject, method_name) click to toggle source
    # File lib/rr/injections/double_injection.rb, line 14
14:         def exists?(subject, method_name)
15:           instances.include?(subject) && instances[subject].include?(method_name.to_sym)
16:         end
instances() click to toggle source
    # File lib/rr/injections/double_injection.rb, line 51
51:         def instances
52:           @instances ||= HashWithObjectIdKey.new do |hash, subject_object|
53:             hash.set_with_object_id(subject_object, {})
54:           end
55:         end
new(subject, method_name, subject_class) click to toggle source
    # File lib/rr/injections/double_injection.rb, line 62
62:       def initialize(subject, method_name, subject_class)
63:         @subject = subject
64:         @subject_class = subject_class
65:         @method_name = method_name.to_sym
66:         @doubles = []
67:         @bypass_bound_method = nil
68:       end
reset() click to toggle source
    # File lib/rr/injections/double_injection.rb, line 18
18:         def reset
19:           instances.each do |subject, method_double_map|
20:             method_double_map.keys.each do |method_name|
21:               reset_double(subject, method_name)
22:             end
23:           end
24:         end
reset_double(subject, method_name) click to toggle source

Resets the DoubleInjection for the passed in subject and method_name.

    # File lib/rr/injections/double_injection.rb, line 45
45:         def reset_double(subject, method_name)
46:           double_injection = Injections::DoubleInjection.instances[subject].delete(method_name)
47:           Injections::DoubleInjection.instances.delete(subject) if Injections::DoubleInjection.instances[subject].empty?
48:           double_injection.reset
49:         end
verify(*subjects) click to toggle source
    # File lib/rr/injections/double_injection.rb, line 26
26:         def verify(*subjects)
27:           subjects = Injections::DoubleInjection.instances.keys if subjects.empty?
28:           subjects.each do |subject|
29:             instances.include?(subject) &&
30:               instances[subject].keys.each do |method_name|
31:                 verify_double(subject, method_name)
32:               end &&
33:               instances.delete(subject)
34:           end
35:         end
verify_double(subject, method_name) click to toggle source

Verifies the DoubleInjection for the passed in subject and method_name.

    # File lib/rr/injections/double_injection.rb, line 38
38:         def verify_double(subject, method_name)
39:           Injections::DoubleInjection.instances[subject][method_name].verify
40:         ensure
41:           reset_double subject, method_name
42:         end

Public Instance Methods

bind() click to toggle source

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 79
79:       def bind
80:         if subject_respond_to_method?(method_name)
81:           if subject_has_method_defined?(method_name)
82:             if subject_is_proxy_for_method?(method_name)
83:               bind_method
84:             else
85:               bind_method_with_alias
86:             end
87:           else
88:             Injections::MethodMissingInjection.create(subject)
89:             Injections::SingletonMethodAddedInjection.create(subject)
90:           end
91:         else
92:           bind_method
93:         end
94:         self
95:       end
bypass_bound_method() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 146
146:       def bypass_bound_method
147:         @bypass_bound_method = true
148:         yield
149:       ensure
150:         @bypass_bound_method = nil
151:       end
dispatch_method(args, block) click to toggle source
     # File lib/rr/injections/double_injection.rb, line 121
121:       def dispatch_method(args, block)
122:         dispatch = MethodDispatches::MethodDispatch.new(self, args, block)
123:         if @bypass_bound_method
124:           dispatch.call_original_method
125:         else
126:           dispatch.call
127:         end
128:       end
dispatch_method_missing(method_name, args, block) click to toggle source
     # File lib/rr/injections/double_injection.rb, line 130
130:       def dispatch_method_missing(method_name, args, block)
131:         MethodDispatches::MethodMissingDispatch.new(subject, method_name, args, block).call
132:       end
original_method_alias_name() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 138
138:       def original_method_alias_name
139:         "__rr__original_#{@method_name}"
140:       end
original_method_missing_alias_name() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 142
142:       def original_method_missing_alias_name
143:         MethodDispatches::MethodMissingDispatch.original_method_missing_alias_name
144:       end
register_double(double) click to toggle source

RR::DoubleInjection#register_double adds the passed in Double into this DoubleInjection’s list of Double objects.

    # File lib/rr/injections/double_injection.rb, line 72
72:       def register_double(double)
73:         @doubles << double
74:       end
reset() click to toggle source

It binds the original method implementation on the subject if one exists.

     # File lib/rr/injections/double_injection.rb, line 109
109:       def reset
110:         if subject_has_original_method?
111:           subject_class.__send__(:remove_method, method_name)
112:           subject_class.__send__(:alias_method, method_name, original_method_alias_name)
113:           subject_class.__send__(:remove_method, original_method_alias_name)
114:         else
115:           if subject_has_method_defined?(method_name)
116:             subject_class.__send__(:remove_method, method_name)
117:           end
118:         end
119:       end
subject_has_original_method_missing?() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 134
134:       def subject_has_original_method_missing?
135:         subject_respond_to_method?(original_method_missing_alias_name)
136:       end
verify() click to toggle source

RR::DoubleInjection#verify verifies each Double TimesCalledExpectation are met.

     # File lib/rr/injections/double_injection.rb, line 99
 99:       def verify
100:         @doubles.each do |double|
101:           double.verify
102:         end
103:       end

Protected Instance Methods

bind_method() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 175
175:       def bind_method
176:         subject = @subject.is_a?(Class) && !@subject.name.to_s.empty? ? @subject.name : "self"
177:         subject_class.class_eval(        def #{@method_name}(*args, &block)          arguments = MethodArguments.new(args, block)          RR::Injections::DoubleInjection.create(#{subject}, :#{@method_name}).dispatch_method(arguments.arguments, arguments.block)        end, __FILE__, __LINE__ + 1)
178:       end
bind_method_with_alias() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 170
170:       def bind_method_with_alias
171:         subject_class.__send__(:alias_method, original_method_alias_name, method_name)
172:         bind_method
173:       end
deferred_bind_method() click to toggle source
     # File lib/rr/injections/double_injection.rb, line 163
163:       def deferred_bind_method
164:         unless subject_has_method_defined?(original_method_alias_name)
165:           bind_method_with_alias
166:         end
167:         @performed_deferred_bind = true
168:       end
subject_is_proxy_for_method?(method_name_in_question) click to toggle source
     # File lib/rr/injections/double_injection.rb, line 154
154:       def subject_is_proxy_for_method?(method_name_in_question)
155:         !(
156:         class << @subject;
157:           self;
158:         end).
159:           instance_methods.
160:           detect {|method_name| method_name.to_sym == method_name_in_question.to_sym}
161:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.