Skip to content

Commit 6fc3352

Browse files
trinistrandrykonchin
authored andcommitted
Enable File.socket? test on Windows, improve FileTest.socket?
1 parent febada7 commit 6fc3352

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

core/file/socket_spec.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,10 @@
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
7-
end
86

9-
describe "File.socket?" do
107
it "returns false if file does not exist" do
118
File.socket?("I_am_a_bogus_file").should == false
129
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
4210
end

core/filetest/socket_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
describe "FileTest.socket?" do
55
it_behaves_like :file_socket, :socket?, FileTest
6+
7+
it "returns false if file does not exist" do
8+
FileTest.socket?("I_am_a_bogus_file").should == false
9+
end
610
end

shared/file/socket.rb

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

0 commit comments

Comments
 (0)