Skip to content

Commit

Permalink
Add tests for compound matching on Output matchers
Browse files Browse the repository at this point in the history
This is the issue reported in rspec#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.
  • Loading branch information
nevinera committed Aug 18, 2024
1 parent ff04d47 commit cda1c90
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/rspec/matchers/built_in/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cda1c90

Please sign in to comment.