Sha256: aae3cc6697caf39226b3c503a1b6e4ebd583b98047819d6aa491f448ab88b73f

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))

describe "ProgressBar rate output" do
  let(:progress_bar) { ProgressBar.new(100, :rate) }

  before do
    Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
    progress_bar
    Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
  end

  subject { progress_bar.to_s }

  describe "at count=0" do
    before do
      progress_bar.count = 0
    end

    it { should == "[  0.00/s]" }
  end

  describe "at count=50" do
    before do
      progress_bar.count = 50
    end

    it { should == "[  5.00/s]" }
  end

  describe "at count=100" do
    before do
      progress_bar.count = 100
    end

    it { should == "[ 10.00/s]" }
  end

  describe "with a shorter max" do
    let(:progress_bar) { ProgressBar.new(42, :rate) }

    before do
      Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
      progress_bar.count = 21
      Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
    end

    it { should == "[ 2.10/s]" }
  end

  describe "with a longer max" do
    let(:progress_bar) { ProgressBar.new(4242, :rate) }

    before do
      Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
      progress_bar.count = 21
      Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
    end

    it { should == "[   2.10/s]" }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
progress_bar-1.3.3 spec/rate_spec.rb
progress_bar-1.3.2 spec/rate_spec.rb