Class: ScrubytLoggingTestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/scrubyt/logging.rb

Defined Under Namespace

Classes: FauxOutputStream

Instance Method Summary collapse

Instance Method Details

#setup_logger_with_faux_output_stream!(*logger_args) ⇒ Object



113
114
115
116
117
118
# File 'lib/scrubyt/logging.rb', line 113

def setup_logger_with_faux_output_stream!(*logger_args)
  @stream = FauxOutputStream.new
  logger = Scrubyt::Logger.new(*logger_args)
  logger.output_stream = @stream
  Scrubyt.logger = logger
end

#test_simple_messages_are_output_correctlyObject



125
126
127
128
129
130
131
132
# File 'lib/scrubyt/logging.rb', line 125

def test_simple_messages_are_output_correctly
  setup_logger_with_faux_output_stream!

  Scrubyt.log :ACTION, 'i just did something'

  assert_equal 1, @stream.size
  assert_equal '[ACTION] i just did something', @stream.first
end

#test_that_loggers_can_be_limited_to_specfied_message_levelsObject



143
144
145
146
147
148
149
150
151
# File 'lib/scrubyt/logging.rb', line 143

def test_that_loggers_can_be_limited_to_specfied_message_levels
  setup_logger_with_faux_output_stream! :ERROR

  Scrubyt.log :ACTION, 'i just did something'
  Scrubyt.log :ERROR, 'something bad happened'

  assert_equal 1, @stream.size
  assert_equal '[ERROR] something bad happened', @stream.first
end

#test_that_logging_works_with_nil_loggerObject



120
121
122
123
# File 'lib/scrubyt/logging.rb', line 120

def test_that_logging_works_with_nil_logger
  Scrubyt.logger = nil
  assert_nothing_raised { Scrubyt.log(:ERROR, 'message') }
end

#test_that_multiline_messages_are_output_correctlyObject



134
135
136
137
138
139
140
141
# File 'lib/scrubyt/logging.rb', line 134

def test_that_multiline_messages_are_output_correctly
  setup_logger_with_faux_output_stream!

  Scrubyt.log :ERROR, ['something bad happened', 'dear oh dear']

  assert_equal 1, @stream.size
  assert_equal "[ERROR] something bad happened\n        dear oh dear", @stream.first
end