Rspec, Cucumber: best speed database clean strategy

后端 未结 4 1723
庸人自扰
庸人自扰 2021-02-05 14:17

I would like to increase the speed of my tests.

  1. Should I use use_transactional_fixtures or go with the database_cleaner gem?
  2. Whi
4条回答
  •  既然无缘
    2021-02-05 15:07

    RSpec.configure do |config|
    
      config.before(:suite) do
        DatabaseCleaner.clean_with(:truncation)
      end
    
      config.before(:each) do
        DatabaseCleaner.strategy = :transaction
      end
    
      config.before(:each, :js => true) do
        DatabaseCleaner.strategy = :truncation
      end
    
      config.before(:each) do
        DatabaseCleaner.start
      end
    
      config.after(:each) do
        DatabaseCleaner.clean
      end
    
    end
    

    This is from Avdi Grimm's post about database cleaner and Rspec. Step-by-step analysis of the code is in the article.

提交回复
热议问题