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/union_spec.rb b/lib/rb/spec/union_spec.rb
index fad649c..db08cab 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -17,21 +17,19 @@
 # under the License.
 #
 
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
 
-class ThriftUnionSpec < Spec::ExampleGroup
-  include Thrift
-  include SpecNamespace
+describe 'Union' do
 
-  describe Union do
+  describe Thrift::Union do
     it "should return nil value in unset union" do
-      union = My_union.new
+      union = SpecNamespace::My_union.new
       union.get_set_field.should == nil
       union.get_value.should == nil
     end
 
     it "should set a field and be accessible through get_value and the named field accessor" do
-      union = My_union.new
+      union = SpecNamespace::My_union.new
       union.integer32 = 25
       union.get_set_field.should == :integer32
       union.get_value.should == 25
@@ -39,30 +37,30 @@
     end
 
     it "should work correctly when instantiated with static field constructors" do
-      union = My_union.integer32(5)
+      union = SpecNamespace::My_union.integer32(5)
       union.get_set_field.should == :integer32
       union.integer32.should == 5
     end
 
     it "should raise for wrong set field" do
-      union = My_union.new
+      union = SpecNamespace::My_union.new
       union.integer32 = 25
       lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
     end
-     
+
     it "should not be equal to nil" do
-      union = My_union.new
+      union = SpecNamespace::My_union.new
       union.should_not == nil
     end
-     
+
     it "should not equate two different unions, i32 vs. string" do
-      union = My_union.new(:integer32, 25)
-      other_union = My_union.new(:some_characters, "blah!")
+      union = SpecNamespace::My_union.new(:integer32, 25)
+      other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
       union.should_not == other_union
     end
 
     it "should properly reset setfield and setvalue" do
-      union = My_union.new(:integer32, 25)
+      union = SpecNamespace::My_union.new(:integer32, 25)
       union.get_set_field.should == :integer32
       union.some_characters = "blah!"
       union.get_set_field.should == :some_characters
@@ -71,24 +69,24 @@
     end
 
     it "should not equate two different unions with different values" do
-      union = My_union.new(:integer32, 25)
-      other_union = My_union.new(:integer32, 400)
+      union = SpecNamespace::My_union.new(:integer32, 25)
+      other_union = SpecNamespace::My_union.new(:integer32, 400)
       union.should_not == other_union
     end
 
     it "should not equate two different unions with different fields" do
-      union = My_union.new(:integer32, 25)
-      other_union = My_union.new(:other_i32, 25)
+      union = SpecNamespace::My_union.new(:integer32, 25)
+      other_union = SpecNamespace::My_union.new(:other_i32, 25)
       union.should_not == other_union
     end
 
     it "should inspect properly" do
-      union = My_union.new(:integer32, 25)
+      union = SpecNamespace::My_union.new(:integer32, 25)
       union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
     end
 
     it "should not allow setting with instance_variable_set" do
-      union = My_union.new(:integer32, 27)
+      union = SpecNamespace::My_union.new(:integer32, 27)
       union.instance_variable_set(:@some_characters, "hallo!")
       union.get_set_field.should == :integer32
       union.get_value.should == 27
@@ -99,42 +97,42 @@
       trans = Thrift::MemoryBufferTransport.new
       proto = Thrift::BinaryProtocol.new(trans)
 
-      union = My_union.new(:integer32, 25)
+      union = SpecNamespace::My_union.new(:integer32, 25)
       union.write(proto)
 
-      other_union = My_union.new(:integer32, 25)
+      other_union = SpecNamespace::My_union.new(:integer32, 25)
       other_union.read(proto)
       other_union.should == union
     end
 
     it "should raise when validating unset union" do
-      union = My_union.new
+      union = SpecNamespace::My_union.new
       lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
 
-      other_union = My_union.new(:integer32, 1)
+      other_union = SpecNamespace::My_union.new(:integer32, 1)
       lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
     end
 
     it "should validate an enum field properly" do
-      union = TestUnion.new(:enum_field, 3)
+      union = SpecNamespace::TestUnion.new(:enum_field, 3)
       union.get_set_field.should == :enum_field
-      lambda { union.validate }.should raise_error(ProtocolException, "Invalid value of field enum_field!")
+      lambda { union.validate }.should raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
 
-      other_union = TestUnion.new(:enum_field, 1)
-      lambda { other_union.validate }.should_not raise_error(ProtocolException, "Invalid value of field enum_field!")
+      other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
+      lambda { other_union.validate }.should_not raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
     end
 
     it "should properly serialize and match structs with a union" do
-      union = My_union.new(:integer32, 26)
-      swu = Struct_with_union.new(:fun_union => union)
+      union = SpecNamespace::My_union.new(:integer32, 26)
+      swu = SpecNamespace::Struct_with_union.new(:fun_union => union)
 
       trans = Thrift::MemoryBufferTransport.new
       proto = Thrift::CompactProtocol.new(trans)
 
       swu.write(proto)
 
-      other_union = My_union.new(:some_characters, "hello there")
-      swu2 = Struct_with_union.new(:fun_union => other_union)
+      other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
+      swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
 
       swu2.should_not == swu
 
@@ -143,30 +141,30 @@
     end
 
     it "should support old style constructor" do
-      union = My_union.new(:integer32 => 26)
+      union = SpecNamespace::My_union.new(:integer32 => 26)
       union.get_set_field.should == :integer32
       union.get_value.should == 26
     end
 
     it "should not throw an error when inspected and unset" do
-      lambda{TestUnion.new().inspect}.should_not raise_error
+      lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
     end
 
     it "should print enum value name when inspected" do
-      My_union.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
+      SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
 
-      My_union.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>" 
+      SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
     end
 
     it "should offer field? methods" do
-      My_union.new.some_enum?.should be_false
-      My_union.new(:some_enum => SomeEnum::ONE).some_enum?.should be_true
-      My_union.new(:im_true => false).im_true?.should be_true
-      My_union.new(:im_true => true).im_true?.should be_true
+      SpecNamespace::My_union.new.some_enum?.should be_false
+      SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?.should be_true
+      SpecNamespace::My_union.new(:im_true => false).im_true?.should be_true
+      SpecNamespace::My_union.new(:im_true => true).im_true?.should be_true
     end
 
     it "should pretty print binary fields" do
-      TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
+      SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
     end
 
     it "should be comparable" do
@@ -177,10 +175,10 @@
         [1,   1,  1,  0]]
 
       objs = [
-        TestUnion.new(:string_field, "blah"), 
-        TestUnion.new(:string_field, "blahblah"),
-        TestUnion.new(:i32_field, 1),
-        TestUnion.new()]
+        SpecNamespace::TestUnion.new(:string_field, "blah"),
+        SpecNamespace::TestUnion.new(:string_field, "blahblah"),
+        SpecNamespace::TestUnion.new(:i32_field, 1),
+        SpecNamespace::TestUnion.new()]
 
       for y in 0..3
         for x in 0..3