Search⌘ K
AI Features

Making the Test Pass

Explore strategies to make your initial test pass in Rails applications using test-driven development. Understand how to write minimal, effective code to clear errors, run tests with RSpec commands, and progress through the TDD cycle from failing tests to passing ones, laying the foundation for better code design.

TDD starting points

Now it’s time to make the first test pass.

But how?

It seems like a straightforward question, but it has a few different answers.

  • The purist way: Do the simplest thing that could work. In this case, work means to minimally pass the test without regard to the larger context. Or it might even mean to “write the minimum amount of code to clear the current error without regard to the larger context.”
  • The practical way: Write the code we know we need to eventually write, effectively skipping steps that seem too small to be valuable.
TDD starting points
  • The teaching way: This method is somewhere between the other two and lets us best explain how and why test-driven development works without getting bogged down in details or skipping too many steps.

Ultimately, there isn’t a one-size-fits-all answer to the question. The goal is to make the test pass ...