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
57 58 59 60 61 62 |
# File 'lib/std_out_err_logger.rb', line 57 def setup @original_stdout = $stdout @original_stderr = $stderr $stdout = StringIO.new $stderr = StringIO.new end |
#teardown ⇒ Object
64 65 66 67 |
# File 'lib/std_out_err_logger.rb', line 64 def teardown $stdout = @original_stdout $stderr = @original_stderr end |
#test_initialize_with_file ⇒ Object
75 76 77 78 79 80 |
# File 'lib/std_out_err_logger.rb', line 75 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
69 70 71 72 73 |
# File 'lib/std_out_err_logger.rb', line 69 def test_initialize_without_file logger = StdOutErrLogger.new assert_nil logger.file assert_equal Logger::DEBUG, logger.level end |
#test_logging_error ⇒ Object
96 97 98 99 100 101 |
# File 'lib/std_out_err_logger.rb', line 96 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
82 83 84 85 86 87 |
# File 'lib/std_out_err_logger.rb', line 82 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
115 116 117 118 119 120 |
# File 'lib/std_out_err_logger.rb', line 115 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
89 90 91 92 93 94 |
# File 'lib/std_out_err_logger.rb', line 89 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
103 104 105 106 107 |
# File 'lib/std_out_err_logger.rb', line 103 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
109 110 111 112 113 |
# File 'lib/std_out_err_logger.rb', line 109 def test_logging_with_block logger = StdOutErrLogger.new logger.info { "Block message" } assert_equal "Block message\n", $stdout.string end |