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/base_protocol_spec.rb b/lib/rb/spec/base_protocol_spec.rb
index bd9b59b..c0f9cfc 100644
--- a/lib/rb/spec/base_protocol_spec.rb
+++ b/lib/rb/spec/base_protocol_spec.rb
@@ -17,17 +17,16 @@
 # under the License.
 #
 
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
 
-class ThriftBaseProtocolSpec < Spec::ExampleGroup
-  include Thrift
+describe 'BaseProtocol' do
 
   before(:each) do
     @trans = mock("MockTransport")
-    @prot = BaseProtocol.new(@trans)
+    @prot = Thrift::BaseProtocol.new(@trans)
   end
 
-  describe BaseProtocol do
+  describe Thrift::BaseProtocol do
     # most of the methods are stubs, so we can ignore them
 
     it "should make trans accessible" do
@@ -51,16 +50,16 @@
       @prot.should_receive(:write_string).with('string').ordered
       struct = mock('Struct')
       struct.should_receive(:write).with(@prot).ordered
-      @prot.write_type(Types::BOOL, 'bool')
-      @prot.write_type(Types::BYTE, 'byte')
-      @prot.write_type(Types::DOUBLE, 'double')
-      @prot.write_type(Types::I16, 'i16')
-      @prot.write_type(Types::I32, 'i32')
-      @prot.write_type(Types::I64, 'i64')
-      @prot.write_type(Types::STRING, 'string')
-      @prot.write_type(Types::STRUCT, struct)
+      @prot.write_type(Thrift::Types::BOOL, 'bool')
+      @prot.write_type(Thrift::Types::BYTE, 'byte')
+      @prot.write_type(Thrift::Types::DOUBLE, 'double')
+      @prot.write_type(Thrift::Types::I16, 'i16')
+      @prot.write_type(Thrift::Types::I32, 'i32')
+      @prot.write_type(Thrift::Types::I64, 'i64')
+      @prot.write_type(Thrift::Types::STRING, 'string')
+      @prot.write_type(Thrift::Types::STRUCT, struct)
       # all other types are not implemented
-      [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
+      [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
         lambda { @prot.write_type(type, type.to_s) }.should raise_error(NotImplementedError)
       end
     end
@@ -73,15 +72,15 @@
       @prot.should_receive(:read_i64).ordered
       @prot.should_receive(:read_double).ordered
       @prot.should_receive(:read_string).ordered
-      @prot.read_type(Types::BOOL)
-      @prot.read_type(Types::BYTE)
-      @prot.read_type(Types::I16)
-      @prot.read_type(Types::I32)
-      @prot.read_type(Types::I64)
-      @prot.read_type(Types::DOUBLE)
-      @prot.read_type(Types::STRING)
+      @prot.read_type(Thrift::Types::BOOL)
+      @prot.read_type(Thrift::Types::BYTE)
+      @prot.read_type(Thrift::Types::I16)
+      @prot.read_type(Thrift::Types::I32)
+      @prot.read_type(Thrift::Types::I64)
+      @prot.read_type(Thrift::Types::DOUBLE)
+      @prot.read_type(Thrift::Types::STRING)
       # all other types are not implemented
-      [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
+      [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
         lambda { @prot.read_type(type) }.should raise_error(NotImplementedError)
       end
     end
@@ -94,67 +93,67 @@
       @prot.should_receive(:read_i64).ordered
       @prot.should_receive(:read_double).ordered
       @prot.should_receive(:read_string).ordered
-      @prot.skip(Types::BOOL)
-      @prot.skip(Types::BYTE)
-      @prot.skip(Types::I16)
-      @prot.skip(Types::I32)
-      @prot.skip(Types::I64)
-      @prot.skip(Types::DOUBLE)
-      @prot.skip(Types::STRING)
-      @prot.skip(Types::STOP) # should do absolutely nothing
+      @prot.skip(Thrift::Types::BOOL)
+      @prot.skip(Thrift::Types::BYTE)
+      @prot.skip(Thrift::Types::I16)
+      @prot.skip(Thrift::Types::I32)
+      @prot.skip(Thrift::Types::I64)
+      @prot.skip(Thrift::Types::DOUBLE)
+      @prot.skip(Thrift::Types::STRING)
+      @prot.skip(Thrift::Types::STOP) # should do absolutely nothing
     end
 
     it "should skip structs" do
       real_skip = @prot.method(:skip)
       @prot.should_receive(:read_struct_begin).ordered
       @prot.should_receive(:read_field_begin).exactly(4).times.and_return(
-        ['field 1', Types::STRING, 1],
-        ['field 2', Types::I32, 2],
-        ['field 3', Types::MAP, 3],
-        [nil, Types::STOP, 0]
+        ['field 1', Thrift::Types::STRING, 1],
+        ['field 2', Thrift::Types::I32, 2],
+        ['field 3', Thrift::Types::MAP, 3],
+        [nil, Thrift::Types::STOP, 0]
       )
       @prot.should_receive(:read_field_end).exactly(3).times
       @prot.should_receive(:read_string).exactly(3).times
       @prot.should_receive(:read_i32).ordered
-      @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRING, 1])
+      @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
       # @prot.should_receive(:read_string).exactly(2).times
       @prot.should_receive(:read_map_end).ordered
       @prot.should_receive(:read_struct_end).ordered
-      real_skip.call(Types::STRUCT)
+      real_skip.call(Thrift::Types::STRUCT)
     end
 
     it "should skip maps" do
       real_skip = @prot.method(:skip)
-      @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRUCT, 1])
+      @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
       @prot.should_receive(:read_string).ordered
       @prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
-      @prot.should_receive(:read_field_begin).ordered.and_return([nil, Types::STOP, nil]);
+      @prot.should_receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
       @prot.should_receive(:read_struct_end).ordered
       @prot.should_receive(:read_map_end).ordered
-      real_skip.call(Types::MAP)
+      real_skip.call(Thrift::Types::MAP)
     end
 
     it "should skip sets" do
       real_skip = @prot.method(:skip)
-      @prot.should_receive(:read_set_begin).ordered.and_return([Types::I64, 9])
+      @prot.should_receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
       @prot.should_receive(:read_i64).ordered.exactly(9).times
       @prot.should_receive(:read_set_end)
-      real_skip.call(Types::SET)
+      real_skip.call(Thrift::Types::SET)
     end
 
     it "should skip lists" do
       real_skip = @prot.method(:skip)
-      @prot.should_receive(:read_list_begin).ordered.and_return([Types::DOUBLE, 11])
+      @prot.should_receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
       @prot.should_receive(:read_double).ordered.exactly(11).times
       @prot.should_receive(:read_list_end)
-      real_skip.call(Types::LIST)
+      real_skip.call(Thrift::Types::LIST)
     end
   end
 
-  describe BaseProtocolFactory do
+  describe Thrift::BaseProtocolFactory do
     it "should raise NotImplementedError" do
       # returning nil since Protocol is just an abstract class
-      lambda {BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
+      lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
     end
   end
 end