Skip to content

Commit 273e281

Browse files
andrykonchineregon
authored andcommitted
Add specs for IO.select
1 parent 810ed27 commit 273e281

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

spec/ruby/core/io/select_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@
114114
it "raises an ArgumentError when passed a negative timeout" do
115115
-> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError)
116116
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
117150
end
118151

119152
describe "IO.select when passed nil for timeout" do

0 commit comments

Comments
 (0)