From 2e4f9d61dc840ba04328bfecef084b995ab5e366 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Wed, 18 Jun 2008 01:16:50 +0000 Subject: [PATCH] rb: Enhance the backwards compatibility spec to ensure that the deprecated method names really do correspond to the new method names git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669005 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/spec/backwards_compatibility_spec.rb | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/rb/spec/backwards_compatibility_spec.rb b/lib/rb/spec/backwards_compatibility_spec.rb index 5c1bc195..eb35a95c 100644 --- a/lib/rb/spec/backwards_compatibility_spec.rb +++ b/lib/rb/spec/backwards_compatibility_spec.rb @@ -102,13 +102,32 @@ context "Backwards compatibility" do :getTransport => :get_transport } } + STDERR.stub!(:puts) # stub the deprecation warnings mapping.each_pair do |klass, methods| + # save these so they can be used after being mocked up + defn_method = klass.method(:define_method) + inst_method = klass.method(:instance_method) methods.each_pair do |oldmeth, newmeth| - # at the moment there's no way to introspect the deprecated methods - # to make sure they point to the new ones - # so let's just make sure both old and new methods exist + # ensure that calling the old method will call the new method + # and then redefine the old method to be the new one klass.should be_method_defined(oldmeth) klass.should be_method_defined(newmeth) + orig_method = inst_method.call(:initialize) + defn_method.call(:initialize, proc {} ) # stub out initialize + begin + mockmeth = mock("UnboundMethod: #{newmeth}") + mockmeth.should_receive(:bind).and_return do + mock("Method: #{newmeth}").tee do |meth| + meth.should_receive(:call) + end + end + klass.should_receive(:instance_method).with(newmeth).twice.and_return(mockmeth) + klass.should_receive(:define_method).with(oldmeth, mockmeth) + klass.new.send oldmeth + klass.rspec_verify + ensure + defn_method.call(:initialize, orig_method) + end end end end -- 2.17.1