Sha256: 44b8aeb718893d22e70dcccbb6b225b40890234fd8473abc8e030f7068dafde4

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe Mongo::Event::Publisher do

  describe '#publish' do

    let(:listeners) do
      Mongo::Event::Listeners.new
    end

    let(:klass) do
      Class.new do
        include Mongo::Event::Publisher

        def initialize(listeners)
          @event_listeners = listeners
        end
      end
    end

    let(:publisher) do
      klass.new(listeners)
    end

    let(:listener) do
      double('listener')
    end

    context 'when the event has listeners' do

      before do
        listeners.add_listener('test', listener)
        listeners.add_listener('test', listener)
      end

      it 'handles the event for each listener' do
        expect(listener).to receive(:handle).with('test').twice
        publisher.publish('test', 'test')
      end
    end

    context 'when the event has no listeners' do

      it 'does not handle anything' do
        expect(listener).to receive(:handle).never
        publisher.publish('test', 'test')
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/mongo/event/publisher_spec.rb
mongo-2.17.4 spec/mongo/event/publisher_spec.rb
mongo-2.18.3 spec/mongo/event/publisher_spec.rb
mongo-2.18.2 spec/mongo/event/publisher_spec.rb
mongo-2.17.3 spec/mongo/event/publisher_spec.rb
mongo-2.18.1 spec/mongo/event/publisher_spec.rb
mongo-2.18.0 spec/mongo/event/publisher_spec.rb
mongo-2.17.2 spec/mongo/event/publisher_spec.rb
mongo-2.16.3 spec/mongo/event/publisher_spec.rb
mongo-2.18.0.beta1 spec/mongo/event/publisher_spec.rb
mongo-2.16.2 spec/mongo/event/publisher_spec.rb
mongo-2.17.1 spec/mongo/event/publisher_spec.rb
mongo-2.16.1 spec/mongo/event/publisher_spec.rb
mongo-2.17.0 spec/mongo/event/publisher_spec.rb
mongo-2.16.0 spec/mongo/event/publisher_spec.rb
mongo-2.15.1 spec/mongo/event/publisher_spec.rb
mongo-2.16.0.alpha1 spec/mongo/event/publisher_spec.rb
mongo-2.15.0 spec/mongo/event/publisher_spec.rb