1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
require "spec_helper"
describe Bunny::Queue, "#pop" do
let(:connection) do
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
automatically_recover: false)
c.start
c
end
after :each do
connection.close if connection.open?
end
context "with all defaults" do
it "fetches a messages which is automatically acknowledged" do
ch = connection.create_channel
q = ch.queue("", exclusive: true)
x = ch.default_exchange
msg = "xyzzy"
x.publish(msg, routing_key: q.name)
sleep(0.5)
get_ok, properties, content = q.pop
expect(get_ok).to be_kind_of(Bunny::GetResponse)
expect(properties).to be_kind_of(Bunny::MessageProperties)
expect(properties.content_type).to eq("application/octet-stream")
expect(get_ok.routing_key).to eq(q.name)
expect(get_ok.delivery_tag).to be_kind_of(Bunny::VersionedDeliveryTag)
expect(content).to eq(msg)
expect(q.message_count).to eq 0
ch.close
end
end
context "with an empty queue" do
it "returns an empty response" do
ch = connection.create_channel
q = ch.queue("", exclusive: true)
q.purge
get_empty, properties, content = q.pop
expect(get_empty).to eq(nil)
expect(properties).to eq(nil)
expect(content).to eq(nil)
expect(q.message_count).to eq 0
ch.close
end
end
end
describe Bunny::Channel, "#basic_get" do
let(:connection) do
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
automatically_recover: false, continuation_timeout: 3000)
c.start
c
end
after :each do
connection.close if connection.open?
end
context "with a non-existent queue" do
it "throws a NOT_FOUND" do
ch = connection.create_channel
expect do
ch.basic_get "non_existent_#{rand.to_s}"
end.to raise_error(Bunny::NotFound)
end
end
end
|