spec/sneakers/configuration_spec.rb in sneakers-1.0.4 vs spec/sneakers/configuration_spec.rb in sneakers-1.1.0
- old
+ new
@@ -1,69 +1,91 @@
require 'spec_helper'
describe Sneakers::Configuration do
- it 'should assign a default value for :amqp' do
- with_env('RABBITMQ_URL', nil) do
- config = Sneakers::Configuration.new
- config[:amqp].must_equal 'amqp://guest:guest@localhost:5672'
+ describe 'with a connection' do
+ let(:connection) { Object.new }
+
+ it 'does not use vhost option if it is specified' do
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
+ with_env('RABBITMQ_URL', url) do
+ config = Sneakers::Configuration.new
+ config.merge!({ :vhost => 'test_host', :connection => connection })
+ config.has_key?(:vhost).must_equal false
+ end
end
- end
- it 'should assign a default value for :vhost' do
- with_env('RABBITMQ_URL', nil) do
+ it 'does not amqp option if it is specified' do
+ url = 'amqp://foo:bar@localhost:5672'
config = Sneakers::Configuration.new
- config[:vhost].must_equal '/'
+ config.merge!({ :amqp => url, :connection => connection })
+ config.has_key?(:vhost).must_equal false
end
end
- it 'should read the value for amqp from RABBITMQ_URL' do
- url = 'amqp://foo:bar@localhost:5672'
- with_env('RABBITMQ_URL', url) do
- config = Sneakers::Configuration.new
- config[:amqp].must_equal url
+ describe 'without a connection' do
+ it 'should assign a default value for :amqp' do
+ with_env('RABBITMQ_URL', nil) do
+ config = Sneakers::Configuration.new
+ config[:amqp].must_equal 'amqp://guest:guest@localhost:5672'
+ end
end
- end
- it 'should read the value for vhost from RABBITMQ_URL' do
- url = 'amqp://foo:bar@localhost:5672/foobarvhost'
- with_env('RABBITMQ_URL', url) do
- config = Sneakers::Configuration.new
- config[:vhost].must_equal 'foobarvhost'
+ it 'should assign a default value for :vhost' do
+ with_env('RABBITMQ_URL', nil) do
+ config = Sneakers::Configuration.new
+ config[:vhost].must_equal '/'
+ end
end
- end
- it 'should parse vhost from amqp option' do
- env_url = 'amqp://foo:bar@localhost:5672/foobarvhost'
- with_env('RABBITMQ_URL', env_url) do
- url = 'amqp://foo:bar@localhost:5672/testvhost'
- config = Sneakers::Configuration.new
- config.merge!({ :amqp => url })
- config[:vhost].must_equal 'testvhost'
+ it 'should read the value for amqp from RABBITMQ_URL' do
+ url = 'amqp://foo:bar@localhost:5672'
+ with_env('RABBITMQ_URL', url) do
+ config = Sneakers::Configuration.new
+ config[:amqp].must_equal url
+ end
end
- end
- it 'should not parse vhost from amqp option if vhost is specified explicitly' do
- url = 'amqp://foo:bar@localhost:5672/foobarvhost'
- config = Sneakers::Configuration.new
- config.merge!({ :amqp => url, :vhost => 'test_host' })
- config[:vhost].must_equal 'test_host'
- end
+ it 'should read the value for vhost from RABBITMQ_URL' do
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
+ with_env('RABBITMQ_URL', url) do
+ config = Sneakers::Configuration.new
+ config[:vhost].must_equal 'foobarvhost'
+ end
+ end
- it 'should use vhost option if it is specified' do
- url = 'amqp://foo:bar@localhost:5672/foobarvhost'
- with_env('RABBITMQ_URL', url) do
+ it 'should parse vhost from amqp option' do
+ env_url = 'amqp://foo:bar@localhost:5672/foobarvhost'
+ with_env('RABBITMQ_URL', env_url) do
+ url = 'amqp://foo:bar@localhost:5672/testvhost'
+ config = Sneakers::Configuration.new
+ config.merge!({ :amqp => url })
+ config[:vhost].must_equal 'testvhost'
+ end
+ end
+
+ it 'should not parse vhost from amqp option if vhost is specified explicitly' do
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
config = Sneakers::Configuration.new
- config.merge!({ :vhost => 'test_host' })
+ config.merge!({ :amqp => url, :vhost => 'test_host' })
config[:vhost].must_equal 'test_host'
end
- end
- it 'should use default vhost if vhost is not specified in amqp option' do
- url = 'amqp://foo:bar@localhost:5672'
- config = Sneakers::Configuration.new
- config.merge!({ :amqp => url })
- config[:vhost].must_equal '/'
+ it 'should use vhost option if it is specified' do
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
+ with_env('RABBITMQ_URL', url) do
+ config = Sneakers::Configuration.new
+ config.merge!({ :vhost => 'test_host' })
+ config[:vhost].must_equal 'test_host'
+ end
+ end
+
+ it 'should use default vhost if vhost is not specified in amqp option' do
+ url = 'amqp://foo:bar@localhost:5672'
+ config = Sneakers::Configuration.new
+ config.merge!({ :amqp => url })
+ config[:vhost].must_equal '/'
+ end
end
def with_env(key, value)
old_value = ENV[key]
ENV[key] = value