Class: StdOutErrLoggerTest
- Defined in:
- lib/std_out_err_logger.rb
Instance Method Summary collapse
-
#setup ⇒ Object
Redirect STDOUT and STDERR to capture them for assertions.
- #teardown ⇒ Object
- #test_initialize_with_file ⇒ Object
- #test_initialize_without_file ⇒ Object
- #test_logging_error ⇒ Object
- #test_logging_info ⇒ Object
- #test_logging_unknown_severity ⇒ Object
- #test_logging_warning ⇒ Object
- #test_logging_with_array ⇒ Object
- #test_logging_with_block ⇒ Object
Instance Method Details
#setup ⇒ Object
Redirect STDOUT and STDERR to capture them for assertions
55 56 57 58 59 60 |
# File 'lib/std_out_err_logger.rb', line 55 def setup @original_stdout = $stdout @original_stderr = $stderr $stdout = StringIO.new $stderr = StringIO.new end |
#teardown ⇒ Object
62 63 64 65 |
# File 'lib/std_out_err_logger.rb', line 62 def teardown $stdout = @original_stdout $stderr = @original_stderr end |
#test_initialize_with_file ⇒ Object
73 74 75 76 77 78 |
# File 'lib/std_out_err_logger.rb', line 73 def test_initialize_with_file Tempfile.open do |file| logger = StdOutErrLogger.new(file.path) assert_equal file.path, logger.file end end |
#test_initialize_without_file ⇒ Object
67 68 69 70 71 |
# File 'lib/std_out_err_logger.rb', line 67 def test_initialize_without_file logger = StdOutErrLogger.new assert_nil logger.file assert_equal Logger::DEBUG, logger.level end |
#test_logging_error ⇒ Object
94 95 96 97 98 99 |
# File 'lib/std_out_err_logger.rb', line 94 def test_logging_error logger = StdOutErrLogger.new logger.error('Error message') assert_empty $stdout.string assert_equal "Error message\n", $stderr.string end |
#test_logging_info ⇒ Object
80 81 82 83 84 85 |
# File 'lib/std_out_err_logger.rb', line 80 def test_logging_info logger = StdOutErrLogger.new logger.info('Info message') assert_equal "Info message\n", $stdout.string assert_empty $stderr.string end |
#test_logging_unknown_severity ⇒ Object
113 114 115 116 117 118 |
# File 'lib/std_out_err_logger.rb', line 113 def test_logging_unknown_severity logger = StdOutErrLogger.new logger.add(Logger::UNKNOWN, 'Unknown severity message') assert_empty $stdout.string assert_equal "Unknown severity message\n", $stderr.string end |
#test_logging_warning ⇒ Object
87 88 89 90 91 92 |
# File 'lib/std_out_err_logger.rb', line 87 def test_logging_warning logger = StdOutErrLogger.new logger.warn('Warning message') assert_empty $stdout.string assert_equal "Warning message\n", $stderr.string end |
#test_logging_with_array ⇒ Object
101 102 103 104 105 |
# File 'lib/std_out_err_logger.rb', line 101 def test_logging_with_array logger = StdOutErrLogger.new logger.info(['Message line 1', 'Message line 2']) assert_equal "Message line 1\nMessage line 2\n", $stdout.string end |
#test_logging_with_block ⇒ Object
107 108 109 110 111 |
# File 'lib/std_out_err_logger.rb', line 107 def test_logging_with_block logger = StdOutErrLogger.new logger.info { 'Block message' } assert_equal "Block message\n", $stdout.string end |