Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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 on rails 如何在rails中测试文件上载以进行集成测试?_Ruby On Rails_Integration Testing_Fixtures - Fatal编程技术网

Ruby on rails 如何在rails中测试文件上载以进行集成测试?

Ruby on rails 如何在rails中测试文件上载以进行集成测试?,ruby-on-rails,integration-testing,fixtures,Ruby On Rails,Integration Testing,Fixtures,我做了一些集成测试,如下所示: def user.excel_import fixture_excel = fixture_file_upload('goodsins.xls', 'text/xls') post excel_import_goods_ins_goods_ins_path, :dump=> {:excel_file=>fixture_excel}, :html => { :multipart => "true" }

我做了一些集成测试,如下所示:

 def user.excel_import
          fixture_excel = fixture_file_upload('goodsins.xls', 'text/xls')
          post excel_import_goods_ins_goods_ins_path, :dump=> {:excel_file=>fixture_excel}, :html => { :multipart => "true" }
          assert_response :redirect
          assert_redirected_to goods_ins_path
       end
但是当我运行测试时,它说:goodsins.xls文件不存在。 仅供参考:我将文件放在名为fixtures的文件夹中

有什么想法吗?非常感谢

此处的注释:表示需要在路径或文件名之前包含斜杠

尝试
fixture\u file\u上传('/goodsins.xls',text/xls')
看看这是否有帮助

夹具文件上传源:

# File actionpack/lib/action_controller/test_process.rb, line 523
def fixture_file_upload(path, mime_type = nil, binary = false)
  if ActionController::TestCase.respond_to?(:fixture_path)
    fixture_path = ActionController::TestCase.send(:fixture_path)
  end

  ActionController::TestUploadedFile.new("#{fixture_path}#{path}",
    mime_type, binary)
end
问题所有者的更新:

解决方案:


include ActionDispatch::TestProcess
添加到
test\u helper.rb

是的,我已经在路径或文件名之前使用了斜杠,但它仍然不存在。。。。在功能测试上它工作得很好,但是在集成测试上它不工作…但是你的链接对我来说非常有用。。。给我的thx。。。解决方案就是将这个include ActionDispatch::TestProcess添加到下面的test\u helper.rb中。这种测试传统上称为控制器测试。