Skip to content

Commit b67d5d9

Browse files
committed
Enable File.socket? test on Windows, improve FileTest.socket?
1 parent d770427 commit b67d5d9

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

core/file/socket_spec.rb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
11
require_relative '../../spec_helper'
22
require_relative '../../shared/file/socket'
3-
require 'socket'
43

54
describe "File.socket?" do
65
it_behaves_like :file_socket, :socket?, File
76
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: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
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+
# Can't create a File::Stat object if file doesn't exist.
4+
skip if @object == FileStat
5+
6+
@object.send(@method, "I_am_a_bogus_file").should == false
7+
end
8+
9+
it "returns false if the file is not a socket" do
10+
filename = tmp("i_exist")
11+
touch(filename)
12+
13+
@object.send(@method, filename).should == false
14+
15+
rm_r filename
16+
end
17+
18+
it "returns true if the file is a socket" do
19+
require 'socket'
20+
21+
# We need a really short name here.
22+
# On Linux the path length is limited to 107, see unix(7).
23+
name = tmp("s")
24+
server = UNIXServer.new(name)
25+
26+
@object.send(@method, name).should == true
27+
28+
server.close
29+
rm_r name
30+
end
31+
32+
it "accepts an object that has a #to_path method" do
33+
obj = Object.new
34+
def obj.to_path
35+
__FILE__
36+
end
37+
38+
@object.send(@method, obj).should == false
39+
end
340
end

0 commit comments

Comments
 (0)