Sha256: 2d6e58083e3d61231643c3708d46f0f6c1eeeeea536deb14ac707e751441e4be

Contents?: true

Size: 1.54 KB

Versions: 39

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'
require 'puppet/util/profiler'

describe Puppet::Util::Profiler::AroundProfiler do
  let(:child) { TestAroundProfiler.new() }
  let(:profiler) { Puppet::Util::Profiler::AroundProfiler.new }

  before :each do
    profiler.add_profiler(child)
  end

  it "returns the value of the profiled segment" do
    retval = profiler.profile("Testing", ["testing"]) { "the return value" }

    retval.should == "the return value"
  end

  it "propagates any errors raised in the profiled segment" do
    expect do
      profiler.profile("Testing", ["testing"]) { raise "a problem" }
    end.to raise_error("a problem")
  end

  it "makes the description and the context available to the `start` and `finish` methods" do
    profiler.profile("Testing", ["testing"]) { }

    child.context.should == "Testing"
    child.description.should == "Testing"
  end

  it "calls finish even when an error is raised" do
    begin
      profiler.profile("Testing", ["testing"]) { raise "a problem" }
    rescue
      child.context.should == "Testing"
    end
  end

  it "supports multiple profilers" do
    profiler2 = TestAroundProfiler.new
    profiler.add_profiler(profiler2)
    profiler.profile("Testing", ["testing"]) {}

    child.context.should == "Testing"
    profiler2.context.should == "Testing"
  end

  class TestAroundProfiler
    attr_accessor :context, :description

    def start(description, metric_id)
      description
    end

    def finish(context, description, metric_id)
      @context = context
      @description = description
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.6 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.5 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.4 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.3 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.2 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.1 spec/unit/util/profiler/around_profiler_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/profiler/around_profiler_spec.rb