Skip to content

Commit

Permalink
Merge pull request #54 from zenspider/zenspider/remove_all_warnings
Browse files Browse the repository at this point in the history
Resolve all warnings emitted during testing
  • Loading branch information
tas50 authored Jul 22, 2019
2 parents 7e9373f + 616f57e commit 8721333
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/mixlib/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ module Mixlib
module Log

include Logging
@logger, @loggers = nil

def reset!
@logger ||= nil
@loggers ||= []
close!
@logger, @loggers = nil, nil
@logger = @loggers = nil
@metadata = {}
end

Expand All @@ -46,7 +47,7 @@ def loggers
# and creates a new one if it doesn't yet exist
##
def logger
@logger || init
@logger ||= init
end

# Sets the log device to +new_log_device+. Any additional loggers
Expand Down Expand Up @@ -170,7 +171,7 @@ def method_missing(method_symbol, *args, &block)

def logger_for(*opts)
if opts.empty?
Mixlib::Log::Logger.new(STDOUT)
Mixlib::Log::Logger.new($stdout)
elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) }
opts.first
else
Expand All @@ -190,6 +191,7 @@ def loggers_to_close
# via public API. In order to reduce amount of impact and
# handle only File type log devices I had to use this method
# to get access to it.
next unless logger.instance_variable_defined?(:"@logdev")
next unless (logdev = logger.instance_variable_get(:"@logdev"))
loggers_to_close << logger if logdev.filename
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mixlib/log/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def trace?; @level <= TRACE; end
#
# +logdev+::
# The log device. This is a filename (String) or IO object (typically
# +STDOUT+, +STDERR+, or an open file).
# +$stdout+, +$stderr+, or an open file).
# +shift_age+::
# Number of old log files to keep, *or* frequency of rotation (+daily+,
# +weekly+ or +monthly+).
Expand Down
19 changes: 13 additions & 6 deletions spec/mixlib/log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,36 @@ def #{method_name}(message)
end

it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do
expect(lambda { Logit.level = :the_roots }).to raise_error(ArgumentError)
expect { Logit.level = :the_roots }.to raise_error(ArgumentError)
end

it "should raise an ArgumentError if you try and set the level to something strange using the method form" do
expect(lambda { Logit.level(:the_roots) }).to raise_error(ArgumentError)
expect { Logit.level(:the_roots) }.to raise_error(ArgumentError)
end

it "should pass other method calls directly to logger" do
Logit.level = :debug
expect(Logit).to be_debug
expect(lambda { 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
logdev = StringIO.new
Logit.init(logdev)
Logit.level = :debug
expect(Logit).to be_debug
expect(lambda { Logit.add(Logger::DEBUG, "Gimme some sugar!") }).to_not raise_error
expect { Logit.add(Logger::DEBUG, "Gimme some sugar!") }.to_not raise_error
expect(logdev.string).to match(/Gimme some sugar/)
end

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
Expand Down Expand Up @@ -203,6 +209,7 @@ def #{method_name}(message)
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

Expand Down

0 comments on commit 8721333

Please sign in to comment.