I have a few features that require large amounts of data to be loaded into the test db before they're run. I have tagged these specs as "slow". What I'm trying to accomplish is that any feature spec tagged as "slow" will populate the db just once, use it for all specs in that feature and then clean the entire db after that feature is complete.
Here's how I have setup the 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
These features are then setup like:
feature "Options page", :slow do
before(:each) do
DatabaseCleaner.strategy = :truncation, { except: %w[ products options models prices ] }
end
end
This has worked ok for me up until database_cleaner 1.3. Now, a few specs will run ok, but then they all start failing with:
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
Is there a different strategy I should be using here? Does anyone have experience with what I'm trying to accomplish here?