当我使用 Spork 时,如何确保帮助程序和模型在 RSpec 中重新加载?

发布于 2024-12-18 14:22:58 字数 73 浏览 0 评论 0原文

似乎我的助手(有时还有我的模型)在每次使用 Spork 运行时都没有重新加载。我应该将什么放入“Spork.each_run”块中?

It seems like my helpers (and sometimes my models) aren't being reloaded on each run with Spork. What should I be putting into my "Spork.each_run" block?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

棒棒糖 2024-12-25 14:22:58

我遇到了同样的问题,所以我在each_run块中设置了这个:

Spork.each_run do
  # This code will be run each time you run your specs.
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
  FactoryGirl.reload

  Dir[File.join(File.dirname(__FILE__), '..', 'app', 'helpers', '*.rb')].each do |file|
    require file
  end
end

另外,不要忘记在你的config/environments/test.rb中:

config.cache_classes = !(ENV['DRB'] == 'true')

I had the same issue, so I set this in my each_run block:

Spork.each_run do
  # This code will be run each time you run your specs.
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
  FactoryGirl.reload

  Dir[File.join(File.dirname(__FILE__), '..', 'app', 'helpers', '*.rb')].each do |file|
    require file
  end
end

Also, don't forget this in your config/environments/test.rb:

config.cache_classes = !(ENV['DRB'] == 'true')
套路撩心 2024-12-25 14:22:58

这可能是因为您将它们加载到 prefork 块中。如果您在那里加载内容,您的测试运行得更快,但有时您需要重新加载。您可以加载“each_run”块,但测试会更慢。如果您更喜欢速度,则可以在需要重新加载时重新启动 Spork 服务器。这样,prefork 块将再次运行,并且您的模型和助手将被重新加载。

It may be because you load them in the prefork block. If you load the stuff there, your test run faster, but sometimes you need to reload. You could load on the "each_run" block, but test would be slower. If you prefer speed, you can restart the Spork server when you see that you need the reload. This way, the prefork block will run again and your models and helpers will be reloaded.

亣腦蒛氧 2024-12-25 14:22:58

我从来没有遇到过这些问题,也许是因为我也使用了 Ryan Bates 的 RailsCast 中描述的 Guard gem?

http://railscasts.com/episodes/285-spork

I never had these problems, and maybe it's because I'm also using the Guard gem like described in Ryan Bates' RailsCast?

http://railscasts.com/episodes/285-spork

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文