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

查看:103
本文介绍了如何配置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中的报告程序/格式化程序-但没有不正确的stdout.
  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天全站免登陆