mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make benchmark('something', silence: true) actually work
This commit is contained in:
parent
eb65f04fb2
commit
e768913141
3 changed files with 19 additions and 1 deletions
|
@ -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 a new issue