Method: RSpec::Mocks::ExampleMethods#instance_spy

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

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

Constructs a test double that is optimized for use with have_received against a specific class. If the given class name has been loaded, only instance methods defined on the class are allowed to be stubbed. With a normal double one has to stub methods in order to be able to spy them. An instance_spy automatically spies on all instance methods to which the class responds.

Overloads:

  • #instance_spy(doubled_class) ⇒ Object

    Parameters:

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

    Parameters:

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

      name or description to be used in failure messages

  • #instance_spy(doubled_class, stubs) ⇒ Object

    Parameters:

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

      hash of message/return-value pairs

  • #instance_spy(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



144
145
146
# File 'lib/rspec/mocks/example_methods.rb', line 144

def instance_spy(*args)
  instance_double(*args).as_null_object
end