Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rSpec destroy files after suite finishes

In my rSpec tests I test paperclip's ability to upload photos to my system and save them with a given user.

This is great however upon my tests finishing, i have all these extra files on my system. How do i auto delete this upon completion of my test suite.

thanks mike

like image 488
Mike Silvis Avatar asked Apr 11 '12 20:04

Mike Silvis


2 Answers

It's simpler to just delete the entire test directory. Plus, slightly less overhead and easier to read.

# spec_helper.rb

config.after(:suite) do
  FileUtils.rm_rf(Dir["#{Rails.root}/public/system/test"])
end
like image 81
Mike Rapadas Avatar answered Sep 28 '22 03:09

Mike Rapadas


I've not used Paperclip, but I assume those files are saved in a somewhat constant place, such as (random example) tmp/paperclip/photos/.

If that's the case, within your spec_helper, you can add:

config.after(:suite) do # or :each or :all
    Dir["#{Rails.root}/tmp/paperclip/**/*"].each do |file|
        File.delete(file)
    end
end
like image 45
MrDanA Avatar answered Sep 28 '22 03:09

MrDanA