Skip to content

Commit

Permalink
Merge pull request #4375 from lest/benchmark-helper
Browse files Browse the repository at this point in the history
add benchmark helper that works in erb
  • Loading branch information
josevalim committed Jan 7, 2012
2 parents 686f94e + 904e544 commit b5dceaf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 2 additions & 3 deletions actionpack/lib/action_view/helpers.rb
@@ -1,12 +1,11 @@
require 'active_support/benchmarkable'

module ActionView #:nodoc:
module Helpers #:nodoc:
extend ActiveSupport::Autoload

autoload :ActiveModelHelper
autoload :AssetTagHelper
autoload :AtomFeedHelper
autoload :BenchmarkHelper
autoload :CacheHelper
autoload :CaptureHelper
autoload :ControllerHelper
Expand All @@ -33,10 +32,10 @@ module Helpers #:nodoc:
extend SanitizeHelper::ClassMethods
end

include ActiveSupport::Benchmarkable
include ActiveModelHelper
include AssetTagHelper
include AtomFeedHelper
include BenchmarkHelper
include CacheHelper
include CaptureHelper
include ControllerHelper
Expand Down
13 changes: 13 additions & 0 deletions actionpack/lib/action_view/helpers/benchmark_helper.rb
@@ -0,0 +1,13 @@
require 'active_support/benchmarkable'

module ActionView
module Helpers
module BenchmarkHelper
include ActiveSupport::Benchmarkable

def benchmark(*)
capture { super }
end
end
end
end
24 changes: 24 additions & 0 deletions actionpack/test/template/benchmark_helper_test.rb
@@ -0,0 +1,24 @@
require 'abstract_unit'
require 'stringio'

class BenchmarkHelperTest < ActionView::TestCase
include RenderERBUtils
tests ActionView::Helpers::BenchmarkHelper

def test_output_in_erb
output = render_erb("Hello <%= benchmark do %>world<% end %>")
expected = 'Hello world'
assert_equal expected, output
end

def test_returns_value_from_block
assert_equal 'test', benchmark { 'test' }
end

def test_default_message
log = StringIO.new
self.stubs(:logger).returns(Logger.new(log))
benchmark {}
assert_match(log.rewind && log.read, /Benchmarking \(\d+.\d+ms\)/)
end
end

0 comments on commit b5dceaf

Please sign in to comment.