每次使用 Spork 运行时强制重新加载 application_controller
我正在使用 Spork 来加速我的 RSpec 测试。不幸的是,我的 application_controller.rb
在每次运行时都没有重新加载,因此我在修改它时必须重新启动 Spork。有没有办法在每次测试运行时强制重新加载?我想我需要在 Spork.each_run
中添加一些行。
I am using Spork to speed up my RSpec tests. Unfortunately my application_controller.rb
gets not reloaded on each run so that I have to restart Spork when modifying it. Is there a way to force a reload on each test run? I guess I need some additional line in Spork.each_run
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
ActiveSupport::Dependency.clear
放入 Spork.each_run 块中。当您完成自动测试 application_controller.rb 后,我会删除它,尽管新的延迟应该不会太糟糕。Try putting
ActiveSupport::Dependencies.clear
into the Spork.each_run block. I would then remove this when you're done autotesting application_controller.rb, although the new delay shouldn't be too bad.我遇到了同样的问题,但 Spork 被设计为自动重新加载 application_controller.rb 而不进行任何更改。所以我深入研究了它,正如这篇博客文章中的评论中提到的< /a> 我运行了
spork --diagnose
。它列出了 spork 最初加载的所有文件以及每个文件加载方式的回溯。这表明,在我的应用程序中,我碰巧有一个引用 ApplicationController 子类的初始化程序,因此它最初正在加载。一旦我打破了这种依赖关系,当使用 Spork 时,我的 application_controller.rb 就开始在每次测试运行时正确重新加载。I had the same issue, but Spork is designed to automatically reload application_controller.rb without changes. So I dug into it and as mentioned in a comment in this blog post I ran
spork --diagnose
. It lists all of the files initially loaded by spork and the backtrace for how each file was loaded. This showed me that in my app I happened to have an initializer that was referencing a subclass of ApplicationController and thus it was getting loading initially. Once I broke that dependency my application_controller.rb started reloading correctly on each test run when using Spork.