Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Optimal RSpec Database Cleaner config
Capybara.javascript_driver = :webkit # Selenium works, but not as well
RSpec.configure do |config|
config.use_transactional_fixtures = false
# Use transactions by default
config.before :each do
DatabaseCleaner.strategy = :transaction
end
# For the javascript-enabled tests, switch to truncation, but *only on tables that were used*
config.before :each, :js => true do
DatabaseCleaner.strategy = :truncation, {:pre_count => true}
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