TransportException should be raised when Socket is not open instead of IOError
diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb
index f5e6f3b..b3476ea 100644
--- a/lib/rb/lib/thrift/transport/socket.rb
+++ b/lib/rb/lib/thrift/transport/socket.rb
@@ -62,7 +62,7 @@
end
def write(str)
- raise IOError, "closed stream" unless open?
+ raise TransportException.new(TransportException::NOT_OPEN, "closed stream") unless open?
str = Bytes.force_binary_encoding(str)
begin
if @timeout.nil? or @timeout == 0
@@ -94,7 +94,7 @@
end
def read(sz)
- raise IOError, "closed stream" unless open?
+ raise TransportException.new(TransportException::NOT_OPEN, "closed stream") unless open?
begin
if @timeout.nil? or @timeout == 0
diff --git a/lib/rb/spec/socket_spec_shared.rb b/lib/rb/spec/socket_spec_shared.rb
index 32bdb71..2015ac0 100644
--- a/lib/rb/spec/socket_spec_shared.rb
+++ b/lib/rb/spec/socket_spec_shared.rb
@@ -67,8 +67,8 @@
@socket.open
allow(@handle).to receive(:closed?).and_return(true)
expect(@socket).not_to be_open
- expect { @socket.write("fail") }.to raise_error(IOError, "closed stream")
- expect { @socket.read(10) }.to raise_error(IOError, "closed stream")
+ expect { @socket.write("fail") }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
+ expect { @socket.read(10) }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should support the timeout accessor for read" do