[rspec-users] Database clearing

Matt Wynne matt at mattwynne.net
Sat Sep 20 06:31:06 EDT 2008

On 20 Sep 2008, at 01:59, Scott Taylor wrote:

>> There's another approach though that I haven't tried yet.  One of the
>> guys I work with truncates all the tables in the db before every
>> example.  He says this runs as fast or faster than transactional
>> fixtures, and has the added benefit of NOT being in a transaction,  
>> which
>> means that if he actually DOES use a transaction in his  
>> application code
>> then he can test it very easily.  I've not tried it, but it seems  
>> like a
>> cool idea.

We have a few lines of code in our features steps/env.rb that does this

1. patch AR to stash each AR object created in an array
2. in an After do block, call destroy on each of those objects.

We can probably share if anyone would like to see this.


In case you wondered: The opinions expressed in this email are my own  
and do not necessarily reflect the views of any former, current or  
future employers of mine.

More information about the rspec-users mailing list