Paperclip 4, Amazon S3 & rspec: how to stub file upload?
amazon-s3, paperclip, rspec, ruby-on-rails
Solution
Add this to your `rails_helper.rb` in your config block:
RSpec.configure do |config|
# Stub saving of files to S3
config.before(:each) do
allow_any_instance_of(Paperclip::Attachment).to receive(:save).and_return(true)
end
end
Problem
I'm writing tests with rspec and am a bit struggling with Paperclip 4. At the moment I'm using webmock to stub requests but image processing is slowing tests down. Everything I read suggest to use stubs like so: ``` Profile.any_instance.stub(:save_attached_files).and_return(true) ``` It doesn't work since :save_attached_files disappeared with Paperclip 4 as far as I can tell. What's the proper way to do it now ? Thanks