Skip to content

Commit

Permalink
capture and assert warning in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Oct 12, 2023
1 parent 45ad516 commit d4f2ac0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/lib/docbookrx/docbookrx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/support/extensions/helpers.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d4f2ac0

Please sign in to comment.