Ok, here's what I've come up with on the spur of the moment (goes in
spec_helper.rb):

 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}")
    end
  end

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
reference).

Best,
Todd
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to