Last active
December 16, 2016 11:29
-
-
Save mcls/f975a73aa8bc0ab0299727bf4f83c930 to your computer and use it in GitHub Desktop.
DatabaseCleaner gem setup for RSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: spec/support/database_cleaner.rb | |
require 'database_cleaner' | |
# More info: https://github.com/DatabaseCleaner/database_cleaner | |
RSpec.configure do |config| | |
config.before(:suite) do | |
# Ensure a clean slate | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.around(:each) do |example| | |
if example.metadata[:js] | |
# JS-based tests use multiple processes, so we can't use database | |
# transactions there. | |
DatabaseCleaner.strategy = :truncation | |
else | |
DatabaseCleaner.strategy = :transaction | |
end | |
DatabaseCleaner.start | |
example.run | |
DatabaseCleaner.clean | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment