Author: Kevin Ballard <kevin@rapleaf.com>
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@671979
13f79535-47bb-0310-9956-
ffa450edef68
end
def open?
- !@handle.nil?
+ !@handle.nil? and !@handle.closed?
end
def write(str)
+ raise IOError, "closed stream" unless open?
begin
@handle.write(str)
rescue StandardError
end
def read(sz, partial=false)
+ raise IOError, "closed stream" unless open?
begin
if partial
data = @handle.readpartial(sz)
lambda { @socket.write("fail") }.should raise_error
@socket.should_not be_open
end
+
+ it "should raise an error when the stream is closed" do
+ @socket.open
+ @handle.stub!(:closed?).and_return(true)
+ @socket.should_not be_open
+ lambda { @socket.write("fail") }.should raise_error(IOError, "closed stream")
+ lambda { @socket.read(10) }.should raise_error(IOError, "closed stream")
+ end
end