Skip to content

Instantly share code, notes, and snippets.

@gbpereira
Last active May 25, 2022 05:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gbpereira/c065097865a96db65973 to your computer and use it in GitHub Desktop.
Save gbpereira/c065097865a96db65973 to your computer and use it in GitHub Desktop.
Clean up carrierwave's files for rspec. Ruby 2.0, Rails 4.0.2.
Dir["#{Rails.root}/app/uploaders/*.rb"].each { |file| require file }
if defined?(CarrierWave)
CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
klass.class_eval do
def cache_dir
"#{Rails.root}/spec/support/uploads/cache"
end
def store_dir
"#{Rails.root}/spec/support/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
end
end
config.after(:all) do
if Rails.env.test?
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
end
end
@hajpoj
Copy link

hajpoj commented May 11, 2015

thanks! the require was what i was missing

@ryamakuchi
Copy link

ryamakuchi commented Oct 25, 2019

In my case it worked fine if I wrote in rails_helper.rb instead of spec_helper.rb.

Thank you for the idea!

@AzhirAhmadi
Copy link

me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment