spec/unit/bunny_mock/exchange_spec.rb in bunny-mock-1.2.0 vs spec/unit/bunny_mock/exchange_spec.rb in bunny-mock-1.2.1
- old
+ new
@@ -1,172 +1,155 @@
describe BunnyMock::Exchange do
- context '::declare' do
+ context '::declare' do
- it 'should create a direct exchange' do
+ it 'should create a direct exchange' do
+ expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :direct).class).to eq(BunnyMock::Exchanges::Direct)
+ end
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :direct).class).to eq(BunnyMock::Exchanges::Direct)
- end
+ it 'should create a topic exchange' do
+ expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :topic).class).to eq(BunnyMock::Exchanges::Topic)
+ end
- it 'should create a topic exchange' do
+ it 'should create a fanout exchange' do
+ expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :fanout).class).to eq(BunnyMock::Exchanges::Fanout)
+ end
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :topic).class).to eq(BunnyMock::Exchanges::Topic)
- end
+ it 'should create a header exchange' do
+ expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :header).class).to eq(BunnyMock::Exchanges::Header)
+ end
- it 'should create a fanout exchange' do
+ it 'should default to a direct exchange' do
+ expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg').class).to eq(BunnyMock::Exchanges::Direct)
+ end
+ end
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :fanout).class).to eq(BunnyMock::Exchanges::Fanout)
- end
+ context '#bind' do
- it 'should create a header exchange' do
+ before do
+ @source = @channel.exchange 'xchg.source'
+ @receiver = @channel.exchange 'xchg.receiver'
+ end
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :header).class).to eq(BunnyMock::Exchanges::Header)
- end
+ it 'should bind by exchange instance' do
+ @receiver.bind @source
- it 'should default to a direct exchange' do
+ expect(@receiver.bound_to?(@source)).to be_truthy
+ expect(@source.routes_to?(@receiver)).to be_truthy
+ end
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg').class).to eq(BunnyMock::Exchanges::Direct)
- end
- end
+ it 'should bind by exchange name' do
+ @receiver.bind @source.name
- context '#bind' do
+ expect(@receiver.bound_to?(@source)).to be_truthy
+ expect(@source.routes_to?(@receiver)).to be_truthy
+ end
- before do
- @source = @channel.exchange 'xchg.source'
- @receiver = @channel.exchange 'xchg.receiver'
- end
+ it 'should raise error when exchange does not exists' do
+ expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
+ end
+ end
- it 'should bind by exchange instance' do
+ context '#unbind' do
- @receiver.bind @source
+ before do
+ @source = @channel.exchange 'xchg.source'
+ @receiver = @channel.exchange 'xchg.receiver'
- expect(@receiver.bound_to?(@source)).to be_truthy
- expect(@source.routes_to?(@receiver)).to be_truthy
- end
+ @receiver.bind @source
+ end
- it 'should bind by exchange name' do
+ it 'should unbind by exchange instance' do
+ @receiver.unbind @source
- @receiver.bind @source.name
+ expect(@receiver.bound_to?(@source)).to be_falsey
+ expect(@source.routes_to?(@receiver)).to be_falsey
+ end
- expect(@receiver.bound_to?(@source)).to be_truthy
- expect(@source.routes_to?(@receiver)).to be_truthy
- end
+ it 'should unbind by exchange name' do
+ @receiver.unbind @source.name
- it 'should raise error when exchange does not exists' do
+ expect(@receiver.bound_to?(@source)).to be_falsey
+ expect(@source.routes_to?(@receiver)).to be_falsey
+ end
- expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
- end
- end
+ it 'should raise error when exchange does not exists' do
+ expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
+ end
+ end
- context '#unbind' do
+ context '#bound_to?' do
- before do
- @source = @channel.exchange 'xchg.source'
- @receiver = @channel.exchange 'xchg.receiver'
+ before do
+ @source = @channel.exchange 'xchg.source'
+ @receiver = @channel.exchange 'xchg.receiver'
+ end
- @receiver.bind @source
- end
+ context 'should return true if bound' do
- it 'should unbind by exchange instance' do
+ it 'by instance' do
+ @receiver.bind @source
+ expect(@receiver.bound_to?(@source)).to be_truthy
+ end
- @receiver.unbind @source
+ it 'by name' do
+ @receiver.bind @source
+ expect(@receiver.bound_to?(@source.name)).to be_truthy
+ end
- expect(@receiver.bound_to?(@source)).to be_falsey
- expect(@source.routes_to?(@receiver)).to be_falsey
- end
+ it 'by routing key' do
+ @receiver.bind @source, routing_key: 'xchg.route'
- it 'should unbind by exchange name' do
+ expect(@receiver.bound_to?(@source)).to be_falsey
+ expect(@receiver.bound_to?(@source, routing_key: 'xchg.route')).to be_truthy
+ end
+ end
- @receiver.unbind @source.name
+ it 'return false otherwise' do
+ expect(@receiver.bound_to?(@source)).to be_falsey
+ end
- expect(@receiver.bound_to?(@source)).to be_falsey
- expect(@source.routes_to?(@receiver)).to be_falsey
- end
+ it 'should raise error when exchange does not exists' do
+ expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
+ end
+ end
- it 'should raise error when exchange does not exists' do
+ context '#routes_to?' do
- expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
- end
- end
+ before do
+ @source = @channel.exchange 'xchg.source'
+ @receiver = @channel.exchange 'xchg.receiver'
- context '#bound_to?' do
+ @receiver.bind @source
+ end
- before do
- @source = @channel.exchange 'xchg.source'
- @receiver = @channel.exchange 'xchg.receiver'
- end
+ it 'should return true if bound' do
+ expect(@receiver.bound_to?(@source)).to be_truthy
+ expect(@source.routes_to?(@receiver)).to be_truthy
+ end
- context 'should return true if bound' do
+ it 'should return false if unbound' do
+ @receiver.unbind @source
- it 'by instance' do
+ expect(@receiver.bound_to?(@source)).to be_falsey
+ expect(@source.routes_to?(@receiver)).to be_falsey
+ end
- @receiver.bind @source
+ context 'when using #has_binding?' do
+ it 'should output a deprecation warning' do
+ expect { @source.has_binding?(@receiver) }.to output(/DEPRECATED/).to_stderr
+ end
+ end
+ end
- expect(@receiver.bound_to?(@source)).to be_truthy
- end
+ context '#delete' do
- it 'by name' do
+ before do
+ @exchange = @channel.direct 'xchg.direct'
+ @exchange.delete
+ end
- @receiver.bind @source
-
- expect(@receiver.bound_to?(@source.name)).to be_truthy
- end
-
- it 'by routing key' do
-
- @receiver.bind @source, routing_key: 'xchg.route'
-
- expect(@receiver.bound_to?(@source)).to be_falsey
- expect(@receiver.bound_to?(@source, routing_key: 'xchg.route')).to be_truthy
- end
- end
-
- it 'return false otherwise' do
-
- expect(@receiver.bound_to?(@source)).to be_falsey
- end
-
- it 'should raise error when exchange does not exists' do
-
- expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
- end
- end
-
- context '#routes_to?' do
-
- before do
- @source = @channel.exchange 'xchg.source'
- @receiver = @channel.exchange 'xchg.receiver'
-
- @receiver.bind @source
- end
-
- it 'should unbind by exchange instance' do
-
- @receiver.unbind @source
-
- expect(@receiver.bound_to?(@source)).to be_falsey
- expect(@source.routes_to?(@receiver)).to be_falsey
- end
-
- it 'should unbind by exchange name' do
-
- @receiver.unbind @source.name
-
- expect(@receiver.bound_to?(@source)).to be_falsey
- expect(@source.routes_to?(@receiver)).to be_falsey
- end
- end
-
- context '#delete' do
-
- before do
- @exchange = @channel.direct 'xchg.direct'
- @exchange.delete
- end
-
- it 'should remove exchange from session' do
-
- expect(@session.exchange_exists?(@exchange.name)).to be_falsey
- end
- end
+ it 'should remove exchange from session' do
+ expect(@session.exchange_exists?(@exchange.name)).to be_falsey
+ end
+ end
end