Gau*_*rma 4 rspec ruby-on-rails paperclip rspec-rails
Failure/Error: post :create, Devise.token_authentication_key => @foo.authentication_token, receipt_image: "foo.png"
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "foo.png"
Run Code Online (Sandbox Code Playgroud)
如何在rspec代码中传递图像,我也尝试使用curl命令的@ foo.png.
在模型级别,您需要将它传递给打开的图像:
@foo.image = File.open(Rails.root.join("spec", "fixtures", "sticker.jpg"))
@foo.save!
Run Code Online (Sandbox Code Playgroud)
在控制器级别上,您传递一个String,即图像的路径.这是最好的绝对路径.
params[:foo][:image] = Rails.root.join("spec", "fixtures", "sticker.jpg")
post :new, params
Run Code Online (Sandbox Code Playgroud)