Sha256: f66b3c5bdce13cb7d19637d713db20e6ac0c062cccf736f3339218f5b8b36802

Contents?: true

Size: 1.74 KB

Versions: 9

Compression:

Stored size: 1.74 KB

Contents

require 'test/unit'
require 'helper'
require 'webgen/logger'

class TestLogger < Test::Unit::TestCase

  def test_initialize
    l = Webgen::Logger.new(io = StringIO.new)
    assert_equal(:normal, l.verbosity)
    assert_equal(::Logger::WARN, l.level)
    assert_equal(false, l.sync)
  end

  def test_setters
    l = Webgen::Logger.new(io = StringIO.new)
    l.verbosity = :quiet
    l.level = ::Logger::DEBUG
    assert_equal(::Logger::DEBUG, l.level)
    assert_equal(:quiet, l.verbosity)
  end

  def test_log_sync
    l = Webgen::Logger.new(io = StringIO.new, true)
    l.error { 'error' }
    l.stdout { 'hallo' }
    l.warn { 'warn' }
    l.info { 'info' }
    l.debug { 'debug' }
    assert_equal("ERROR -- error\nhallo\n WARN -- warn\n", io.string)
  end

  def test_log_async
    l = Webgen::Logger.new(io = StringIO.new, false)
    l.error { 'error' }
    l.stdout { 'hallo' }
    assert_equal("hallo\n", io.string)
  end

  def test_verbosity_levels
    l = Webgen::Logger.new(io = StringIO.new)
    l.verbose { 'vrb'}
    l.stdout { 'std' }
    assert_equal("std\n", io.string)

    io.string = ''
    l.verbosity = :verbose
    l.verbose { 'vrb' }
    assert_equal("vrb\n", io.string)

    io.string = ''
    l.verbosity = :quiet
    l.stdout { 'vrb' }
    assert_equal("", io.string)
  end

  def test_debug_format
    l = Webgen::Logger.new(io = StringIO.new, true)
    l.level = ::Logger::DEBUG
    l.info('source') { 'hallo' }
    assert_equal(" INFO -- source: hallo\n", io.string)
  end

  def test_log_output
    l = Webgen::Logger.new(io = StringIO.new, true)
    l.error { 'hallo' }
    assert_equal('', l.log_output)

    l = Webgen::Logger.new(io = StringIO.new, false)
    l.error { 'hallo' }
    assert_equal("ERROR -- hallo\n", l.log_output)
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 test/test_logger.rb
gettalong-webgen-0.5.5.20081001 test/test_logger.rb
gettalong-webgen-0.5.5.20081010 test/test_logger.rb
webgen-0.5.0 test/test_logger.rb
webgen-0.5.2 test/test_logger.rb
webgen-0.5.1 test/test_logger.rb
webgen-0.5.3 test/test_logger.rb
webgen-0.5.4 test/test_logger.rb
webgen-0.5.5 test/test_logger.rb