Sha256: 1df9f74154fd569b20c45cfc4e5763f43d65d8cf2bb9e353cb91ebfeea40e4a8

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

class SourceSubscriber
  include Reactor::Subscribable

  def self.fire_worker(event)
    :method_called
  end
end

class FailingEventWorker < Reactor::Workers::EventWorker
end

class MyEventWorker < Reactor::Workers::EventWorker
  self.source = SourceSubscriber
  self.action = :fire_worker
  self.delay  = 0
  self.deprecated = false
end

class MyBlockWorker < Reactor::Workers::EventWorker
  self.source = SourceSubscriber
  self.action = lambda { |event| :block_ran }
  self.delay  = 0
  self.deprecated = false
end

class MyDelayedWorker < Reactor::Workers::EventWorker
  self.source = SourceSubscriber
  self.action = :fire_worker
  self.delay  = 1 # seconds
  self.deprecated = false
end

describe Reactor::Workers::EventWorker do
  let(:event_name) { :fire_worker }
  let(:event_data) { Hash[my_event_data: true] }

  it_behaves_like 'configurable subscriber worker'

  describe '#perform' do
    let(:klass) { MyEventWorker }
    subject { klass.new.perform(event_data) }

    context 'for unconfigured worker' do
      let(:klass) { FailingEventWorker }

      it 'raises an error' do
        expect { subject }.to raise_error(Reactor::UnconfiguredWorkerError)
      end
    end

    before { allow_any_instance_of(klass).to receive(:should_perform?).and_return(true) }

    it 'calls class method by symbol' do
      expect(subject).to eq(:method_called)
    end

    context 'for block workers' do
      let(:klass) { MyBlockWorker }
      it { is_expected.to eq(:block_ran) }
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reactor-2.0.1 spec/workers/event_worker_spec.rb
reactor-2.0.0 spec/workers/event_worker_spec.rb
reactor-1.0.2 spec/workers/event_worker_spec.rb
reactor-1.0.1 spec/workers/event_worker_spec.rb
reactor-1.0.0 spec/workers/event_worker_spec.rb