Skip to content

Instantly share code, notes, and snippets.

@fabianoleittes
Forked from dnagir/database_cleaner.rb
Created November 27, 2012 17:37
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 fabianoleittes/4155758 to your computer and use it in GitHub Desktop.
Save fabianoleittes/4155758 to your computer and use it in GitHub Desktop.
Using transactional DB cleanup
# spec/support/database_cleaner.rb
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with :truncation # Delete leftovers if any
DatabaseCleaner.strategy = :transaction
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
# spec/spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment