Spork Capybara,config.cache_classes冲突

发布于 2024-11-15 01:12:52 字数 316 浏览 3 评论 0原文

我正在尝试使用 TestUnit 设置 Spork 和 Capybara,并且正在运行 陷入 test.rb 配置问题。

问题是 Spork 要求 config.cache_classes 设置为 false,以便模型中的更改可以 运行测试时会得到反映,而无需重置 Spork 所有 时间。

另一方面,水豚似乎需要 config.cache_classes 设置为 true,否则集成测试 只是似乎不起作用。

我只是在寻找任何可能的解决方案/解释。是 这仅存在于 TestUnit 中,或者这可能是 bug,我应该这样报告它吗?任何帮助都会很大 赞赏!

I'm trying to setup Spork and Capybara with TestUnit, and am running
into a test.rb config problem.

The issue is that Spork requires that
config.cache_classes be set to false, so that changes in the model can
be reflected when running tests without having to reset Spork all the
time.

Capybara, on the other hand, seems to require that
config.cache_classes be set to true, otherwise the integration tests
just don't seem to work.

I'm just looking for any possible solution / explanation for this. Is
this something that only exists within TestUnit, or is this perhaps a
bug and I should report it as such? Any help would be greatly
appreciated!

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

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

发布评论

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

评论(2

ペ泪落弦音 2024-11-22 01:12:52

我建议采取类似于this 一。您要做的主要事情是将您的 config.cache_classes 设置为 true,但强制 Spork 在每次运行时重新加载您的模型和依赖项:

Spork.each_run do
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
end if Spork.using_spork?

希望这将使 cache_classes 对于 Capybara 为 true,但它也将允许您的模型并在测试运行之间重新加载观察者。

I would recommend taking an approach similar to this one. The main thing you'll want to do is set your config.cache_classes to true, but force Spork to reload your models and dependencies on each run:

Spork.each_run do
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
end if Spork.using_spork?

Hopefully this will allow the cache_classes to be true for Capybara, but it will also allow your models and observers to be reloaded between test runs.

对你再特殊 2024-11-22 01:12:52

我在叉勺和黄瓜上遇到了类似的问题。我找到的解决方案是:

config.cache_classes = (ENV['DRB'] == 'true' ? false : true)

spork设置DRB环境。我不认为这是解决这个问题的最优雅的方法,但是如果水豚设置了一些环境变量,你可以使用它吗?

I ran into a similar issue with spork and cucumber. The solution I found was :

config.cache_classes = (ENV['DRB'] == 'true' ? false : true)

spork sets the DRB environment. I dont think this is the most elegant way to solve this, but if capybara sets some env variable, you could use that ?

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