rod mclaughlin


How Test-Driven Development can dig you out of a hole (17 feb 13)

I have an ancient Rails app, pdxspurs.com. Its test coverage falls a little short of 100%. But my next version of pdxspurs.com will be even better.

I'm going to use it to demonstrate coding a Rails 4 app. It'll be a simple example of a site where you

  • join
  • get an email if you forgot your password
  • login
  • write messages
  • write comments on other people's messages
  • etc.

To make it compatible with the latest Rails 4 beta release, I had to make many changes. I tried to make all the changes to the existing app, but each fix broke something else. 

Then I realized what to do: start with a blank Rails app, and introduce lines of code from the existing app, one at a time, always driven by tests.

For example, I wrote a test which creates a user. The test framework said there is no 'user' model. So I created one. Then the test said there is no 'users' table. So I wrote a migration. Etc..

Having tests drive the gradual import of bits and pieces from the old project is a much better way of recreating the app. I only import what's needed, I solve each issue one at a time, and the site will end up fully tested.



Back
Portland London