Skip to Content

RSpec - Disable 'process' carrierwave to improve RSpec performance

Posted on

Problem

Our CI takes ~30 mins to run and we need to find some ways to improve our testing run time.

After using rspec -profile options to detect top 100 slowest test cases, we try to deep down and find the reasons why this test is slow.

One of those reasons is: We still use carrierwave processing image feature in test environment. After an image is uploaded, we process resize_to_fit this image to another size.

So each time we run FactoryBot.create :user, :with_image, it take time to upload and resize the image.

Solution

Disable processing image in Test environment.

# config/initializers/carrierwave.rb

if Rails.env.test? or Rails.env.cucumber?
  CarrierWave.configure do |config|
    config.storage = :file
    config.enable_processing = false
  end
end

If you need to test your processing, you should test it in isolation, and enable processing only for those tests that need it.

References

comments powered by Disqus