Implements the methods needed for a pure test double. RSpec::Mocks::Mock includes this module, and it is provided for cases where you want a pure test double without subclassing RSpec::Mocks::Mock.
Extends the TestDouble module onto the given object and initializes it as a test double.
@example
module = Module.new RSpec::Mocks::TestDouble.extend_onto(module, "MyMixin", :foo => "bar") module.foo #=> "bar"
# File lib/rspec/mocks/test_double.rb, line 17 def self.extend_onto(object, name=nil, stubs_and_options={}) object.extend self object.send(:__initialize_as_test_double, name, stubs_and_options) 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.
# File lib/rspec/mocks/test_double.rb, line 32 def ==(other) other == __mock_proxy end
@private
# File lib/rspec/mocks/test_double.rb, line 37 def inspect "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>" end
@private
# File lib/rspec/mocks/test_double.rb, line 49 def respond_to?(message, incl_private=false) __mock_proxy.null_object? && message != :to_ary ? true : super end
@private
# File lib/rspec/mocks/test_double.rb, line 42 def to_s inspect.gsub('<','[').gsub('>',']') end
Generated with the Darkfish Rdoc Generator 2.