Tuesday, November 10, 2009

Factory.create(:factory_girl, :fixtures => false)

Rails fixtures are a great starting point, but you can't live with them on a large project.
While working on a feature recently I kept breaking other unit tests while working with working in the associated fixtures. The relationship graph between all these objects is quite large, and I quickly decided this wasn't a game I wanted to play anymore.
FactoryGirl isn't new, and I've actually played around with FactoryGirl in the past. It didn't take much effort to add a test/factories.rb, specify a few Factory objects and then bask in the win.
Tests written. New feature added. Existing tests continue to work. Everybody is happy.
Over the last few weeks we have almost entirely replaced fixtures as we've encountered them. At this point in time it is quicker to replace the fixtures than it is to continue repairing fixtures.
Yay, our tests aren't as brittle anymore :)
For everything but the most trivial project, I'll be dropping fixtures at the start of the project.

No comments: