Object
@private
@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
@private
# File lib/rspec/mocks/proxy.rb, line 26 26: def allow_message_expectations_on_nil? 27: !warn_about_expectations_on_nil 28: end
@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
@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
@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
@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
@private
# File lib/rspec/mocks/proxy.rb, line 57 57: def already_proxied_respond_to 58: @already_proxied_respond_to = true 59: end
@private
# File lib/rspec/mocks/proxy.rb, line 62 62: def already_proxied_respond_to? 63: @already_proxied_respond_to 64: end
@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
@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
@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
@private
# File lib/rspec/mocks/proxy.rb, line 44 44: def null_object? 45: @null_object 46: end
@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
@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
@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
@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
@private
# File lib/rspec/mocks/proxy.rb, line 82 82: def remove_stub(method_name) 83: method_double[method_name].remove_stub 84: end
# 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
# 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
# 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
# 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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.