Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.03 KB | None | 0 0
  1. require 'spec_helper'
  2. require "bunny"
  3.  
  4. describe "RabbitMQ" do
  5.   it 'should send and recieve a message' do
  6.     TestBunny.send("test1", "hello")
  7.     message = TestBunny.subscribe("test1")
  8.     expect(message).to_not eq(nil)
  9.   end
  10.  
  11.   it 'consumer should recieve the correct message' do
  12.     correct_message = "iamcorrect"
  13.     TestBunny.send("test2", correct_message)
  14.     message = TestBunny.subscribe("test2")
  15.     expect(message).to eq(correct_message)
  16.   end
  17.  
  18.   it 'should be able to create a new Bunny connection' do
  19.     pass = false
  20.     begin
  21.       TestBunny.connect
  22.       pass = true
  23.     rescue
  24.     end
  25.     expect(pass).to eq(true)
  26.   end
  27.  
  28.   it 'should send and recieve multiple messages without loss' do
  29.     recieved = 0
  30.     to_send = 10
  31.     to_send.times do
  32.       TestBunny.send("test3", "hello")
  33.       message = TestBunny.subscribe("test3")
  34.       recieved += 1 if !!message
  35.     end
  36.     expect(recieved).to eq(to_send)
  37.   end
  38.  
  39.   it 'should not accept an integer as a queue' do
  40.     expect {
  41.       TestBunny.send(1, "hello")
  42.     }.to raise_error
  43.   end
  44.  
  45.   it 'should not accept nil as a queue' do
  46.     expect {
  47.       TestBunny.send(nil, "hello")
  48.     }.to raise_error
  49.   end
  50.  
  51.   it 'should not accept very large string as a queue' do
  52.     expect {
  53.       TestBunny.send(SecureRandom.hex(200000), "hello")
  54.     }.to raise_error
  55.   end
  56.  
  57.   it 'should not accept object as a queue' do
  58.     expect {
  59.       TestBunny.send(Object.new, "hello")
  60.     }.to raise_error
  61.   end
  62.  
  63.   it 'should not accept nil as message' do
  64.     expect {
  65.       TestBunny.send("test4", nil)
  66.     }.to raise_error
  67.   end
  68.  
  69.   it 'should not accept class as message' do
  70.     expect {
  71.       TestBunny.send("test4", Object)
  72.     }.to raise_error
  73.   end
  74.  
  75.   it 'should not send a message without a queue' do
  76.     expect {
  77.       TestBunny.send("test4", Object)
  78.     }.to raise_error
  79.   end
  80.  
  81.   it 'should not send a message without a queue' do
  82.     expect {
  83.       TestBunny.send("test4", Object)
  84.     }.to raise_error
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement