Class | Spec::Mocks::Mock |
In: |
lib/spec/mocks/mock.rb
|
Parent: | Object |
Creates a new mock with a name (that will be used in error messages only) == Options:
# File lib/spec/mocks/mock.rb, line 10 10: def initialize(name, stubs_and_options={}) 11: @name = name 12: @options = parse_options(stubs_and_options) 13: assign_stubs(stubs_and_options) 14: end
This allows for comparing the mock to other objects that proxy such as ActiveRecords belongs_to proxy objects By making the other object run the comparison, we‘re sure the call gets delegated to the proxy target This is an unfortunate side effect from ActiveRecord, but this should be safe unless the RHS redefines == in a nonsensical manner
# File lib/spec/mocks/mock.rb, line 21 21: def ==(other) 22: other == __mock_proxy 23: end
# File lib/spec/mocks/mock.rb, line 35 35: def inspect 36: "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>" 37: end
# File lib/spec/mocks/mock.rb, line 25 25: def method_missing(sym, *args, &block) 26: __mock_proxy.instance_eval {@messages_received << [sym, args, block]} 27: begin 28: return self if __mock_proxy.null_object? 29: super(sym, *args, &block) 30: rescue NameError 31: __mock_proxy.raise_unexpected_message_error sym, *args 32: end 33: end