spec/sneakers/configuration_spec.rb in sneakers-1.0.2 vs spec/sneakers/configuration_spec.rb in sneakers-1.0.3
- old
+ new
@@ -30,13 +30,46 @@
config = Sneakers::Configuration.new
config[:vhost].must_equal 'foobarvhost'
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'
+ 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 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
+
def with_env(key, value)
old_value = ENV[key]
ENV[key] = value
yield
ensure
ENV[key] = old_value
end
-end
\ No newline at end of file
+end