How to access stdout or stderr in a Capybara integ

2019-05-05 18:05发布

问题:

I'm trying to debug some Capybara integration tests and running into an unexpected issue. When I set a breakpoint inside a Capybara test, I can inspect variables, but i can not call puts or $stdout.puts or $stderr.puts. To understand what I mean look at this output:

(rdb:1) "foo"
"foo"
(rdb:1) puts "foo"
nil

Presumably this is because Capybara captures both stderr and stdout as part of its standard operation in order to keep things quiet with selenium drivers, etc. I get that, but the problem is that inspecting strings in the ruby debugger escapes newlines, which makes it impossible to read long formatted strings like HTML.

How can I get a reference to the active terminal to output something for debugging purposes using IO#puts?

回答1:

Have you taken a look at the Capybara-cli maybe that will help doing debuging that way.

https://github.com/vspy/capybara-console