Sha256: 3bf491a15afbb1af9ccb208f49d5a67b8c13e5b70733ace64e10bf68e81f54a6

Contents?: true

Size: 890 Bytes

Versions: 23

Compression:

Stored size: 890 Bytes

Contents

module QueueEngineExamples
  
  let(:queue) { engine[:test_queue] }

  it 'Engine' do
    engine.queues.must_be_empty
    
    queue = engine[:test_engine]
    queue.must_be_instance_of engine.class.const_get(:Queue)
    engine.queues.must_equal [:test_engine]
    
    engine[:test_engine].must_equal queue
    
    engine.clear
    engine.queues.must_be_empty
  end

  it 'Queue (push/pop)' do
    queue.must_be_empty
    
    queue.push 'msg_1'
    queue.push 'msg_2'
    
    queue.size.must_equal 2
    queue.to_a.must_equal %w(msg_1 msg_2)

    queue.pop.must_equal 'msg_1'

    queue.size.must_equal 1
    queue.to_a.must_equal %w(msg_2)
  end

  it 'Listener' do
    queue.push 'msg_1'
    queue.push 'msg_2'

    messages = []

    listener.listen(queue) do |msg|
      messages << msg
      listener.stop if queue.empty?
    end

    messages.must_equal %w(msg_1 msg_2)
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
asynchronic-0.2.1 spec/queue_engine/queue_engine_examples.rb
asynchronic-0.2.0 spec/queue_engine/queue_engine_examples.rb
asynchronic-0.1.0 spec/queue_engine/queue_engine_examples.rb