Mic*_*lle 5 integration-testing ruby-on-rails 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" }
assert_response :redirect
assert_redirected_to goods_ins_path
end
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时,据说:goodsins.xls文件不存在.仅供参考:我把文件放在名为fixtures的文件夹中.
任何的想法?非常感谢你
这里的注释:http://apidock.com/rails/ActionController/TestProcess/fixture_file_upload表示您需要在路径或文件名前包含斜杠.
试着fixture_file_upload('/goodsins.xls', 'text/xls')看看是否有帮助.
fixture_file_upload来源:
# 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
Run Code Online (Sandbox Code Playgroud)
问题所有者更新:
解:
添加include ActionDispatch::TestProcess到test_helper.rb
| 归档时间: |
|
| 查看次数: |
1728 次 |
| 最近记录: |