如何配置 rspec 以使用 spork 显示输出? [英] How can I configure rspec to show output with spork?

查看:24
本文介绍了如何配置 rspec 以使用 spork 显示输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行 spork 以加快测试速度,但运行它们时没有输出.是否有我需要修改的配置?

I have spork running to speed up my tests but there is no output when I run them. Is there a configuration that I need to modify?

推荐答案

刚遇到这个问题,在 spork 1.0.0rc4 和 rspec 2.14.1/rspec-core 2.14.8 上运行.据我所知,问题在于:

Just ran into this as well, running on spork 1.0.0rc4 and rspec 2.14.1 / rspec-core 2.14.8 . As far as I could figure it out, the problem lies in the following:

  1. Spork 将 $stdout 配置为指向 localhost:port(drb 客户端),以便将所有报告器输出发送到 drb 客户端.现在,这会在运行 Spork.prefork 之后发生.
  2. 在我的 Spork.prefork 块中,我(自然地)正在执行 RSpec.configure do |config|,其中一个配置调用(特别是 config.mock_with :rr)导致了一系列调用,最终导致要初始化 RSpec.configuration 中的报告器/格式化程序 - 但没有错误的标准输出.
  3. RSpec.configuration 有一个重置方法(标记为 @private 但很可惜),它刷新初始化的报告器/格式化程序,以便延迟重新初始化.
  4. 此外,不知何故 RSpec.configuration.output_stream 从未设置.最重要的是,将此代码添加到 Spork.each_run 似乎可以解决问题:

  1. Spork configures the $stdout to point to localhost:port (drb client) so that all reporter output is sent to the drb client. This now happens after the Spork.prefork is ran.
  2. In my Spork.prefork block I was (naturally) doing RSpec.configure do |config|, and one of the config calls there (in particular config.mock_with :rr), was causing a sequence of calls that eventually caused the reporter/formatters in RSpec.configuration to be initialized - but without the incorrect stdout.
  3. RSpec.configuration has a reset method (marked as @private but alas), which flushes the initialized reporter/formatters, to be lazily reinitialized.
  4. Also, somehow RSpec.configuration.output_stream is never set. Bottom line, adding this code to Spork.each_run appears to fix the problem:

if Spork.using_spork?
    RSpec.configure do |config|
        config.reset
        config.output_stream = $stdout
    end
end

如果有人知道解决这个问题的更优雅的方法,请告诉!

If anyone knows of a more elegant way to solve this, please tell!

这篇关于如何配置 rspec 以使用 spork 显示输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆