From 3ed0c4829acc705058463f2d4a91209a7fe9812e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 6 Dec 2016 16:44:04 +0200 Subject: [PATCH] log test --- lib/logging.rb | 7 ++++++- test/lib/test_all.rb | 1 + test/lib/test_log.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/lib/test_all.rb create mode 100644 test/lib/test_log.rb diff --git a/lib/logging.rb b/lib/logging.rb index 1a19f213..79dc249f 100644 --- a/lib/logging.rb +++ b/lib/logging.rb @@ -18,7 +18,7 @@ module Logging module Methods def log return @logger if @logger - @logger = Logger.new STDOUT + @logger = Logger.new log_stream @logger.progname = self.name.split("::").last @logger.datetime_format = '%M:%S' @logger.level = Logger::INFO @@ -42,5 +42,10 @@ module Logging raise "unknown log level #{l}" end end + + private + def log_stream + STDOUT + end end end diff --git a/test/lib/test_all.rb b/test/lib/test_all.rb new file mode 100644 index 00000000..c506daf8 --- /dev/null +++ b/test/lib/test_all.rb @@ -0,0 +1 @@ +require_relative "log_test" diff --git a/test/lib/test_log.rb b/test/lib/test_log.rb new file mode 100644 index 00000000..3516fccf --- /dev/null +++ b/test/lib/test_log.rb @@ -0,0 +1,34 @@ +require_relative '../helper' + +class MemLogger + def self.stream + @stream + end + def self.log_stream + @stream = StringIO.new + end + include Logging +end + +class LoggerTest < MiniTest::Test + + def setup + @logger = MemLogger.new + end + + def test_debug + assert @logger.log.debug "Debug" + end + def test_info + assert @logger.log.info "Info" + assert MemLogger.stream.string.include? "Info" + end + def test_warn + assert @logger.log.warn "Warn" + assert MemLogger.stream.string.include? "Warn" + end + def test_error + assert @logger.log.error "Error" + assert MemLogger.stream.string.include? "Error" + end +end