Skip to content

Instantly share code, notes, and snippets.

@waterlink
Last active August 29, 2015 13:57
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 waterlink/9795421 to your computer and use it in GitHub Desktop.
Save waterlink/9795421 to your computer and use it in GitHub Desktop.
database_cleaner support config file for RSpec
# spec/support/database_cleaner.rb
# inspired by this article http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
# and later edited according to thoughtbot/suspenders setup (truncation => deletion)
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:deletion)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :deletion
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