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
This commit is contained in:
Kevin Clark 2008-06-18 01:16:50 +00:00
parent 4eea89737a
commit 2e4f9d61dc

View File

@ -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