Occasionally, somebody recommends or asks about using FactoryGirl to generate seed data for an application. We recommend against it for a few reasons:
- The default attributes of a factory may change over time. This means
that, when you’re using FactoryGirl to generate data in
seeds.rb, you’ll need to explicitly assign each attribute in order to ensure that the data is correct, defeating the purpose.
- Attributes may be added, renamed, or removed. This means your seeds file
will always need to be up to date with your factories as well as your
database schema. You likely won’t be running
rake db:seedevery time you change a migration. So, your seeds file may become out of sync and it won’t be immediately obvious. You’ll likely notice a breakage when a new developer comes onto the project.
- Data will still need to be checked for presence before insertion. The ActiveRecord gem gives you this with the “find or create” methods to locate a record or create it if it can’t be found. In addition, those methods will basically force you to manually define each attribute you want assigned, making Factory Girl unnecessary.
If you found this useful, you might also enjoy: