Method: RSpec::Mocks::ExampleMethods#instance_double

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

#instance_double(doubled_class) ⇒ Object #instance_double(doubled_class, name) ⇒ Object #instance_double(doubled_class, stubs) ⇒ Object #instance_double(doubled_class, name, stubs) ⇒ Object

Constructs a test double against a specific class. If the given class name has been loaded, only instance methods defined on the class are allowed to be stubbed. In all other ways it behaves like a double.

Overloads:

  • #instance_double(doubled_class) ⇒ Object

    Parameters:

    • doubled_class (String, Class)
  • #instance_double(doubled_class, name) ⇒ Object

    Parameters:

    • doubled_class (String, Class)
    • name (String/Symbol)

      name or description to be used in failure messages

  • #instance_double(doubled_class, stubs) ⇒ Object

    Parameters:

    • doubled_class (String, Class)
    • stubs (Hash)

      hash of message/return-value pairs

  • #instance_double(doubled_class, name, stubs) ⇒ Object

    Parameters:

    • doubled_class (String, Class)
    • name (String/Symbol)

      name or description to be used in failure messages

    • stubs (Hash)

      hash of message/return-value pairs

Returns:

  • InstanceVerifyingDouble



56
57
58
59
# File 'lib/rspec/mocks/example_methods.rb', line 56

def instance_double(doubled_class, *args)
  ref = ObjectReference.for(doubled_class)
  ExampleMethods.declare_verifying_double(InstanceVerifyingDouble, ref, *args)
end