Sha256: 41d2a81844551bbb3a2679c9d726b2f6f6685305d0990fe677e5fb0ee9f5b049

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

# encoding: UTF-8

require 'spec_helper'

include ProgressReporters

describe ProgressReporters::ProgressReporter do
  before(:each) do
    collector  # call to instantiate collector
  end

  context 'with a linear reporter' do
    let(:reporter) { ProgressReporter.new }
    let(:collector) { LinearCollector.new(reporter) }

    context 'with a linear task' do
      let(:task) { LinearTask.new(reporter) }

      it 'reports progress' do
        task.execute(10)

        collector.progress_notifications.each_with_index do |notification, idx|
          expect(notification.quantity).to eq(idx)
          expect(notification.total).to eq(10)
          expect(notification.percentage).to eq(10 * idx)
        end

        expect(collector.complete_notification).to_not be_nil
      end

      it 'should only report progress every other time when step is set to 2' do
        reporter.set_step(2)
        task.execute(10)

        expect(collector.progress_notifications.size).to eq(5)

        collector.progress_notifications.each_with_index do |notification, idx|
          expect(notification.quantity).to eq(idx * 2)
          expect(notification.total).to eq(10)
          expect(notification.percentage).to eq(10 * (idx * 2))
        end
      end

      it 'should be able to reset itself' do
        task.execute(10)
        expect(reporter.last_count).to eq(9)
        reporter.reset
        expect(reporter.last_count).to eq(0)
      end
    end

    context 'with a nil reporter' do
      let(:reporter) { NilProgressReporter.new }
      let(:collector) { LinearCollector.new(reporter) }

      context 'with a linear task' do
        let(:task) { LinearTask.new(reporter) }

        it 'should not actually report any progress' do
          task.execute(10)
          expect(collector.progress_notifications).to be_empty
          expect(collector.complete_notification).to be_nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
progress-reporters-1.0.0 spec/progress_reporter_spec.rb