Using Mocks to Specify Behavior

In addition to merely replacing expensive method calls, test doubles enable a different style of testing where you validate the application’s behavior rather than its ending state. In most of the tests you’ve seen throughout the book, the test validates the result of a computation: it’s testing whether something is true at the end of an action. When using doubles, however, you have the opportunity to test the process’s behavior during the test rather than the outcome.

Often, this kind of test makes sense given a relatively complex set of object interactions. You don’t exactly have that here, but you can use your controller as a reasonable stand-in. Some features of controller tests are deprecated in Rails 5, ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.