0

I am trying to set up cleaning of my specs using database_cleaner gem. I have the following simple config in my spec_helper.rb:

require 'database_cleaner'


RSpec.configure do |config|
  config.use_transactional_fixtures = false

  config.before :suite do
    DatabaseCleaner.strategy = :truncation
  end

  config.before :each do
    DatabaseCleaner.start
  end

  config.after :each do
    DatabaseCleaner.clean
  end
end

Running the spec though, I'm noticing that my database gets completely wiped out after DatabaseCleaner.clean is executed. I'm sure it's meant to clean up only the effects of the test... Any ideas what may cause such behavior?

alexs333
  • 12,143
  • 11
  • 51
  • 89
  • 2
    **DatabaseCleaner.clean** expected behaviour is to wipe whole DB, so you have a clean start(nothing leaks) from test to test. – Kocur4d Mar 18 '13 at 13:05

1 Answers1

4

It's because you've got the strategy set to :truncation, this does indeed clear the whole thing.

If you want to limit it to just what's done in test, then change the strategy to :transaction

Broadly speaking, truncation is very simple, and shouldn't be a problem in the TEST database.

muttonlamb
  • 6,341
  • 3
  • 26
  • 35