rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Compound expectations of OutputMatcher do not receive captured output

Open wspurgin opened this issue 2 years ago • 11 comments

Compound expectations with OutputMatcher not receiving captured output

:heart: Thanks for any help on this in advance - it might just be user error.

When constructing a compound expectation using the output matcher, I'd expect something like this to pass:

expect { puts "foo\nbar" }.to(output(/foo/).to_stdout & output(/bar/).to_stdout)
# or to use the `.and` style
expect { puts "foo\nbar" }.to output(/foo/).to_stdout
                          .and output(/bar/).to_stdout

Instead a failure is reported:

Failure/Error: expect { puts "foo\nbar" }.to(output(/foo/).to_stdout & output(/bar/).to_stdout)
       expected block to output /bar/ to stdout, but output nothing

Running them individually passes however:

expect { puts "foo\nbar" }.to output(/foo/).to_stdout
expect { puts "foo\nbar" }.to output(/bar/).to_stdout
# => Passes

Your environment

  • Ruby version: 3.1.0
  • rspec-expectations version: 3.12.0

Steps to reproduce

expect { puts "foo\nbar" }.to(output(/foo/).to_stdout & output(/bar/).to_stdout)
# or to use the `.and` style
expect { puts "foo\nbar" }.to output(/foo/).to_stdout
                          .and output(/bar/).to_stdout

Expected behavior

I'd expect that compound statements would both use the same STDOUT output and match against that

Actual behavior

Failure/Error: expect { puts "foo\nbar" }.to(output(/foo/).to_stdout & output(/bar/).to_stdout)
       expected block to output /bar/ to stdout, but output nothing

wspurgin avatar Dec 02 '22 15:12 wspurgin