(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:
If you want to test that only people of a certain role can edit another person’s favorite movie list, then your test is spread out amongst 7 files (don’t forget the test file and the actual class file). Maddening enough when you’re writing it, but super crazy insane to debug when the test breaks. More than likely a developer will delete/comment out the the test when it breaks, or they will change it so passes but breaks functionality.
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.