13

spork で rspec テストを実行すると、カピバラの 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

助言がありますか?

4

2 に答える 2

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

Capybarasave_and_open_pageは Launchy gem を使用しています。だから私は、これらの宝石の1つにスタブされているSTDOUTと信じています。STDERR

于 2013-05-27T08:06:33.920 に答える
0

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-09-20T23:25:34.790 に答える