我正在尝试使用 attachment_fu 编写工作文件上传功能的规范。但是,作者给出的用于测试的示例代码要求我要求 action_controller/test_process
以便我可以访问 ActionController::UploadedStringIO
类。我以前在 rails 2.x 中使用过它,但对于 rails 3,它无法找到 test_process
文件。
如何继续测试 Rails 3 中的文件上传功能?
最佳答案
我能够在 Rails3 和 rspec 中很好地使用 fixture_file_upload。
我刚刚将 include ActionDispatch::TestProcess
添加到 spec_helper.rb,然后将如下内容作为文件数据传递:
fixture_file_upload(Rails.root.join("spec/support/test.png"), 'image/png')
编辑:我升级的东西改变了它的行为以始终包含灯具路径,所以我切换到这个而不是 fixture_file_upload:
Rack::Test::UploadedFile.new(Rails.root.join("spec/support/test.png"), 'image/png')
关于ruby-on-rails - 在 Rails 3 中进行 attachment_fu 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3966263/