Skip to content
Browse files

Turn one example (automatic binding for default exchange) into our in…

…itial integration spec. So far, so good.
  • Loading branch information...
1 parent e105669 commit ca2efd97de6a7542bd73e463983865e89d3e08f8 @michaelklishin michaelklishin committed Jan 18, 2011
Showing with 76 additions and 0 deletions.
  1. +61 −0 spec/integration/automatic_binding_for_default_direct_exchange_spec.rb
  2. +15 −0 spec/spec_helper.rb
View
61 spec/integration/automatic_binding_for_default_direct_exchange_spec.rb
@@ -0,0 +1,61 @@
+# encoding: utf-8
+
+require 'spec_helper'
+
+describe "Queue that was bound to default direct exchange thanks to Automatic Mode (section 2.1.2.4 in AMQP 0.9.1 spec" do
+
+ #
+ # Environment
+ #
+
+ include AMQP::Spec
+
+ default_timeout 10
+
+ amqp_before do
+ @channel = MQ.new
+
+ @queue1 = @channel.queue("queue1")
+ @queue2 = @channel.queue("queue2")
+
+ # Rely on default direct exchange binding, see section 2.1.2.4 Automatic Mode in AMQP 0.9.1 spec.
+ @exchange = MQ::Exchange.default
+ end
+
+
+
+ #
+ # Examples
+ #
+
+ it "receives messages with routing key equals it's name" do
+ number_of_received_messages = 0
+ expected_number_of_messages = 3
+ dispatched_data = "to be received by queue1"
+
+ @queue1.subscribe do |payload|
+ number_of_received_messages += 1
+ payload.should == dispatched_data
+
+ if number_of_received_messages == expected_number_of_messages
+ $stdout.puts "Got all the messages I expected, wrapping up..."
+ done
+ else
+ n = expected_number_of_messages - number_of_received_messages
+ $stdout.puts "Still waiting for #{n} more message(s)"
+ end
+ end # subscribe
+
+ 4.times do
+ @exchange.publish("some white noise", :routing_key => "killa key")
+ end
+
+ expected_number_of_messages.times do
+ @exchange.publish(dispatched_data, :routing_key => @queue1.name)
+ end
+
+ 4.times do
+ @exchange.publish("some white noise", :routing_key => "killa key")
+ end
+ end # it
+end # describe
View
15 spec/spec_helper.rb
@@ -26,6 +26,21 @@ def symbolize_keys
AMQP_OPTS = {:host => 'localhost', :port => 5672}
end
+
+if RUBY_VERSION == "1.8.7"
+ module ArrayExtensions
+ def sample
+ self.choice
+ end # sample
+ end
+
+ class Array
+ include ArrayExtensions
+ end
+end
+
+
+
# Shorthand for mocking subject's instance variable
def subject_mock(name, as_null = false)
mock = mock(name)

0 comments on commit ca2efd9

Please sign in to comment.
Something went wrong with that request. Please try again.