Parent

Included Modules

Class/Module Index [+]

Quicksearch

Spec::Mocks::Mock

Public Class Methods

new(name=nil, stubs_and_options={}) click to toggle source

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.

# File lib/spec/mocks/mock.rb, line 10
def initialize(name=nil, stubs_and_options={})
  if name.is_a?(Hash) && stubs_and_options.empty?
    stubs_and_options = name
    @name = nil
  else
    @name = name
  end
  @options = extract_options(stubs_and_options)
  assign_stubs(stubs_and_options)
end

Public Instance Methods

==(other) click to toggle source

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.

# File lib/spec/mocks/mock.rb, line 25
def ==(other)
  other == __mock_proxy
end
inspect() click to toggle source
# File lib/spec/mocks/mock.rb, line 29
def inspect
  "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
end
to_s() click to toggle source
# File lib/spec/mocks/mock.rb, line 33
def to_s
  inspect.gsub('<','[').gsub('>',']')
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.