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

http://robots.thoughtbot.com/post/159805334/make-your-test-suite-uncomfortably-fast
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.
http://fakeweb.rubyforge.org
http://robots.thoughtbot.com/post/219216005/fake-it
And turn on FakeWeb.allow_net_connect = false



What's Next?

blog comments powered by Disqus