On Wed, May 25, 2011 at 5:34 PM, David C.
Anyway, I was curious what you guys use to create Factories?
The factory girl docs on
http://rubydoc.info/gems/factory_girl/1.3.3/frames offer a few options.
Look for the :default_strategy option and the :factory option on
Yeah, :default_strategy helps somewhat… but not really. I have done a
of tests/profiling and even if I resorted to Factory.build() for
it ends up being much slower than just making the objects myself.
I won’t get rid of factory_girl outright - it’s a good little tool to
when you need to create a mini-database, which happens quite a bit in
practice (testing scopes, and so on).
But I think a good rule of thumb is not use it like a basic defacto
object-instantiation tool. Maybe that’s my bad, but articles,
etc. actually tell people to do this - and given it’s performance
implications, I believe that should NOT be a best practice.
For me, I will use normal Rails/Ruby objects until they become too
cumbersome to build in order to satisfy validations or when I need to
something in the database because that is part of the test. Otherwise,
better to work with pure, transient objects that you create yourself.
I have literally got my entire test suite to run in 25 seconds when it
to run in over 90 before. That’s quite a big jump - several times faster
than swapping to an in-memory database.
I only wish I knew this when I started my Rails app and just following
I believe to be the “true” best practice from the start. I guess I gotta
live and learn. I hope others don’t fall into the same pitfall like I