Skip to content

Commit 5758b3e

Browse files
committed
Enable File.socket? test on Windows, improve FileTest.socket?
1 parent 7bace0d commit 5758b3e

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

core/file/socket_spec.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,3 @@
55
describe "File.socket?" do
66
it_behaves_like :file_socket, :socket?, File
77
end
8-
9-
describe "File.socket?" do
10-
it "returns false if file does not exist" do
11-
File.socket?("I_am_a_bogus_file").should == false
12-
end
13-
14-
it "returns false if the file is not a socket" do
15-
filename = tmp("i_exist")
16-
touch(filename)
17-
18-
File.socket?(filename).should == false
19-
20-
rm_r filename
21-
end
22-
end
23-
24-
platform_is_not :windows do
25-
describe "File.socket?" do
26-
before :each do
27-
# We need a really short name here.
28-
# On Linux the path length is limited to 107, see unix(7).
29-
@name = tmp("s")
30-
@server = UNIXServer.new @name
31-
end
32-
33-
after :each do
34-
@server.close
35-
rm_r @name
36-
end
37-
38-
it "returns true if the file is a socket" do
39-
File.socket?(@name).should == true
40-
end
41-
end
42-
end

shared/file/socket.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
11
describe :file_socket, shared: true do
2-
it "accepts an object that has a #to_path method"
2+
it "returns false if file does not exist" do
3+
File.socket?("I_am_a_bogus_file").should == false
4+
end
5+
6+
it "returns false if the file is not a socket" do
7+
filename = tmp("i_exist")
8+
touch(filename)
9+
10+
File.socket?(filename).should == false
11+
12+
rm_r filename
13+
end
14+
15+
it "returns true if the file is a socket" do
16+
# We need a really short name here.
17+
# On Linux the path length is limited to 107, see unix(7).
18+
name = tmp("s")
19+
server = UNIXServer.new(name)
20+
21+
File.socket?(name).should == true
22+
23+
server.close
24+
rm_r name
25+
end
26+
27+
it "accepts an object that has a #to_path method" do
28+
obj = Object.new
29+
def obj.to_path
30+
__FILE__
31+
end
32+
33+
File.socket?(obj).should == false
34+
end
335
end

0 commit comments

Comments
 (0)