Created
January 10, 2014 20:31
-
-
Save jsteiner/8362013 to your computer and use it in GitHub Desktop.
Database Cleaner
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
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.before(:each, js: true) do | |
DatabaseCleaner.strategy = :truncation | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, that's the thing - Database Cleaner is no longer necessary since Rails 5, as they added 1st class transaction rollback support. You can just set 'use transactional fixtures' to true in test.rb and call it a day.
Anyone still following this - just upgrade to Rails 5, and use the default rspec/capybara configuration out of the box and everything will just work.
However, if upgrading to Rails 5 is easier said than done for a particular project in your case - I actually did just use database cleaner (today) for one project that is still using Rails 4. Just use the current config they have posted on the database cleaner github readme (https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example). I copy pasted that and was good to go immediately.