Let's Write Some Rails

Previous chapter

In the previous chapter, we created some basic functionality for a project-management application using test-driven development.

In this chapter

In this chapter, we’ll augment the model testing by testing the entire Rails stack’s logic from request to response using end-to-end tests. To do this, we’ll use a tool called Capybara to help write our end-to-end tests.

A good test suite consists of a few end-to-end tests, many tests that target a single unit, and relatively few tests covering an intermediate amount of code. By moving logic outside the Rails controller and views, we can turn those harder-to-test parts of Rails tests into code that can be tested with faster and more robust unit tests.

Let’s write some rails

To start a test-driven development process, it’s important to have some requirements in mind. Without some sense of what our code should be doing, it’s hard to write tests to describe behavior.

Requirements gathering

For the purposes of the given example, let’s assume we’re our client and we’re working on a small project, so we don’t exactly need military-grade precision. Here’s an informal list of the first few things we’ll tackle:

Get hands-on with 1200+ tech skills courses.