我想測試一個載波圖像上傳到模型,使用RSpec /水豚/工廠女孩的Rails。
這個特定的測試測試了圖像應該存在的驗證。資產文件夾的路徑,來自RSpec測試
目前,我有這樣的代碼:
it "should accept a spotlight record with spotlight info" do
feature = create :feature, spotlight: true, spotlight_description: "description", spotlight_image: File.open(Rails.root.join "/app/assets/shopstar_logo_stamp.png")
expect(feature).to be_valid
end
但不知何故,沒有檢測到圖像,我得到這個錯誤:
Failures:
1) Feature validations should accept a spotlight record with spotlight info
Failure/Error: feature = create :feature, spotlight: true, spotlight_description: "description", spotlight_image: File.open(Rails.root.join "/app/assets/shopstar_logo_stamp.png")
Errno::ENOENT:
No such file or directory - /app/assets/shopstar_logo_stamp.png
# ./spec/models/feature_spec.rb:32:in `initialize'
# ./spec/models/feature_spec.rb:32:in `open'
# ./spec/models/feature_spec.rb:32:in `block (3 levels) in <top (required)>'
我如何可以指定一個路徑資產中的圖像並將其用於測試?
或者,或者,測試載波圖像上傳的更好方法是什麼?
您好Marco - 我的回答對您有幫助嗎?如果是這樣,請接受它。 – Anthony 2014-10-06 22:06:25