Ultimate rspec/capybara database cleaner
This should be saved somewhere in spec/support/database_cleaner.rb
. Two key features are: example.metadata[:type]
to determinate that it's an feature and should be run with truncation and second is to wrap it all into around
hook insted of before
, to execute after other after
hook's - this helped me with some wierd DB dedlocks.
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.around(:each) do |example|
DatabaseCleaner.strategy = if example.metadata[:js] || example.metadata[:type] == 'feature'
:truncation
else
:transaction
end
DatabaseCleaner.start
example.run
Capybara.reset_sessions!
DatabaseCleaner.clean
end
end
Written by Gatis Tomsons
Related protips
1 Response
This saved me a lot of time. Thank you.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#