Sha256: fdc69ae7353236c7950e5659231884437500a5d0eb4b361df309f3a61c4dd292

Contents?: true

Size: 1007 Bytes

Versions: 91

Compression:

Stored size: 1007 Bytes

Contents

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

91 entries across 88 versions & 3 rubygems

Version Path
mongo-2.4.0 spec/mongo/event/publisher_spec.rb
mongo-2.3.1 spec/mongo/event/publisher_spec.rb
mongo-2.4.0.rc1 spec/mongo/event/publisher_spec.rb
mongo-2.4.0.rc0 spec/mongo/event/publisher_spec.rb
mongo-2.3.0 spec/mongo/event/publisher_spec.rb
mongo-2.2.7 spec/mongo/event/publisher_spec.rb
mongo-2.2.6 spec/mongo/event/publisher_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongo-2.2.5/spec/mongo/event/publisher_spec.rb
mongo-2.2.5 spec/mongo/event/publisher_spec.rb
mongo-2.2.4 spec/mongo/event/publisher_spec.rb
mongo-2.2.3 spec/mongo/event/publisher_spec.rb
mongo-2.2.2 spec/mongo/event/publisher_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongo-2.2.1/spec/mongo/event/publisher_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mongo-2.2.1/spec/mongo/event/publisher_spec.rb
mongo-2.2.1 spec/mongo/event/publisher_spec.rb
mongo-2.2.0 spec/mongo/event/publisher_spec.rb
mongo-2.2.0.rc0 spec/mongo/event/publisher_spec.rb
mongo-2.1.2 spec/mongo/event/publisher_spec.rb
mongo-2.1.1 spec/mongo/event/publisher_spec.rb
mongo-2.1.0 spec/mongo/event/publisher_spec.rb