Sha256: a11cabdd2d1edfae4404a05db15fd4f1cfefbafce29521688e63966f4a524781

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

module SandthornSequelProjection
  describe EventHandlerCollection do
    let(:collection) { EventHandlerCollection.new }
    let(:projection) { Object.new }

    describe "#add" do
      it "adds the handler to the collection" do
        handler_data = :foo
        collection.define(handler_data)
        expect(collection.handlers.length).to eq(1)
        handler = collection.handlers.first
        expect(handler.message).to eq(:foo)
      end
    end

    describe "#handle" do
      it "calls handle on each handler for every event, in order" do
        events = [1,2]
        handler1 = :foo
        handler2 = :bar
        handlers = [handler1, handler2]
        handlers.each do |handler|
          collection.define(handler)
        end
        collection.handlers.each do |handler|
          expect(handler).to receive(:handle).ordered.with(projection, 1).once
        end
        collection.handlers.each do |handler|
          expect(handler).to receive(:handle).ordered.with(projection, 2).once
        end
        collection.handle(projection, events)
      end
    end


  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sandthorn_sequel_projection-0.1.0 spec/event_handler_collection_spec.rb
sandthorn_sequel_projection-0.0.4 spec/event_handler_collection_spec.rb
sandthorn_sequel_projection-0.0.3 spec/event_handler_collection_spec.rb
sandthorn_sequel_projection-0.0.2 spec/event_handler_collection_spec.rb
sandthorn_sequel_projection-0.0.1 spec/event_handler_collection_spec.rb