Actually turn off deprecation when Thrift::DEPRECATION is false


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668910 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb
index 62ff396..03a7427 100644
--- a/lib/rb/spec/deprecation_spec.rb
+++ b/lib/rb/spec/deprecation_spec.rb
@@ -1,6 +1,23 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
+shared_examples_for "deprecation" do
+  before(:all) do
+    # ensure deprecation is turned on
+    Thrift.send :remove_const, :DEPRECATION
+    Thrift.const_set :DEPRECATION, true
+  end
+
+  after(:all) do
+    # now turn it off again
+    # no other specs should want it
+    Thrift.send :remove_const, :DEPRECATION
+    Thrift.const_set :DEPRECATION, false
+  end
+end
+
 describe 'deprecate!' do
+  it_should_behave_like "deprecation"
+
   def stub_stderr(callstr)
     STDERR.should_receive(:puts).with("Warning: calling deprecated method #{callstr}")
   end
@@ -135,6 +152,8 @@
 end
 
 describe "deprecate_class!" do
+  it_should_behave_like "deprecation"
+
   it "should create a new global constant that points to the old one" do
     begin
       klass = Class.new do
@@ -146,7 +165,7 @@
       DeprecationSpecOldClass.should eql(klass)
       DeprecationSpecOldClass.new.foo.should == "foo"
     ensure
-      Object.send :remove_const, :DeprecationSpecOldClass
+      Object.send :remove_const, :DeprecationSpecOldClass if Object.const_defined? :DeprecationSpecOldClass
     end
   end
 end