Search

Factories with Realistic Data

Brandon Beacher

1 min read

Sep 27, 2011

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?

Steve Sparks

Reviewer Big Nerd Ranch

Steve Sparks has been a Nerd since 2011 and an electronics geek since age five. His primary focus is on iOS, watchOS, and tvOS development. He plays guitar and makes strange and terrifying contraptions. He lives in Atlanta with his family.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News