rb: Ensure the transport is closed if an exception is raised serializing data in Client.send_message [THRIFT-75]

Author: Kevin Ballard <kevin@rapleaf.com>


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@680538 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/client_spec.rb b/lib/rb/spec/client_spec.rb
index b92bbec..980552b 100644
--- a/lib/rb/spec/client_spec.rb
+++ b/lib/rb/spec/client_spec.rb
@@ -65,5 +65,17 @@
       end
       lambda { @client.receive_message(nil) }.should raise_error(StandardError)
     end
+
+    it "should close the transport if an error occurs while sending a message" do
+      @prot.stub!(:write_message_begin)
+      @prot.should_not_receive(:write_message_end)
+      mock_args = mock("#<TestMessage_args:mock>")
+      mock_args.should_receive(:write).with(@prot).and_raise(StandardError)
+      trans = mock("MockTransport")
+      @prot.stub!(:trans).and_return(trans)
+      trans.should_receive(:close)
+      klass = mock("TestMessage_args", :new => mock_args)
+      lambda { @client.send_message("testMessage", klass) }.should raise_error(StandardError)
+    end
   end
 end