【问题标题】:How to transition from spork to spring?如何从 spork 过渡到 spring?
【发布时间】:2015-01-13 18:15:47
【问题描述】:

我目前正在使用带有 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 的引用还是需要用某些东西替换它们?

【问题讨论】:

    标签: ruby-on-rails rspec cucumber spork rails-spring


    【解决方案1】:

    正如您在问题中提到的,没有 Prefork 块。文档提供了一种解决方法:只需将现有的 Spork.prefork 块移动到初始化程序或 Rails 将在加载时拾取并运行的任何地方。

    来自https://github.com/rails/spring#running-code-before-forking

    没有 Spring.before_fork 回调。要在 fork 之前运行某些内容,您可以将其放在 ~/.spring.rbconfig/spring.rb 或应用程序初始化时运行的任何文件中,例如 config/application.rbconfig/environments/*.rbconfig/initializers/*.rb

    至于您的 Spork.each_run 块,由于您使用的是 Rspec,您可以将其移动到 before(:suite) 块中。请参阅 before and after hooks 上的 Rspec 文档

    【讨论】:

      【解决方案2】:

      只需删除所有出现的Spork 并安装spring

      然后运行bundle exec spring binstub --all

      现在,如果您运行 bin/rails c,它将使用 spring

      对于rspec,请使用spring-commands-rspec

      【讨论】:

        猜你喜欢
        • 2010-11-10
        • 2014-02-16
        • 2015-05-07
        • 2013-02-24
        • 2015-03-28
        • 2010-11-08
        • 1970-01-01
        • 1970-01-01
        • 2016-08-26
        相关资源
        最近更新 更多