parent
56bdddc923
commit
816b48f567
|
@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency 'faraday', '~> 0.9.0'
|
||||
spec.add_dependency 'net-http-persistent', '~> 2.9.4'
|
||||
spec.add_dependency 'lookout-statsd', '~> 0.9.0'
|
||||
spec.add_dependency 'hashie'
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'rubygems'
|
||||
require 'protobuf'
|
||||
require 'hashie'
|
||||
|
||||
require 'elementary/middleware'
|
||||
require 'elementary/transport'
|
||||
|
@ -22,6 +23,8 @@ module Elementary
|
|||
# will be passed down to the transport layer. This will depend on what
|
||||
# options are available by the underlying transport
|
||||
def initialize(service, opts={})
|
||||
opts = Hashie::Mash.new(opts)
|
||||
|
||||
if service.nil? || service.superclass != Protobuf::Rpc::Service
|
||||
raise ArgumentError,
|
||||
"Cannot construct an Elementary::Connection with `#{service}` (#{service.class})"
|
||||
|
|
|
@ -21,6 +21,38 @@ describe Elementary::Connection do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with an opts hash' do
|
||||
subject(:connection) { described_class.new(Elementary::Rspec::Simple, opts) }
|
||||
|
||||
context 'with symbolic keys' do
|
||||
let(:opts) { { :hosts => [{:host => 'foo', :prefix => '/bar'}] } }
|
||||
|
||||
it { should be_instance_of described_class }
|
||||
|
||||
it 'should have one host, with a host key and a prefix key' do
|
||||
hosts = connection.instance_variable_get(:@hosts)
|
||||
|
||||
expect(hosts.size).to be 1
|
||||
expect(hosts.first[:host]).to eql opts[:hosts].first[:host]
|
||||
expect(hosts.first[:prefix]).to eql opts[:hosts].first[:prefix]
|
||||
end
|
||||
end
|
||||
|
||||
context 'with string keys' do
|
||||
let(:opts) { { 'hosts' => [{'host' => 'foo', 'prefix' => '/bar'}] } }
|
||||
|
||||
it { should be_instance_of described_class }
|
||||
|
||||
it 'should have one host, with a host key and a prefix key' do
|
||||
hosts = connection.instance_variable_get(:@hosts)
|
||||
|
||||
expect(hosts.size).to be 1
|
||||
expect(hosts.first[:host]).to eql opts['hosts'].first['host']
|
||||
expect(hosts.first[:prefix]).to eql opts['hosts'].first['prefix']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a simple RPC service' do
|
||||
let(:opts) { {} }
|
||||
let(:connection) do
|
||||
|
|
Loading…
Reference in New Issue