(This is the first of three posts on Rails fixtures)
So you have a Person object that has a many to many relationship with Roles and Movies (maybe this is site where people track their favorite movies). So to test it you need to have the following files:
- and the join tables:
Long tests that repeat themselves look bad, from a DRY (don't repeat yourself) point of view but consider this: A fixture that is useful for 10 tests tells you nothing about any one test. Many times I've faced a broken test that relies on a bloated fixture and been pretty well stumped. There's all sorts of crap on this thing that have nothing to do with the test I'm trying to fix, so now I need to understand 10 tests to fix one. That takes time and makes people hate testing.
See my next post for why fixtures are still useful.
See also Jay Fields's Testing: Inline Setup and Josh Cronemeyer's Are Rails Test Fixtures Good or Evil?