From 3e71d894259f157ebbc32af56d8222c0d35b0ff0 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 30 Sep 2023 14:58:46 +0200 Subject: [PATCH] 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. --- library/socket/unixsocket/addr_spec.rb | 5 ++-- library/socket/unixsocket/inspect_spec.rb | 4 +-- .../socket/unixsocket/local_address_spec.rb | 2 -- library/socket/unixsocket/new_spec.rb | 6 ++-- library/socket/unixsocket/open_spec.rb | 10 +++---- library/socket/unixsocket/pair_spec.rb | 5 ++-- .../unixsocket/partially_closable_spec.rb | 4 +-- library/socket/unixsocket/path_spec.rb | 6 ++-- library/socket/unixsocket/peeraddr_spec.rb | 6 ++-- library/socket/unixsocket/recv_io_spec.rb | 7 ++--- library/socket/unixsocket/recvfrom_spec.rb | 7 ++--- library/socket/unixsocket/send_io_spec.rb | 7 ++--- library/socket/unixsocket/shared/new.rb | 28 +++++++++---------- 13 files changed, 39 insertions(+), 58 deletions(-) diff --git a/library/socket/unixsocket/addr_spec.rb b/library/socket/unixsocket/addr_spec.rb index e8431bea16..d93e061312 100644 --- a/library/socket/unixsocket/addr_spec.rb +++ b/library/socket/unixsocket/addr_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#addr" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#addr" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) diff --git a/library/socket/unixsocket/inspect_spec.rb b/library/socket/unixsocket/inspect_spec.rb index d2e3cabbd3..a542ba6db5 100644 --- a/library/socket/unixsocket/inspect_spec.rb +++ b/library/socket/unixsocket/inspect_spec.rb @@ -1,8 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#inspect" do - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#inspect" do it "returns sockets fd for unnamed sockets" do begin s1, s2 = UNIXSocket.socketpair diff --git a/library/socket/unixsocket/local_address_spec.rb b/library/socket/unixsocket/local_address_spec.rb index cbf315f9f4..734253e7f5 100644 --- a/library/socket/unixsocket/local_address_spec.rb +++ b/library/socket/unixsocket/local_address_spec.rb @@ -46,9 +46,7 @@ end end end -end -with_feature :unix_socket do describe 'UNIXSocket#local_address with a UNIX socket pair' do before :each do @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) diff --git a/library/socket/unixsocket/new_spec.rb b/library/socket/unixsocket/new_spec.rb index 05a6b3eda2..df6a2eefcc 100644 --- a/library/socket/unixsocket/new_spec.rb +++ b/library/socket/unixsocket/new_spec.rb @@ -1,6 +1,8 @@ require_relative '../spec_helper' require_relative 'shared/new' -describe "UNIXSocket.new" do - it_behaves_like :unixsocket_new, :new +with_feature :unix_socket do + describe "UNIXSocket.new" do + it_behaves_like :unixsocket_new, :new + end end diff --git a/library/socket/unixsocket/open_spec.rb b/library/socket/unixsocket/open_spec.rb index 99ad151bb8..61def30abb 100644 --- a/library/socket/unixsocket/open_spec.rb +++ b/library/socket/unixsocket/open_spec.rb @@ -2,12 +2,12 @@ require_relative '../fixtures/classes' require_relative 'shared/new' -describe "UNIXSocket.open" do - it_behaves_like :unixsocket_new, :open -end +with_feature :unix_socket do + describe "UNIXSocket.open" do + it_behaves_like :unixsocket_new, :open + end -describe "UNIXSocket.open" do - platform_is_not :windows do + describe "UNIXSocket.open" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) diff --git a/library/socket/unixsocket/pair_spec.rb b/library/socket/unixsocket/pair_spec.rb index 0cdc55f998..9a66c56c10 100644 --- a/library/socket/unixsocket/pair_spec.rb +++ b/library/socket/unixsocket/pair_spec.rb @@ -2,9 +2,8 @@ require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -describe "UNIXSocket#pair" do - platform_is_not :windows do - +with_feature :unix_socket do + describe "UNIXSocket#pair" do it_should_behave_like :partially_closable_sockets before :each do diff --git a/library/socket/unixsocket/partially_closable_spec.rb b/library/socket/unixsocket/partially_closable_spec.rb index 4f6ef8abd9..ef7d0f0b2a 100644 --- a/library/socket/unixsocket/partially_closable_spec.rb +++ b/library/socket/unixsocket/partially_closable_spec.rb @@ -2,9 +2,8 @@ require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -platform_is_not :windows do +with_feature :unix_socket do describe "UNIXSocket partial closability" do - before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -20,6 +19,5 @@ end it_should_behave_like :partially_closable_sockets - end end diff --git a/library/socket/unixsocket/path_spec.rb b/library/socket/unixsocket/path_spec.rb index 317ffc0975..a608378e4f 100644 --- a/library/socket/unixsocket/path_spec.rb +++ b/library/socket/unixsocket/path_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#path" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#path" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -24,5 +23,4 @@ @client.path.should == "" end end - end diff --git a/library/socket/unixsocket/peeraddr_spec.rb b/library/socket/unixsocket/peeraddr_spec.rb index 0b6b1ccf04..72bc96b1fe 100644 --- a/library/socket/unixsocket/peeraddr_spec.rb +++ b/library/socket/unixsocket/peeraddr_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#peeraddr" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#peeraddr" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -26,5 +25,4 @@ }.should raise_error(Errno::ENOTCONN) end end - end diff --git a/library/socket/unixsocket/recv_io_spec.rb b/library/socket/unixsocket/recv_io_spec.rb index 533f02a0fa..1dbc4538e3 100644 --- a/library/socket/unixsocket/recv_io_spec.rb +++ b/library/socket/unixsocket/recv_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#recv_io" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#recv_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -41,9 +40,7 @@ @io.should be_an_instance_of(File) end end -end -with_feature :unix_socket do describe 'UNIXSocket#recv_io' do before do @file = File.open('/dev/null', 'w') diff --git a/library/socket/unixsocket/recvfrom_spec.rb b/library/socket/unixsocket/recvfrom_spec.rb index c0e1cf670b..fedf74bb2f 100644 --- a/library/socket/unixsocket/recvfrom_spec.rb +++ b/library/socket/unixsocket/recvfrom_spec.rb @@ -1,8 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#recvfrom" do - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#recvfrom" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -42,10 +42,7 @@ sock.close end end -end - -with_feature :unix_socket do describe 'UNIXSocket#recvfrom' do describe 'using a socket pair' do before do diff --git a/library/socket/unixsocket/send_io_spec.rb b/library/socket/unixsocket/send_io_spec.rb index a2a7d26539..80f3550c6d 100644 --- a/library/socket/unixsocket/send_io_spec.rb +++ b/library/socket/unixsocket/send_io_spec.rb @@ -1,9 +1,8 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "UNIXSocket#send_io" do - - platform_is_not :windows do +with_feature :unix_socket do + describe "UNIXSocket#send_io" do before :each do @path = SocketSpecs.socket_path @server = UNIXServer.open(@path) @@ -32,9 +31,7 @@ @io.read.should == File.read(@send_io_path) end end -end -with_feature :unix_socket do describe 'UNIXSocket#send_io' do before do @file = File.open('/dev/null', 'w') diff --git a/library/socket/unixsocket/shared/new.rb b/library/socket/unixsocket/shared/new.rb index bfb7ed3886..f075b03c5e 100644 --- a/library/socket/unixsocket/shared/new.rb +++ b/library/socket/unixsocket/shared/new.rb @@ -2,23 +2,21 @@ require_relative '../../fixtures/classes' describe :unixsocket_new, shared: true do - platform_is_not :windows do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @client.close if @client - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close if @client + @server.close + SocketSpecs.rm_socket @path + end - it "opens a unix socket on the specified file" do - @client = UNIXSocket.send(@method, @path) + it "opens a unix socket on the specified file" do + @client = UNIXSocket.send(@method, @path) - @client.addr[0].should == "AF_UNIX" - @client.should_not.closed? - end + @client.addr[0].should == "AF_UNIX" + @client.should_not.closed? end end