diff options
author | Ryan Davis <ryand-ruby@zenspider.com> | 2019-06-05 19:46:59 -0700 |
---|---|---|
committer | Ryan Davis <ryand-ruby@zenspider.com> | 2019-06-06 13:36:29 -0700 |
commit | d0dc22161e5d6da10581855b9a61fa277f291801 (patch) | |
tree | 8e33eb4253590f4ea632cdd12f332cd5ed0a8411 /spec/mixlib | |
parent | 9b2d51adfff3d6dda5e8fc0ca1d5c0eb40e7a393 (diff) | |
download | mixlib-log-d0dc22161e5d6da10581855b9a61fa277f291801.tar.gz |
Use $stdout instead of STDOUT for the default logdev.
This makes it testable using minitest/rspec IO
assertions/expectations. STDOUT/STDERR should only be used to restore
$stdout/$stderr if something goes haywire. The globals should be used
for everyday use.
Also bolstered an IO test to prevent the output from going to the
rspec result output.
Signed-off-by: Ryan Davis <zenspider@chef.io>
Diffstat (limited to 'spec/mixlib')
-rw-r--r-- | spec/mixlib/log_spec.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb index bbf290b..b58c4e2 100644 --- a/spec/mixlib/log_spec.rb +++ b/spec/mixlib/log_spec.rb @@ -142,9 +142,14 @@ RSpec.describe Mixlib::Log do end it "should pass other method calls directly to logger" do - Logit.level = :debug - expect(Logit).to be_debug - expect { Logit.debug("Gimme some sugar!") }.to_not raise_error + expect do + # this needs to be inside of the block because the level setting + # is causing the init, which grabs $stderr before rspec replaces + # it for output testing. + Logit.level = :debug + expect(Logit).to be_debug + Logit.debug("Gimme some sugar!") + end.to output(/DEBUG: Gimme some sugar!/).to_stdout end it "should pass add method calls directly to logger" do @@ -158,6 +163,7 @@ RSpec.describe Mixlib::Log do it "should default to STDOUT if init is called with no arguments" do logger_mock = Struct.new(:formatter, :level).new + # intentionally STDOUT to avoid unfailable test expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock) Logit.init end @@ -203,6 +209,7 @@ RSpec.describe Mixlib::Log do end it "should return nil from its logging methods" do + # intentionally STDOUT to avoid unfailable test expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object } Logit.init |