Simulating Requests

Ideally, your controllers are relatively simple. The complicated functionality is in a model or other object and is being tested in your unit tests for those objects. One reason this is a best practice is that models are easier to test than requests because they’re easier to extract and use independently in a test framework.

Prescription 25A request test should test behavior of a single request. A request test should not fail because of problems in the model.

A request test that overlaps with model behavior is part of the awkward middle ground of testing that the Rails 5 changes are designed to avoid. If the request test is going to the database, then the test is slower than it needs to be. And if a model failure can cascade ...

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.