From d4f2ac06d28a6688b36d16458b48cc6503956cfe Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Thu, 12 Oct 2023 02:29:19 -0600 Subject: [PATCH] capture and assert warning in test suite --- spec/lib/docbookrx/docbookrx_spec.rb | 8 +++++--- spec/support/extensions/helpers.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 spec/support/extensions/helpers.rb diff --git a/spec/lib/docbookrx/docbookrx_spec.rb b/spec/lib/docbookrx/docbookrx_spec.rb index 5e701fa..b8545fd 100644 --- a/spec/lib/docbookrx/docbookrx_spec.rb +++ b/spec/lib/docbookrx/docbookrx_spec.rb @@ -474,9 +474,11 @@ | Dam |=== EOS - output = Docbookrx.convert input - - expect(output).to include(expected) + capture_stdio do |_, stderr| + output = Docbookrx.convert input + expect(output).to include(expected) + expect(stderr.string).to include('5 columns specified in table \'Control parameters\', but only 4 headers') + end end it 'should convert nested program listings in listitems correctly' do diff --git a/spec/support/extensions/helpers.rb b/spec/support/extensions/helpers.rb new file mode 100644 index 0000000..6979961 --- /dev/null +++ b/spec/support/extensions/helpers.rb @@ -0,0 +1,15 @@ +require 'stringio' + +module RSpec::Support::Helpers + def capture_stdio + old_stdout, $stdout = $stdout, StringIO.new + old_stderr, $stderr = $stderr, StringIO.new + yield $stdout, $stderr + ensure + $stdout, $stderr = old_stdout, old_stderr + end +end + +RSpec.configure do |config| + config.include RSpec::Support::Helpers +end