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



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

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

#teardownObject



60
61
62
63
# File 'lib/repla/logger/test/tc_logger.rb', line 60

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

#test_loggerObject



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
150
151
152
153
154
155
156
157
158
# File 'lib/repla/logger/test/tc_logger.rb', line 65

def test_logger
  test_count = 0

  # Test Error
  message = 'Testing log error'
  @logger.error(message)
  test_message = nil
  Repla::Test.block_until do
    test_message = @test_log_helper.last_log_message
    message == test_message
  end
  assert_equal(message, test_message)
  test_class = @test_log_helper.last_log_class
  assert_equal('error', test_class)
  result_count = @test_log_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test Message
  message = 'Testing log message'
  @logger.info(message)
  test_message = nil
  Repla::Test.block_until do
    test_message = @test_log_helper.last_log_message
    message == test_message
  end
  assert_equal(message, test_message)
  test_class = @test_log_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_log_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)
  test_message = nil
  Repla::Test.block_until do
    test_message = @test_log_helper.last_log_message
    message == test_message
  end
  assert_equal(message, test_message)
  test_class = @test_log_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_log_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)
  test_message = nil
  Repla::Test.block_until do
    test_message = @test_log_helper.last_log_message
    message == test_message
  end
  assert_equal(message, test_message)
  test_class = @test_log_helper.last_log_class
  assert_equal('message', test_class)
  result_count = @test_log_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count)

  # Test empty string is ignored
  # Test blank space is ignored
  # Note this uses the same `message` from the last test
  @logger.info('')
  @logger.info("  \t")
  sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
  test_message = @test_log_helper.last_log_message
  assert_equal(message, test_message)
  test_class = @test_log_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_log_helper.last_log_message
  # assert_equal(message, test_message, "The messages should match")
  # test_class = @test_log_helper.last_log_class
  # assert_equal("message", test_class, "The classes should match")
  # result_count = @test_log_helper.number_of_log_messages
  # test_count += 1
  # assert_equal(test_count, result_count)
end

#test_long_inputObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/repla/logger/test/tc_logger.rb', line 160

def test_long_input
  message = '
Line 1

Line 2
Line 3
'
  lines = 3
  @logger.info(message)
  result_count = nil
  Repla::Test.block_until do
    result_count = @test_log_helper.number_of_log_messages
    result_count == lines
  end
  assert_equal(result_count, lines)

  (1..lines).each do |i|
    result = @test_log_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