-
-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
output matcher: add as_tty
method to make the simulated stream behave as a TTY
#1459
Conversation
I think its reasonable to respect the original |
Thanks for such a fast feedback 😄
Of course 🤦 (see failed build). I had only ran the tests locally and hadn't even thought of that. -- Putting it all together, I will:
Once again, thank you! |
What I just pushed is without implementing the |
I just pushed an attempt at implementing |
as_tty
method to make the simulated stream behave as a TTY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thank you.
Can you add a couple of examples covering those parts where it raises when as_tty is not compatible with “in any process”?
‘output’ calls can be chained, too? output('foo').to_stdout.and output('bar').to_stdout.as_tty. Will it work as expected? Should as_tty be specified for both?
I am sorry, Iam from my phone, does it even chain properly, or just my wishful thinking?
* Error out when using it with *_from_any_process * Chain matchers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, a few suggestions
Co-authored-by: Jon Rowe <mail@jonrowe.co.uk>
Co-authored-by: Jon Rowe <mail@jonrowe.co.uk>
Great! Thanks! |
The problem
I have an app which prints some output only if the standard output is a TTY. I'd say it's a relative standard practice:
Currently, this can't be tested with
expect { ... }.to output(...).to_stdout
because$stdout
is replaced with aStringIO
, which always returnsfalse
for.tty?
, so the code never prints.If this is a problem RSpec wants to fix (I guess you can argue that it's an antipattern and should be implemented in a different way), this PR does it.
The fix
$stdout
is still replaced with aStringIO
and the matcher works the same, but some specific methods are called on the original stream. I only added.tty?
because that's my usecase, but I guess there are other methods for which this could make sense (now or in the future).I haven't contributed to RSpec before so I'm not familiar with coding standards, style, etc., so I appreciate any feedback, particularly on the following problem: I had to add an exception for the libraries allowed to be loaded fordelegate
(in fact there is another one forstringio
for the same reason). Is this acceptable? If not, there are at least two alternatives I could implement:Do some trick to requiredelegate
and define the class on runtime only onceoutput
has been called. This is already done for thetempfile
require, although it would be a bit trickier than that because the class needs to be defined to.Not useSimpleDelegator
and implement the behavior usingmethod_missing
.Is any of these approaches preferred?Update: the description above no longer mathes the implementation, which I've changed according to the feedback received. It's simpler now and doesn't need such a long explanation 😅