Add caller info to the deprecation warning
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668915 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb
index 2f7d898..b3fd12e 100644
--- a/lib/rb/lib/thrift/deprecation.rb
+++ b/lib/rb/lib/thrift/deprecation.rb
@@ -17,6 +17,7 @@
def #{old}(*args, &block)
old, new = #{[old,new].inspect}
STDERR.puts "Warning: calling deprecated method \#{self.is_a?(Module) ? "\#{self}." : "\#{self.class}#"}\#{old}"
+ STDERR.puts " from \#{caller.first}"
target = (self.is_a?(Module) ? (class << self;self;end) : self.class)
target.send :define_method, old, target.instance_method(new) # unwrap
target.instance_method(new).bind(self).call(*args, &block)
diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb
index 03a7427..08e1504 100644
--- a/lib/rb/spec/deprecation_spec.rb
+++ b/lib/rb/spec/deprecation_spec.rb
@@ -18,8 +18,10 @@
describe 'deprecate!' do
it_should_behave_like "deprecation"
- def stub_stderr(callstr)
+ def stub_stderr(callstr, offset=1)
STDERR.should_receive(:puts).with("Warning: calling deprecated method #{callstr}")
+ line = caller.first[/\d+$/].to_i + offset
+ STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
end
it "should work for Module methods" do
@@ -95,8 +97,8 @@
end
deprecate! :old1 => :new1, :old2 => :new2
end
- stub_stderr("#{klass.inspect}#old1").ordered
- stub_stderr("#{klass.inspect}#old2").ordered
+ stub_stderr("#{klass.inspect}#old1", 3).ordered
+ stub_stderr("#{klass.inspect}#old2", 3).ordered
inst = klass.new
inst.old1.should == "new 1"
inst.old2.should == "new 2"