Skip to content

Instantly share code, notes, and snippets.

@felipeelias
Last active December 10, 2015 17:48
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save felipeelias/4469873 to your computer and use it in GitHub Desktop.
Save felipeelias/4469873 to your computer and use it in GitHub Desktop.
Simple 'database cleaner' approach using `config.around`. Was able to cut down some seconds out of the suite. Thanks to @brandonhilkert
RSpec.configure do |config|
config.around do |example|
# For examples using capybara-webkit for example.
# Remove this if you don't use it or anything similar
if example.metadata[:js]
example.run
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY")
else
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
end
end
end
end
@adriancb
Copy link

I saw a dramatic improvement in the test suite I'm working with... When I mean dramatic, I mean 8 minutes to 27 seconds...

I'm running jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_51-b11-457-11M4509 [darwin-x86_64]

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