|
114 | 114 | it "raises an ArgumentError when passed a negative timeout" do
|
115 | 115 | -> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError)
|
116 | 116 | end
|
| 117 | + |
| 118 | + describe "returns the available descriptors when the file descriptor" do |
| 119 | + it "is in both read and error arrays" do |
| 120 | + @wr.write("foobar") |
| 121 | + result = IO.select([@rd], nil, [@rd]) |
| 122 | + result.should == [[@rd], [], []] |
| 123 | + end |
| 124 | + |
| 125 | + it "is in both write and error arrays" do |
| 126 | + result = IO.select(nil, [@wr], [@wr]) |
| 127 | + result.should == [[], [@wr], []] |
| 128 | + end |
| 129 | + |
| 130 | + it "is in both read and write arrays" do |
| 131 | + filename = tmp("IO_select_read_write_file") |
| 132 | + w = File.open(filename, 'w+') |
| 133 | + begin |
| 134 | + IO.select([w], [w], []).should == [[w], [w], []] |
| 135 | + ensure |
| 136 | + w.close |
| 137 | + rm_r filename |
| 138 | + end |
| 139 | + |
| 140 | + IO.select([@wr], [@wr], []).should == [[], [@wr], []] |
| 141 | + |
| 142 | + @wr.write("foobar") |
| 143 | + # CRuby on macOS returns [[@rd], [@rd], []], weird but we accept it here, probably only for pipe read-end |
| 144 | + [ |
| 145 | + [[@rd], [], []], |
| 146 | + [[@rd], [@rd], []] |
| 147 | + ].should.include? IO.select([@rd], [@rd], []) |
| 148 | + end |
| 149 | + end |
117 | 150 | end
|
118 | 151 |
|
119 | 152 | describe "IO.select when passed nil for timeout" do
|
|
0 commit comments