Sha256: e19f0be3faec4d51b7cc18a76dde23a4c29d0179baf47e98fe62d87537a9327e

Contents?: true

Size: 1.37 KB

Versions: 39

Compression:

Stored size: 1.37 KB

Contents

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

describe Puppet::Util::Profiler do
  let(:profiler) { TestProfiler.new() }

  it "supports adding profilers" do
    subject.add_profiler(profiler)
    subject.current[0].should == profiler
  end

  it "supports removing profilers" do
    subject.add_profiler(profiler)
    subject.remove_profiler(profiler)
    subject.current.length.should == 0
  end

  it "supports clearing profiler list" do
    subject.add_profiler(profiler)
    subject.clear
    subject.current.length.should == 0
  end

  it "supports profiling" do
    subject.add_profiler(profiler)
    subject.profile("hi", ["mymetric"]) {}
    profiler.context[:metric_id].should == ["mymetric"]
    profiler.context[:description].should == "hi"
    profiler.description.should == "hi"
  end

  it "supports profiling without a metric id" do
    subject.add_profiler(profiler)
    subject.profile("hi") {}
    profiler.context[:metric_id].should == nil
    profiler.context[:description].should == "hi"
    profiler.description.should == "hi"
  end

  class TestProfiler
    attr_accessor :context, :metric, :description

    def start(description, metric_id)
      {:metric_id => metric_id,
       :description => description}
    end

    def finish(context, description, metric_id)
      @context = context
      @metric_id = metric_id
      @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_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.6 spec/unit/util/profiler_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.5 spec/unit/util/profiler_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.4 spec/unit/util/profiler_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.3 spec/unit/util/profiler_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.2 spec/unit/util/profiler_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/profiler_spec.rb
puppet-3.8.1 spec/unit/util/profiler_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/profiler_spec.rb