Created
November 18, 2013 07:22
-
-
Save bingxie/7523930 to your computer and use it in GitHub Desktop.
A better use of database_cleaner with RSpec. In spec_helper.rb
This file contains 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
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