2

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:
t56k
  • 6,769
  • 9
  • 52
  • 115
  • Can you show us your ``database.yml``? – dgilperez Feb 19 '15 at 01:19
  • My bet is you have the same database configuration for ``test`` and ``development`` in your ``database.yml``. If so, define different databases for the two environments. – dgilperez Feb 19 '15 at 01:21
  • Another possible cause is that you have ``RAILS_ENV='develop'`` in you ``spec_helper.rb`` – dgilperez Feb 19 '15 at 01:22
  • @dgilperez Yeah, that line isn't in my spec_helper either. Or test.rb. – t56k Feb 19 '15 at 01:28
  • 1
    I'd suggest you alter your database.yml file so that the development configuration is no longer valid (e.g. bad username, bad password, bad database name or non-existent entry.). If you are indeed accessing the development database during your test, you should see an exception that should let you diagnose what's going on. – Peter Alfvin Feb 19 '15 at 05:55
  • Hi @CD-RUM, did you finally managed to solve this or find the cause? Thanks in advance! – bigardone May 21 '15 at 05:23
  • I did! Forgot about this thread. I'll post my answer now. – t56k May 22 '15 at 06:18

1 Answers1

1

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'
t56k
  • 6,769
  • 9
  • 52
  • 115