Skip to content

Instantly share code, notes, and snippets.

@mateusg
Forked from carloslopes/database_cleaner.rb
Last active August 29, 2015 13:56
Show Gist options
  • Save mateusg/9138787 to your computer and use it in GitHub Desktop.
Save mateusg/9138787 to your computer and use it in GitHub Desktop.
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.before :suite do
DatabaseCleaner.clean_with :truncation
end
config.before :each do
if example.metadata[:js] || example.metadata[:truncation]
config.use_transactional_fixtures = false
DatabaseCleaner.strategy = :truncation
else
config.use_transactional_fixtures = true
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
end
config.after :each do
if example.metadata[:js]
DatabaseCleaner.clean_with :truncation
else
DatabaseCleaner.clean_with :transaction
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment