Sha256: 9419100746be2afba22f4d7c6dd80a9fb9e8d717e3a04cac1532e36a6c580f4f

Contents?: true

Size: 1.11 KB

Versions: 35

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'
module Startback
  class Event
    describe Bus::Memory do

      subject{
        Bus::Memory::Sync.new
      }

      it 'allows emiting an receiving' do
        seen = nil
        subject.listen("user_changed") do |evt|
          seen = evt
        end
        subject.emit(Event.new("user_changed", {id: 12}))
        expect(seen).to be_a(Event)
        expect(seen.type).to eql("user_changed")
        expect(seen.data.to_h).to eql({id: 12})
      end

      it 'allows mixin Symbol vs. String for event type' do
        seen = nil
        subject.listen(:user_changed) do |evt|
          seen = evt
        end
        subject.emit(Event.new(:user_changed, {id: 12}))
        expect(seen).to be_a(Event)
        expect(seen.type).to eql("user_changed")
        expect(seen.data.to_h).to eql({id: 12})
      end

      it 'raises emit errors synchronously' do
        subject.listen("user_changed") do |evt|
          raise "An error occured"
        end
        expect {
          subject.emit(Event.new("user_changed", {id: 12}))
        }.to raise_error("An error occured")
      end

    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
startback-1.0.3 spec/unit/event/bus/memory/test_sync.rb
startback-1.0.2 spec/unit/event/bus/memory/test_sync.rb
startback-1.0.1 spec/unit/event/bus/memory/test_sync.rb
startback-1.0.0 spec/unit/event/bus/memory/test_sync.rb
startback-0.19.4 spec/unit/event/bus/memory/test_sync.rb
startback-0.19.3 spec/unit/event/bus/memory/test_sync.rb
startback-0.19.1 spec/unit/event/bus/memory/test_sync.rb
startback-0.19.0 spec/unit/event/bus/memory/test_sync.rb
startback-0.18.2 spec/unit/event/bus/memory/test_sync.rb
startback-0.18.1 spec/unit/event/bus/memory/test_sync.rb
startback-0.18.0 spec/unit/event/bus/memory/test_sync.rb
startback-0.17.4 spec/unit/event/bus/memory/test_sync.rb
startback-0.17.3 spec/unit/event/bus/memory/test_sync.rb
startback-0.17.2 spec/unit/event/bus/memory/test_sync.rb
startback-0.17.1 spec/unit/event/bus/memory/test_sync.rb
startback-0.17.0 spec/unit/event/bus/memory/test_sync.rb
startback-0.16.0 spec/unit/event/bus/memory/test_sync.rb
startback-0.15.5 spec/unit/event/bus/memory/test_sync.rb
startback-0.15.4 spec/unit/event/bus/memory/test_sync.rb
startback-0.15.3 spec/unit/event/bus/memory/test_sync.rb