Sha256: e8f1e4ad4c60ec489964f490ac010404d6e5c4523fe321d05403d48d40302c00

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'
module Startback
  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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
startback-0.11.5 spec/unit/bus/memory/test_sync.rb
startback-0.11.4 spec/unit/bus/memory/test_sync.rb
startback-0.11.3 spec/unit/bus/memory/test_sync.rb
startback-0.11.0 spec/unit/bus/memory/test_sync.rb
startback-0.10.1 spec/unit/bus/memory/test_sync.rb
startback-0.10.0 spec/unit/bus/memory/test_sync.rb
startback-0.9.1 spec/unit/bus/memory/test_sync.rb
startback-0.9.0 spec/unit/bus/memory/test_sync.rb
startback-0.8.3 spec/unit/bus/memory/test_sync.rb
startback-0.8.2 spec/unit/bus/memory/test_sync.rb
startback-0.8.1 spec/unit/bus/memory/test_sync.rb
startback-0.8.0 spec/unit/bus/memory/test_sync.rb
startback-0.7.6 spec/unit/bus/memory/test_sync.rb
startback-0.7.5 spec/unit/bus/memory/test_sync.rb
startback-0.7.4 spec/unit/bus/memory/test_sync.rb
startback-0.7.3 spec/unit/bus/memory/test_sync.rb
startback-0.7.2 spec/unit/bus/memory/test_sync.rb
startback-0.7.1 spec/unit/bus/memory/test_sync.rb
startback-0.7.0 spec/unit/bus/memory/test_sync.rb
startback-0.6.0 spec/unit/bus/memory/test_sync.rb