Rails Tip/Rant #326: Watch those fixtures

Posted by Eric Stewart Thu, 29 Sep 2005 14:17:00 GMT

For several months now I’ve been working on a RubyOnRails project for a client with my cohort Brad. Though I had been experimenting with rails prior to this project, this is the first commercial project with the framework that I have done. And we all know how that’s where you learn the true strengths and weaknessess of a framework. I’ll be adding tips and observations from this project and wanted to start with a simple one.

Fixtures suck! And they are fantastic all at the same time. Coming from a background of heavy unit testing (we’re JUnit junkies) the concept of fixtures is a very welcome feature. I can’t ask for an easier way to write tests for a database backed application. However…..

It’s way too easy to spend a lot of time trying to get new tests working only to find you aren’t including the right fixtures in your test. It’s something that should be trivial, yet we have tripped on admittedly way too many times before developing the right habits.

The lesson that newcomers to Rails can try to learn is that it’s easy to forget new fixtures that need to be added, especially when adding new tests to existing unit tests and the functionality you are testing involves that new table you just added. When things don’t seem to run just right (tests) and you can’t figure out why, check your fixtures.

Comments

(leave url/email »)

   Comment Markup Help Preview comment