From: Kevin Clark Date: Wed, 18 Jun 2008 00:56:08 +0000 (+0000) Subject: Actually turn off deprecation when Thrift::DEPRECATION is false X-Git-Tag: 0.2.0~639 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=96cc5164928e589e23171e4a61437599748e55d2;p=common%2Fthrift.git 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/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb index 0ee4e264..f7221b44 100644 --- a/lib/rb/lib/thrift/deprecation.rb +++ b/lib/rb/lib/thrift/deprecation.rb @@ -9,6 +9,7 @@ class Module # 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 @@ module Kernel # 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 diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb index 62ff3965..03a7427d 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 @@ describe 'deprecate!' do 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 @@ describe "deprecate_class!" do 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