rails 3 中的attachment_fu 测试
我正在尝试使用 Attachment_fu 编写工作文件上传功能的规范。但是,作者提供的用于测试的示例代码要求我需要 action_controller/test_process
,以便我可以访问 ActionController::UploadedStringIO
类。我之前在 Rails 2.x 中使用过这个,但对于 Rails 3,它无法找到 test_process
文件。
如何继续测试 Rails 3 中的文件上传功能?
I am trying to write specs for a working file upload functionality using attachment_fu. However, the sample code given by the author for testing requires me to require action_controller/test_process
so that I have access to ActionController::UploadedStringIO
class. I have used this before in rails 2.x but for rails 3, it fails to locate the test_process
file.
How do I go ahead with testing the file upload functionality in rails 3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够将fixture_file_upload 与Rails3 和rspec 一起使用。
我刚刚将
include ActionDispatch::TestProcess
添加到 spec_helper.rb,然后传递类似以下内容作为文件数据:编辑:我升级的内容更改了它的行为以始终包含固定装置路径,因此我切换到这个而不是fixture_file_upload:
I was able to use fixture_file_upload just fine with Rails3 and rspec.
I just added
include ActionDispatch::TestProcess
to the spec_helper.rb, and then passed something like the following as the filedata:EDIT: Something I upgraded changed the behavior of this to always include the fixtures path, so I switched to this instead of fixture_file_upload:
我现在正在测试 Rails 3 中的文件上传,尽管我不知道我的答案会有多大帮助。您可以更改测试吗?就我个人而言,我使用的是黄瓜/水豚方法。 Capybara 的 DSL 定义
就个人而言,这似乎是比与 StringIO 对象交互更好的测试方法......随意反驳。
I'm working on testing file uploads in rails 3 right now, although I don't know how helpful my answer will be. Would it be possible for you to change the test? Personally, I'm using a Cucumber/Capybara approach. Capybara's DSL defines
Personally this seems a better way to test than interacting with the StringIO object...feel free to retort.
对于 Rails 3 来说,找到这个有点棘手。
您仍然可以使用
fixture_file_upload
函数,但您必须添加:include ActionDispatch::TestProcess
到您的测试用例中。
这对 Rspec 根本不起作用。我只需获取文件本身并直接发布文件即可。
This was somewhat tricky to find for Rails 3
You can still use the
fixture_file_upload
function, but you have to add:include ActionDispatch::TestProcess
To your test case.
This didn't work at all with Rspec. I just had to grab the file itself and post the file directly.