Class: Spec::Mocks::Mock

Class | Spec::Mocks::Mock
In: | lib/spec/mocks/mock.rb
Parent: | Object

### Methods

== inspect method_missing new

### Included Modules

Methods

### Public Class methods

new(name, stubs_and_options={})

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 lib/spec/mocks/mock.rb, line 9
     9:       def initialize(name, stubs_and_options={})
    10:         @name = name
    11:         @options = parse_options(stubs_and_options)
    12:         assign_stubs(stubs_and_options)
    13:       end

### Public Instance methods

==(other)

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 lib/spec/mocks/mock.rb, line 19
    19:       def ==(other)
    20:         other == __mock_proxy
    21:       end

inspect()

[Source]

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

method_missing(sym, *args, &block)

[Source]

        # File lib/spec/mocks/mock.rb, line 23
    23:       def method_missing(sym, *args, &block)
    24:         __mock_proxy.instance_eval {@messages_received << [sym, args, block]}
    25:         begin
    26:           return self if __mock_proxy.null_object?
    27:           super(sym, *args, &block)
    28:         rescue NameError
    29:           __mock_proxy.raise_unexpected_message_error sym, *args
    30:         end
    31:       end

[Validate]