Thrift-1644:Upgrade RSpec to 2.11.x and refactor specs as needed
Client: rb
Patch: Nathan Beyer
Upgrading to rspec2.
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1391280 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/server_spec.rb b/lib/rb/spec/server_spec.rb
index a633956..0e952ab 100644
--- a/lib/rb/spec/server_spec.rb
+++ b/lib/rb/spec/server_spec.rb
@@ -16,39 +16,30 @@
# specific language governing permissions and limitations
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftServerSpec < Spec::ExampleGroup
- include Thrift
+describe 'Server' do
- describe BaseServer do
+ describe Thrift::BaseServer do
it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
- server = BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
- server.instance_variable_get(:'@transport_factory').should be_an_instance_of(BaseTransportFactory)
- server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(BinaryProtocolFactory)
+ server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
+ server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory)
+ server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory)
end
# serve is a noop, so can't test that
end
- shared_examples_for "servers" do
+ describe Thrift::SimpleServer do
before(:each) do
@processor = mock("Processor")
@serverTrans = mock("ServerTransport")
@trans = mock("BaseTransport")
@prot = mock("BaseProtocol")
@client = mock("Client")
- @server = server_type.new(@processor, @serverTrans, @trans, @prot)
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
- end
-
- describe SimpleServer do
- it_should_behave_like "servers"
-
- def server_type
- SimpleServer
- end
-
+
it "should serve in the main thread" do
@serverTrans.should_receive(:listen).ordered
@serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
@@ -68,11 +59,14 @@
end
end
- describe ThreadedServer do
- it_should_behave_like "servers"
-
- def server_type
- ThreadedServer
+ describe Thrift::ThreadedServer do
+ before(:each) do
+ @processor = mock("Processor")
+ @serverTrans = mock("ServerTransport")
+ @trans = mock("BaseTransport")
+ @prot = mock("BaseProtocol")
+ @client = mock("Client")
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should serve using threads" do
@@ -95,16 +89,18 @@
end
end
- describe ThreadPoolServer do
- it_should_behave_like "servers"
-
- def server_type
- # put this stuff here so it runs before the server is created
+ describe Thrift::ThreadPoolServer do
+ before(:each) do
+ @processor = mock("Processor")
+ @serverTrans = mock("ServerTransport")
+ @trans = mock("BaseTransport")
+ @prot = mock("BaseProtocol")
+ @client = mock("Client")
@threadQ = mock("SizedQueue")
SizedQueue.should_receive(:new).with(20).and_return(@threadQ)
@excQ = mock("Queue")
Queue.should_receive(:new).and_return(@excQ)
- ThreadPoolServer
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should set up the queues" do
@@ -113,21 +109,13 @@
end
it "should serve inside a thread" do
- Thread.should_receive(:new).and_return do |block|
- @server.should_receive(:serve)
- block.call
- @server.rspec_verify
- end
+ @server.should_receive(:serve)
@excQ.should_receive(:pop).and_throw(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)
end
it "should avoid running the server twice when retrying rescuable_serve" do
- Thread.should_receive(:new).and_return do |block|
- @server.should_receive(:serve)
- block.call
- @server.rspec_verify
- end
+ @server.should_receive(:serve)
@excQ.should_receive(:pop).twice.and_throw(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)