Back to Rspec

Configuring responses

rspec-mocks/features/configuring_responses/README.md

4.0.0.beta11.0 KB
Original Source

Configuring responses

When allowing or expecting messages, the default response is to return nil. Several methods are provided to configure how the test double responds to the message.

  • <a href="./configuring-responses/returning-a-value">and_return</a>
  • <a href="./configuring-responses/raising-an-error">and_raise</a>
  • <a href="./configuring-responses/mixed-responses">and_invoke</a>
  • <a href="./configuring-responses/throwing">and_throw</a>
  • <a href="./configuring-responses/yielding">and_yield</a>
  • <a href="./configuring-responses/calling-the-original-implementation">and_call_original</a>
  • <a href="./configuring-responses/wrapping-the-original-implementation">and_wrap_original</a>

In addition, you can provide a block implementation to respond in any manner you wish.

Note: for simplicity, the examples here use allow rather than expect, but these APIs apply equally to both cases.