The perfect RSpec config
spec/support/. Aside from rspec, make sure your
dependencies include database_cleaner >= 0.9.1 and capybara-webkit.
RSpec.configure do |config| config.use_transactional_fixtures = false
# Use transactions by default config.before :each do DatabaseCleaner.strategy = :transaction end
config.before :each do DatabaseCleaner.start end
config.after :each do DatabaseCleaner.clean end end
See on github
Note for Postgres users
:pre_count option has (or had) a bug for Postgres, where it just blew up. I submitted a patch, and it should be in the next release. As of this writing it’s at 0.9.1. So until a higher version is out, you should add database_cleaner to your Gemfile like this:
gem 'database_cleaner', :git => 'git://github.com/bmabey/database_cleaner.git'