mirror of https://github.com/rails/rails
Make benchmark('something', silence: true) actually work
This commit is contained in:
parent
eb65f04fb2
commit
e768913141
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) { }
|
||||
|
|
Loading…
Reference in New Issue