I found the following comment on a blog from @ryanb in 2012, and to this day it is still a spot on, comprehensive list of everything I see people do wrong with factories to make their lives unintentionally harder:
While factories can get you in trouble, the key is to use them correctly. Here are some suggestions.
- The base factory should be just enough to get validations passing and never contain specific data that is used by a test.
- If you need an association, make a separate factory for it (such as comment_with_article) but keep the base factories free of associations unless they are required to make a valid record.
- Don't attempt to get fancy, such as building has_many associations with factories. Any factory overly complex should be moved up into the test so it is clear what it is doing.
- Always use "build" instead of "create" in factory girl when possible. This will lead to faster, lighter tests.
Follow these simple rules and factories are awesome. Fixtures hide data important to a test and can quickly become a mess of attributes and associations which test are dependent on. Tests should avoid external dependencies whenever possible.
I don't consider a factory an external dependency if it does not contain data that makes a test pass. It is meant to be a clean slate just to get validations and attr_accessible working in Active Record.
Ryan Bates on March 5, 2012