2018-10-02 17:02:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2018-10-02 17:02:27 -04:00
|
|
|
require "active_support/logger_silence"
|
|
|
|
require "logger"
|
|
|
|
|
|
|
|
class LoggerSilenceTest < ActiveSupport::TestCase
|
|
|
|
class MyLogger < ::Logger
|
2018-10-03 19:23:49 -04:00
|
|
|
include ActiveSupport::LoggerSilence
|
2018-10-02 17:02:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@io = StringIO.new
|
|
|
|
@logger = MyLogger.new(@io)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "#silence silences the log" do
|
|
|
|
@logger.silence(Logger::ERROR) do
|
|
|
|
@logger.info("Foo")
|
|
|
|
end
|
|
|
|
@io.rewind
|
|
|
|
|
|
|
|
assert_empty @io.read
|
|
|
|
end
|
|
|
|
|
|
|
|
test "#debug? is true when setting the temporary level to Logger::DEBUG" do
|
|
|
|
@logger.level = Logger::INFO
|
|
|
|
|
|
|
|
@logger.silence(Logger::DEBUG) do
|
|
|
|
assert_predicate @logger, :debug?
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_predicate @logger, :info?
|
|
|
|
end
|
|
|
|
end
|