I just finished Step 3 of the Test-Driven Rails trail.
It feels like we are taking very small steps to making sure each line in the spec passes or doesn’t return an error. Here’s how the video goes about the start of getting it green:
- Write the test, where a user can successfully create a todo
- The test fails, because no link is on the index, so we add it.
- The test fails again because the route
new_todo_pathdoesn’t exist, so we add it. - But now we need to add the
newcontroller action. - And touch
new.html.erb. - And generate a
Todomodel, so we can create a form on thenewview.
After each of those steps, rspec was ran. But is that level of detail typical in practice? I feel like we could go on and create everything needed for a new action/view, and test from there… To then see a failure that we need a model Todo for Todo.new.
When I worked through the second half of the video (getting the spec green after click_on "Submit"), I forced myself to only write one or two lines of code, until I get another error message. I added the create route, then redirect_to, then the @todos.each line in the index, and so on… But if I were writing this app like I normally do, I would do everything related to the create action, and displaying the info in one go, then calling rspec.