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

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

我目前正在使用带有 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 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 文档

关于ruby-on-rails - 如何从spork过渡到spring?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928777/

相关文章:

java - Cucumber:不允许扩展定义步骤定义或 Hook 的类

ruby-on-rails - 是否有用于页面统计的 Rails Gem?

ruby-on-rails - 当 guard 退出时, Spring 并没有停止

ruby-on-rails - 为什么我的 Ubuntu 在明确卸载并安装上一个版本后仍然声称 Ruby on Rails 的版本是 4.0.0?

ruby-on-rails - Database_Cleaner 在规范中间销毁 HTTP 请求之间的记录

ruby-on-rails - RSpec: stub 私有(private)方法

CSS 文件位置 Ruby

ruby-on-rails - 尝试从 Rails 控制台使用 JSON 语法测试 HTTP 请求

ruby - capybara 与 cucumber |获取 cookie

javascript - 支持自动化测试的 Backbone JS应用程序的BDD