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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With