我正在用rspec编写测试,并且在Paperclip 4方面有些挣扎。目前,我正在使用webmock stub 请求,但是图像处理使测试变慢了。
我阅读的所有内容都建议使用 stub ,如下所示:
Profile.any_instance.stub(:save_attached_files).and_return(true)
据我所知,因为:save_attached_files在Paperclip 4中消失了,所以它不起作用。
现在正确的方法是什么?
谢谢
最佳答案
将此添加到配置块中的rails_helper.rb
中:
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
关于ruby-on-rails - 回形针4,Amazon S3和Rspec : how to stub file upload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21850466/