Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails test database won't wipe

I'm running rails 3.0.3 and using rspec-rails 2.4.1 with a postgresql database. Whenever I run my RSpec tests, the data remains at the end. Does anyone know how to get rails or rspec to wipe the test environment's data between each use?

Please tell me if there's any further information that could make answering my question easier.

Thanks!
Tristan

like image 668
WoodenKitty Avatar asked Dec 05 '22 23:12

WoodenKitty


1 Answers

Install the database_cleaner gem and then add this to your spec_helper.rb.

Spec::Runner.configure do |config|

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end
like image 184
bobbywilson0 Avatar answered Dec 14 '22 15:12

bobbywilson0