test/appenders/test_io.rb in logging-0.8.0 vs test/appenders/test_io.rb in logging-0.9.0

- old
+ new

@@ -1,6 +1,5 @@ -# $Id$ require File.join(File.dirname(__FILE__), %w[.. setup]) module TestLogging module TestAppenders @@ -34,14 +33,28 @@ @appender.close assert_raise(RuntimeError) {@appender.append event} end def test_append_error + # setup an internal logger to capture error messages from the IO + # appender + log = StringIO.new + Logging::Logger[Logging::Appenders::IO].add_appenders( + Logging::Appenders::IO.new('__internal_io', log) + ) + Logging::Logger[Logging::Appenders::IO].level = 'all' + + + # close the string IO object so we get an error @sio.close event = ::Logging::LogEvent.new('TestLogger', @levels['warn'], [1, 2, 3, 4], false) - assert_raise(IOError) {@appender.append event} + @appender.append event + + log.seek 0 + assert_equal "ERROR Logging::Appenders::IO : <IOError> not opened for writing", log.readline.strip + assert_equal false, @appender.closed? assert_equal 5, @appender.level end def test_close @@ -74,11 +87,25 @@ @appender.close assert_raise(RuntimeError) {@appender << 'message'} end def test_concat_error + # setup an internal logger to capture error messages from the IO + # appender + log = StringIO.new + Logging::Logger[Logging::Appenders::IO].add_appenders( + Logging::Appenders::IO.new('__internal_io', log) + ) + Logging::Logger[Logging::Appenders::IO].level = 'all' + + # close the string IO object so we get an error @sio.close - assert_raise(IOError) {@appender << 'oopsy'} + @appender << 'oopsy' + + log.seek 0 + assert_equal "ERROR Logging::Appenders::IO : <IOError> not opened for writing", log.readline.strip + + # and the appender does not close itself assert_equal false, @appender.closed? assert_equal 5, @appender.level end def test_flush