rails test database won't wipe rails test database won't wipe postgresql postgresql

rails test database won't wipe


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  endend


Use transactional examples to rollback the data after every test run

RSpec.configure do |config|  config.use_transactional_examples = trueend


You don't need any extra gem in order to clean your test DB between runs. In your spec_helper.rb file, configure rspec as follows:

RSpec.configure do |c|  c.around(:each) do |example|    ActiveRecord::Base.connection.transaction do      example.run      raise ActiveRecord::Rollback    end  endend