[rspec-users] Database clearing

Todd Tyree todd at snappl.co.uk
Sat Sep 20 08:08:21 EDT 2008

Ok, here's what I've come up with on the spur of the moment (goes in

 config.after(:each) do
    result = ActiveRecord::Base.connection.execute('SHOW TABLES;')
    while table = result.fetch_row
      # Or whatever you think is appropriate.
      next if table.index('schema_migrations') or table.index('roles')
      ActiveRecord::Base.connection.execute("TRUNCATE #{table}")

The main problem is that it's slow.  I tried batching them all up, and
running them in a single execute, but foundered on the mysql_options
multi-statements setting (it seems that mysql won't, by default, allow
multi-statement strings unless you set the multi-statement flag after init
and before connect. Not sure how to do this from Base.connect, or even if
it's possible.  Sorry, lost track of the article where I found the original

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080920/ed3dd99d/attachment.html>

More information about the rspec-users mailing list