1 require 'abstract_unit'
2 require 'action_view/helpers/benchmark_helper'
4 class BenchmarkHelperTest
< ActionView
::TestCase
5 tests ActionView
::Helpers::BenchmarkHelper
14 def method_missing(method
, *args
)
15 @logged << [method
, args
]
20 @controller ||= Struct
.new(:logger).new(MockLogger
.new
)
23 def test_without_block
24 assert_raise(LocalJumpError
) { benchmark
}
25 assert controller
.logger
.logged
.empty
?
30 benchmark
{ i_was_run
= true }
32 assert
1, controller
.logger
.logged
.size
38 benchmark('test_run') { i_was_run
= true }
40 assert
1, controller
.logger
.logged
.size
41 assert_last_logged
'test_run'
44 def test_with_message_and_level
46 benchmark('debug_run', :debug) { i_was_run
= true }
48 assert
1, controller
.logger
.logged
.size
49 assert_last_logged
'debug_run', :debug
53 def assert_last_logged(message
= 'Benchmarking', level
= :info)
54 last
= controller
.logger
.logged
.last
56 assert_equal level
, last
.first
57 assert
1, last
[1].size
58 assert last
[1][0] =~
/^#{message} \(.*\)$/