October 31, 2007
Fixture improvements
Just found out via the Rails Envy podcast about improvements to the much-derided Rails fixture implementation, recently added into the trunk.
This addresses some of the problems that FixtureReplacement set out to cure. I'll be sticking with FixtureReplacement, however, because:
- All test data is conveniently located in a single file, example_data.rb (depending on how much test data you need this may be a plus or a minus)
- The convenience methods (create_model and new_model) allow you to create new test data on the fly; as such:
- You have more flexibility; you're not limited to a pre-determined set of fixtures set in stone before your test run
- You can create/tweak your test data closer to where it is actually used, making for much more readable specs
- The selective overriding capability allows you to make the attributes that are relevant to a particular situation really stand out (see this example)
- FixtureReplacement is great for experimenting in the script/console
I think there's room for both "Foxy Fixtures" (ugh) and something like FixtureReplacement in core Rails. I'd like to see the latter merged in some day.
Posted by wincent at October 31, 2007 3:51 PM


