From 02266d805b087d977cf775f04b72e60e35ee7019 Mon Sep 17 00:00:00 2001 From: Jack Danger Canty Date: Wed, 15 Jul 2015 09:09:58 -0700 Subject: [PATCH] Adding RSpec and first test --- rbhive.gemspec | 1 + spec/rbhive/connection_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 spec/rbhive/connection_spec.rb 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