...

/

Using Mocks to Specify Behavior

Using Mocks to Specify Behavior

Learn about controller testing deprecation, controller responsibility, mock objects, and brittle tests mock.

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

Controller testing deprecation

Often, this kind of test makes sense given a relatively complex set of object interactions. We don’t exactly have that here, but we can use the controller as a reasonable stand-in. Some features of controller tests are deprecated in Rails 5. Still, we won’t touch any of the deprecated features, and we’ll test the controller as its own unit, without dependencies on any other code. We think using ...