Updated RubySpec source to 55122684.
[rbx.git] / spec / frozen / 1.8 / core / io / popen_spec.rb
blob975811b2fc5307813ddd131090034f8c60f96d1d
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')
12       end
13     end
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|
18           io.write("bar")
19           io.read 3
20         end
22         data.should == "bar"
23       end
25       it "writes to a write-only pipe" do
26         begin
27           tmp_file = tmp "IO_popen_spec_#{$$}"
29           data = IO.popen "cat > #{tmp_file}", 'w' do |io|
30             io.write 'bar'
32             lambda { io.read.should }.should \
33               raise_error(IOError, 'not opened for reading')
34           end
36           File.read(tmp_file).should == 'bar'
38         ensure
39           File.unlink tmp_file if File.exist? tmp_file
40         end
41       end
42     end
44     it "allows the io to be closed inside the block" do
45       io = IO.popen('yes', 'r') do |io|
46         io.close
48         io.closed?.should == true
50         io
51       end
53       io.closed?.should == true
54     end
55   #end
57   it "needs to be reviewed for spec completeness"
58 end