Author: kclark
Date: Tue Jun 17 17:57:46 2008
New Revision: 668915
URL: http://svn.apache.org/viewvc?rev=668915&view=rev
Log:
Add caller info to the deprecation warning
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=668915&r1=668914&r2=668915&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:57:46
2008
@@ -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)
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=668915&r1=668914&r2=668915&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:57:46
2008
@@ -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"