Make benchmark('something', silence: true) actually work

上级 eb65f04f
* Make `benchmark('something', silence: true)` actually work
*DHH*
* Add `#on_weekday?` method to `Date`, `Time`, and `DateTime`.
`#on_weekday?` returns `true` if the receiving date/time does not fall on a Saturday
......
......@@ -38,7 +38,7 @@ def benchmark(message = "Benchmarking", options = {})
options[:level] ||= :info
result = nil
ms = Benchmark.ms { result = options[:silence] ? silence { yield } : yield }
ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
logger.send(options[:level], '%s (%.1fms)' % [ message, ms ])
result
else
......
......@@ -41,6 +41,20 @@ def test_with_message
assert_last_logged 'test_run'
end
def test_with_silence
assert_difference 'buffer.count', +2 do
benchmark('test_run') do
logger.info "SOMETHING"
end
end
assert_difference 'buffer.count', +1 do
benchmark('test_run', silence: true) do
logger.info "NOTHING"
end
end
end
def test_within_level
logger.level = ActiveSupport::Logger::DEBUG
benchmark('included_debug_run', :level => :debug) { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册