使用fixture_file_upload方法Rails 4 Rspec

我正在使用FactoryGirl和Rspec测试我的Image对象的创建。

我正在使用我正在使用的

photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) } 

但我突然间得到了

 Paperclip::AdapterRegistry::NoHandlerError: No handler found for "# 

所以在阅读各种post之后我已经改为fixture_file_upload方法,但是在创建对象时遇到了麻烦。

images.rb

 include ActionDispatch::TestProcess FactoryGirl.define do factory :image do transient do photo_name 'validated_image.jpg' end photo { fixture_file_upload(Rails.root.join('spec', 'fixtures', photo_name), 'image/jpeg') } end 

虽然最初我试过这个,因为我的rails_helper声明了夹具路径

 photo { fixture_file_upload photo_name, 'image/jpeg' } # config.fixture_path = "#{::Rails.root}/spec/fixtures" # rails_helper # Would produce error 'validated_image.jpg file does not exist' 

我当前的实现(vey top)在执行此操作时不会创建Image的实例

 it 'creates a new image' do expect do post :create, image: FactoryGirl.attributes_for(:image) end.to change(Image, :count).by(1) end # ERROR # expected #count to have changed by 1, but was changed by 0 

我在这里遗漏了什么?

谢谢