Chapter 7. Rails Application Testing
Introduction
If you cringe at the idea of testing software, then you should think about the alternatives, and what testing really means. Historically, testing was assigned to the most junior member of the team, a summer intern, or even someone whoâs not really very good but canât be fired. Itâs not taken seriously. And testing normally doesnât take place until after the application has been declared âfinishedâ (or some value of finished): itâs often an afterthought that delays your release schedule precisely when you canât afford any delays.
But it doesnât have to be this way. Most programmers find debugging much more unpleasant than testing. Debugging is usually what triggers mental images of staring at someone elseâs code, trying to understand how it works, only so you can fix the part that doesnât actually work. Debugging is almost universally accepted as being an unpleasant task. (If youâre thinking that you sometimes get a kick out of debugging, then imagine fixing a bug, only to have it crop up again repeatedly, perhaps with slight variations. The joy of solving the mystery becomes something more like mopping floors.)
The fact that debugging can be unpleasant is exactly what makes testing appealing and, as it turns out, enjoyable. As you build up a suite of tests for each part of your application, itâs as if youâre buying insurance that you wonât have to debug that code in the future. Thinking of tests as insurance ...
Get Rails Cookbook 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.