Sha256: 7055ed3474628412a978e4e9ea7dfc28100adc70bcb0c67ba3f72eb59f392706

Contents?: true

Size: 1.97 KB

Versions: 21

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe RequestLogAnalyzer::Tracker::Duration do

  describe '#report' do

    before(:each) do
      @tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :value => :duration)
      @tracker.prepare
    end

    it "should generate a report without errors when one category is present" do
      @tracker.update(request(:category => 'a', :duration => 0.2))
      lambda { @tracker.report(mock_output) }.should_not raise_error
    end

    it "should generate a report without errors when no category is present" do
      lambda { @tracker.report(mock_output) }.should_not raise_error
    end

    it "should generate a report without errors when multiple categories are present" do
      @tracker.update(request(:category => 'a', :duration => 0.2))
      @tracker.update(request(:category => 'b', :duration => 0.2))
      lambda { @tracker.report(mock_output) }.should_not raise_error
    end

    it "should generate a YAML output" do
      @tracker.update(request(:category => 'a', :duration => 0.2))
      @tracker.update(request(:category => 'b', :duration => 0.2))
      @tracker.to_yaml_object.keys.should =~ ['a', 'b']
      @tracker.to_yaml_object['a'].should include(:min => 0.2, :hits => 1, :max => 0.2, :mean => 0.2, :sum => 0.2, :sum_of_squares => 0.0)
      @tracker.to_yaml_object['b'].should include(:min => 0.2, :hits => 1, :max => 0.2, :mean => 0.2, :sum => 0.2, :sum_of_squares => 0.0)
    end
  end
  
  describe '#display_value' do
    before(:each) { @tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :value => :duration) }
    
    it "should only display seconds when time < 60" do
      @tracker.display_value(33.12).should == '33.12s'
    end

    it "should display minutes and wholeseconds when time > 60" do
      @tracker.display_value(63.12).should == '1m03s'
    end

    it "should display minutes and wholeseconds when time > 60" do
      @tracker.display_value(3601.12).should == '1h00m01s'
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
request-log-analyzer-1.12.5 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.12.4 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.12.3 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.12.2 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.12.1 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.12.0 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.11.1 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.11.0 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.10.1 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.10.0 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.10 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.9 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.8 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.7 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.6 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.5 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.4 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.3 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.2 spec/unit/tracker/duration_tracker_spec.rb
request-log-analyzer-1.9.1 spec/unit/tracker/duration_tracker_spec.rb