diff --git a/rbhive.gemspec b/rbhive.gemspec index 8ef2cc2..3bf82d2 100644 --- a/rbhive.gemspec +++ b/rbhive.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| spec.add_dependency('thrift', '~> 0.9') spec.add_dependency('json') + spec.add_development_dependency 'rspec' spec.add_development_dependency 'rake' spec.add_development_dependency 'bundler', '>= 1.3' diff --git a/spec/rbhive/connection_spec.rb b/spec/rbhive/connection_spec.rb new file mode 100644 index 0000000..a674ddd --- /dev/null +++ b/spec/rbhive/connection_spec.rb @@ -0,0 +1,23 @@ +require 'rbhive/connection' + +describe RBHive do + describe '.connect' do + + # Mock any attempts to open a socket + let(:socket) { double('Thrift::Socket').as_null_object } + before do + allow(Thrift::Socket).to receive(:new).and_return(socket) + end + + let(:server) { 'localhost' } + let(:port) { 10_000 } + + it 'yields the connection to the block' do + expect(@connection).to be(nil) + RBHive.connect(server, port) do |connection| + @connection = connection + end + expect(@connection.class).to be(RBHive::Connection) + end + end +end