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

This commit is contained in:
David Heinemeier Hansson 2016-02-20 18:41:33 +01:00
parent eb65f04fb2
commit e768913141
3 changed files with 19 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* 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

View File

@ -38,7 +38,7 @@ module ActiveSupport
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

View File

@ -41,6 +41,20 @@ class BenchmarkableTest < ActiveSupport::TestCase
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) { }