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)
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
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"