Parent

RSpec::Mocks::Proxy

@private

Public Class Methods

allow_message_expectations_on_nil() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 17
17:         def allow_message_expectations_on_nil
18:           @warn_about_expectations_on_nil = false
19: 
20:           # ensure nil.rspec_verify is called even if an expectation is not set in the example
21:           # otherwise the allowance would effect subsequent examples
22:           RSpec::Mocks::space.add(nil) unless RSpec::Mocks::space.nil?
23:         end
allow_message_expectations_on_nil?() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 26
26:         def allow_message_expectations_on_nil?
27:           !warn_about_expectations_on_nil
28:         end
new(object, name=nil, options={}) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 32
32:       def initialize(object, name=nil, options={})
33:         @object = object
34:         @name = name
35:         @error_generator = ErrorGenerator.new object, name, options
36:         @expectation_ordering = RSpec::Mocks::space.expectation_ordering
37:         @messages_received = []
38:         @options = options
39:         @already_proxied_respond_to = false
40:         @null_object = false
41:       end
warn_about_expectations_on_nil() click to toggle source

@private

   # File lib/rspec/mocks/proxy.rb, line 7
7:         def warn_about_expectations_on_nil
8:           defined?(@warn_about_expectations_on_nil) ? @warn_about_expectations_on_nil : true
9:         end
warn_about_expectations_on_nil=(new_value) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 12
12:         def warn_about_expectations_on_nil=(new_value)
13:           @warn_about_expectations_on_nil = new_value
14:         end

Public Instance Methods

add_message_expectation(location, method_name, opts={}, &block) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 67
67:       def add_message_expectation(location, method_name, opts={}, &block)        
68:         method_double[method_name].add_expectation @error_generator, @expectation_ordering, location, opts, &block
69:       end
add_negative_message_expectation(location, method_name, &implementation) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 72
72:       def add_negative_message_expectation(location, method_name, &implementation)
73:         method_double[method_name].add_negative_expectation @error_generator, @expectation_ordering, location, &implementation
74:       end
add_stub(location, method_name, opts={}, &implementation) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 77
77:       def add_stub(location, method_name, opts={}, &implementation)
78:         method_double[method_name].add_stub @error_generator, @expectation_ordering, location, opts, &implementation
79:       end
already_proxied_respond_to() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 57
57:       def already_proxied_respond_to
58:         @already_proxied_respond_to = true
59:       end
already_proxied_respond_to?() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 62
62:       def already_proxied_respond_to?
63:         @already_proxied_respond_to
64:       end
as_null_object() click to toggle source

@private Tells the object to ignore any messages that aren’t explicitly set as stubs or message expectations.

    # File lib/rspec/mocks/proxy.rb, line 51
51:       def as_null_object
52:         @null_object = true
53:         @object
54:       end
has_negative_expectation?(message) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 104
104:       def has_negative_expectation?(message)
105:         method_double[message].expectations.detect {|expectation| expectation.negative_expectation_for?(message)}
106:       end
message_received(message, *args, &block) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 114
114:       def message_received(message, *args, &block)
115:         expectation = find_matching_expectation(message, *args)
116:         stub = find_matching_method_stub(message, *args)
117: 
118:         if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
119:           expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
120:           if expectation = find_almost_matching_expectation(message, *args)
121:             expectation.advise(*args) unless expectation.expected_messages_received?
122:           end
123:           stub.invoke(*args, &block)
124:         elsif expectation
125:           expectation.invoke(*args, &block)
126:         elsif expectation = find_almost_matching_expectation(message, *args)
127:           expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
128:           raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(message) or null_object?)
129:         elsif stub = find_almost_matching_stub(message, *args)
130:           stub.advise(*args)
131:           raise_unexpected_message_args_error(stub, *args)
132:         elsif @object.is_a?(Class)
133:           @object.superclass.__send__(message, *args, &block)
134:         else
135:           @object.__send__(:method_missing, message, *args, &block)
136:         end
137:       end
null_object?() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 44
44:       def null_object?
45:         @null_object
46:       end
raise_unexpected_message_args_error(expectation, *args) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 140
140:       def raise_unexpected_message_args_error(expectation, *args)
141:         @error_generator.raise_unexpected_message_args_error(expectation, *args)
142:       end
raise_unexpected_message_error(method_name, *args) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 145
145:       def raise_unexpected_message_error(method_name, *args)
146:         @error_generator.raise_unexpected_message_error method_name, *args
147:       end
received_message?(method_name, *args, &block) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 99
 99:       def received_message?(method_name, *args, &block)
100:         @messages_received.any? {|array| array == [method_name, args, block]}
101:       end
record_message_received(message, *args, &block) click to toggle source

@private

     # File lib/rspec/mocks/proxy.rb, line 109
109:       def record_message_received(message, *args, &block)
110:         @messages_received << [message, args, block]
111:       end
remove_stub(method_name) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 82
82:       def remove_stub(method_name)
83:         method_double[method_name].remove_stub
84:       end
reset() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 94
94:       def reset
95:         method_doubles.each {|d| d.reset}
96:       end
verify() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 87
87:       def verify
88:         method_doubles.each {|d| d.verify}
89:       ensure
90:         reset
91:       end

Private Instance Methods

find_almost_matching_expectation(method_name, *args) click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 164
164:       def find_almost_matching_expectation(method_name, *args)
165:         method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args) && !expectation.called_max_times?}
166:       end
find_almost_matching_stub(method_name, *args) click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 172
172:       def find_almost_matching_stub(method_name, *args)
173:         method_double[method_name].stubs.find {|stub| stub.matches_name_but_not_args(method_name, *args)}
174:       end
find_matching_expectation(method_name, *args) click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 159
159:       def find_matching_expectation(method_name, *args)
160:         method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args) && !expectation.called_max_times?} || 
161:           method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args)}
162:       end
find_matching_method_stub(method_name, *args) click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 168
168:       def find_matching_method_stub(method_name, *args)
169:         method_double[method_name].stubs.find {|stub| stub.matches?(method_name, *args)}
170:       end
method_double() click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 151
151:       def method_double
152:         @method_double ||= Hash.new {|h,k| h[k] = MethodDouble.new(@object, k, self) }
153:       end
method_doubles() click to toggle source
     # File lib/rspec/mocks/proxy.rb, line 155
155:       def method_doubles
156:         method_double.values
157:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.