test/test_rcron.rb in rcron-0.1.1 vs test/test_rcron.rb in rcron-0.1.2

- old
+ new

@@ -1,30 +1,42 @@ -$LOAD_PATH << "." +$LOAD_PATH.unshift File.dirname(__FILE__) require 'helper' class TestRcron < Test::Unit::TestCase - class LogStream + class FakeLogger def initialize @lines = [] end - def puts str - $stdout.puts str + def log header, str + $stdout.puts header + ' ' + str @lines << str end + def info msg + log '[I]', msg + end + + def warn msg + log '[W]', msg + end + + def error msg + log '[E]', msg + end + def count pat @lines.select { |e| e =~ pat }.count end end def test_empty_q rcron = RCron.new - log = LogStream.new - rcron.start(log) + logger = FakeLogger.new + rcron.start(logger) - assert_equal 1, log.count(/completed/) + assert_equal 1, logger.count(/completed/) end def test_blockless rcron = RCron.new assert_raise(ArgumentError) { rcron.q('test task 1', "* * * * *") } @@ -106,11 +118,11 @@ end def test_non_exclusive puts 'non exclusive' counter = 0 - log = LogStream.new + log = FakeLogger.new rcron = RCron.new truth = true rcron.q('non-exclusive', '* * * * *') do |task| counter += 1 truth &&= counter == task.threads.length @@ -125,11 +137,11 @@ end def test_exclusive puts 'exclusive' counter = 0 - log = LogStream.new + log = FakeLogger.new rcron = RCron.new rcron.q('exclusive', '* * * * *', :exclusive => true) do |task| counter += 1 sleep 60 * 2 + 10 task.dq @@ -159,10 +171,10 @@ "*/2 * * * * task number 2", "*/3 * * * * task number 3"].join($/), rcron.tab end def test_exception - log = LogStream.new + log = FakeLogger.new rcron = RCron.new rcron.q('Exceptional', '* * * * *') do |task| task.dq sleep 80 raise Exception.new("this-error")