包括ActionDispatch :: TestProcess阻止防护重新正确加载 [英] include ActionDispatch::TestProcess prevents guard from reloading properly

查看:70
本文介绍了包括ActionDispatch :: TestProcess阻止防护重新正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用fix_file_upload在我的rspec中测试一些文件上传

I'm using fixture_file_upload to test some file uploads in my rspecs

如果我只是将其放入规格中,则会发现未找到方法的错误.

If I just put it in the spec I get an error for method not found.

要使其正常工作,我在规范中加入了ActionDispatch :: TestProcess,但是自从我这样做以来,我发现该保护措施在我进行更改时无法正确地重新加载规范文件,它会继续针对旧版本的规范运行测试文件.

To get it working I put include ActionDispatch::TestProcess in my spec but I have found since I did that, that guard is not correctly reloading spec files when I make changes, it keeps running the tests against the old version of the files.

我可以通过停止并重新启动后卫来解决此问题,但这有点违背了目的.

I can work around this by stopping and restarting guard, but it kind of defeats the purpose.

如何防止这种情况发生?我应该如何引用fixture_file_upload或将include放在哪里?

How do I prevent this from happening? How should I reference fixture_file_upload or where should I put the include?

推荐答案

我不知道问题的确切出处,但我遇到了一些由ActionDispatch::TestProcess本人引起的奇怪问题.但是,您可以使用替代方法代替fixture_file_upload,这意味着您可以删除有问题的include.

I don't know the exact source of the problem, but I have had some strange issues caused by ActionDispatch::TestProcess myself. You can, however, use a workaround instead of fixture_file_upload, meaning you can remove the problematic include.

如果您有这样的事情(例如在工厂中):

If you have something like this (e.g. in a factory):

include ActionDispatch::TestProcess

fixture_file_upload('spec/factories/test.png', 'image/png')

您可以将其替换为:

Rack::Test::UploadedFile.new('spec/factories/test.png', 'image/png')

如果您查看 fixture_file_upload 的来源,那么您基本上会看到它只需调用上面的代码即可.

If you look at the source of fixture_file_upload you'll see it essentially just calls the above code.

这篇关于包括ActionDispatch :: TestProcess阻止防护重新正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆