Skip to content

Commit 3e71d89

Browse files
herwinweregon
authored andcommitted
Wrap tests for unixsocket in an outer guard block
Normalize to `with_feature :unix_socket`, which is more descriptive and generic than checking for windows.
1 parent 978823f commit 3e71d89

13 files changed

+39
-58
lines changed

library/socket/unixsocket/addr_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#addr" do
5-
6-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#addr" do
76
before :each do
87
@path = SocketSpecs.socket_path
98
@server = UNIXServer.open(@path)

library/socket/unixsocket/inspect_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#inspect" do
5-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#inspect" do
66
it "returns sockets fd for unnamed sockets" do
77
begin
88
s1, s2 = UNIXSocket.socketpair

library/socket/unixsocket/local_address_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
end
4747
end
4848
end
49-
end
5049

51-
with_feature :unix_socket do
5250
describe 'UNIXSocket#local_address with a UNIX socket pair' do
5351
before :each do
5452
@sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)

library/socket/unixsocket/new_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative 'shared/new'
33

4-
describe "UNIXSocket.new" do
5-
it_behaves_like :unixsocket_new, :new
4+
with_feature :unix_socket do
5+
describe "UNIXSocket.new" do
6+
it_behaves_like :unixsocket_new, :new
7+
end
68
end

library/socket/unixsocket/open_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
require_relative '../fixtures/classes'
33
require_relative 'shared/new'
44

5-
describe "UNIXSocket.open" do
6-
it_behaves_like :unixsocket_new, :open
7-
end
5+
with_feature :unix_socket do
6+
describe "UNIXSocket.open" do
7+
it_behaves_like :unixsocket_new, :open
8+
end
89

9-
describe "UNIXSocket.open" do
10-
platform_is_not :windows do
10+
describe "UNIXSocket.open" do
1111
before :each do
1212
@path = SocketSpecs.socket_path
1313
@server = UNIXServer.open(@path)

library/socket/unixsocket/pair_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
require_relative '../fixtures/classes'
33
require_relative '../shared/partially_closable_sockets'
44

5-
describe "UNIXSocket#pair" do
6-
platform_is_not :windows do
7-
5+
with_feature :unix_socket do
6+
describe "UNIXSocket#pair" do
87
it_should_behave_like :partially_closable_sockets
98

109
before :each do

library/socket/unixsocket/partially_closable_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
require_relative '../fixtures/classes'
33
require_relative '../shared/partially_closable_sockets'
44

5-
platform_is_not :windows do
5+
with_feature :unix_socket do
66
describe "UNIXSocket partial closability" do
7-
87
before :each do
98
@path = SocketSpecs.socket_path
109
@server = UNIXServer.open(@path)
@@ -20,6 +19,5 @@
2019
end
2120

2221
it_should_behave_like :partially_closable_sockets
23-
2422
end
2523
end

library/socket/unixsocket/path_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#path" do
5-
6-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#path" do
76
before :each do
87
@path = SocketSpecs.socket_path
98
@server = UNIXServer.open(@path)
@@ -24,5 +23,4 @@
2423
@client.path.should == ""
2524
end
2625
end
27-
2826
end

library/socket/unixsocket/peeraddr_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#peeraddr" do
5-
6-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#peeraddr" do
76
before :each do
87
@path = SocketSpecs.socket_path
98
@server = UNIXServer.open(@path)
@@ -26,5 +25,4 @@
2625
}.should raise_error(Errno::ENOTCONN)
2726
end
2827
end
29-
3028
end

library/socket/unixsocket/recv_io_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#recv_io" do
5-
6-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#recv_io" do
76
before :each do
87
@path = SocketSpecs.socket_path
98
@server = UNIXServer.open(@path)
@@ -41,9 +40,7 @@
4140
@io.should be_an_instance_of(File)
4241
end
4342
end
44-
end
4543

46-
with_feature :unix_socket do
4744
describe 'UNIXSocket#recv_io' do
4845
before do
4946
@file = File.open('/dev/null', 'w')

library/socket/unixsocket/recvfrom_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#recvfrom" do
5-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#recvfrom" do
66
before :each do
77
@path = SocketSpecs.socket_path
88
@server = UNIXServer.open(@path)
@@ -42,10 +42,7 @@
4242
sock.close
4343
end
4444
end
45-
end
4645

47-
48-
with_feature :unix_socket do
4946
describe 'UNIXSocket#recvfrom' do
5047
describe 'using a socket pair' do
5148
before do

library/socket/unixsocket/send_io_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
require_relative '../spec_helper'
22
require_relative '../fixtures/classes'
33

4-
describe "UNIXSocket#send_io" do
5-
6-
platform_is_not :windows do
4+
with_feature :unix_socket do
5+
describe "UNIXSocket#send_io" do
76
before :each do
87
@path = SocketSpecs.socket_path
98
@server = UNIXServer.open(@path)
@@ -32,9 +31,7 @@
3231
@io.read.should == File.read(@send_io_path)
3332
end
3433
end
35-
end
3634

37-
with_feature :unix_socket do
3835
describe 'UNIXSocket#send_io' do
3936
before do
4037
@file = File.open('/dev/null', 'w')

library/socket/unixsocket/shared/new.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
require_relative '../../fixtures/classes'
33

44
describe :unixsocket_new, shared: true do
5-
platform_is_not :windows do
6-
before :each do
7-
@path = SocketSpecs.socket_path
8-
@server = UNIXServer.open(@path)
9-
end
5+
before :each do
6+
@path = SocketSpecs.socket_path
7+
@server = UNIXServer.open(@path)
8+
end
109

11-
after :each do
12-
@client.close if @client
13-
@server.close
14-
SocketSpecs.rm_socket @path
15-
end
10+
after :each do
11+
@client.close if @client
12+
@server.close
13+
SocketSpecs.rm_socket @path
14+
end
1615

17-
it "opens a unix socket on the specified file" do
18-
@client = UNIXSocket.send(@method, @path)
16+
it "opens a unix socket on the specified file" do
17+
@client = UNIXSocket.send(@method, @path)
1918

20-
@client.addr[0].should == "AF_UNIX"
21-
@client.should_not.closed?
22-
end
19+
@client.addr[0].should == "AF_UNIX"
20+
@client.should_not.closed?
2321
end
2422
end

0 commit comments

Comments
 (0)