Sha256: f96537a5abe203f51c05c9c5aff6691ed386aee6e7d903266dd86bc67050aaab

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe DispatchRider::Handlers::Base do
  class NoProcessImplemented < DispatchRider::Handlers::Base
  end

  class ProcessImplemented < DispatchRider::Handlers::Base
    def process(options)
      "good job"
    end
  end
  
  class ProcessWithImmediateRetry < DispatchRider::Handlers::Base
    def process(options)
      raise "I have failed!"
    end
    
    def retry_timeout; :immediate; end
  end
  
  class ProcessWithTenSecondRetry < DispatchRider::Handlers::Base
    def process(options)
      raise "I have failed!"
    end
    
    def retry_timeout; 10*60; end
  end

  describe "#do_process" do
    let(:message){ double(:message, subject: 'some_message', body: { 'guid' => DispatchRider::Debug::PUBLISHER_MESSAGE_GUID }) }

    context "when class doesn't implement process" do
      let(:handler){ NoProcessImplemented.new }

      example do
        expect {
          handler.do_process(message)
        }.to raise_exception NotImplementedError, "Method 'process' not overridden in subclass!"
      end
    end

    context "when the class does implement process" do
      let(:handler){ ProcessImplemented.new }

      example do
        expect {
          handler.do_process(message)
        }.to_not raise_exception
      end

      example do
        handler.do_process(message).should == "good job"
      end
    end
    
    context "when the class wants to immediately retry" do
      let(:handler) { ProcessWithImmediateRetry.new }
      
      example do
        message.should_receive(:return_to_queue)
        
        expect {
          handler.do_process(message)
        }.to raise_exception "I have failed!"
      end
    end
    
    context "when the class wants to retry in 10 seconds" do
      let(:handler) { ProcessWithTenSecondRetry.new }
      
      example do
        message.should_receive(:extend_timeout).with(10*60)
        
        expect {
          handler.do_process(message)
        }.to raise_exception "I have failed!"
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dispatch-rider-1.5.3 spec/lib/dispatch-rider/handlers/base_spec.rb
dispatch-rider-1.5.2 spec/lib/dispatch-rider/handlers/base_spec.rb
dispatch-rider-1.5.1 spec/lib/dispatch-rider/handlers/base_spec.rb
dispatch-rider-1.5.0 spec/lib/dispatch-rider/handlers/base_spec.rb
dispatch-rider-1.4.2 spec/lib/dispatch-rider/handlers/base_spec.rb