Froze rails gems
[depot.git] / vendor / rails / actionpack / test / template / benchmark_helper_test.rb
1 require 'abstract_unit'
2 require 'action_view/helpers/benchmark_helper'
3
4 class BenchmarkHelperTest < ActionView::TestCase
5 tests ActionView::Helpers::BenchmarkHelper
6
7 class MockLogger
8 attr_reader :logged
9
10 def initialize
11 @logged = []
12 end
13
14 def method_missing(method, *args)
15 @logged << [method, args]
16 end
17 end
18
19 def controller
20 @controller ||= Struct.new(:logger).new(MockLogger.new)
21 end
22
23 def test_without_block
24 assert_raise(LocalJumpError) { benchmark }
25 assert controller.logger.logged.empty?
26 end
27
28 def test_defaults
29 i_was_run = false
30 benchmark { i_was_run = true }
31 assert i_was_run
32 assert 1, controller.logger.logged.size
33 assert_last_logged
34 end
35
36 def test_with_message
37 i_was_run = false
38 benchmark('test_run') { i_was_run = true }
39 assert i_was_run
40 assert 1, controller.logger.logged.size
41 assert_last_logged 'test_run'
42 end
43
44 def test_with_message_and_level
45 i_was_run = false
46 benchmark('debug_run', :debug) { i_was_run = true }
47 assert i_was_run
48 assert 1, controller.logger.logged.size
49 assert_last_logged 'debug_run', :debug
50 end
51
52 private
53 def assert_last_logged(message = 'Benchmarking', level = :info)
54 last = controller.logger.logged.last
55 assert 2, last.size
56 assert_equal level, last.first
57 assert 1, last[1].size
58 assert last[1][0] =~ /^#{message} \(.*\)$/
59 end
60 end