Search code examples
ruby-on-railsruby-on-rails-4rspecdatabase-cleaner

DatabaseCleaner cleans test and development?


Why does this configuration seem to clean both my test and my development databases? It's pretty annoying to have to reseed development every time I run rspec.

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

database.yml

development:
  adapter: postgresql
  database: m_development
  encoding: utf8
  pool: 5
  username: booltox
  password:

test:
  adapter: postgresql
  database: m_test
  encoding: utf8
  pool: 5
  username: booltox
  password:

Solution

  • Pretty foolish of me but this might help someone else. Don't forget to define your environment in your spec_helper.rb (thanks @dgilperez):

    ENV['RAILS_ENV'] ||= 'test'