[rspec-users] Why use DatabaseCleaner with rSpec?

Ben Mabey ben at benmabey.com
Tue Feb 8 13:25:23 EST 2011

On 2/8/11 10:49 AM, Marcelo de Moraes Serpa wrote:
> Hi list,
> I've used DatabaseCleaner in the past, but only when using Cucumber
> and Selenium (or Steak + Celerity) since turning on
> transactional_fixtures would prevent the data being accessible from
> app-server that is also triggered for the tests. This works fine, and
> is a de-facto solution for this problem.
> I don't see why I would want to use DatabaseCleaner with rspec though,
> since everything is in the same process, transactional_fixtures could
> do fine, in theory. Or not?
> Marcelo.

If you are using RSpec with Rails and have a *single* ActiveRecord 
connection for your app then you do not need to use DatabaseCleaner and 
the built in transactional_fixtures method will do just great.  Once you 
need to either
   a) use a non-AR DB (e.g. mongodb, couchdb)
   b) have an out of process testing scenario (e.g. selenium)
   c) clean multiple connections (with an ActiveRecord DB or otherwise) or
   d) are not testing a Rails app (where the transactional_fixtures come 
then using DatabaseCleaner will make your life easier.


More information about the rspec-users mailing list