1
我在測試圖像下載時遇到了困難。如何使用RSpec的send_file方法測試下載圖像?
def download_img
@image = Photo.find params[:id] unless params[:id].nil?
@c = Cat.find params[:cat_id] unless params[:cat_id].nil?
@foo = @image.foo unless @image.nil?
send_file(Paperclip.io_adapters.for(@image.file).path, type: "jpeg", :disposition => "attachment", :filename => @image.name)
end
我的RSpec的測試(控制器):
describe 'download_img' do
before do
get :download_img, { id: image.id }
end
it 'retrieves image by id' do
img = Photo.find image.id
expect(img).not_to be_nil
end
it 'downloads image' do
page.response_headers["Content-Type"].should == "application/jpg"
page.response_headers["Content-Disposition"].should == "attachment; filename=\"image.name.jpg\""
end
end
當我運行兩個測試中,我得到一個錯誤RSpec的測試:「沒有這樣的文件或目錄@ rb_sysopen - /家庭/公/系統/照片/文件/ 000/000/001/foo/IMG123.JPG「
謝謝。