1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require File.dirname(__FILE__) + '/fixtures/classes'
5 describe "IO#close_read" do
8 @io = IO.popen 'cat', "r+"
12 @io.close unless @io.closed?
15 it "closes the read end of a duplex I/O stream" do
18 lambda { @io.read }.should raise_error(IOError)
21 it "raises an IOError on subsequent invocations" do
24 lambda { @io.close_read }.should raise_error(IOError)
27 it "allows subsequent invocation of close" do
30 lambda { @io.close }.should_not raise_error
33 it "raises an IOError if the stream is writable and not duplexed" do
34 io = File.open tmp('io.close.txt'), 'w'
37 lambda { io.close_read }.should raise_error(IOError)
39 io.close unless io.closed?
43 it "closes the stream if it is neither writable nor duplexed" do
44 io_close_path = tmp 'io.close.txt'
45 FileUtils.touch io_close_path
47 io = File.open io_close_path
51 io.closed?.should == true
54 it "raises IOError on closed stream" do
57 lambda { @io.close_read }.should raise_error(IOError)