Sha256: e697c79ec9ffcdb83d262d2af2e27ec5d37f5ee793aa48b9b6a2e44343821d73

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

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

describe ProgressBar::WithProgress do
  context "with block" do
    let!(:bar){ ProgressBar.new }

    before{
      Range.include ProgressBar::WithProgress
      allow(ProgressBar).to receive(:new){ |max| bar.max = max; bar }
    }

    it "should set max and increment on each iteration" do
      (1..20).each_with_progress do |i|
        break if i > 10
      end
      expect(bar.max).to eq 20
      expect(bar.count).to eq 10
    end
  end

  context "without block" do
    let!(:bar){ ProgressBar.new }

    before{
      Range.include ProgressBar::WithProgress
      allow(ProgressBar).to receive(:new){ |max| bar.max = max; bar }
    }

    it "should give Enumerator" do
      enum = (1..20).each_with_progress
      expect(enum).to be_kind_of(Enumerator)
      expect(bar.max).to eq 20
      expect(bar.count).to eq 0

      res = enum.map{ |i| i + 1 }
      expect(res).to eq (2..21).to_a
      expect(bar.count).to eq 20
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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