Sha256: f081cf7631f6e1f78d4cccea38c99dd71b5287031d0b5f0abb56c261de92267b
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true RSpec.describe FiniteMachine::MessageQueue do it "dispatches all events" do event_queue = FiniteMachine::MessageQueue.new event_queue.start called = [] event1 = double(:event1, dispatch: called << 'event1_dispatched') event2 = double(:event2, dispatch: called << 'event2_dispatched') expect(event_queue.size).to be_zero event_queue << event1 event_queue << event2 event_queue.join(0.001) expect(called).to match_array(['event1_dispatched', 'event2_dispatched']) event_queue.shutdown end it "logs error" do event_queue = FiniteMachine::MessageQueue.new event_queue.start event = spy(:event) allow(event).to receive(:dispatch) { raise } expect(FiniteMachine::Logger).to receive(:error) event_queue << event event_queue.join(0.02) expect(event_queue).to be_empty end it "notifies listeners" do event_queue = FiniteMachine::MessageQueue.new event_queue.start called = [] event1 = double(:event1, dispatch: true) event2 = double(:event2, dispatch: true) event3 = double(:event3, dispatch: true) event_queue.subscribe(:listener1) { |event| called << event } event_queue << event1 event_queue << event2 event_queue << event3 event_queue.join(0.02) event_queue.shutdown expect(called).to match_array([event1, event2, event3]) end it "allows to shutdown event queue" do event_queue = FiniteMachine::MessageQueue.new event_queue.start event1 = double(:event1, dispatch: true) event2 = double(:event2, dispatch: true) event3 = double(:event3, dispatch: true) expect(event_queue.running?).to be(true) event_queue << event1 event_queue << event2 event_queue.shutdown event_queue << event3 expect(event_queue.running?).to be(false) event_queue.join(0.001) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
finite_machine-0.12.1 | spec/unit/message_queue_spec.rb |
finite_machine-0.12.0 | spec/unit/message_queue_spec.rb |