Sha256: ff2f51b40060b34a052ea9f66ffcab05b1c48f4e48108bbf145d340ee6e8a753

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

Stored size: 1.39 KB

Contents

require 'abstract_unit'
require 'action_view/helpers/benchmark_helper'

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

  class MockLogger
    attr_reader :logged

    def initialize
      @logged = []
    end

    def method_missing(method, *args)
      @logged << [method, args]
    end
  end

  def controller
    @controller ||= Struct.new(:logger).new(MockLogger.new)
  end

  def test_without_block
    assert_raise(LocalJumpError) { benchmark }
    assert controller.logger.logged.empty?
  end

  def test_defaults
    i_was_run = false
    benchmark { i_was_run = true }
    assert i_was_run
    assert 1, controller.logger.logged.size
    assert_last_logged
  end

  def test_with_message
    i_was_run = false
    benchmark('test_run') { i_was_run = true }
    assert i_was_run
    assert 1, controller.logger.logged.size
    assert_last_logged 'test_run'
  end

  def test_with_message_and_level
    i_was_run = false
    benchmark('debug_run', :debug) { i_was_run = true }
    assert i_was_run
    assert 1, controller.logger.logged.size
    assert_last_logged 'debug_run', :debug
  end

  private
    def assert_last_logged(message = 'Benchmarking', level = :info)
      last = controller.logger.logged.last
      assert 2, last.size
      assert_equal level, last.first
      assert 1, last[1].size
      assert last[1][0] =~ /^#{message} \(.*\)$/
    end
end

Version data entries

15 entries across 14 versions & 6 rubygems

Version Path
radiant-0.7.2 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/pkg/actionpack-2.2.2/test/template/benchmark_helper_test.rb
actionpack-2.2.3 test/template/benchmark_helper_test.rb
actionpack-2.1.2 test/template/benchmark_helper_test.rb
actionpack-2.2.2 test/template/benchmark_helper_test.rb
actionpack-2.1.0 test/template/benchmark_helper_test.rb
actionpack-2.1.1 test/template/benchmark_helper_test.rb
antfarm-0.3.0 rails/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
antfarm-0.4.0 rails/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
eactionpack-2.1.2 test/template/benchmark_helper_test.rb
radiant-0.7.0 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiant-0.7.1 vendor/rails/actionpack/test/template/benchmark_helper_test.rb