1 require File.dirname(__FILE__) + '/../../spec_helper'
3 describe "IO::popen" do
4 # NOTE: cause Errno::EBADF on 1.8.6
5 #ruby_bug "#", "1.8.6" do
6 it "reads from a read-only pipe" do
7 IO.popen("echo foo", "r") do |io|
8 io.read.should == "foo\n"
10 lambda { io.write('foo').should }.should \
11 raise_error(IOError, 'not opened for writing')
15 platform_is_not :windows do
16 it "reads and writes to a read/write pipe" do
17 data = IO.popen("cat", "r+") do |io|
25 it "writes to a write-only pipe" do
27 tmp_file = tmp "IO_popen_spec_#{$$}"
29 data = IO.popen "cat > #{tmp_file}", 'w' do |io|
32 lambda { io.read.should }.should \
33 raise_error(IOError, 'not opened for reading')
36 File.read(tmp_file).should == 'bar'
39 File.unlink tmp_file if File.exist? tmp_file
44 it "allows the io to be closed inside the block" do
45 io = IO.popen('yes', 'r') do |io|
48 io.closed?.should == true
53 io.closed?.should == true
57 it "needs to be reviewed for spec completeness"