Sha256: 69b9923f1483bcbd1b47976d82f2d0f9e4006e3ae06de3b6417be65255d610fc

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# encoding: UTF-8

require 'spec_helper'

include ProgressReporters

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

  context 'with a metered reporter' do
    let(:reporter) { MeteredProgressReporter.new }
    let(:collector) { MeteredCollector.new(reporter) }

    context 'with a staged task' do
      let(:task) { MeteredTask.new(reporter) }

      it 'reports progress and calculates the average rate' do
        reporter.set_calc_type(:avg)
        task.execute(10, 0.5, 0)

        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(idx * 10)
          expect(notification.rate).to eq(idx == 0 ? 0 : 2.0)
        end
      end

      it 'reports progress and calculates the moving average rate' do
        reporter.set_calc_type(:moving_avg)
        reporter.set_window_size(2)
        task.execute(10, 1, 1)

        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(idx * 10)

          rate = case idx
            when 0 then 0.0
            when 1 then 1.0
            else
              (1 / (0.5 + (idx - 1))).round(2)
          end

          expect(notification.rate).to eq(rate)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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