log test
This commit is contained in:
parent
fe203b55f1
commit
3ed0c4829a
@ -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
|
||||
|
1
test/lib/test_all.rb
Normal file
1
test/lib/test_all.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "log_test"
|
34
test/lib/test_log.rb
Normal file
34
test/lib/test_log.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user