Sha256: 43d0d228cb2a99429a2db17ed2ab00c34e4e1fdf6b0ace0463a8cdea30ec3823

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

RSpec.describe 'Batch' do
  module Sidekiq
    module Batch
      class Status
      end
    end
  end

  load File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/rspec/sidekiq/batch.rb'))

  describe 'NullObject' do
    describe '#method_missing' do
      it 'returns itself' do
        batch = Sidekiq::Batch.new
        expect(batch.non_existent_method).to eq(batch)
      end
    end
  end

  describe 'NullBatch' do
  end

  describe 'NullStatus' do
    let(:batch) {  Sidekiq::Batch.new }

    subject { batch.status }

    describe '#total' do
      it 'returns 0 when no jobs' do
        expect(subject.total).to eq(0)
      end

      it 'returns 1 when 1 job' do
        batch.jobs do
          TestWorker.perform_async('5')
        end

        expect(subject.total).to eq(1)
      end
    end

    describe '#failures' do
      it 'returns 0' do
        expect(subject.failures).to eq(0)
      end
    end

    describe '#bid' do
      it 'returns a bid' do
        expect(subject.bid).to_not be_nil
      end
    end

    describe '#join' do
      class MyCallback
        def on_event(status, options); end
      end

      before(:each) do
        batch.on(:event, MyCallback, my_arg: 42)
      end

      it 'executes callbacks' do
        expect_any_instance_of(MyCallback).to receive(:on_event).with(subject, { my_arg: 42 })
        subject.join
      end
    end

    describe '#initialize' do
      it 'uses default argument values when none are provided' do
        expect { Sidekiq::Batch::Status.new }.to_not raise_error
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-sidekiq-3.0.3 spec/rspec/sidekiq/batch_spec.rb
rspec-sidekiq-3.0.2 spec/rspec/sidekiq/batch_spec.rb
rspec-sidekiq-3.0.1 spec/rspec/sidekiq/batch_spec.rb
rspec-sidekiq-3.0.0 spec/rspec/sidekiq/batch_spec.rb