Ruby 使用fixture\u文件\u上传方法Rails 4 Rspec
我正在用FactoryGirl和Rspec测试图像对象的创建 最初我一直在做我正在使用的事情Ruby 使用fixture\u文件\u上传方法Rails 4 Rspec,ruby,ruby-on-rails-4,rspec,Ruby,Ruby On Rails 4,Rspec,我正在用FactoryGirl和Rspec测试图像对象的创建 最初我一直在做我正在使用的事情 photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) } 但是突然之间我变得 Paperclip::AdapterRegistry::NoHandlerError: No handler found for "#<File:0x00000003bf15c8> 虽然最初我在rails\u助手中声明了fixt
photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) }
但是突然之间我变得
Paperclip::AdapterRegistry::NoHandlerError:
No handler found for "#<File:0x00000003bf15c8>
虽然最初我在rails\u助手中声明了fixture路径,所以我尝试了这个方法
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)在执行此操作时没有创建映像实例
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
我有什么遗漏吗
谢谢最后,您是否能够使用Rspec 4的
fixture\u file\u upload
?我有一些相关的问题。我很想听听你的建议。
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