spec/integration/exchange_declaration_spec.rb in amqp-1.0.0.pre2 vs spec/integration/exchange_declaration_spec.rb in amqp-1.0.0

- old
+ new

@@ -125,47 +125,37 @@ done end # it end # context - context "when exchange name was specified as a blank string" do - it 'returns direct exchange with server-generated name' do - pending <<-EOF - This has to be fixed in RabbitMQ first - https://bugzilla.rabbitmq.com/show_bug.cgi?id=23509 - EOF - @channel.direct("") do |exchange| - exchange.name.should_not be_empty - done - end - end - end # context - - context "when passive option is used" do context "and exchange with given name already exists" do it "silently returns" do - name = "a_new_direct_exchange declared at #{Time.now.to_i}" + name = "a_new_direct_exchange declared at #{Time.now.to_i}" + channel = AMQP::Channel.new - original_exchange = @channel.direct(name) - exchange = @channel.direct(name, :passive => true) + original_exchange = channel.direct(name) + exchange = channel.direct(name, :passive => true) exchange.should == original_exchange done end # it end context "and exchange with given name DOES NOT exist" do it "raises an exception" do - pending "Not yet supported" + channel = AMQP::Channel.new + channel.on_error do |ch, channel_close| + @error_code = channel_close.reply_code + end - expect { - exchange = @channel.direct("direct exchange declared at #{Time.now.to_i}", :passive => true) - }.to raise_error + exchange = channel.direct("direct exchange declared at #{Time.now.to_i}", :passive => true) - done + done(0.5) { + @error_code.should == 404 + } end # it end # context end # context @@ -221,31 +211,20 @@ end # context context "when exchange is re-declared with parameters different from original declaration" do it "raises an exception" do - @channel.direct("previously.declared.durable.direct.exchange", :durable => true) + channel = AMQP::Channel.new + channel.direct("previously.declared.durable.direct.exchange", :durable => true) expect { - @channel.direct("previously.declared.durable.direct.exchange", :durable => false) + channel.direct("previously.declared.durable.direct.exchange", :durable => false) }.to raise_error(AMQP::IncompatibleOptionsError) done end # it end # context - - context "when exchange is re-declared with irrelevent parameters different from original declaration" do - it "doesn't raise an exception" do - @channel.direct("previously.declared.durable.direct.exchange", :durable => true) - - expect { - @channel.direct("previously.declared.durable.direct.exchange", :durable => true, :header => {:random => 'stuff' }) - }.to_not raise_error(AMQP::IncompatibleOptionsError) - - done - end # it - end # context end # describe @@ -285,17 +264,22 @@ done end # it end context "and exchange with given name DOES NOT exist" do - it "raises an exception" do - pending "Not yet supported" + it "results in a channel exception" do + channel = AMQP::Channel.new + channel.on_error do |ch, channel_close| + @error_code = channel_close.reply_code + end - expect { - exchange = @channel.fanout("fanout exchange declared at #{Time.now.to_i}", :passive => true) - }.to raise_error + exchange = channel.fanout("fanout exchange declared at #{Time.now.to_i}", :passive => true) + done(0.5) { + @error_code.should == 404 + } + done end # it end # context end # context @@ -352,14 +336,15 @@ end # context context "when exchange is re-declared with parameters different from original declaration" do it "raises an exception" do - @channel.fanout("previously.declared.durable.topic.exchange", :durable => true) + channel = AMQP::Channel.new + channel.fanout("previously.declared.durable.topic.exchange", :durable => true) expect { - @channel.fanout("previously.declared.durable.topic.exchange", :durable => false) + channel.fanout("previously.declared.durable.topic.exchange", :durable => false) }.to raise_error(AMQP::IncompatibleOptionsError) done end # it end # context @@ -375,21 +360,21 @@ it "declares a new topic exchange with that name" do exchange = @channel.topic(name) exchange.name.should == name done - end + end # it end # context context "when exchange name is omitted" do it "uses amq.topic" do exchange = @channel.topic exchange.name.should == "amq.topic" exchange.name.should_not == "amq.topic2" done - end + end # it end # context context "when passive option is used" do context "and exchange with given name already exists" do it "silently returns" do @@ -400,24 +385,27 @@ exchange.should == original_exchange done end # it - end + end # context context "and exchange with given name DOES NOT exist" do - it "raises an exception" do - pending "Not yet supported" + it "results in a channel exception" do + channel = AMQP::Channel.new + channel.on_error do |ch, channel_close| + @error_code = channel_close.reply_code + end - expect { - exchange = @channel.topic("topic exchange declared at #{Time.now.to_i}", :passive => true) - }.to raise_error + exchange = channel.topic("topic exchange declared at #{Time.now.to_i}", :passive => true) - done + done(0.5) { + @error_code.should == 404 + } end # it end # context - end # context + end context "when exchange is declared as durable" do it "returns a new durable topic exchange" do exchange = @channel.topic("a_new_durable_topic_exchange", :durable => true) @@ -468,20 +456,18 @@ done end # it end # context - context "when exchange is re-declared with parameters different from original declaration" do + context "when exchange is re-declared with parameters different from the original declaration" do amqp_after do done end it "raises an exception" do channel = AMQP::Channel.new - channel.topic("previously.declared.durable.topic.exchange", :durable => true) - channel.should be_open expect { channel.topic("previously.declared.durable.topic.exchange", :durable => false) }.to raise_error(AMQP::IncompatibleOptionsError) @@ -496,11 +482,12 @@ describe "#headers" do context "when exchange name is specified" do let(:name) { "new.headers.exchange" } it "declares a new headers exchange with that name" do - exchange = @channel.headers(name) + channel = AMQP::Channel.new + exchange = channel.headers(name) exchange.name.should == name done end @@ -510,91 +497,101 @@ amqp_after do done end it "uses amq.match" do - exchange = @channel.headers + channel = AMQP::Channel.new + exchange = channel.headers exchange.name.should == "amq.match" exchange.name.should_not == "amq.headers" done end end # context context "when passive option is used" do context "and exchange with given name already exists" do it "silently returns" do - name = "a_new_headers_exchange declared at #{Time.now.to_i}" + name = "a_new_headers_exchange declared at #{Time.now.to_i}" + channel = AMQP::Channel.new - original_exchange = @channel.headers(name) - exchange = @channel.headers(name, :passive => true) + original_exchange = channel.headers(name) + exchange = channel.headers(name, :passive => true) exchange.should == original_exchange done end # it end context "and exchange with given name DOES NOT exist" do it "raises an exception" do - pending "Not yet supported" + channel = AMQP::Channel.new + channel.on_error do |ch, channel_close| + @error_code = channel_close.reply_code + end - expect { - exchange = @channel.headers("headers exchange declared at #{Time.now.to_i}", :passive => true) - }.to raise_error + exchange = channel.headers("headers exchange declared at #{Time.now.to_i}", :passive => true) - done + done(0.5) { + @error_code.should == 404 + } end # it end # context end # context context "when exchange is declared as durable" do it "returns a new durable headers exchange" do - exchange = @channel.headers("a_new_durable_headers_exchange", :durable => true) + channel = AMQP::Channel.new + exchange = channel.headers("a_new_durable_headers_exchange", :durable => true) exchange.should be_durable exchange.should_not be_transient done end # it end # context context "when exchange is declared as non-durable" do it "returns a new NON-durable headers exchange" do - exchange = @channel.headers("a_new_non_durable_headers_exchange", :durable => false) + channel = AMQP::Channel.new + exchange = channel.headers("a_new_non_durable_headers_exchange", :durable => false) exchange.should_not be_durable exchange.should be_transient done end # it end # context context "when exchange is declared as auto-deleted" do it "returns a new auto-deleted headers exchange" do - exchange = @channel.headers("a new auto-deleted headers exchange", :auto_delete => true) + channel = AMQP::Channel.new + exchange = channel.headers("a new auto-deleted headers exchange", :auto_delete => true) exchange.should be_auto_deleted done end # it end # context context "when exchange is declared as auto-deleted" do it "returns a new auto-deleted headers exchange" do - exchange = @channel.headers("a new non-auto-deleted headers exchange", :auto_delete => false) + channel = AMQP::Channel.new + exchange = channel.headers("a new non-auto-deleted headers exchange", :auto_delete => false) exchange.should_not be_auto_deleted done end # it end # context context "when exchange is declared without explicit :nowait parameter" do it "is declared with :nowait by default" do - exchange = @channel.headers("a new non-auto-deleted headers exchange", :auto_delete => false) + channel = AMQP::Channel.new + exchange = channel.headers("a new non-auto-deleted headers exchange", :auto_delete => false) exchange.should_not be_auto_deleted done end # it end # context @@ -604,45 +601,17 @@ amqp_after do done end it "raises an exception" do - @channel.headers("previously.declared.durable.headers.exchange", :durable => true) + channel = AMQP::Channel.new + channel.headers("previously.declared.durable.headers.exchange", :durable => true) expect { - @channel.headers("previously.declared.durable.headers.exchange", :durable => false) + channel.headers("previously.declared.durable.headers.exchange", :durable => false) }.to raise_error(AMQP::IncompatibleOptionsError) done - end # it - end # context - - - context "when exchange is re-declared with parameters different from original declaration on two separate channels" do - it "raises an exception" do - channel2 = AMQP::Channel.new - @channel.headers("previously.declared.durable.headers.exchange", :durable => true) - - channel2.on_error do |ch, channel_close| - puts "reply_text: #{channel_close.reply_text}, reply_code: #{channel_close.reply_code}" - done - end - channel2.headers("previously.declared.durable.headers.exchange", :durable => false) - end # it - end # context - - - - context "when exchange is re-declared with type different from original declaration on two separate channels" do - it "raises an exception" do - channel2 = AMQP::Channel.new - @channel.topic("previously.declared.durable.topic.exchange", :durable => true) - - channel2.on_error do |ch, channel_close| - puts "reply_text: #{channel_close.reply_text}, reply_code: #{channel_close.reply_code}" - done - end - channel2.headers("previously.declared.durable.topic.exchange", :durable => true) end # it end # context end # describe end # describe AMQP