test/test_logging.rb in logging-2.2.2 vs test/test_logging.rb in logging-2.3.0
- old
+ new
@@ -9,12 +9,12 @@
def setup
super
@levels = ::Logging::LEVELS
@lnames = ::Logging::LNAMES
- @fn = File.join(TMP, 'test.log')
- @glob = File.join(TMP, '*.log')
+ @fn = File.join(@tmpdir, 'test.log')
+ @glob = File.join(@tmpdir, '*.log')
end
def test_backtrace
assert_equal true, ::Logging.backtrace
@@ -251,8 +251,33 @@
def test_version
assert_match %r/\d+\.\d+\.\d+/, ::Logging.version
end
- end # class TestLogging
-end # module TestLogging
+ class Failer
+ class WriteError < StandardError ; end
+ def self.write(*args)
+ raise WriteError.new("Oh noooooo")
+ end
+ end
+ def test_error_handling
+ logger = ::Logging.logger Failer, 2, 100
+ logger.appenders.first.level = :debug
+
+ # No errors are raised by default
+ logger.fatal 'this is a debug message'
+ # Always reset the level; we disable appenders that raise by setting them
+ # to :off
+ logger.appenders.first.level = :debug
+
+ begin
+ Logging.raise_errors = true
+ assert_raises Failer::WriteError do
+ logger.fatal 'this fails because the file descriptor is closed'
+ end
+ ensure
+ Logging.raise_errors = false
+ end
+ end
+ end
+end