amatsuda / database_rewinder

minimalist's tiny and ultra-fast database cleaner
MIT License
807 stars 91 forks source link

Share solution #28

Open Paxa opened 9 years ago

Paxa commented 9 years ago

When I change to database rewinder our tests become slower, because in many cases we used transaction strategy.

Here is solution that worked for us: Use DatabaseRewinder only for capybara+js examples, for others - DatabaseCleaner with db transactions

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseRewinder.clean_all
  end

  config.before(:each) do |example|
    if example.metadata[:js]
      # nothing
    else
      DatabaseCleaner.start
    end
  end

  config.after(:each) do |example|
    if example.metadata[:js]
      DatabaseRewinder.clean
    else
      DatabaseCleaner.clean
      DatabaseRewinder.cleaners.each {|c| c.send(:reset) }
    end
  end
end
skatkov commented 9 years ago

Nice tip. I'm trying this out in y project as well, have best things out both gems here ;)

machty commented 7 years ago

What does the DatabaseRewinder.cleaners.each {|c| c.send(:reset) } line do?

machty commented 7 years ago

Oh does it reset the tracked data as to which tables were mutated?