I have some rspec tests to check the output of a command.
Previously, I was mocking the entire $stdout.string and I could do this:
expect($stdout.string).to include 'DEBUG -- : Request Headers:'
expect($stdout.string).to include 'Bearer foo'
expect($stdout.string).to include 'Some other thing'
I'm refactoring this to switch to the rspec output(arg).to_stdout method.
However, looking at the docs, it only seems to allow giving a string or a regex:
RSpec.describe "output.to_stdout matcher" do
specify { expect { print('foo') }.to output.to_stdout }
specify { expect { print('foo') }.to output('foo').to_stdout }
specify { expect { print('foo') }.to output(/foo/).to_stdout }
I tried chaining expectations and it didn't work:
expect { print 'foo bar baz' }.to output(/foo/).to_stdout.and output(/bar/).to_stdout.and output(/baz/).to_stdout
Gives result:
Failure/Error: expect { print 'foo bar baz' }.to output(/foo/).to_stdout.and output(/bar/).to_stdout.and output(/baz/).to_stdout
expected block to output /bar/ to stdout, but output nothing
...and:
expected block to output /baz/ to stdout, but output nothing
Is there a way to give an array of expected strings?