save_and_open_page and spork, spork is loosing test suite / output
Asked Answered
I

2

13

When i run my rspec tests with spork, every time i use capybara's save_and_open_page, spork is loosing the test suite.. or maybe doesnt output anything anymore...

See the log

# => 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

Any suggestions?

Incendiarism answered 9/4, 2013 at 7:10 Comment(1)
I created an issue on github: github.com/sporkrb/spork/issues/226Incendiarism
R
0

I found the real solution for described problem at http://blog.mikecordell.com/2013/08/14/guard-and-capybara's-save_and_open_page.html. Special thanks to the actual author of this solution.

Simply add:

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

to the spec_helper.rb

Ritenuto answered 20/9, 2014 at 23:25 Comment(0)
H
1

Somehow your STDOUT is getting replaced with some other buffer. So whatever is being written by Capybara to STDOUT is getting ignored or consumed somewhere else.

Try the following:

# 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's save_and_open_page uses Launchy gem. So I believe the STDOUT and STDERR are getting stubbed in one of these gems.

Husain answered 27/5, 2013 at 8:6 Comment(4)
hm i will investiate this further... thank you for your answer, i will mark it when i know more!Incendiarism
@Lichtamberg ,I tried the above solution and couldn't get it to work. Were you able to get around this issue ? I would appreciate any pointers..Aldebaran
Thanks a lot, this works for me ..but I keep getting a warning ` warning: already initialized constant STDOUT` . So , I changed the after(:each) to STDOUT ||= @old_stdout STDERR ||= @old_stderr Now, the warnings and notices have stopped. Is this the right way to do it ?Aldebaran
@lnreddy, so I was not sure whether the tests are using $stdout or STDOUT hence I included both in the solution. Try to see if it works only with changing $stdout, if that works you don't even need to reset the STDOUT variableHusain
R
0

I found the real solution for described problem at http://blog.mikecordell.com/2013/08/14/guard-and-capybara's-save_and_open_page.html. Special thanks to the actual author of this solution.

Simply add:

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

to the spec_helper.rb

Ritenuto answered 20/9, 2014 at 23:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.