Skip to content

Instantly share code, notes, and snippets.

@MelnikVasya
Forked from gbpereira/spec_helper.rb
Created April 4, 2017 16:34
Show Gist options
  • Select an option

  • Save MelnikVasya/1a794396b70ebcbede40055140d804f5 to your computer and use it in GitHub Desktop.

Select an option

Save MelnikVasya/1a794396b70ebcbede40055140d804f5 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment