Clean your Sequel databases with Database Cleaner.
See https://github.com/DatabaseCleaner/database_cleaner for more information.
# Gemfile
group :test do
gem 'database_cleaner-sequel'
end
# test_helper.rb
DatabaseCleaner[:sequel].strategy = :transaction
class Minitest::Spec
before :each do
DatabaseCleaner[:sequel].start
end
after :each do
DatabaseCleaner[:sequel].clean
end
end
Here is an overview of the supported strategies:
Truncation | Transaction | Deletion |
---|---|---|
Yes | Yes | Yes |
(Default strategy is denoted in bold)
ORM | How to access | Notes |
---|---|---|
Sequel | DatabaseCleaner[:sequel] |
Multiple databases supported; specify DatabaseCleaner[:sequel, {:connection => Sequel.connect(uri)}] |
Due to an inconsistency in JRuby's implementation of Fibers, Sequel gives a different connection to DatabaseCleaner.start
than is used for tests run between .start
and .clean
. This can be worked around by running your tests in a block like DatabaseCleaner.cleaning { run_my_tests }
instead, which does not use Fibers.
See LICENSE for details.