2014-10-10 34 views
1

我想找到我上次上傳的文件(使用Carrierwave)並運行與Rspec的have_dimensions方法。定位上傳的文件與Rspec 3

目前我的測試結果失敗,錯誤是

Failure/Error: expect(@uploader.large_animal_image).to have_dimensions(555, 365) 
Errno::ENOENT: 
    No such file or directory @ rb_sysopen - 

我的測試看起來像這樣(以下試過他們的GitHub頁面,但如預期的文件上傳沒有工作的示例)

require 'rails_helper' 
require 'carrierwave/test/matchers' 

describe AnimalImage do 
    include CarrierWave::Test::Matchers 

    before(:each) do 
    AnimalImageUploader.enable_processing = true 
    @animal = FactoryGirl.create(:image) 
    @uploader = AnimalImageUploader.new(@animal, :image) 
    ap(@uploader) 
    @uploader.store! 
    end 

    after(:each) do 
    @uploader.remove! 
    AnimalImageUploader.enable_processing = false 
end 

context 'Image Versions' do 

    it 'should scale large_animal_image to 555 x 365 ' do 
    expect(@uploader.large_animal_image).to have_dimensions(555, 365) 
    end 
end  
end 

ap(@uploader)輸出

#<AnimalImageUploader:0x000000080ae738 @model=#<AnimalImage id: 50, animal_id: nil, image: "yp2.jpg", created_at: "2014-10-10 07:41:20", updated_at: "2014-10-10 07:41:20">, @mounted_as=:image> 

它CRE阿泰以下文件

/support 
    /animal_image 
    /image 
    /50 
    yp2.jpg 
    large_animal_image_yp2.jpg 

我怎樣才能訪問這些文件,以對它們運行have_dimensions方法?

感謝

回答

1

好了,所以搞清楚@uploader.store!做什麼(我傻)

我需要存儲我的文件解決了這個

before(:each) do 
AnimalImageUploader.enable_processing = true 
file = File.open("#{Rails.root}/spec/fixtures/yp2.jpg") 
@animal = AnimalImage.create!(image: file) 
@uploader = AnimalImageUploader.new(@animal, :image) 
@uploader.store!(file) 
end