Skip to content

Instantly share code, notes, and snippets.

@mattbrictson
Created May 18, 2012 23:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mattbrictson/2728030 to your computer and use it in GitHub Desktop.
Save mattbrictson/2728030 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

@MikeBlyth
Copy link

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
Copy link

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

@scottkf
Copy link

scottkf commented Nov 8, 2012

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

@klebervirgilio
Copy link

Cool!! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment