Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Faster Capybara Specs
gem 'database_cleaner', group: :test
RSpec.configure do |config|
# ...
config.use_transactional_fixtures = false
config.before(:each) do
DatabaseCleaner.strategy = if example.metadata[:js]
:truncation
else
:transaction
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
@mattbrictson

This comment has been minimized.

Copy link
Owner Author

mattbrictson commented May 21, 2012

More information in this blog post: http://blog.55minutes.com/2012/05/faster-capybara-specs/

@MikeBlyth

This comment has been minimized.

Copy link

MikeBlyth commented Aug 29, 2012

Thanks, his is great! I experimented with every way I could think of to put the transaction strategy into only the needed tests, but didn't realize there was this example.metadata[:js] trick. This should definitely be put into the docs for database_cleaner on github.

@topherfangio

This comment has been minimized.

Copy link

topherfangio commented Oct 17, 2012

Man, this is super helpful! Just reduced by tests from 1 minute 8 seconds to 18 seconds! Thans so much :-D

@scottkf

This comment has been minimized.

Copy link

scottkf commented Nov 8, 2012

This also fixed some other issues rspec+capybara-webkit was having as well. Thanks!

@klebervirgilio

This comment has been minimized.

Copy link

klebervirgilio commented Jan 16, 2013

Cool!! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.