Class: TestLogger

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/repla/logger/test/tc_logger.rb

Overview

Test logger

Instance Method Summary collapse

Instance Method Details

#setupObject



52
53
54
55
56
# File 'lib/repla/logger/test/tc_logger.rb', line 52

def setup
  @logger = Repla::Logger.new
  @logger.show
  @test_view_helper = LogHelper.new(@logger.window_id, @logger.view_id)
end

#teardownObject



58
59
60
61
# File 'lib/repla/logger/test/tc_logger.rb', line 58

def teardown
  window = Repla::Window.new(@logger.window_id)
  window.close
end

#test_loggerObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/repla/logger/test/tc_logger.rb', line 63

def test_logger
  test_count = 0

  # Test Error
  message = 'Testing log error'
  @logger.error(message)
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('error', test_class)
  result_count = @test_view_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test Message
  message = 'Testing log message'
  @logger.info(message)
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_view_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test Only Error Prefix
  # Note the trailing whitespace is trimmed
  message = Repla::Logger::ERROR_PREFIX.rstrip
  @logger.info(message)
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_view_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test Only Message Prefix
  # Note the trailing whitespace is trimmed
  message = Repla::Logger::MESSAGE_PREFIX.rstrip
  @logger.info(message)
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_view_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test Blank Spaces
  @logger.info("  \t")
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('message', test_class)

  # Test Empty String
  @logger.info('')
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_view_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_view_helper.last_log_class
  assert_equal('message', test_class)

  # TODO: Also add the following tests the `Log.replabundle`

  # Test Whitespace
  # White space to the left should be preserved, whitespace to the right
  # should be removed This test fails because retrieving the `innerText`
  # doesn't preserve whitepace.

  # message = "\t Testing log message"
  # @logger.info(message + "\t ")
  # sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  # test_message = @test_view_helper.last_log_message
  # assert_equal(message, test_message, "The messages should match")
  # test_class = @test_view_helper.last_log_class
  # assert_equal("message", test_class, "The classes should match")
  # result_count = @test_view_helper.number_of_log_messages
  # test_count += 1
  # assert_equal(test_count, result_count)
end

#test_long_inputObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/repla/logger/test/tc_logger.rb', line 151

def test_long_input
  message = '
Line 1

Line 2
Line 3
'
  @logger.info(message)
  sleep Repla::Test::TEST_PAUSE_TIME * 2 # Pause for output to be processed
  result_count = @test_view_helper.number_of_log_messages
  assert_equal(result_count, 3, 'The number of log messages should match')

  (1..3).each do |i|
    result = @test_view_helper.log_message_at_index(i - 1)
    test_result = "Line #{i}"
    assert_equal(result,
                 test_result,
                 'The number of log messages should match')
  end
end