Sha256: d350b9f03fe0498cc40248577ed54458773b7987f89299d969a49ac6840140e3

Contents?: true

Size: 1.85 KB

Versions: 18

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe DispatchRider::Publisher::Base do

  class DummyPublisher < DispatchRider::Publisher::Base
    destinations [:sns_message_queue, :file_system_queue]
    subject "Loud Cheering"

    def self.publish(cheer)
      new.publish(cheer)
    end
  end

  class DummyCustomPublisher < DispatchRider::Publisher::Base
    destinations :sqs_message_queue
    subject "Ferocious Tigers!"

    def self.publish(body, publisher)
      new(publisher).publish(body)
    end
  end

  describe ".default_publisher" do
    example do
      expect(described_class.default_publisher).to be_a(DispatchRider::Publisher)
    end
  end

  describe ".publish" do
    context "in the base class" do
      example do
        expect {
          described_class.publish
        }.to raise_error NotImplementedError
      end
    end

    context "in a derived class with publish implemented" do
      let(:message) do
        {
          destinations: [:sns_message_queue, :file_system_queue],
          message: {
            subject: "Loud Cheering",
            body: {
              "bla" => "WOOOOOOOO!",
            }
          }
        }
      end

      example do
        expect(DummyPublisher.default_publisher).to receive(:publish).with(message)
        DummyPublisher.publish "bla" => "WOOOOOOOO!"
      end
    end

    context "in a derived class with publish implemented and a custom publisher" do
      let(:message) do
        {
          destinations: [:sqs_message_queue],
          message: {
            subject: "Ferocious Tigers!",
            body: {
              "bla" => "RAAAAAWWWWW!",
            },
          }
        }
      end

      let(:publisher) { double(:publisher) }

      example do
        expect(publisher).to receive(:publish).with(message)
        DummyCustomPublisher.publish({"bla" => "RAAAAAWWWWW!"}, publisher)
      end
    end
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dispatch-rider-1.9.0 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.6 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.5 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.4 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.3 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.2 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.1 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.8.0 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.7.2 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.7.1 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.7.0 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.6.2 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.6.1 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.6.0 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.5.3 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.5.2 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.5.1 spec/lib/dispatch-rider/publisher/base_spec.rb
dispatch-rider-1.5.0 spec/lib/dispatch-rider/publisher/base_spec.rb