From e88c786f37788391a426a68fb2327138dd9b2a8b Mon Sep 17 00:00:00 2001 From: Sergio Gil Date: Thu, 16 May 2024 16:28:56 +0200 Subject: [PATCH] output matcher: add a couple of extra tests * Error out when using it with *_from_any_process * Chain matchers --- spec/rspec/matchers/built_in/output_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/rspec/matchers/built_in/output_spec.rb b/spec/rspec/matchers/built_in/output_spec.rb index a57b4693a..0dd01efd4 100644 --- a/spec/rspec/matchers/built_in/output_spec.rb +++ b/spec/rspec/matchers/built_in/output_spec.rb @@ -233,6 +233,18 @@ def print_to_stream(msg) expect { print "foo" }.to output("foo").as_tty # <- wrong call, `to_std(out|err)` is missing }.to raise_error(/can only be used with `to_stdout` or `to_stderr`/) end + + it "errors out nicely when attempting it with *_from_any_process" do + expect { + expect { print "foo" }.to output("foo").to_stdout_from_any_process.as_tty + }.to raise_error(/can only be used with `to_stdout` or `to_stderr`/) + end + + it "can be chained" do + expect { print "foo" if $stdout.tty?; $stderr.print "bar" if $stderr.tty? }. + to output("foo").to_stdout.as_tty. + and output("bar").to_stderr.as_tty + end end end end