Factory Girl Testing Speed By ThoughtBot

Factory Girl is a testing framework for Ruby On Rails written by ThoughtBot.com.

This page has notes from ThoughtBot about how to do Factory Girl testing speed optimizations.
Thanks to Dan Croak, author of Factory Girl, for providing these ideas.

Related: Factory Girl Testing Setup By ThoughtBot

To use RAM instead of the database

We rely on only writing to the database when necessary.
We use Factory.build or .stub instead of .create, never hitting the wire

To use parallel databases

We create 4 test databases and on rake, the tests run in parallel, using the different databases.
Why 4? Good question. i don't know if we've tried having more, found a limit, and backed off.

To use Cucumber's Direct Model Access

For example, as long as you have integration coverage for the sign up process, you can feel confident using FactoryGirl for a "I am signed up and confirmed as 'user@example.com'" step, instead of a step that actually submits the sign up form again.

To use FakeWeb for HTTP network connections

We use the FakeWeb library on all projects to make sure we don't make http calls.
And turn on FakeWeb.allow_net_connect = false

What's Next?

blog comments powered by Disqus