Muting test suites since 2014
Usage
Tired of seeing garbage printed to the screen during your test suite? Would you
like to prove that your fancy custom Logger is actually working? Mute
is here
to help!
Mute
can be used to mute and capture standard out or standard error in your
Ruby program. This is most useful in tests where output should be tested, not
displayed.
To capture standard out:
require 'mute'
output = Mute::IO.capture_stdout do
puts 'Hello World!'
end
puts output
#=> Hello World!
To capture standard error:
require 'mute'
output = Mute::IO.capture_stderr do
$stderr.puts 'Oops!'
end
puts output
#=> Oops!
Use it in your test suite to verify output:
require 'mute'
describe MyLogger do
it 'prints the message to standard out' do
message = 'Hello World!'
output = Mute::IO.capture_stdout do
MyLogger.new.print message
end
expect(output).to include message
end
end
Or just mute stdout completely for the whole test suite:
# spec/spec_helper.rb
require 'mute'
Mute::IO.capture_stdout
Installation
$ gem install mute
Contributing
Please see the Contributing Document
Changelog
Please see the Changelog Document
License
Copyright (C) 2014 Chris Hunt, MIT License