使用rspec和数据库清理执行并行测试

时间:2015-06-06 17:41:24

标签: ruby-on-rails ruby rspec database-cleaner parallel-testing

我已将rspec升级到版本3.2,现在运行规范时出现了很多数据库错误(Mysql2::Error: Duplicate entry)。规格似乎并行运行。我正在使用database cleaner gem (1.4.1),它在升级之前正在运行。怎么了?这是我的spec_helper文件:

Capybara.javascript_driver = :webkit

RSpec.configure do |config|
  config.filter_run_excluding :broken => true
  config.filter_run :focus => true
  config.run_all_when_everything_filtered = true
  config.infer_spec_type_from_file_location!

  config.infer_base_class_for_anonymous_controllers = false

  config.order = "random"

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.strategy = :deletion, {except: %w[users]}
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end

0 个答案:

没有答案