Sha256: d0b4c8514671ebfbe401fb9d86399fd450ba79281b09b2644017188ea6971e3f

Contents?: true

Size: 1003 Bytes

Versions: 12

Compression:

Stored size: 1003 Bytes

Contents

require "pact_broker/events/subscriber"
require "pact_broker/events/publisher"

module PactBroker
  module Events
    describe "#subscribe" do
      class TestPublisher
        include PactBroker::Events::Publisher

        def broadcast_foo(id)
          broadcast(:foo, id )
        end
      end

      class TestListener
        attr_reader :events

        def initialize
          @events = []
        end

        def foo(params)
          @events << params
        end
      end

      it "allows overlapping subscriptions" do
        listener_1 = TestListener.new
        listener_2 = TestListener.new
        PactBroker::Events.subscribe(listener_1) do
          TestPublisher.new.broadcast_foo(1)
          PactBroker::Events.subscribe(listener_2) do
            TestPublisher.new.broadcast_foo(2)
          end
          TestPublisher.new.broadcast_foo(3)
        end

        expect(listener_1.events).to eq [1, 2, 3]
        expect(listener_2.events).to eq [2]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.89.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.88.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.87.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.86.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.85.1 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.85.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.84.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.83.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.82.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.81.0 spec/lib/pact_broker/events/subscriber_spec.rb
pact_broker-2.80.0 spec/lib/pact_broker/events/subscriber_spec.rb