Sha256: bb8b6fb7c7556ff3196d258e20d8bff233b914f36da1cfb255c5546ed3f6a57c

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require "spec_helper"

describe Tabs::Metrics::Task do

  let(:metric) { Tabs.create_metric("foo", "task") }
  let(:now) { Time.utc(2000, 1, 1, 0, 0) }
  let(:token_1) { "2gd7672gjh3" }
  let(:token_2) { "17985jh34gj" }
  let(:token_3) { "27f98fhgh1x" }

  describe ".start" do

  end

  describe ".complete" do

    it "raises an UnstartedTaskMetricError if the metric has not yet been started" do
      lambda { metric.complete("foobar") }.should raise_error(Tabs::Metrics::Task::UnstartedTaskMetricError)
    end

  end

  describe ".stats" do

    it "returns the expected value" do
      Timecop.freeze(now)
      metric.start(token_1)
      metric.start(token_2)
      Timecop.freeze(now + 2.minutes)
      metric.complete(token_1)
      metric.start(token_3)
      Timecop.freeze(now + 3.minutes)
      metric.complete(token_3)
      stats = metric.stats((now - 5.minutes)..(now + 5.minutes), :minute)
      expect(stats).to eq(
        {
          started: 3,
          completed: 2,
          completed_within_period: 2,
          completion_rate: 0.18,
          average_completion_time: 1.5
        }
      )
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tabs-0.6.3 spec/lib/tabs/task_spec.rb
tabs-0.6.2 spec/lib/tabs/task_spec.rb
tabs-0.6.1 spec/lib/tabs/task_spec.rb