【问题标题】:save_and_open_page and spork, spork is loosing test suite / outputsave_and_open_page 和 spork,spork 正在丢失测试套件/输出
【发布时间】:2013-04-09 07:10:10
【问题描述】:

当我使用 spork 运行我的 rspec 测试时,每次我使用 capybara 的 save_and_open_page 时,spork 都会丢失测试套件......或者可能不再输出任何东西......

查看日志

# => without save_and_open_page
09:04:24 - INFO - Spork server for RSpec, Test::Unit successfully started

09:04:24 - INFO - Guard::RSpec is running
09:04:24 - INFO - Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/myuser/.rvm/gems/ruby-1.9.3-p392/gems/guard-rspec-2.5.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec"]...
................

Finished in 4.1 seconds
16 examples, 0 failures


Randomized with seed 50331

Done.

# => with save_and_open_page, no .... are shown anymore
09:04:29 - INFO - Guard is now watching at '/Users/myuser/coding/myproject'
09:04:39 - INFO - Running: spec/features/registration/registration_process_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/myuser/.rvm/gems/ruby-1.9.3-p392/gems/guard-rspec-2.5.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/features/registration/registration_process_spec.rb"]...
Done.

# => without save_and_open_page, also no .... anymore (after restart it works again)
[1] guard(main)> Running tests with args ["--drb", "-f", "progress", "-r", "/Users/myuser/.rvm/gems/ruby-1.9.3-p392/gems/guard-rspec-2.5.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/features/registration/registration_process_spec.rb"]...
Done.

    # => here i added some errors into my code... still no error message shown...
[1] guard(main)> Running tests with args ["--drb", "-f", "progress", "-r", "/Users/myuser/.rvm/gems/ruby-1.9.3-p392/gems/guard-rspec-2.5.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/features/registration/registration_process_spec.rb"]...
Done.

# only works again after restarting spork

有什么建议吗?

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3 capybara spork


【解决方案1】:

不知何故,您的STDOUT 被其他缓冲区所取代。因此,Capybara 向 STDOUT 写入的任何内容都会被忽略或在其他地方消耗。

尝试以下方法:

# Add global before/after blocks
before :each do
  @old_stdout, @old_stderr = STDOUT, STDERR
end

after :each do
  STDOUT,  STDERR  = @old_stdout, @old_stderr

  # Some gems use $stdout and $stderr, instead of STDOUT and STDERR, replace those too
  $stdout, $stderr = @old_stdout, @old_stderr
end

Capybara 的 save_and_open_page 使用 Launchy gem。所以我相信STDOUTSTDERR 会被这些宝石中的一个存根。

【讨论】:

  • 嗯,我会进一步调查这个...谢谢你的回答,当我知道更多时,我会标记它!
  • @Lichtamberg ,我尝试了上述解决方案,但无法正常工作。你能解决这个问题吗?我将不胜感激任何指针..
  • 非常感谢,这对我有用..但我不断收到警告 `warning: already initialized constant STDOUT` 。因此,我将 after(:each) 更改为 STDOUT ||= @old_stdout STDERR ||= @old_stderr 现在,警告和通知已经停止。这是正确的做法吗?
  • @lnreddy,所以我不确定测试是使用$stdout 还是STDOUT,因此我将两者都包含在解决方案中。尝试查看它是否仅适用于更改 $stdout,如果有效,您甚至不需要重置 STDOUT 变量
【解决方案2】:

我在http://blog.mikecordell.com/2013/08/14/guard-and-capybara's-save_and_open_page.html 找到了所描述问题的真正解决方案。特别感谢此解决方案的实际作者。

只需添加:

RSpec.configure do |config|
  config.before(:each) do
    @old_stdout, @old_stderr = STDOUT, STDERR
  end

  config.after(:each) do
    $stdout, $stderr = @old_stdout, @old_stderr
  end
end

spec_helper.rb

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2013-11-16
    相关资源
    最近更新 更多