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 0ee4e26..f7221b4 100644
--- a/lib/rb/lib/thrift/deprecation.rb
+++ b/lib/rb/lib/thrift/deprecation.rb
@@ -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
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