aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/benchmark_helper_test.rb
blob: 1bdda22959c109cc0934491124ab4133ca6a9ebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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