Skip to content

Instantly share code, notes, and snippets.

@bingxie
Created November 18, 2013 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bingxie/7523930 to your computer and use it in GitHub Desktop.
Save bingxie/7523930 to your computer and use it in GitHub Desktop.
A better use of database_cleaner with RSpec. In spec_helper.rb
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation #start the process by truncating all the tables
end
config.before(:each) do
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation # for javascript tests using :truncation
else
DatabaseCleaner.strategy = :transaction #use the faster transaction strategy
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment