Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phallstrom/f0faf5b7c3733fa527f50723528f6de2 to your computer and use it in GitHub Desktop.
Save phallstrom/f0faf5b7c3733fa527f50723528f6de2 to your computer and use it in GitHub Desktop.
spec/support/database_cleaner.rb
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
# The README for DatabaseCleaner suggests this should be simpler, but it
# doesn't work using their examples. This does however, so don't touch it :-)
config.around(:each) do |example|
if example.metadata[:truncation]
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
example.run
DatabaseCleaner.clean
else
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.cleaning do
example.run
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment