Class: TestLogger

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/webconsole/logger/test/tc_logger.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



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

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

#teardownObject



64
65
66
67
# File 'lib/webconsole/logger/test/tc_logger.rb', line 64

def teardown
  WebConsole::Tests::Helper::quit
  assert(!WebConsole::Tests::Helper::is_running, "The application should not be running.")
end

#test_loggerObject



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
# File 'lib/webconsole/logger/test/tc_logger.rb', line 69

def test_logger
  test_count = 0

  # Test Error
  message = "Testing log error"
  @logger.error(message)
  sleep WebConsole::Tests::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("error", test_class, "The classes should match")
  result_count = @test_view_helper.number_of_log_messages
  test_count += 1
  assert_equal(test_count, result_count, "The number of log messages should match")

  # Test Message
  message = "Testing log message"
  @logger.info(message)
  sleep WebConsole::Tests::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, "The number of log messages should match")

  # Test Only Error Prefix
  message = WebConsole::Logger::ERROR_PREFIX.rstrip # Note the trailing whitespace is trimmed
  @logger.info(message)
  sleep WebConsole::Tests::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, "The number of log messages should match")

  # Test Only Message Prefix
  message = WebConsole::Logger::MESSAGE_PREFIX.rstrip # Note the trailing whitespace is trimmed
  @logger.info(message)
  sleep WebConsole::Tests::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, "The number of log messages should match")

  # Test Blank Spaces
  @logger.info("  \t")
  sleep WebConsole::Tests::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")

  # Test Empty String
  @logger.info("")
  sleep WebConsole::Tests::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")

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

  # 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 WebConsole::Tests::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, "The number of log messages should match")
end

#test_long_inputObject



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

def test_long_input
  message = %q(
Line 1

Line 2
Line 3
)
  @logger.info(message)
  sleep WebConsole::Tests::TEST_PAUSE_TIME # 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 { |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