我正在测试使用FactoryGirl和Rspec创建我的Image对象。
我一直在做我正在使用
photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) }
但突然间我得到了
Paperclip::AdapterRegistry::NoHandlerError:
No handler found for "#<File:0x00000003bf15c8>
因此,在阅读各种帖子后,我已更改为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
我在这里遗漏了什么吗?
由于