Sha256: d3cb6e870ed0c93b1e503d0e6e6ec874bf94c9b333cd798d6744a0e0bffa379a

Contents?: true

Size: 1.98 KB

Versions: 38

Compression:

Stored size: 1.98 KB

Contents

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

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

  def teardown
    controller.logger.send(:clear_buffer)
  end

  def controller
    logger = ActiveSupport::BufferedLogger.new(StringIO.new)
    logger.auto_flushing = false
    @controller ||= Struct.new(:logger).new(logger)
  end

  def test_without_block
    assert_raise(LocalJumpError) { benchmark }
    assert buffer.empty?
  end

  def test_defaults
    i_was_run = false
    benchmark { i_was_run = true }
    assert i_was_run
    assert_last_logged
  end

  def test_with_message
    i_was_run = false
    benchmark('test_run') { i_was_run = true }
    assert i_was_run
    assert_last_logged 'test_run'
  end

  def test_with_message_and_deprecated_level
    i_was_run = false

    assert_deprecated do
      benchmark('debug_run', :debug) { i_was_run = true }
    end

    assert i_was_run
    assert_last_logged 'debug_run'
  end

  def test_within_level
    controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
    benchmark('included_debug_run', :level => :debug) { }
    assert_last_logged 'included_debug_run'
  end

  def test_outside_level
    controller.logger.level = ActiveSupport::BufferedLogger::ERROR
    benchmark('skipped_debug_run', :level => :debug) { }
    assert_no_match(/skipped_debug_run/, buffer.last)
  ensure
    controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
  end

  def test_without_silencing
    benchmark('debug_run', :silence => false) do
      controller.logger.info "not silenced!"
    end

    assert_equal 2, buffer.size
  end

  def test_with_silencing
    benchmark('debug_run', :silence => true) do
      controller.logger.info "silenced!"
    end

    assert_equal 1, buffer.size
  end


  private
    def buffer
      controller.logger.send(:buffer)
    end
  
    def assert_last_logged(message = 'Benchmarking')
      assert_match(/^#{message} \(.*\)$/, buffer.last)
    end
end

Version data entries

38 entries across 37 versions & 12 rubygems

Version Path
elkinsware-erubis_rails_helper-0.6.0 test/template/benchmark_helper_test.rb
elkinsware-erubis_rails_helper-0.6.1 test/template/benchmark_helper_test.rb
elkinsware-erubis_rails_helper-0.9.0 test/template/benchmark_helper_test.rb
elkinsware-erubis_rails_helper-0.9.1 test/template/benchmark_helper_test.rb
elkinsware-erubis_rails_helper-0.9.5 test/template/benchmark_helper_test.rb
ghazel-erubis_rails_helper-0.9.5 test/template/benchmark_helper_test.rb
mitio-erubis_rails_helper-1.0.1 test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.2.4 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.2 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.1.8 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.1.7 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.1.6 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
radiantcms-couchrest_model-0.1.5 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
erubis_rails_helper-1.0.0 test/template/benchmark_helper_test.rb
radiant-0.8.2 vendor/rails/actionpack/test/template/benchmark_helper_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/actionpack/test/template/benchmark_helper_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/actionpack/pkg/actionpack-2.3.3/test/template/benchmark_helper_test.rb