Chapter 1Introduction

Test-driven development, or TDD, is the counterintuitive idea that developers will improve both the design and the accuracy of their code by writing the code test-first. When adding new logic to a program, the TDD process starts by writing an automated test describing the behavior of code that does not yet exist. In a strict TDD process, new logic is added to the program only after a failing test is written to prompt the creation of the logic.

Writing tests before code, rather than after, allows your tests to help guide the design of your code in small, incremental steps. Over time this creates a well-factored codebase that is easy to change.

We’ll apply the TDD process to the creation of applications using Ruby and ...

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.