Ruby on rails 如何在rails应用程序中使用rspec和database_cleaner保留某些表的测试数据

Ruby on rails 如何在rails应用程序中使用rspec和database_cleaner保留某些表的测试数据,ruby-on-rails,rspec,rspec-rails,database-cleaner,Ruby On Rails,Rspec,Rspec Rails,Database Cleaner,我有一些特性需要在运行测试数据库之前将大量数据加载到测试数据库中。我已将这些规格标记为“慢速”。我试图实现的是,任何标记为“slow”的特性规范只会填充数据库一次,将其用于该特性中的所有规范,然后在该特性完成后清理整个数据库 下面是我如何设置spec_helper.rb的: RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end con

我有一些特性需要在运行测试数据库之前将大量数据加载到测试数据库中。我已将这些规格标记为“慢速”。我试图实现的是,任何标记为“slow”的特性规范只会填充数据库一次,将其用于该特性中的所有规范,然后在该特性完成后清理整个数据库

下面是我如何设置spec_helper.rb的:

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.after(:all, :slow => true) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean
  end

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

  config.after(:each) do
    DatabaseCleaner.clean
  end
end
然后将这些功能设置为:

feature "Options page", :slow do
  before(:each) do
    DatabaseCleaner.strategy = :truncation, { except: %w[ products options models prices ] }
  end
end
在database_cleaner 1.3之前,这对我来说还可以。现在,一些规范可以正常运行,但随后它们都开始出现故障:

Failure/Error: Unable to find matching line from backtrace
     ActiveRecord::StatementInvalid:
       Mysql2::Error: SAVEPOINT active_record_1 does not exist: ROLLBACK TO SAVEPOINT active_record_1

我在这里应该使用不同的策略吗?有人对我在这里要完成的工作有经验吗?

这仍然是个问题吗?您是否尝试升级到较新版本的
数据库\u cleaner