1 require File.dirname(__FILE__) + '/../../spec_helper'
5 @io = File.open tmp('io.close.txt'), 'w'
9 @io.close unless @io.closed?
12 it "closes the stream" do
13 lambda { @io.close }.should_not raise_error
14 @io.closed?.should == true
18 @io.close.should == nil
21 it "makes the stream unavailable for any further data operations" do
24 lambda { @io.write "attempt to write" }.should raise_error(IOError)
25 lambda { @io.read }.should raise_error(IOError)
28 it "raises an IOError on subsequent invocations" do
31 lambda { @io.close }.should raise_error(IOError)
34 it "raises when a file descriptor is closed twice" do
35 io2 = IO.new @io.fileno
38 lambda { io2.close }.should raise_error(Errno::EBADF)
43 describe "IO#close on an IO.popen stream" do
46 io = IO.popen 'yes', 'r'
48 io.pid.should_not == 0
52 lambda { io.pid }.should raise_error(IOError, 'closed stream')
56 io = IO.popen 'true', 'r'
59 $?.exitstatus.should == 0
61 io = IO.popen 'false', 'r'
64 $?.exitstatus.should == 1
67 it "waits for the child to exit" do
68 io = IO.popen 'yes', 'r'
71 $?.exitstatus.should_not == 0 # SIGPIPE/EPIPE