Skip to content

Commit 904e544

Browse files
committedJan 7, 2012
add benchmark helper that works in erb
1 parent 686f94e commit 904e544

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed
 

Diff for: ‎actionpack/lib/action_view/helpers.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
require 'active_support/benchmarkable'
2-
31
module ActionView #:nodoc:
42
module Helpers #:nodoc:
53
extend ActiveSupport::Autoload
64

75
autoload :ActiveModelHelper
86
autoload :AssetTagHelper
97
autoload :AtomFeedHelper
8+
autoload :BenchmarkHelper
109
autoload :CacheHelper
1110
autoload :CaptureHelper
1211
autoload :ControllerHelper
@@ -33,10 +32,10 @@ module Helpers #:nodoc:
3332
extend SanitizeHelper::ClassMethods
3433
end
3534

36-
include ActiveSupport::Benchmarkable
3735
include ActiveModelHelper
3836
include AssetTagHelper
3937
include AtomFeedHelper
38+
include BenchmarkHelper
4039
include CacheHelper
4140
include CaptureHelper
4241
include ControllerHelper
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'active_support/benchmarkable'
2+
3+
module ActionView
4+
module Helpers
5+
module BenchmarkHelper
6+
include ActiveSupport::Benchmarkable
7+
8+
def benchmark(*)
9+
capture { super }
10+
end
11+
end
12+
end
13+
end

Diff for: ‎actionpack/test/template/benchmark_helper_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'abstract_unit'
2+
require 'stringio'
3+
4+
class BenchmarkHelperTest < ActionView::TestCase
5+
include RenderERBUtils
6+
tests ActionView::Helpers::BenchmarkHelper
7+
8+
def test_output_in_erb
9+
output = render_erb("Hello <%= benchmark do %>world<% end %>")
10+
expected = 'Hello world'
11+
assert_equal expected, output
12+
end
13+
14+
def test_returns_value_from_block
15+
assert_equal 'test', benchmark { 'test' }
16+
end
17+
18+
def test_default_message
19+
log = StringIO.new
20+
self.stubs(:logger).returns(Logger.new(log))
21+
benchmark {}
22+
assert_match(log.rewind && log.read, /Benchmarking \(\d+.\d+ms\)/)
23+
end
24+
end

0 commit comments

Comments
 (0)