Method: RSpec::Mocks::ExampleMethods#object_double

Defined in:
lib/rspec/mocks/example_methods.rb

#object_double(object_or_name) ⇒ Object #object_double(object_or_name, name) ⇒ Object #object_double(object_or_name, stubs) ⇒ Object #object_double(object_or_name, name, stubs) ⇒ Object

Constructs a test double against a specific object. Only the methods the object responds to are allowed to be stubbed. If a String argument is provided, it is assumed to reference a constant object which is used for verification. In all other ways it behaves like a double.

Overloads:

  • #object_double(object_or_name) ⇒ Object

    Parameters:

    • object_or_name (String, Object)
  • #object_double(object_or_name, name) ⇒ Object

    Parameters:

    • object_or_name (String, Object)
    • name (String/Symbol)

      name or description to be used in failure messages

  • #object_double(object_or_name, stubs) ⇒ Object

    Parameters:

    • object_or_name (String, Object)
    • stubs (Hash)

      hash of message/return-value pairs

  • #object_double(object_or_name, name, stubs) ⇒ Object

    Parameters:

    • object_or_name (String, Object)
    • name (String/Symbol)

      name or description to be used in failure messages

    • stubs (Hash)

      hash of message/return-value pairs

Returns:

  • ObjectVerifyingDouble



102
103
104
105
# File 'lib/rspec/mocks/example_methods.rb', line 102

def object_double(object_or_name, *args)
  ref = ObjectReference.for(object_or_name, :allow_direct_object_refs)
  ExampleMethods.declare_verifying_double(ObjectVerifyingDouble, ref, *args)
end