From cda1c904d257ec4c48ebedec2d7023eb6a653c24 Mon Sep 17 00:00:00 2001 From: Eric Mueller Date: Sat, 18 May 2024 23:24:24 -0400 Subject: [PATCH] Add tests for compound matching on Output matchers This is the issue reported in #1391 - expecting like expect { puts "foobar" } .to output.to_stdout(/foo/) .and output.to_stdout(/bar/) fails, because the two matchers get nested, and inner matcher catches the stream write, hiding it from the outer one. --- spec/rspec/matchers/built_in/output_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/rspec/matchers/built_in/output_spec.rb b/spec/rspec/matchers/built_in/output_spec.rb index 3873013d1..9035aa095 100644 --- a/spec/rspec/matchers/built_in/output_spec.rb +++ b/spec/rspec/matchers/built_in/output_spec.rb @@ -139,6 +139,12 @@ def invalid_block }.to fail_including("expected block to not output a string starting with \"f\" to #{stream_name}, but output \"foo\"\nDiff") end end + + context "expect { ... }.to output(matcher1).#{matcher_method}.and output(matcher2).#{matcher_method}" do + it "passes if the block outputs lines to #{stream_name} matching both matchers" do + expect { print_to_stream "foo_bar" }.to matcher(/foo/).and matcher(/bar/) + end + end end module RSpec