Factories with Realistic Data
Here at Highgroove we often use the popular Factory Girl gem in our tests.
I also like to use a data generation library like Forgery in combination with Factory Girl.
Forgery allows me to improve my factories by using realistic instead of contrived data.
For example, here is a User factory without Forgery:
And here is the same factory with Forgery:
Now, each user created by the factory gets a realistic email address.
This becomes useful if you include Factory Girl and Forgery in the development group, in addition to the test group, in your Gemfile:
Now your factories are available from the Rails console in development mode.
Let’s say you want to spin up some records in your local development database so you can see a view fully populated with realistic data. From the console simply do:
Now you’ve got great looking data on screen for a demo, screencast, or perhaps some debugging.
What do you think? Is realistic data in your factories important to you?