Sha256: 60d52ce3cab6f533435e9c327db9cd99ca9565c76a5e51d3e18a7f0b47605886

Contents?: true

Size: 1.09 KB

Versions: 36

Compression:

Stored size: 1.09 KB

Contents

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

      subject{
        Bus::Memory::Async.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 'does not raise errors synchronously' do
        subject.listen("user_changed") do |evt|
          raise "An error occured"
        end
        expect {
          subject.emit(Event.new("user_changed", {id: 12}))
        }.not_to raise_error
      end

    end
  end
end

Version data entries

36 entries across 36 versions & 3 rubygems

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