Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使用fixture\u文件\u上传方法Rails 4 Rspec_Ruby_Ruby On Rails 4_Rspec - Fatal编程技术网

Ruby 使用fixture\u文件\u上传方法Rails 4 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

我正在用FactoryGirl和Rspec测试图像对象的创建

最初我一直在做我正在使用的事情

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