[LRUG] Making your tests run fast enough?

Simon Coffey simon at tribesports.com
Tue Jan 24 03:05:51 PST 2012


If you are using factories, and your models have a bunch of required
associations, then only getting your factories to persist their data to the
DB when strictly necessary should provide a speed bump. The latest version
of factory_girl supports a :method => :build option on associations that
means the association will only be saved when the parent is. This means you
can do a Factory.build(:whatever) without it triggering a bunch of inserts
on associated tables.

Alternatively Fabrication (http://fabricationgem.org/) supports lazy
creation of associations, but it does so via some rather invasive
overwriting of association methods, which is less than ideal.

It's no substitute for decoupling your business models from AR, but it's a
quick and (relatively) easy win.

Cheers,
Simon

On 24 January 2012 10:07, Mark Burns <markthedeveloper at gmail.com> wrote:

> Preferring mocks over factories can help. Spork can help too by preloading
> the Rails environment.
> That's tended to be enough for me, although you can do distributed tests
> too.
>
> https://www.ruby-toolbox.com/categories/distributed_testing
>
> Also I presume you're not hitting the web, but if you are then VCR with
> WebMock is good
>
>
> On 24 January 2012 19:02, Jonathan <j.fantham at gmail.com> wrote:
>
>> Mine are really slow, but yesterday Glenn made a suggestion of using a
>> ramdisk to speed the database access which seemed like a good idea! I
>> haven't had the opportunity to try it yet but I read into it and if
>> you're on *nix it seems pretty easy to do.
>>
>> On 24 January 2012 09:57, Joel Chippindale
>> <joel.chippindale at econsultancy.com> wrote:
>> > Test speed seems to be a perennial issue for our team.
>> >
>> > Currently running a single spec file in our rails (v3.0, running under
>> REE)
>> > app takes about 20 seconds and running a single cucumber scenario 30+
>> > seconds. This is too slow for comfortable test driven
>> development/design.
>> >
>> > We've recently started using the spec_no_rails pattern (as outlined by
>> Corey
>> > Haines
>> > here http://www.confreaks.com/videos/641-gogaruco2011-fast-rails-tests)
>> to
>> > avoid loading rails, in some of our specs. This has enabled us to run
>> some
>> > of our specs in couple of seconds (i.e. fast enough). However this
>> currently
>> > only applies to the small subset of our specs that we have isolated from
>> > rails. We'd like it if all our tests ran this fast.
>> >
>> > How fast are your tests/specs/cucumber? Are they fast enough for you? If
>> > they are, what have you done to make this so?
>> >
>> > J.
>> >
>> > --
>> > Joel Chippindale
>> > CTO - http://econsultancy.com
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Chat mailing list
>> > Chat at lists.lrug.org
>> > http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>> >
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>


-- 
Simon Coffey
Developer, Tribesports
simon at tribesports.com | 07960 004 857
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120124/a20c2bb6/attachment.html>


More information about the Chat mailing list