SQLite3::SQLException when using database_cleaner with Rails / Spork / RSpec SQLite3::SQLException when using database_cleaner with Rails / Spork / RSpec sqlite sqlite

SQLite3::SQLException when using database_cleaner with Rails / Spork / RSpec


The accepted answer makes all tests slower (when it's not needed) by truncating after each one.

Just add

config.use_transactional_fixtures = false

when using database_cleaner.

If you have both config.use_transactional_fixtures = true and DatabaseCleaner.strategy = :transaction you're going to start a transaction inside another transaction and that's not allowed.


I found the solution to be changing the entire strategy to :truncation. Updated spec_helper:

require 'spork'require 'database_cleaner'Spork.prefork do  RSpec.configure do |config|    config.use_transactional_fixtures = false    config.before(:suite) do      DatabaseCleaner.strategy = :truncation    end    config.before(:each) do      DatabaseCleaner.start    end    config.after(:each) do      DatabaseCleaner.clean    end  endendSpork.each_run doend