Author: kclark
Date: Tue Jun 17 17:56:08 2008
New Revision: 668910

URL: http://svn.apache.org/viewvc?rev=668910&view=rev
Log:
Actually turn off deprecation when Thrift::DEPRECATION is false

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
    incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb?rev=668910&r1=668909&r2=668910&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb Tue Jun 17 17:56:08 
2008
@@ -9,6 +9,7 @@
   # Example:
   #   deprecate! :readAll => :read_all
   def deprecate!(methods)
+    return unless Thrift::DEPRECATION
     methods.each_pair do |old, new|
       module_eval <<-EOF
         def #{old}(*args, &block)
@@ -35,6 +36,7 @@
   # another idea is to not make the old name a pointer to the new, but rather
   # a pointer to a proxy class that logs deprecation warnings and forwards 
methods
   def deprecate_class!(klasses)
+    return unless Thrift::DEPRECATION
     klasses.each_pair do |old, new|
       Object.const_set old, new
     end

Modified: incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb?rev=668910&r1=668909&r2=668910&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb Tue Jun 17 17:56:08 
2008
@@ -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


Reply via email to