rSpec destroy files after suite finishes

paperclip, rspec-rails, ruby-on-rails-3

Solution

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

Problem

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

Original source