#104 Speeding Up Tests
11/5/2017

Summary

Slow tests can slow down your development process. Using parallel_tests, you can speed up your test suite by multiple threads and running the tests in groups.
1
rails test 4:54 min

Summary

Gemfilegroup :development, :test do
  ...
  gem 'parallel_tests'
  gem 'database_cleaner'
end
config/database.ymltest:
  <<: *default
  database: db/test<%= ENV['TEST_ENV_NUMBER'] %>.sqlite3
spec/support/database_cleaner.rb# Don't forget to add the below comment to your rails_helper.rb
# require 'support/database_cleaner' or 
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

RSpec.configure do |config|
 
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end
 
  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
  end
 
  config.before(:each, type: :feature) do
    DatabaseCleaner.strategy = :truncation
  end
 
  config.before(:each) do
    DatabaseCleaner.start
  end
 
  config.after(:each) do
    DatabaseCleaner.clean
  end
 
end


Photo
Daniel Leong said 16 days ago:

Could you also do a Test::Unit example? 


From what I do know, there are caveat around that. 

Login to Comment