module RSpec::Mocks::TestDouble

def self.extend_onto(object, name=nil, stubs={})

module.foo #=> "bar"
RSpec::Mocks::TestDouble.extend_onto(module, "MyMixin", :foo => "bar")
module = Module.new

@example

initializes it as a test double.
Extends the TestDouble module onto the given object and
def self.extend_onto(object, name=nil, stubs={})
  object.extend self
  object.send(:__initialize_as_test_double, name, stubs)
end

def ==(other)

target.
the comparison, we're sure the call gets delegated to the proxy
ActiveRecords belongs_to proxy objects. By making the other object run
This allows for comparing the mock to other objects that proxy such as
def ==(other)
  other == __mock_proxy
end

def __build_mock_proxy(order_group)

Other tags:
    Private: -
def __build_mock_proxy(order_group)
  Proxy.new(self, order_group, @name)
end

def __initialize_as_test_double(name=nil, stubs={})

def __initialize_as_test_double(name=nil, stubs={})
  if Hash === name && stubs.empty?
    stubs = name
    @name = nil
  else
    @name = name
  end
  assign_stubs(stubs)
end

def __mock_proxy

def __mock_proxy
  ::RSpec::Mocks.proxy_for(self)
end

def as_null_object

returned.
are declared, they'll work as expected. If not, the receiver is
Tells the object to respond to all messages. If specific stub values
def as_null_object
  __mock_proxy.as_null_object
end

def assign_stubs(stubs)

def assign_stubs(stubs)
  stubs.each_pair do |message, response|
    __mock_proxy.add_simple_stub(message, response)
  end
end

def initialize(name=nil, stubs={})

messages only)
Creates a new test double with a `name` (that will be used in error
def initialize(name=nil, stubs={})
  __initialize_as_test_double(name, stubs)
end

def inspect

Other tags:
    Private: -
def inspect
  "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
end

def method_missing(message, *args, &block)

def method_missing(message, *args, &block)
  if __mock_proxy.null_object?
    case message
    when :to_int        then return 0
    when :to_a, :to_ary then return nil
    end
  end
  __mock_proxy.record_message_received(message, *args, &block)
  begin
    __mock_proxy.null_object? ? self : super
  rescue NameError
    # Required wrapping doubles in an Array on Ruby 1.9.2
    raise NoMethodError if [:to_a, :to_ary].include? message
    __mock_proxy.raise_unexpected_message_error(message, *args)
  end
end

def null_object?

Returns true if this object has received `as_null_object`
def null_object?
  __mock_proxy.null_object?
end

def respond_to?(message, incl_private=false)

Other tags:
    Private: -
def respond_to?(message, incl_private=false)
  __mock_proxy.null_object? ? true : super
end

def to_s

Other tags:
    Private: -
def to_s
  inspect.gsub('<','[').gsub('>',']')
end