Class Spec::Mocks::Mock
In: vendor/plugins/rspec/lib/spec/mocks/mock.rb
Parent: Object

Methods

==   inspect   method_missing   new   to_s  

Included Modules

Methods

Public Class methods

Creates a new mock with a name (that will be used in error messages only) == Options:

  • :null_object - if true, the mock object acts as a forgiving null object allowing any message to be sent to it.

[Source]

    # File vendor/plugins/rspec/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

Public Instance methods

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

[Source]

    # File vendor/plugins/rspec/lib/spec/mocks/mock.rb, line 21
21:       def ==(other)
22:         other == __mock_proxy
23:       end

[Source]

    # File vendor/plugins/rspec/lib/spec/mocks/mock.rb, line 35
35:       def inspect
36:         "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
37:       end

[Source]

    # File vendor/plugins/rspec/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

[Source]

    # File vendor/plugins/rspec/lib/spec/mocks/mock.rb, line 39
39:       def to_s
40:         inspect.gsub('<','[').gsub('>',']')
41:       end

[Validate]