加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何从spork过渡到spring?

发布时间:2020-12-17 03:17:54 所属栏目:百科 来源:网络整理
导读:我目前正在使用Spork with Guard,Rspec和Cucumber.我想转移到 Spring,但找不到任何需要更改的文档. 具体来说,我很好奇我是否需要更改我的: require 'spork'Spork.prefork do # ...endSpork.each_run do # ...end …有类似的东西: require 'spring'Spring.p
我目前正在使用Spork with Guard,Rspec和Cucumber.我想转移到 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 or config/spring.rb or in any of the files which get run when your application initializes,such as config/application.rb,config/environments/*.rb or config/initializers/*.rb.

至于你的Spork.each_run块,因为你正在使用Rspec,你可以将它移动到before(:suite)块中.请参阅before and after hooks上的Rspec文档

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读