Sha256: 57695390a1492eba5f39a0166a14752088b750cb4d76242c205bb470e9fc7d60

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require "spec_helper"

describe Qsagi::Queue do
  it "and push and pop from a queue" do
    ExampleQueue.connect do |queue|
      queue.push("message")
      result = queue.pop
      result.payload.should == "message"
    end
  end

  describe "self.exchange" do
    it "configures the exchange" do
      queue_on_exchange1 = Class.new(ExampleQueue) do
        exchange "exchange1"
      end
      queue_on_exchange2 = Class.new(ExampleQueue) do
        exchange "exchange2"
      end
      queue_on_exchange1.connect do |queue|
        queue.push "message1"
      end
      queue_on_exchange1.connect do |queue|
        message = queue.pop
        message.payload.should == "message1"
        message.exchange.should == "exchange1"
      end
      queue_on_exchange2.connect do |queue|
        queue.pop.should be_nil
      end
    end
  end

  describe "clear" do
    it "clears the queue" do
      ExampleQueue.connect do |queue|
        queue.push("message")
        queue.clear
        queue.pop.should == nil
      end
    end
  end

  describe "pop" do
    it "automatically acks if :auto_ack is not passed in" do
      ExampleQueue.connect do |queue|
        queue.push("message")
        message = queue.pop
        message.payload.should == "message"
      end
      ExampleQueue.connect do |queue|
        message = queue.pop
        message.should == nil
      end
    end

    it "will not automatically ack if :auto_ack is set to false" do
      ExampleQueue.connect do |queue|
        queue.push("message")
        message = queue.pop(:auto_ack => false)
        message.payload.should == "message"
      end
      ExampleQueue.connect do |queue|
        message = queue.pop(:auto_ack => false)
        message.payload.should == "message"
        queue.ack(message)
      end
      ExampleQueue.connect do |queue|
        message = queue.pop(:auto_ack => false)
        message.should == nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qsagi-0.0.1 spec/qsagi/queue_spec.rb