Fixed tests (and the weird assumption that no logger would mean that the code wasnt run)

上级 56861af7
......@@ -23,7 +23,7 @@ module BenchmarkHelper
def benchmark(message = "Benchmarking", level = :info)
if controller.logger
real = Benchmark.realtime { yield }
controller.logger.send level, "#{message} (#{'%.5f' % real})"
controller.logger.send(level, "#{message} (#{'%.5f' % real})")
else
yield
end
......
......@@ -16,32 +16,20 @@ def method_missing(method, *args)
end
end
def setup
@logger = MockLogger.new
end
def test_without_logger_or_block
@logger = nil
assert_nothing_raised { benchmark }
def controller
@controller ||= Struct.new(:logger).new(MockLogger.new)
end
def test_without_block
assert_raise(LocalJumpError) { benchmark }
assert @logger.logged.empty?
end
def test_without_logger
@logger = nil
i_was_run = false
benchmark { i_was_run = true }
assert !i_was_run
assert controller.logger.logged.empty?
end
def test_defaults
i_was_run = false
benchmark { i_was_run = true }
assert i_was_run
assert 1, @logger.logged.size
assert 1, controller.logger.logged.size
assert_last_logged
end
......@@ -49,7 +37,7 @@ def test_with_message
i_was_run = false
benchmark('test_run') { i_was_run = true }
assert i_was_run
assert 1, @logger.logged.size
assert 1, controller.logger.logged.size
assert_last_logged 'test_run'
end
......@@ -57,13 +45,13 @@ def test_with_message_and_level
i_was_run = false
benchmark('debug_run', :debug) { i_was_run = true }
assert i_was_run
assert 1, @logger.logged.size
assert 1, controller.logger.logged.size
assert_last_logged 'debug_run', :debug
end
private
def assert_last_logged(message = 'Benchmarking', level = :info)
last = @logger.logged.last
last = controller.logger.logged.last
assert 2, last.size
assert_equal level, last.first
assert 1, last[1].size
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册