Skip to content

Commit

Permalink
Wrap tests for unixsocket in an outer guard block
Browse files Browse the repository at this point in the history
Normalize to `with_feature :unix_socket`, which is more descriptive and
generic than checking for windows.
  • Loading branch information
herwinw authored and eregon committed Sep 30, 2023
1 parent 978823f commit 3e71d89
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 58 deletions.
5 changes: 2 additions & 3 deletions library/socket/unixsocket/addr_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions library/socket/unixsocket/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions library/socket/unixsocket/local_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions library/socket/unixsocket/new_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions library/socket/unixsocket/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions library/socket/unixsocket/pair_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions library/socket/unixsocket/partially_closable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,6 +19,5 @@
end

it_should_behave_like :partially_closable_sockets

end
end
6 changes: 2 additions & 4 deletions library/socket/unixsocket/path_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -24,5 +23,4 @@
@client.path.should == ""
end
end

end
6 changes: 2 additions & 4 deletions library/socket/unixsocket/peeraddr_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -26,5 +25,4 @@
}.should raise_error(Errno::ENOTCONN)
end
end

end
7 changes: 2 additions & 5 deletions library/socket/unixsocket/recv_io_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 2 additions & 5 deletions library/socket/unixsocket/recvfrom_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions library/socket/unixsocket/send_io_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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')
Expand Down
28 changes: 13 additions & 15 deletions library/socket/unixsocket/shared/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e71d89

Please sign in to comment.