Managing Controller and View Tests

Testing controllers and views is a very tricky part of Rails testing. Unlike model testing (which tends to be isolated to the particular model) or integration testing (which explicitly covers the entire stack), controller and view testing have boundaries that are more blurred. Controlling those boundaries is the difference between tests that run quickly and fail only when the logic being tested is incorrect, and tests that are slower and dependent on logic outside the test.

Ideally, controller tests are written so that they have minimal interaction with the model. There are costs to be balanced. A controller action that has minimal contact with the model and can therefore have that interaction stubbed will ...

Get Rails 4 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.