我目前正在使用带有 Guard、Rspec 和 Cucumber 的 Spork。我想搬到 Spring,但找不到关于我需要更改的内容的任何文档。
具体来说,我很好奇我是否需要改变我的:
require 'spork'
Spork.prefork do
# ...
end
Spork.each_run do
# ...
end
...类似的东西:
require 'spring'
Spring.prefork do
# ...
end
Spring.each_run do
# ...
end
但是,我知道there isn't a
Spring.prefork
because the documentation says so .所以我应该简单地删除对 Spork
的引用吗?或者我需要用什么东西代替它们?
最佳答案
正如您在问题中提到的,没有 Prefork 块。文档提供了一种解决方法:只需移动您现有的 Spork.prefork
块到初始化程序或任何地方,它会在加载时被 Rails 拾取并运行。
来自 https://github.com/rails/spring#running-code-before-forking :
There is no Spring.before_fork callback. To run something before the fork, you can place it in
~/.spring.rb
orconfig/spring.rb
or in any of the files which get run when your application initializes, such asconfig/application.rb
,config/environments/*.rb
orconfig/initializers/*.rb
.
至于你的
Spork.each_run
块,因为你使用的是 Rspec 你可以把它移到 before(:suite)
堵塞。请参阅 before and after hooks 上的 Rspec 文档
关于ruby-on-rails - 如何从spork过渡到spring?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928777/