diff --git a/core/file/socket_spec.rb b/core/file/socket_spec.rb index 5d12e21f55..d3f4eb013a 100644 --- a/core/file/socket_spec.rb +++ b/core/file/socket_spec.rb @@ -1,42 +1,10 @@ require_relative '../../spec_helper' require_relative '../../shared/file/socket' -require 'socket' describe "File.socket?" do it_behaves_like :file_socket, :socket?, File -end -describe "File.socket?" do it "returns false if file does not exist" do File.socket?("I_am_a_bogus_file").should == false end - - it "returns false if the file is not a socket" do - filename = tmp("i_exist") - touch(filename) - - File.socket?(filename).should == false - - rm_r filename - end -end - -platform_is_not :windows do - describe "File.socket?" do - before :each do - # We need a really short name here. - # On Linux the path length is limited to 107, see unix(7). - @name = tmp("s") - @server = UNIXServer.new @name - end - - after :each do - @server.close - rm_r @name - end - - it "returns true if the file is a socket" do - File.socket?(@name).should == true - end - end end diff --git a/core/filetest/socket_spec.rb b/core/filetest/socket_spec.rb index 63a6a31ecb..f274be6318 100644 --- a/core/filetest/socket_spec.rb +++ b/core/filetest/socket_spec.rb @@ -3,4 +3,8 @@ describe "FileTest.socket?" do it_behaves_like :file_socket, :socket?, FileTest + + it "returns false if file does not exist" do + FileTest.socket?("I_am_a_bogus_file").should == false + end end diff --git a/library/socket/addrinfo/afamily_spec.rb b/library/socket/addrinfo/afamily_spec.rb index 7229dab9de..5d075be057 100644 --- a/library/socket/addrinfo/afamily_spec.rb +++ b/library/socket/addrinfo/afamily_spec.rb @@ -23,15 +23,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns Socket::AF_UNIX" do - @addrinfo.afamily.should == Socket::AF_UNIX - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns Socket::AF_UNIX" do + @addrinfo.afamily.should == Socket::AF_UNIX end end end diff --git a/library/socket/addrinfo/family_addrinfo_spec.rb b/library/socket/addrinfo/family_addrinfo_spec.rb index 2bc3b6a2e3..3c2f9f73d8 100644 --- a/library/socket/addrinfo/family_addrinfo_spec.rb +++ b/library/socket/addrinfo/family_addrinfo_spec.rb @@ -50,38 +50,36 @@ end end - with_feature :unix_socket do - describe 'with a UNIX Addrinfo' do - before do - @source = Addrinfo.unix('cats') - end + describe 'with a UNIX Addrinfo' do + before do + @source = Addrinfo.unix('cats') + end - it 'raises ArgumentError if more than 1 argument is given' do - -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError) - end + it 'raises ArgumentError if more than 1 argument is given' do + -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError) + end - it 'returns an Addrinfo when a UNIX socket path is given' do - addr = @source.family_addrinfo('dogs') + it 'returns an Addrinfo when a UNIX socket path is given' do + addr = @source.family_addrinfo('dogs') - addr.should be_an_instance_of(Addrinfo) - end + addr.should be_an_instance_of(Addrinfo) + end - describe 'the returned Addrinfo' do - before do - @addr = @source.family_addrinfo('dogs') - end + describe 'the returned Addrinfo' do + before do + @addr = @source.family_addrinfo('dogs') + end - it 'uses AF_UNIX as the address family' do - @addr.afamily.should == Socket::AF_UNIX - end + it 'uses AF_UNIX as the address family' do + @addr.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @addr.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @addr.pfamily.should == Socket::PF_UNIX + end - it 'uses the given socket path' do - @addr.unix_path.should == 'dogs' - end + it 'uses the given socket path' do + @addr.unix_path.should == 'dogs' end end end diff --git a/library/socket/addrinfo/getnameinfo_spec.rb b/library/socket/addrinfo/getnameinfo_spec.rb index 76579de74c..43b5a2000a 100644 --- a/library/socket/addrinfo/getnameinfo_spec.rb +++ b/library/socket/addrinfo/getnameinfo_spec.rb @@ -22,19 +22,17 @@ platform_is :linux do platform_is_not :android do - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do - before do - @addr = Addrinfo.unix('cats') - @host = Socket.gethostname - end + describe 'using a UNIX Addrinfo' do + before do + @addr = Addrinfo.unix('cats') + @host = Socket.gethostname + end - it 'returns the hostname and UNIX socket path' do - host, path = @addr.getnameinfo + it 'returns the hostname and UNIX socket path' do + host, path = @addr.getnameinfo - host.should == @host - path.should == 'cats' - end + host.should == @host + path.should == 'cats' end end end diff --git a/library/socket/addrinfo/initialize_spec.rb b/library/socket/addrinfo/initialize_spec.rb index b7477efc79..bba361ef70 100644 --- a/library/socket/addrinfo/initialize_spec.rb +++ b/library/socket/addrinfo/initialize_spec.rb @@ -569,23 +569,21 @@ end end - with_feature :unix_socket do - describe 'using separate arguments for a Unix socket' do - before do - @sockaddr = Socket.pack_sockaddr_un('socket') - end + describe 'using separate arguments for a Unix socket' do + before do + @sockaddr = Socket.pack_sockaddr_un('socket') + end - it 'returns an Addrinfo with the correct unix path' do - Addrinfo.new(@sockaddr).unix_path.should == 'socket' - end + it 'returns an Addrinfo with the correct unix path' do + Addrinfo.new(@sockaddr).unix_path.should == 'socket' + end - it 'returns an Addrinfo with the correct protocol family' do - Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC - end + it 'returns an Addrinfo with the correct protocol family' do + Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC + end - it 'returns an Addrinfo with the correct address family' do - Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX - end + it 'returns an Addrinfo with the correct address family' do + Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX end end end diff --git a/library/socket/addrinfo/inspect_sockaddr_spec.rb b/library/socket/addrinfo/inspect_sockaddr_spec.rb index 70ca4dd4d7..6b18c79469 100644 --- a/library/socket/addrinfo/inspect_sockaddr_spec.rb +++ b/library/socket/addrinfo/inspect_sockaddr_spec.rb @@ -32,19 +32,17 @@ end end - with_feature :unix_socket do - describe 'using a UNIX path' do - it 'returns a String containing the UNIX path' do - addr = Addrinfo.unix('/foo/bar') + describe 'using a UNIX path' do + it 'returns a String containing the UNIX path' do + addr = Addrinfo.unix('/foo/bar') - addr.inspect_sockaddr.should == '/foo/bar' - end + addr.inspect_sockaddr.should == '/foo/bar' + end - it 'returns a String containing the UNIX path when using a relative path' do - addr = Addrinfo.unix('foo') + it 'returns a String containing the UNIX path when using a relative path' do + addr = Addrinfo.unix('foo') - addr.inspect_sockaddr.should == 'UNIX foo' - end + addr.inspect_sockaddr.should == 'UNIX foo' end end end diff --git a/library/socket/addrinfo/inspect_spec.rb b/library/socket/addrinfo/inspect_spec.rb index 98e1e83ffa..1442af6162 100644 --- a/library/socket/addrinfo/inspect_spec.rb +++ b/library/socket/addrinfo/inspect_spec.rb @@ -41,25 +41,23 @@ end end - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do - it 'returns a String' do - addr = Addrinfo.unix('/foo') + describe 'using a UNIX Addrinfo' do + it 'returns a String' do + addr = Addrinfo.unix('/foo') - addr.inspect.should == '#' - end + addr.inspect.should == '#' + end - it 'returns a String when using a relative UNIX path' do - addr = Addrinfo.unix('foo') + it 'returns a String when using a relative UNIX path' do + addr = Addrinfo.unix('foo') - addr.inspect.should == '#' - end + addr.inspect.should == '#' + end - it 'returns a String when using a DGRAM socket' do - addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM) + it 'returns a String when using a DGRAM socket' do + addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM) - addr.inspect.should == '#' - end + addr.inspect.should == '#' end end end diff --git a/library/socket/addrinfo/ip_address_spec.rb b/library/socket/addrinfo/ip_address_spec.rb index 4522cf5cfd..193432e861 100644 --- a/library/socket/addrinfo/ip_address_spec.rb +++ b/library/socket/addrinfo/ip_address_spec.rb @@ -21,15 +21,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_address }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_address }.should raise_error(SocketError) end end diff --git a/library/socket/addrinfo/ip_port_spec.rb b/library/socket/addrinfo/ip_port_spec.rb index 4118607db0..f10ce35143 100644 --- a/library/socket/addrinfo/ip_port_spec.rb +++ b/library/socket/addrinfo/ip_port_spec.rb @@ -21,15 +21,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_port }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_port }.should raise_error(SocketError) end end end diff --git a/library/socket/addrinfo/ip_spec.rb b/library/socket/addrinfo/ip_spec.rb index 80e7a62df7..09b9341605 100644 --- a/library/socket/addrinfo/ip_spec.rb +++ b/library/socket/addrinfo/ip_spec.rb @@ -22,15 +22,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ip?.should be_false - end + it "returns false" do + @addrinfo.ip?.should be_false end end end diff --git a/library/socket/addrinfo/ip_unpack_spec.rb b/library/socket/addrinfo/ip_unpack_spec.rb index 6c81c48d1c..58260c4557 100644 --- a/library/socket/addrinfo/ip_unpack_spec.rb +++ b/library/socket/addrinfo/ip_unpack_spec.rb @@ -21,15 +21,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "raises an exception" do - -> { @addrinfo.ip_unpack }.should raise_error(SocketError) - end + it "raises an exception" do + -> { @addrinfo.ip_unpack }.should raise_error(SocketError) end end end diff --git a/library/socket/addrinfo/ipv4_loopback_spec.rb b/library/socket/addrinfo/ipv4_loopback_spec.rb index 10ad084fc9..3a584d4f52 100644 --- a/library/socket/addrinfo/ipv4_loopback_spec.rb +++ b/library/socket/addrinfo/ipv4_loopback_spec.rb @@ -29,15 +29,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4_loopback?.should be_false - end + it "returns false" do + @addrinfo.ipv4_loopback?.should be_false end end end diff --git a/library/socket/addrinfo/ipv4_multicast_spec.rb b/library/socket/addrinfo/ipv4_multicast_spec.rb index f7fead8640..e4b4cfcc84 100644 --- a/library/socket/addrinfo/ipv4_multicast_spec.rb +++ b/library/socket/addrinfo/ipv4_multicast_spec.rb @@ -15,15 +15,13 @@ Addrinfo.ip('::1').should_not.ipv4_multicast? end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4_multicast?.should be_false - end + it "returns false" do + @addrinfo.ipv4_multicast?.should be_false end end end diff --git a/library/socket/addrinfo/ipv4_private_spec.rb b/library/socket/addrinfo/ipv4_private_spec.rb index e5a33b4953..97218b5ba3 100644 --- a/library/socket/addrinfo/ipv4_private_spec.rb +++ b/library/socket/addrinfo/ipv4_private_spec.rb @@ -33,15 +33,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv4_private?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv4_private?.should be_false end end end diff --git a/library/socket/addrinfo/ipv4_spec.rb b/library/socket/addrinfo/ipv4_spec.rb index 7cba8209b6..61f7759b10 100644 --- a/library/socket/addrinfo/ipv4_spec.rb +++ b/library/socket/addrinfo/ipv4_spec.rb @@ -21,15 +21,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv4?.should be_false - end + it "returns false" do + @addrinfo.ipv4?.should be_false end end end diff --git a/library/socket/addrinfo/ipv6_loopback_spec.rb b/library/socket/addrinfo/ipv6_loopback_spec.rb index 9ff8f107bf..ffc75185ea 100644 --- a/library/socket/addrinfo/ipv6_loopback_spec.rb +++ b/library/socket/addrinfo/ipv6_loopback_spec.rb @@ -31,15 +31,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv6_loopback?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv6_loopback?.should be_false end end end diff --git a/library/socket/addrinfo/ipv6_multicast_spec.rb b/library/socket/addrinfo/ipv6_multicast_spec.rb index 2c987b5921..99d4e8cf4d 100644 --- a/library/socket/addrinfo/ipv6_multicast_spec.rb +++ b/library/socket/addrinfo/ipv6_multicast_spec.rb @@ -34,15 +34,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns false" do - @addrinfo.ipv6_multicast?.should be_false - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns false" do + @addrinfo.ipv6_multicast?.should be_false end end end diff --git a/library/socket/addrinfo/ipv6_spec.rb b/library/socket/addrinfo/ipv6_spec.rb index 131e38849c..436d5e930b 100644 --- a/library/socket/addrinfo/ipv6_spec.rb +++ b/library/socket/addrinfo/ipv6_spec.rb @@ -21,15 +21,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns false" do - @addrinfo.ipv6?.should be_false - end + it "returns false" do + @addrinfo.ipv6?.should be_false end end end diff --git a/library/socket/addrinfo/ipv6_to_ipv4_spec.rb b/library/socket/addrinfo/ipv6_to_ipv4_spec.rb index 6dfaf531ae..29050bec20 100644 --- a/library/socket/addrinfo/ipv6_to_ipv4_spec.rb +++ b/library/socket/addrinfo/ipv6_to_ipv4_spec.rb @@ -62,7 +62,7 @@ Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should be_nil end - with_feature :unix_socket do + describe 'for a unix socket' do it 'returns nil for a UNIX Addrinfo' do Addrinfo.unix('foo').ipv6_to_ipv4.should be_nil end diff --git a/library/socket/addrinfo/marshal_dump_spec.rb b/library/socket/addrinfo/marshal_dump_spec.rb index 2d69a33b53..e2c3497f7f 100644 --- a/library/socket/addrinfo/marshal_dump_spec.rb +++ b/library/socket/addrinfo/marshal_dump_spec.rb @@ -42,40 +42,38 @@ end end - with_feature :unix_socket do - describe 'using a UNIX Addrinfo' do + describe 'using a UNIX Addrinfo' do + before do + @addr = Addrinfo.unix('foo') + end + + it 'returns an Array' do + @addr.marshal_dump.should be_an_instance_of(Array) + end + + describe 'the returned Array' do before do - @addr = Addrinfo.unix('foo') + @array = @addr.marshal_dump end - it 'returns an Array' do - @addr.marshal_dump.should be_an_instance_of(Array) + it 'includes the address family as the 1st value' do + @array[0].should == 'AF_UNIX' end - describe 'the returned Array' do - before do - @array = @addr.marshal_dump - end - - it 'includes the address family as the 1st value' do - @array[0].should == 'AF_UNIX' - end - - it 'includes the UNIX path as the 2nd value' do - @array[1].should == @addr.unix_path - end + it 'includes the UNIX path as the 2nd value' do + @array[1].should == @addr.unix_path + end - it 'includes the protocol family as the 3rd value' do - @array[2].should == 'PF_UNIX' - end + it 'includes the protocol family as the 3rd value' do + @array[2].should == 'PF_UNIX' + end - it 'includes the socket type as the 4th value' do - @array[3].should == 'SOCK_STREAM' - end + it 'includes the socket type as the 4th value' do + @array[3].should == 'SOCK_STREAM' + end - it 'includes the protocol as the 5th value' do - @array[4].should == 0 - end + it 'includes the protocol as the 5th value' do + @array[4].should == 0 end end end diff --git a/library/socket/addrinfo/marshal_load_spec.rb b/library/socket/addrinfo/marshal_load_spec.rb index aa20865224..02cef90115 100644 --- a/library/socket/addrinfo/marshal_load_spec.rb +++ b/library/socket/addrinfo/marshal_load_spec.rb @@ -18,18 +18,16 @@ end end - with_feature :unix_socket do - describe 'using a UNIX socket' do - it 'returns a new Addrinfo' do - source = Addrinfo.unix('foo') - addr = Marshal.load(Marshal.dump(source)) + describe 'using a UNIX socket' do + it 'returns a new Addrinfo' do + source = Addrinfo.unix('foo') + addr = Marshal.load(Marshal.dump(source)) - addr.afamily.should == source.afamily - addr.pfamily.should == source.pfamily - addr.socktype.should == source.socktype - addr.protocol.should == source.protocol - addr.unix_path.should == source.unix_path - end + addr.afamily.should == source.afamily + addr.pfamily.should == source.pfamily + addr.socktype.should == source.socktype + addr.protocol.should == source.protocol + addr.unix_path.should == source.unix_path end end end diff --git a/library/socket/addrinfo/pfamily_spec.rb b/library/socket/addrinfo/pfamily_spec.rb index 984744a964..da530b7fdc 100644 --- a/library/socket/addrinfo/pfamily_spec.rb +++ b/library/socket/addrinfo/pfamily_spec.rb @@ -29,15 +29,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns Socket::PF_UNIX" do - @addrinfo.pfamily.should == Socket::PF_UNIX - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns Socket::PF_UNIX" do + @addrinfo.pfamily.should == Socket::PF_UNIX end end end diff --git a/library/socket/addrinfo/protocol_spec.rb b/library/socket/addrinfo/protocol_spec.rb index ea143fc4a8..f6ffc9acf9 100644 --- a/library/socket/addrinfo/protocol_spec.rb +++ b/library/socket/addrinfo/protocol_spec.rb @@ -10,15 +10,13 @@ Addrinfo.tcp('::1', 80).protocol.should == Socket::IPPROTO_TCP end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns 0" do - @addrinfo.protocol.should == 0 - end + it "returns 0" do + @addrinfo.protocol.should == 0 end end end diff --git a/library/socket/addrinfo/shared/to_sockaddr.rb b/library/socket/addrinfo/shared/to_sockaddr.rb index 4f7cf439a0..70d6bfbbfe 100644 --- a/library/socket/addrinfo/shared/to_sockaddr.rb +++ b/library/socket/addrinfo/shared/to_sockaddr.rb @@ -19,15 +19,13 @@ end end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end - - it "returns a sockaddr packed structure" do - @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock') - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end + + it "returns a sockaddr packed structure" do + @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock') end end diff --git a/library/socket/addrinfo/socktype_spec.rb b/library/socket/addrinfo/socktype_spec.rb index b994bea140..e5f02cd759 100644 --- a/library/socket/addrinfo/socktype_spec.rb +++ b/library/socket/addrinfo/socktype_spec.rb @@ -9,15 +9,13 @@ Addrinfo.tcp('127.0.0.1', 80).socktype.should == Socket::SOCK_STREAM end - with_feature :unix_socket do - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns Socket::SOCK_STREAM" do - @addrinfo.socktype.should == Socket::SOCK_STREAM - end + it "returns Socket::SOCK_STREAM" do + @addrinfo.socktype.should == Socket::SOCK_STREAM end end end diff --git a/library/socket/addrinfo/unix_path_spec.rb b/library/socket/addrinfo/unix_path_spec.rb index 6bfb56a4ac..2a9076a354 100644 --- a/library/socket/addrinfo/unix_path_spec.rb +++ b/library/socket/addrinfo/unix_path_spec.rb @@ -1,37 +1,35 @@ require_relative '../spec_helper' -with_feature :unix_socket do - describe "Addrinfo#unix_path" do - describe "for an ipv4 socket" do +describe "Addrinfo#unix_path" do + describe "for an ipv4 socket" do - before :each do - @addrinfo = Addrinfo.tcp("127.0.0.1", 80) - end - - it "raises an exception" do - -> { @addrinfo.unix_path }.should raise_error(SocketError) - end + before :each do + @addrinfo = Addrinfo.tcp("127.0.0.1", 80) + end + it "raises an exception" do + -> { @addrinfo.unix_path }.should raise_error(SocketError) end - describe "for an ipv6 socket" do - before :each do - @addrinfo = Addrinfo.tcp("::1", 80) - end + end - it "raises an exception" do - -> { @addrinfo.unix_path }.should raise_error(SocketError) - end + describe "for an ipv6 socket" do + before :each do + @addrinfo = Addrinfo.tcp("::1", 80) end - describe "for a unix socket" do - before :each do - @addrinfo = Addrinfo.unix("/tmp/sock") - end + it "raises an exception" do + -> { @addrinfo.unix_path }.should raise_error(SocketError) + end + end + + describe "for a unix socket" do + before :each do + @addrinfo = Addrinfo.unix("/tmp/sock") + end - it "returns the socket path" do - @addrinfo.unix_path.should == "/tmp/sock" - end + it "returns the socket path" do + @addrinfo.unix_path.should == "/tmp/sock" end end end diff --git a/library/socket/addrinfo/unix_spec.rb b/library/socket/addrinfo/unix_spec.rb index 4596ece17e..7597533a76 100644 --- a/library/socket/addrinfo/unix_spec.rb +++ b/library/socket/addrinfo/unix_spec.rb @@ -1,36 +1,34 @@ require_relative '../spec_helper' -with_feature :unix_socket do - describe 'Addrinfo.unix' do - it 'returns an Addrinfo instance' do - Addrinfo.unix('socket').should be_an_instance_of(Addrinfo) - end +describe 'Addrinfo.unix' do + it 'returns an Addrinfo instance' do + Addrinfo.unix('socket').should be_an_instance_of(Addrinfo) + end - it 'sets the IP address' do - Addrinfo.unix('socket').unix_path.should == 'socket' - end + it 'sets the IP address' do + Addrinfo.unix('socket').unix_path.should == 'socket' + end - it 'sets the address family' do - Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX - end + it 'sets the address family' do + Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX + end - it 'sets the protocol family' do - Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX - end + it 'sets the protocol family' do + Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX + end - it 'sets the socket type' do - Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM - end + it 'sets the socket type' do + Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM + end - it 'sets a custom socket type' do - addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM) + it 'sets a custom socket type' do + addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM) - addr.socktype.should == Socket::SOCK_DGRAM - end + addr.socktype.should == Socket::SOCK_DGRAM + end - it 'sets the socket protocol to 0' do - Addrinfo.unix('socket').protocol.should == 0 - end + it 'sets the socket protocol to 0' do + Addrinfo.unix('socket').protocol.should == 0 end end diff --git a/library/socket/basicsocket/connect_address_spec.rb b/library/socket/basicsocket/connect_address_spec.rb index 1a1c9982d9..2e318fcb85 100644 --- a/library/socket/basicsocket/connect_address_spec.rb +++ b/library/socket/basicsocket/connect_address_spec.rb @@ -94,61 +94,59 @@ end end - with_feature :unix_socket do - platform_is_not :aix do - describe 'using an unbound UNIX socket' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end - - after do - @client.close - @server.close - rm_r(@path) - end - - it 'raises SocketError' do - -> { @client.connect_address }.should raise_error(SocketError) - end - end - end - - describe 'using a bound UNIX socket' do + platform_is_not :aix do + describe 'using an unbound UNIX socket' do before do @path = SocketSpecs.socket_path - @sock = UNIXServer.new(@path) + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @sock.close + @client.close + @server.close rm_r(@path) end - it 'returns an Addrinfo' do - @sock.connect_address.should be_an_instance_of(Addrinfo) + it 'raises SocketError' do + -> { @client.connect_address }.should raise_error(SocketError) end + end + end - it 'uses the correct socket path' do - @sock.connect_address.unix_path.should == @path - end + describe 'using a bound UNIX socket' do + before do + @path = SocketSpecs.socket_path + @sock = UNIXServer.new(@path) + end - it 'uses AF_UNIX as the address family' do - @sock.connect_address.afamily.should == Socket::AF_UNIX - end + after do + @sock.close + rm_r(@path) + end - it 'uses PF_UNIX as the protocol family' do - @sock.connect_address.pfamily.should == Socket::PF_UNIX - end + it 'returns an Addrinfo' do + @sock.connect_address.should be_an_instance_of(Addrinfo) + end - it 'uses SOCK_STREAM as the socket type' do - @sock.connect_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses the correct socket path' do + @sock.connect_address.unix_path.should == @path + end - it 'uses 0 as the protocol' do - @sock.connect_address.protocol.should == 0 - end + it 'uses AF_UNIX as the address family' do + @sock.connect_address.afamily.should == Socket::AF_UNIX + end + + it 'uses PF_UNIX as the protocol family' do + @sock.connect_address.pfamily.should == Socket::PF_UNIX + end + + it 'uses SOCK_STREAM as the socket type' do + @sock.connect_address.socktype.should == Socket::SOCK_STREAM + end + + it 'uses 0 as the protocol' do + @sock.connect_address.protocol.should == 0 end end end diff --git a/library/socket/basicsocket/getpeereid_spec.rb b/library/socket/basicsocket/getpeereid_spec.rb index 6179211d96..2e03cd3684 100644 --- a/library/socket/basicsocket/getpeereid_spec.rb +++ b/library/socket/basicsocket/getpeereid_spec.rb @@ -2,7 +2,7 @@ require_relative '../fixtures/classes' describe 'BasicSocket#getpeereid' do - with_feature :unix_socket do + platform_is_not :windows do describe 'using a UNIXSocket' do before do @path = SocketSpecs.socket_path diff --git a/library/socket/basicsocket/setsockopt_spec.rb b/library/socket/basicsocket/setsockopt_spec.rb index 1e8d84e1c9..f686e67326 100644 --- a/library/socket/basicsocket/setsockopt_spec.rb +++ b/library/socket/basicsocket/setsockopt_spec.rb @@ -315,22 +315,20 @@ end end - with_feature :unix_socket do - describe 'using a UNIX socket' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end + describe 'using a UNIX socket' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close - rm_r @path - end + after do + @server.close + rm_r @path + end - it 'sets a boolean option' do - @server.setsockopt(:SOCKET, :REUSEADDR, true) - @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true - end + it 'sets a boolean option' do + @server.setsockopt(:SOCKET, :REUSEADDR, true) + @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true end end end diff --git a/library/socket/shared/address.rb b/library/socket/shared/address.rb index f3be9cfb99..3857a40ce8 100644 --- a/library/socket/shared/address.rb +++ b/library/socket/shared/address.rb @@ -129,41 +129,51 @@ end end - with_feature :unix_socket do - describe 'using UNIXSocket' do - before :each do - @path = SocketSpecs.socket_path - @s = UNIXServer.new(@path) - @a = UNIXSocket.new(@path) - @b = @s.accept - @addr = @object.call(@a) - end + describe 'using UNIXSocket' do + before :each do + @path = SocketSpecs.socket_path + @s = UNIXServer.new(@path) + @a = UNIXSocket.new(@path) + @b = @s.accept + @addr = @object.call(@a) + end - after :each do - [@b, @a, @s].each(&:close) - rm_r(@path) - end + after :each do + [@b, @a, @s].each(&:close) + rm_r(@path) + end - it 'uses AF_UNIX as the address family' do - @addr.afamily.should == Socket::AF_UNIX - end + it 'uses AF_UNIX as the address family' do + @addr.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @addr.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @addr.pfamily.should == Socket::PF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @addr.socktype.should == Socket::SOCK_STREAM + it 'uses SOCK_STREAM as the socket type' do + @addr.socktype.should == Socket::SOCK_STREAM + end + + it 'uses the correct socket path' do + if @method == :local_address + @addr.unix_path.should == "" + else + @addr.unix_path.should == @path end + end - it 'uses the correct socket path' do + platform_is_not :windows do + it 'equals address of peer socket' do if @method == :local_address - @addr.unix_path.should == "" + @addr.to_s.should == @b.remote_address.to_s else - @addr.unix_path.should == @path + @addr.to_s.should == @b.local_address.to_s end end + end + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do it 'equals address of peer socket' do if @method == :local_address @addr.to_s.should == @b.remote_address.to_s @@ -171,23 +181,23 @@ @addr.to_s.should == @b.local_address.to_s end end + end - it 'returns an Addrinfo' do - @addr.should be_an_instance_of(Addrinfo) - end + it 'returns an Addrinfo' do + @addr.should be_an_instance_of(Addrinfo) + end - it 'uses 0 as the protocol' do - @addr.protocol.should == 0 - end + it 'uses 0 as the protocol' do + @addr.protocol.should == 0 + end - it 'can be used to connect to the server' do - skip if @method == :local_address - b = @addr.connect - begin - b.remote_address.to_s.should == @addr.to_s - ensure - b.close - end + it 'can be used to connect to the server' do + skip if @method == :local_address + b = @addr.connect + begin + b.remote_address.to_s.should == @addr.to_s + ensure + b.close end end end diff --git a/library/socket/shared/pack_sockaddr.rb b/library/socket/shared/pack_sockaddr.rb index f309aa02c7..4bfcf4edb9 100644 --- a/library/socket/shared/pack_sockaddr.rb +++ b/library/socket/shared/pack_sockaddr.rb @@ -47,23 +47,21 @@ end describe :socket_pack_sockaddr_un, shared: true do - with_feature :unix_socket do - it 'should be idempotent' do - bytes = Socket.public_send(@method, '/tmp/foo').bytes - bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111] - bytes[10..-1].all?(&:zero?).should == true - end + it 'should be idempotent' do + bytes = Socket.public_send(@method, '/tmp/foo').bytes + bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111] + bytes[10..-1].all?(&:zero?).should == true + end - it "packs and unpacks" do - sockaddr_un = Socket.public_send(@method, '/tmp/s') - Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s' - end + it "packs and unpacks" do + sockaddr_un = Socket.public_send(@method, '/tmp/s') + Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s' + end - it "handles correctly paths with multibyte chars" do - sockaddr_un = Socket.public_send(@method, '/home/вася/sock') - path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8') - path.should == '/home/вася/sock' - end + it "handles correctly paths with multibyte chars" do + sockaddr_un = Socket.public_send(@method, '/home/вася/sock') + path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8') + path.should == '/home/вася/sock' end platform_is :linux do @@ -84,7 +82,7 @@ end end - platform_is_not :windows, :aix do + platform_is_not :aix do it "raises ArgumentError for paths that are too long" do # AIX doesn't raise error long_path = 'a' * 110 diff --git a/library/socket/socket/unix_server_loop_spec.rb b/library/socket/socket/unix_server_loop_spec.rb index 0f34d4a50b..6192bc8bf6 100644 --- a/library/socket/socket/unix_server_loop_spec.rb +++ b/library/socket/socket/unix_server_loop_spec.rb @@ -1,58 +1,56 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix_server_loop' do - before do - @path = SocketSpecs.socket_path - end +describe 'Socket.unix_server_loop' do + before do + @path = SocketSpecs.socket_path + end - after do - rm_r(@path) if File.file?(@path) - end + after do + rm_r(@path) if File.file?(@path) + end - describe 'when no connections are available' do - it 'blocks the caller' do - -> { Socket.unix_server_loop(@path) }.should block_caller - end + describe 'when no connections are available' do + it 'blocks the caller' do + -> { Socket.unix_server_loop(@path) }.should block_caller end + end - describe 'when a connection is available' do - before do - @client = nil - end + describe 'when a connection is available' do + before do + @client = nil + end - after do - @sock.close if @sock - @client.close if @client - end + after do + @sock.close if @sock + @client.close if @client + end - it 'yields a Socket and an Addrinfo' do - @sock, addr = nil + it 'yields a Socket and an Addrinfo' do + @sock, addr = nil - thread = Thread.new do - Socket.unix_server_loop(@path) do |socket, addrinfo| - @sock = socket - addr = addrinfo + thread = Thread.new do + Socket.unix_server_loop(@path) do |socket, addrinfo| + @sock = socket + addr = addrinfo - break - end + break end + end - SocketSpecs.loop_with_timeout do - begin - @client = Socket.unix(@path) - rescue SystemCallError - sleep 0.01 - :retry - end + SocketSpecs.loop_with_timeout do + begin + @client = Socket.unix(@path) + rescue SystemCallError + sleep 0.01 + :retry end + end - thread.join + thread.join - @sock.should be_an_instance_of(Socket) - addr.should be_an_instance_of(Addrinfo) - end + @sock.should be_an_instance_of(Socket) + addr.should be_an_instance_of(Addrinfo) end end end diff --git a/library/socket/socket/unix_server_socket_spec.rb b/library/socket/socket/unix_server_socket_spec.rb index fc357740fa..34c3b96d07 100644 --- a/library/socket/socket/unix_server_socket_spec.rb +++ b/library/socket/socket/unix_server_socket_spec.rb @@ -1,48 +1,46 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix_server_socket' do +describe 'Socket.unix_server_socket' do + before do + @path = SocketSpecs.socket_path + end + + after do + rm_r(@path) + end + + describe 'when no block is given' do before do - @path = SocketSpecs.socket_path + @socket = nil end after do - rm_r(@path) + @socket.close end - describe 'when no block is given' do - before do - @socket = nil - end - - after do - @socket.close - end + it 'returns a Socket' do + @socket = Socket.unix_server_socket(@path) - it 'returns a Socket' do - @socket = Socket.unix_server_socket(@path) - - @socket.should be_an_instance_of(Socket) - end + @socket.should be_an_instance_of(Socket) end + end - describe 'when a block is given' do - it 'yields a Socket' do - Socket.unix_server_socket(@path) do |sock| - sock.should be_an_instance_of(Socket) - end + describe 'when a block is given' do + it 'yields a Socket' do + Socket.unix_server_socket(@path) do |sock| + sock.should be_an_instance_of(Socket) end + end - it 'closes the Socket when the block returns' do - socket = nil - - Socket.unix_server_socket(@path) do |sock| - socket = sock - end + it 'closes the Socket when the block returns' do + socket = nil - socket.should be_an_instance_of(Socket) + Socket.unix_server_socket(@path) do |sock| + socket = sock end + + socket.should be_an_instance_of(Socket) end end end diff --git a/library/socket/socket/unix_spec.rb b/library/socket/socket/unix_spec.rb index 4bff59bd4b..2a5d77f96f 100644 --- a/library/socket/socket/unix_spec.rb +++ b/library/socket/socket/unix_spec.rb @@ -1,45 +1,43 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unix' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @socket = nil - end +describe 'Socket.unix' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @socket = nil + end - after do - @server.close - @socket.close if @socket + after do + @server.close + @socket.close if @socket - rm_r(@path) - end + rm_r(@path) + end - describe 'when no block is given' do - it 'returns a Socket' do - @socket = Socket.unix(@path) + describe 'when no block is given' do + it 'returns a Socket' do + @socket = Socket.unix(@path) - @socket.should be_an_instance_of(Socket) - end + @socket.should be_an_instance_of(Socket) end + end - describe 'when a block is given' do - it 'yields a Socket' do - Socket.unix(@path) do |sock| - sock.should be_an_instance_of(Socket) - end + describe 'when a block is given' do + it 'yields a Socket' do + Socket.unix(@path) do |sock| + sock.should be_an_instance_of(Socket) end + end - it 'closes the Socket when the block returns' do - socket = nil - - Socket.unix(@path) do |sock| - socket = sock - end + it 'closes the Socket when the block returns' do + socket = nil - socket.should.closed? + Socket.unix(@path) do |sock| + socket = sock end + + socket.should.closed? end end end diff --git a/library/socket/socket/unpack_sockaddr_in_spec.rb b/library/socket/socket/unpack_sockaddr_in_spec.rb index 79ec68cd18..935b5cb543 100644 --- a/library/socket/socket/unpack_sockaddr_in_spec.rb +++ b/library/socket/socket/unpack_sockaddr_in_spec.rb @@ -32,15 +32,13 @@ end end - with_feature :unix_socket do - it "raises an ArgumentError when the sin_family is not AF_INET" do - sockaddr = Socket.sockaddr_un '/tmp/x' - -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when the sin_family is not AF_INET" do + sockaddr = Socket.sockaddr_un '/tmp/x' + -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError) + end - it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do - addrinfo = Addrinfo.unix('/tmp/sock') - -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do + addrinfo = Addrinfo.unix('/tmp/sock') + -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError) end end diff --git a/library/socket/socket/unpack_sockaddr_un_spec.rb b/library/socket/socket/unpack_sockaddr_un_spec.rb index 12f970f89b..6e0f11de3d 100644 --- a/library/socket/socket/unpack_sockaddr_un_spec.rb +++ b/library/socket/socket/unpack_sockaddr_un_spec.rb @@ -1,26 +1,24 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'Socket.unpack_sockaddr_un' do - it 'decodes sockaddr to unix path' do - sockaddr = Socket.sockaddr_un('/tmp/sock') - Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock' - end +describe 'Socket.unpack_sockaddr_un' do + it 'decodes sockaddr to unix path' do + sockaddr = Socket.sockaddr_un('/tmp/sock') + Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock' + end - it 'returns unix path from a passed Addrinfo' do - addrinfo = Addrinfo.unix('/tmp/sock') - Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock' - end + it 'returns unix path from a passed Addrinfo' do + addrinfo = Addrinfo.unix('/tmp/sock') + Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock' + end - it 'raises an ArgumentError when the sa_family is not AF_UNIX' do - sockaddr = Socket.sockaddr_in(0, '127.0.0.1') - -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError) - end + it 'raises an ArgumentError when the sa_family is not AF_UNIX' do + sockaddr = Socket.sockaddr_in(0, '127.0.0.1') + -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError) + end - it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do - addrinfo = Addrinfo.tcp('127.0.0.1', 0) - -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError) - end + it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do + addrinfo = Addrinfo.tcp('127.0.0.1', 0) + -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError) end end diff --git a/library/socket/spec_helper.rb b/library/socket/spec_helper.rb index 1121542dd5..b33663e02d 100644 --- a/library/socket/spec_helper.rb +++ b/library/socket/spec_helper.rb @@ -2,7 +2,6 @@ require 'socket' MSpec.enable_feature :sock_packet if Socket.const_defined?(:SOCK_PACKET) -MSpec.enable_feature :unix_socket unless PlatformGuard.windows? MSpec.enable_feature :udp_cork if Socket.const_defined?(:UDP_CORK) MSpec.enable_feature :tcp_cork if Socket.const_defined?(:TCP_CORK) MSpec.enable_feature :pktinfo if Socket.const_defined?(:IP_PKTINFO) diff --git a/library/socket/unixserver/accept_nonblock_spec.rb b/library/socket/unixserver/accept_nonblock_spec.rb index dba3de7359..f67941b296 100644 --- a/library/socket/unixserver/accept_nonblock_spec.rb +++ b/library/socket/unixserver/accept_nonblock_spec.rb @@ -1,87 +1,85 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXServer#accept_nonblock" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) +describe "UNIXServer#accept_nonblock" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) - @socket = @server.accept_nonblock - @client.send("foobar", 0) - end + @socket = @server.accept_nonblock + @client.send("foobar", 0) + end - after :each do - @socket.close - @client.close - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @socket.close + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "accepts a connection in a non-blocking way" do - data = @socket.recvfrom(6).first - data.should == "foobar" - end + it "accepts a connection in a non-blocking way" do + data = @socket.recvfrom(6).first + data.should == "foobar" + end - it "returns a UNIXSocket" do - @socket.should be_kind_of(UNIXSocket) - end + it "returns a UNIXSocket" do + @socket.should be_kind_of(UNIXSocket) + end + + it 'returns :wait_readable in exceptionless mode' do + @server.accept_nonblock(exception: false).should == :wait_readable + end +end - it 'returns :wait_readable in exceptionless mode' do - @server.accept_nonblock(exception: false).should == :wait_readable +describe 'UNIXServer#accept_nonblock' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end + + after do + @server.close + rm_r(@path) + end + + describe 'without a client' do + it 'raises IO::WaitReadable' do + -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) end end - describe 'UNIXServer#accept_nonblock' do + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - rm_r(@path) + @client.close + @socket.close if @socket end - describe 'without a client' do - it 'raises IO::WaitReadable' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + describe 'without any data' do + it 'returns a UNIXSocket' do + @socket = @server.accept_nonblock + @socket.should be_an_instance_of(UNIXSocket) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) - end - - after do - @client.close - @socket.close if @socket + @client.write('hello') end - describe 'without any data' do - it 'returns a UNIXSocket' do - @socket = @server.accept_nonblock - @socket.should be_an_instance_of(UNIXSocket) - end + it 'returns a UNIXSocket' do + @socket = @server.accept_nonblock + @socket.should be_an_instance_of(UNIXSocket) end - describe 'with data available' do - before do - @client.write('hello') - end - - it 'returns a UNIXSocket' do + describe 'the returned UNIXSocket' do + it 'can read the data written' do @socket = @server.accept_nonblock - @socket.should be_an_instance_of(UNIXSocket) - end - - describe 'the returned UNIXSocket' do - it 'can read the data written' do - @socket = @server.accept_nonblock - @socket.recv(5).should == 'hello' - end + @socket.recv(5).should == 'hello' end end end diff --git a/library/socket/unixserver/accept_spec.rb b/library/socket/unixserver/accept_spec.rb index 1305bc6220..cc2c922b6f 100644 --- a/library/socket/unixserver/accept_spec.rb +++ b/library/socket/unixserver/accept_spec.rb @@ -1,126 +1,124 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXServer#accept" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end +describe "UNIXServer#accept" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @server.close if @server - SocketSpecs.rm_socket @path - end + after :each do + @server.close if @server + SocketSpecs.rm_socket @path + end - it "accepts what is written by the client" do - client = UNIXSocket.open(@path) + it "accepts what is written by the client" do + client = UNIXSocket.open(@path) - client.send('hello', 0) + client.send('hello', 0) - sock = @server.accept - begin - data, info = sock.recvfrom(5) + sock = @server.accept + begin + data, info = sock.recvfrom(5) - data.should == 'hello' - info.should_not be_empty - ensure - sock.close - client.close - end + data.should == 'hello' + info.should_not be_empty + ensure + sock.close + client.close end + end - it "can be interrupted by Thread#kill" do - t = Thread.new { - @server.accept - } - Thread.pass while t.status and t.status != "sleep" - - # kill thread, ensure it dies in a reasonable amount of time - t.kill - a = 0 - while t.alive? and a < 5000 - sleep 0.001 - a += 1 - end - a.should < 5000 + it "can be interrupted by Thread#kill" do + t = Thread.new { + @server.accept + } + Thread.pass while t.status and t.status != "sleep" + + # kill thread, ensure it dies in a reasonable amount of time + t.kill + a = 0 + while t.alive? and a < 5000 + sleep 0.001 + a += 1 end + a.should < 5000 + end - it "can be interrupted by Thread#raise" do - t = Thread.new { - -> { - @server.accept - }.should raise_error(Exception, "interrupted") - } + it "can be interrupted by Thread#raise" do + t = Thread.new { + -> { + @server.accept + }.should raise_error(Exception, "interrupted") + } - Thread.pass while t.status and t.status != "sleep" - t.raise Exception, "interrupted" - t.join - end + Thread.pass while t.status and t.status != "sleep" + t.raise Exception, "interrupted" + t.join end end -with_feature :unix_socket do - describe 'UNIXServer#accept' do +describe 'UNIXServer#accept' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end + + after do + @server.close + rm_r(@path) + end + + describe 'without a client' do + it 'blocks the calling thread' do + -> { @server.accept }.should block_caller + end + end + + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - rm_r(@path) + @client.close + @socket.close if @socket end - describe 'without a client' do - it 'blocks the calling thread' do - -> { @server.accept }.should block_caller + describe 'without any data' do + it 'returns a UNIXSocket' do + @socket = @server.accept + @socket.should be_an_instance_of(UNIXSocket) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) - end - - after do - @client.close - @socket.close if @socket + @client.write('hello') end - describe 'without any data' do - it 'returns a UNIXSocket' do - @socket = @server.accept - @socket.should be_an_instance_of(UNIXSocket) - end + it 'returns a UNIXSocket' do + @socket = @server.accept + @socket.should be_an_instance_of(UNIXSocket) end - describe 'with data available' do - before do - @client.write('hello') - end - - it 'returns a UNIXSocket' do + describe 'the returned UNIXSocket' do + it 'can read the data written' do @socket = @server.accept - @socket.should be_an_instance_of(UNIXSocket) + @socket.recv(5).should == 'hello' end - describe 'the returned UNIXSocket' do - it 'can read the data written' do - @socket = @server.accept - @socket.recv(5).should == 'hello' - end - + platform_is_not :windows do it "is set to nonblocking" do require 'io/nonblock' @socket = @server.accept @socket.should.nonblock? end + end - it "is set to close on exec" do - @socket = @server.accept - @socket.should.close_on_exec? - end + it "is set to close on exec" do + @socket = @server.accept + @socket.should.close_on_exec? end end end diff --git a/library/socket/unixserver/for_fd_spec.rb b/library/socket/unixserver/for_fd_spec.rb index 8cc55ef391..be1c2df4d7 100644 --- a/library/socket/unixserver/for_fd_spec.rb +++ b/library/socket/unixserver/for_fd_spec.rb @@ -1,23 +1,21 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXServer.for_fd" do - before :each do - @unix_path = SocketSpecs.socket_path - @unix = UNIXServer.new(@unix_path) - end +describe "UNIXServer.for_fd" do + before :each do + @unix_path = SocketSpecs.socket_path + @unix = UNIXServer.new(@unix_path) + end - after :each do - @unix.close if @unix - SocketSpecs.rm_socket @unix_path - end + after :each do + @unix.close if @unix + SocketSpecs.rm_socket @unix_path + end - it "can calculate the path" do - b = UNIXServer.for_fd(@unix.fileno) - b.autoclose = false + it "can calculate the path" do + b = UNIXServer.for_fd(@unix.fileno) + b.autoclose = false - b.path.should == @unix_path - end + b.path.should == @unix_path end end diff --git a/library/socket/unixserver/initialize_spec.rb b/library/socket/unixserver/initialize_spec.rb index 0cc49ef1eb..3728a307b0 100644 --- a/library/socket/unixserver/initialize_spec.rb +++ b/library/socket/unixserver/initialize_spec.rb @@ -1,28 +1,26 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#initialize' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end +describe 'UNIXServer#initialize' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close if @server - rm_r @path - end + after do + @server.close if @server + rm_r @path + end - it 'returns a new UNIXServer' do - @server.should be_an_instance_of(UNIXServer) - end + it 'returns a new UNIXServer' do + @server.should be_an_instance_of(UNIXServer) + end - it 'sets the socket to binmode' do - @server.binmode?.should be_true - end + it 'sets the socket to binmode' do + @server.binmode?.should be_true + end - it 'raises Errno::EADDRINUSE when the socket is already in use' do - -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE) - end + it 'raises Errno::EADDRINUSE when the socket is already in use' do + -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE) end end diff --git a/library/socket/unixserver/listen_spec.rb b/library/socket/unixserver/listen_spec.rb index b90b3bbb09..7938d648c4 100644 --- a/library/socket/unixserver/listen_spec.rb +++ b/library/socket/unixserver/listen_spec.rb @@ -1,21 +1,19 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#listen' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - end +describe 'UNIXServer#listen' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end - after do - @server.close + after do + @server.close - rm_r(@path) - end + rm_r(@path) + end - it 'returns 0' do - @server.listen(1).should == 0 - end + it 'returns 0' do + @server.listen(1).should == 0 end end diff --git a/library/socket/unixserver/new_spec.rb b/library/socket/unixserver/new_spec.rb index a160e3ce5c..7d0c7bf76e 100644 --- a/library/socket/unixserver/new_spec.rb +++ b/library/socket/unixserver/new_spec.rb @@ -1,14 +1,12 @@ require_relative '../spec_helper' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXServer.new" do - it_behaves_like :unixserver_new, :new +describe "UNIXServer.new" do + it_behaves_like :unixserver_new, :new - it "does not use the given block and warns to use UNIXServer::open" do - -> { - @server = UNIXServer.new(@path) { raise } - }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/) - end + it "does not use the given block and warns to use UNIXServer::open" do + -> { + @server = UNIXServer.new(@path) { raise } + }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/) end end diff --git a/library/socket/unixserver/open_spec.rb b/library/socket/unixserver/open_spec.rb index 16453dd3bd..c49df802d0 100644 --- a/library/socket/unixserver/open_spec.rb +++ b/library/socket/unixserver/open_spec.rb @@ -2,25 +2,23 @@ require_relative '../fixtures/classes' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXServer.open" do - it_behaves_like :unixserver_new, :open +describe "UNIXServer.open" do + it_behaves_like :unixserver_new, :open - before :each do - @path = SocketSpecs.socket_path - end + before :each do + @path = SocketSpecs.socket_path + end - after :each do - @server.close if @server - @server = nil - SocketSpecs.rm_socket @path - end + after :each do + @server.close if @server + @server = nil + SocketSpecs.rm_socket @path + end - it "yields the new UNIXServer object to the block, if given" do - UNIXServer.open(@path) do |unix| - unix.path.should == @path - unix.addr.should == ["AF_UNIX", @path] - end + it "yields the new UNIXServer object to the block, if given" do + UNIXServer.open(@path) do |unix| + unix.path.should == @path + unix.addr.should == ["AF_UNIX", @path] end end end diff --git a/library/socket/unixserver/sysaccept_spec.rb b/library/socket/unixserver/sysaccept_spec.rb index e59731878a..c4a4ecc824 100644 --- a/library/socket/unixserver/sysaccept_spec.rb +++ b/library/socket/unixserver/sysaccept_spec.rb @@ -1,51 +1,49 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXServer#sysaccept' do +describe 'UNIXServer#sysaccept' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + end + + after do + @server.close + + rm_r(@path) + end + + describe 'without a client' do + it 'blocks the calling thread' do + -> { @server.sysaccept }.should block_caller + end + end + + describe 'with a client' do before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) end after do - @server.close - - rm_r(@path) + Socket.for_fd(@fd).close if @fd + @client.close end - describe 'without a client' do - it 'blocks the calling thread' do - -> { @server.sysaccept }.should block_caller + describe 'without any data' do + it 'returns an Integer' do + @fd = @server.sysaccept + @fd.should be_kind_of(Integer) end end - describe 'with a client' do + describe 'with data available' do before do - @client = UNIXSocket.new(@path) - end - - after do - Socket.for_fd(@fd).close if @fd - @client.close + @client.write('hello') end - describe 'without any data' do - it 'returns an Integer' do - @fd = @server.sysaccept - @fd.should be_kind_of(Integer) - end - end - - describe 'with data available' do - before do - @client.write('hello') - end - - it 'returns an Integer' do - @fd = @server.sysaccept - @fd.should be_kind_of(Integer) - end + it 'returns an Integer' do + @fd = @server.sysaccept + @fd.should be_kind_of(Integer) end end end diff --git a/library/socket/unixsocket/addr_spec.rb b/library/socket/unixsocket/addr_spec.rb index d93e061312..1afe9b12dc 100644 --- a/library/socket/unixsocket/addr_spec.rb +++ b/library/socket/unixsocket/addr_spec.rb @@ -1,35 +1,33 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#addr" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#addr" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "returns an array" do - @client.addr.should be_kind_of(Array) - end + it "returns an array" do + @client.addr.should be_kind_of(Array) + end - it "returns the address family of this socket in an array" do - @client.addr[0].should == "AF_UNIX" - @server.addr[0].should == "AF_UNIX" - end + it "returns the address family of this socket in an array" do + @client.addr[0].should == "AF_UNIX" + @server.addr[0].should == "AF_UNIX" + end - it "returns the path of the socket in an array if it's a server" do - @server.addr[1].should == @path - end + it "returns the path of the socket in an array if it's a server" do + @server.addr[1].should == @path + end - it "returns an empty string for path if it's a client" do - @client.addr[1].should == "" - end + it "returns an empty string for path if it's a client" do + @client.addr[1].should == "" end end diff --git a/library/socket/unixsocket/initialize_spec.rb b/library/socket/unixsocket/initialize_spec.rb index bf7896ab0e..5dccfcc745 100644 --- a/library/socket/unixsocket/initialize_spec.rb +++ b/library/socket/unixsocket/initialize_spec.rb @@ -1,48 +1,56 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#initialize' do - describe 'using a non existing path' do +describe 'UNIXSocket#initialize' do + describe 'using a non existing path' do + platform_is_not :windows do it 'raises Errno::ENOENT' do -> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ENOENT) end end - describe 'using an existing socket path' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @socket = UNIXSocket.new(@path) + platform_is :windows do + # Why, Windows, why? + it 'raises Errno::ECONNREFUSED' do + -> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ECONNREFUSED) end + end + end - after do - @socket.close - @server.close - rm_r(@path) - end + describe 'using an existing socket path' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @socket = UNIXSocket.new(@path) + end - it 'returns a new UNIXSocket' do - @socket.should be_an_instance_of(UNIXSocket) - end + after do + @socket.close + @server.close + rm_r(@path) + end - it 'sets the socket path to an empty String' do - @socket.path.should == '' - end + it 'returns a new UNIXSocket' do + @socket.should be_an_instance_of(UNIXSocket) + end - it 'sets the socket to binmode' do - @socket.binmode?.should be_true - end + it 'sets the socket path to an empty String' do + @socket.path.should == '' + end + + it 'sets the socket to binmode' do + @socket.binmode?.should be_true + end + platform_is_not :windows do it 'sets the socket to nonblock' do require 'io/nonblock' @socket.should.nonblock? end + end - it 'sets the socket to close on exec' do - @socket.should.close_on_exec? - end - + it 'sets the socket to close on exec' do + @socket.should.close_on_exec? end end end diff --git a/library/socket/unixsocket/inspect_spec.rb b/library/socket/unixsocket/inspect_spec.rb index a542ba6db5..77bb521069 100644 --- a/library/socket/unixsocket/inspect_spec.rb +++ b/library/socket/unixsocket/inspect_spec.rb @@ -1,17 +1,15 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#inspect" do - it "returns sockets fd for unnamed sockets" do - begin - s1, s2 = UNIXSocket.socketpair - s1.inspect.should == "#" - s2.inspect.should == "#" - ensure - s1.close - s2.close - end +describe "UNIXSocket#inspect" do + it "returns sockets fd for unnamed sockets" do + begin + s1, s2 = UNIXSocket.socketpair + s1.inspect.should == "#" + s2.inspect.should == "#" + ensure + s1.close + s2.close end end end diff --git a/library/socket/unixsocket/local_address_spec.rb b/library/socket/unixsocket/local_address_spec.rb index 734253e7f5..0fdec38293 100644 --- a/library/socket/unixsocket/local_address_spec.rb +++ b/library/socket/unixsocket/local_address_spec.rb @@ -1,94 +1,92 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#local_address' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end +describe 'UNIXSocket#local_address' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) + end - after do - @client.close - @server.close + after do + @client.close + @server.close - rm_r(@path) - end - - it 'returns an Addrinfo' do - @client.local_address.should be_an_instance_of(Addrinfo) - end + rm_r(@path) + end - describe 'the returned Addrinfo' do - platform_is_not :aix do - it 'uses AF_UNIX as the address family' do - @client.local_address.afamily.should == Socket::AF_UNIX - end + it 'returns an Addrinfo' do + @client.local_address.should be_an_instance_of(Addrinfo) + end - it 'uses PF_UNIX as the protocol family' do - @client.local_address.pfamily.should == Socket::PF_UNIX - end + describe 'the returned Addrinfo' do + platform_is_not :aix do + it 'uses AF_UNIX as the address family' do + @client.local_address.afamily.should == Socket::AF_UNIX end - it 'uses SOCK_STREAM as the socket type' do - @client.local_address.socktype.should == Socket::SOCK_STREAM + it 'uses PF_UNIX as the protocol family' do + @client.local_address.pfamily.should == Socket::PF_UNIX end + end - platform_is_not :aix do - it 'uses an empty socket path' do - @client.local_address.unix_path.should == '' - end - end + it 'uses SOCK_STREAM as the socket type' do + @client.local_address.socktype.should == Socket::SOCK_STREAM + end - it 'uses 0 as the protocol' do - @client.local_address.protocol.should == 0 + platform_is_not :aix do + it 'uses an empty socket path' do + @client.local_address.unix_path.should == '' end end - end - describe 'UNIXSocket#local_address with a UNIX socket pair' do - before :each do - @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + it 'uses 0 as the protocol' do + @client.local_address.protocol.should == 0 end + end +end - after :each do - @sock.close - @sock2.close - end +describe 'UNIXSocket#local_address with a UNIX socket pair' do + before :each do + @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + end - it 'returns an Addrinfo' do - @sock.local_address.should be_an_instance_of(Addrinfo) - end + after :each do + @sock.close + @sock2.close + end - describe 'the returned Addrinfo' do - it 'uses AF_UNIX as the address family' do - @sock.local_address.afamily.should == Socket::AF_UNIX - end + it 'returns an Addrinfo' do + @sock.local_address.should be_an_instance_of(Addrinfo) + end - it 'uses PF_UNIX as the protocol family' do - @sock.local_address.pfamily.should == Socket::PF_UNIX - end + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @sock.local_address.afamily.should == Socket::AF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @sock.local_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses PF_UNIX as the protocol family' do + @sock.local_address.pfamily.should == Socket::PF_UNIX + end - it 'raises SocketError for #ip_address' do - -> { - @sock.local_address.ip_address - }.should raise_error(SocketError, "need IPv4 or IPv6 address") - end + it 'uses SOCK_STREAM as the socket type' do + @sock.local_address.socktype.should == Socket::SOCK_STREAM + end - it 'raises SocketError for #ip_port' do - -> { - @sock.local_address.ip_port - }.should raise_error(SocketError, "need IPv4 or IPv6 address") - end + it 'raises SocketError for #ip_address' do + -> { + @sock.local_address.ip_address + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end - it 'uses 0 as the protocol' do - @sock.local_address.protocol.should == 0 - end + it 'raises SocketError for #ip_port' do + -> { + @sock.local_address.ip_port + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end + + it 'uses 0 as the protocol' do + @sock.local_address.protocol.should == 0 end end end diff --git a/library/socket/unixsocket/new_spec.rb b/library/socket/unixsocket/new_spec.rb index 6d8ea6dcfe..fea2c1e2b7 100644 --- a/library/socket/unixsocket/new_spec.rb +++ b/library/socket/unixsocket/new_spec.rb @@ -1,14 +1,12 @@ require_relative '../spec_helper' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXSocket.new" do - it_behaves_like :unixsocket_new, :new +describe "UNIXSocket.new" do + it_behaves_like :unixsocket_new, :new - it "does not use the given block and warns to use UNIXSocket::open" do - -> { - @client = UNIXSocket.new(@path) { raise } - }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/) - end + it "does not use the given block and warns to use UNIXSocket::open" do + -> { + @client = UNIXSocket.new(@path) { raise } + }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/) end end diff --git a/library/socket/unixsocket/open_spec.rb b/library/socket/unixsocket/open_spec.rb index 61def30abb..b5e8c6c23a 100644 --- a/library/socket/unixsocket/open_spec.rb +++ b/library/socket/unixsocket/open_spec.rb @@ -2,27 +2,25 @@ require_relative '../fixtures/classes' require_relative 'shared/new' -with_feature :unix_socket do - describe "UNIXSocket.open" do - it_behaves_like :unixsocket_new, :open - end +describe "UNIXSocket.open" do + it_behaves_like :unixsocket_new, :open +end - describe "UNIXSocket.open" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - end +describe "UNIXSocket.open" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + end - after :each do - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @server.close + SocketSpecs.rm_socket @path + end - it "opens a unix socket on the specified file and yields it to the block" do - UNIXSocket.open(@path) do |client| - client.addr[0].should == "AF_UNIX" - client.should_not.closed? - end + it "opens a unix socket on the specified file and yields it to the block" do + UNIXSocket.open(@path) do |client| + client.addr[0].should == "AF_UNIX" + client.should_not.closed? end end end diff --git a/library/socket/unixsocket/pair_spec.rb b/library/socket/unixsocket/pair_spec.rb index b0a3b2af99..9690142668 100644 --- a/library/socket/unixsocket/pair_spec.rb +++ b/library/socket/unixsocket/pair_spec.rb @@ -3,18 +3,16 @@ require_relative '../shared/partially_closable_sockets' require_relative 'shared/pair' -with_feature :unix_socket do - describe "UNIXSocket.pair" do - it_should_behave_like :unixsocket_pair - it_should_behave_like :partially_closable_sockets +describe "UNIXSocket.pair" do + it_should_behave_like :unixsocket_pair + it_should_behave_like :partially_closable_sockets - before :each do - @s1, @s2 = UNIXSocket.pair - end + before :each do + @s1, @s2 = UNIXSocket.pair + end - after :each do - @s1.close - @s2.close - end + after :each do + @s1.close + @s2.close end end diff --git a/library/socket/unixsocket/partially_closable_spec.rb b/library/socket/unixsocket/partially_closable_spec.rb index ef7d0f0b2a..108a6c3063 100644 --- a/library/socket/unixsocket/partially_closable_spec.rb +++ b/library/socket/unixsocket/partially_closable_spec.rb @@ -2,22 +2,20 @@ require_relative '../fixtures/classes' require_relative '../shared/partially_closable_sockets' -with_feature :unix_socket do - describe "UNIXSocket partial closability" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @s1 = UNIXSocket.new(@path) - @s2 = @server.accept - end - - after :each do - @server.close - @s1.close - @s2.close - SocketSpecs.rm_socket @path - end +describe "UNIXSocket partial closability" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @s1 = UNIXSocket.new(@path) + @s2 = @server.accept + end - it_should_behave_like :partially_closable_sockets + after :each do + @server.close + @s1.close + @s2.close + SocketSpecs.rm_socket @path end + + it_should_behave_like :partially_closable_sockets end diff --git a/library/socket/unixsocket/path_spec.rb b/library/socket/unixsocket/path_spec.rb index a608378e4f..ffe7e4bea2 100644 --- a/library/socket/unixsocket/path_spec.rb +++ b/library/socket/unixsocket/path_spec.rb @@ -1,26 +1,24 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#path" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#path" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "returns the path of the socket if it's a server" do - @server.path.should == @path - end + it "returns the path of the socket if it's a server" do + @server.path.should == @path + end - it "returns an empty string for path if it's a client" do - @client.path.should == "" - end + it "returns an empty string for path if it's a client" do + @client.path.should == "" end end diff --git a/library/socket/unixsocket/peeraddr_spec.rb b/library/socket/unixsocket/peeraddr_spec.rb index 72bc96b1fe..10cab13b42 100644 --- a/library/socket/unixsocket/peeraddr_spec.rb +++ b/library/socket/unixsocket/peeraddr_spec.rb @@ -1,28 +1,26 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#peeraddr" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) - end +describe "UNIXSocket#peeraddr" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path - end + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end - it "returns the address family and path of the server end of the connection" do - @client.peeraddr.should == ["AF_UNIX", @path] - end + it "returns the address family and path of the server end of the connection" do + @client.peeraddr.should == ["AF_UNIX", @path] + end - it "raises an error in server sockets" do - -> { - @server.peeraddr - }.should raise_error(Errno::ENOTCONN) - end + it "raises an error in server sockets" do + -> { + @server.peeraddr + }.should raise_error(Errno::ENOTCONN) end end diff --git a/library/socket/unixsocket/recv_io_spec.rb b/library/socket/unixsocket/recv_io_spec.rb index 1dbc4538e3..f0b408f309 100644 --- a/library/socket/unixsocket/recv_io_spec.rb +++ b/library/socket/unixsocket/recv_io_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do +platform_is_not :windows do describe "UNIXSocket#recv_io" do before :each do @path = SocketSpecs.socket_path diff --git a/library/socket/unixsocket/recvfrom_spec.rb b/library/socket/unixsocket/recvfrom_spec.rb index d849fdc302..7fa5c9b600 100644 --- a/library/socket/unixsocket/recvfrom_spec.rb +++ b/library/socket/unixsocket/recvfrom_spec.rb @@ -1,59 +1,105 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe "UNIXSocket#recvfrom" do - before :each do - @path = SocketSpecs.socket_path - @server = UNIXServer.open(@path) - @client = UNIXSocket.open(@path) +describe "UNIXSocket#recvfrom" do + before :each do + @path = SocketSpecs.socket_path + @server = UNIXServer.open(@path) + @client = UNIXSocket.open(@path) + end + + after :each do + @client.close + @server.close + SocketSpecs.rm_socket @path + end + + it "receives len bytes from sock, returning an array containing sent data as first element" do + @client.send("foobar", 0) + sock = @server.accept + sock.recvfrom(6).first.should == "foobar" + sock.close + end + + context "when called on a server's socket" do + platform_is_not :windows do + it "returns an array containing basic information on the client as second element" do + @client.send("foobar", 0) + sock = @server.accept + data = sock.recvfrom(6) + data.last.should == ["AF_UNIX", ""] + sock.close + end end - after :each do - @client.close - @server.close - SocketSpecs.rm_socket @path + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do + it "returns an array containing basic information on the client as second element" do + @client.send("foobar", 0) + sock = @server.accept + data = sock.recvfrom(6) + data.last.should == ["AF_UNIX", ""] + sock.close + end end + end - it "receives len bytes from sock" do - @client.send("foobar", 0) - sock = @server.accept - sock.recvfrom(6).first.should == "foobar" - sock.close + context "when called on a client's socket" do + platform_is_not :windows, :darwin do + it "returns an array containing server's address as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] + sock.close + end end - it "returns an array with data and information on the sender" do - @client.send("foobar", 0) - sock = @server.accept - data = sock.recvfrom(6) - data.first.should == "foobar" - data.last.should == ["AF_UNIX", ""] - sock.close + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do + it "returns an array containing server's address as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + # This may not be correct, depends on what underlying recvfrom actually returns. + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] + sock.close + end end - it "allows an output buffer as third argument" do - buffer = +'' + platform_is :darwin do + it "returns an array containing basic information on the server as second element" do + @client.send("", 0) + sock = @server.accept + sock.send("barfoo", 0) + @client.recvfrom(6).last.should == ["AF_UNIX", ""] + sock.close + end + end + end - @client.send("foobar", 0) - sock = @server.accept - message, = sock.recvfrom(6, 0, buffer) - sock.close + it "allows an output buffer as third argument" do + buffer = +'' - message.should.equal?(buffer) - buffer.should == "foobar" - end + @client.send("foobar", 0) + sock = @server.accept + message, = sock.recvfrom(6, 0, buffer) + sock.close - it "preserves the encoding of the given buffer" do - buffer = ''.encode(Encoding::ISO_8859_1) + message.should.equal?(buffer) + buffer.should == "foobar" + end - @client.send("foobar", 0) - sock = @server.accept - sock.recvfrom(6, 0, buffer) - sock.close + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) - buffer.encoding.should == Encoding::ISO_8859_1 - end + @client.send("foobar", 0) + sock = @server.accept + sock.recvfrom(6, 0, buffer) + sock.close + buffer.encoding.should == Encoding::ISO_8859_1 + end + + platform_is_not :windows do it "uses different message options" do @client.send("foobar", Socket::MSG_PEEK) sock = @server.accept @@ -65,24 +111,34 @@ sock.close end end +end - describe 'UNIXSocket#recvfrom' do - describe 'using a socket pair' do - before do - @client, @server = UNIXSocket.socketpair - @client.write('hello') - end +describe 'UNIXSocket#recvfrom' do + describe 'using a socket pair' do + before do + @client, @server = UNIXSocket.socketpair + @client.write('hello') + end - after do - @client.close - @server.close + after do + @client.close + @server.close + end + + platform_is_not :windows do + it 'returns an Array containing the data and address information' do + @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] end + end + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do it 'returns an Array containing the data and address information' do @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] end end + end + platform_is_not :windows do # These specs are taken from the rdoc examples on UNIXSocket#recvfrom. describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do before do diff --git a/library/socket/unixsocket/remote_address_spec.rb b/library/socket/unixsocket/remote_address_spec.rb index 0b416254d0..84bdff0a6a 100644 --- a/library/socket/unixsocket/remote_address_spec.rb +++ b/library/socket/unixsocket/remote_address_spec.rb @@ -1,45 +1,43 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do - describe 'UNIXSocket#remote_address' do - before do - @path = SocketSpecs.socket_path - @server = UNIXServer.new(@path) - @client = UNIXSocket.new(@path) - end +describe 'UNIXSocket#remote_address' do + before do + @path = SocketSpecs.socket_path + @server = UNIXServer.new(@path) + @client = UNIXSocket.new(@path) + end - after do - @client.close - @server.close + after do + @client.close + @server.close - rm_r(@path) - end + rm_r(@path) + end - it 'returns an Addrinfo' do - @client.remote_address.should be_an_instance_of(Addrinfo) - end + it 'returns an Addrinfo' do + @client.remote_address.should be_an_instance_of(Addrinfo) + end - describe 'the returned Addrinfo' do - it 'uses AF_UNIX as the address family' do - @client.remote_address.afamily.should == Socket::AF_UNIX - end + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @client.remote_address.afamily.should == Socket::AF_UNIX + end - it 'uses PF_UNIX as the protocol family' do - @client.remote_address.pfamily.should == Socket::PF_UNIX - end + it 'uses PF_UNIX as the protocol family' do + @client.remote_address.pfamily.should == Socket::PF_UNIX + end - it 'uses SOCK_STREAM as the socket type' do - @client.remote_address.socktype.should == Socket::SOCK_STREAM - end + it 'uses SOCK_STREAM as the socket type' do + @client.remote_address.socktype.should == Socket::SOCK_STREAM + end - it 'uses the correct socket path' do - @client.remote_address.unix_path.should == @path - end + it 'uses the correct socket path' do + @client.remote_address.unix_path.should == @path + end - it 'uses 0 as the protocol' do - @client.remote_address.protocol.should == 0 - end + it 'uses 0 as the protocol' do + @client.remote_address.protocol.should == 0 end end end diff --git a/library/socket/unixsocket/send_io_spec.rb b/library/socket/unixsocket/send_io_spec.rb index 80f3550c6d..52186ec3cf 100644 --- a/library/socket/unixsocket/send_io_spec.rb +++ b/library/socket/unixsocket/send_io_spec.rb @@ -1,7 +1,7 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -with_feature :unix_socket do +platform_is_not :windows do describe "UNIXSocket#send_io" do before :each do @path = SocketSpecs.socket_path diff --git a/library/socket/unixsocket/shared/pair.rb b/library/socket/unixsocket/shared/pair.rb index ade7fc9852..0f1af43b25 100644 --- a/library/socket/unixsocket/shared/pair.rb +++ b/library/socket/unixsocket/shared/pair.rb @@ -12,18 +12,37 @@ @s2.gets.should == "foo\n" end - it "sets the socket paths to empty Strings" do - @s1.path.should == "" - @s2.path.should == "" - end + platform_is_not :windows do + it "sets the socket paths to empty Strings" do + @s1.path.should == "" + @s2.path.should == "" + end + + it "sets the socket addresses to empty Strings" do + @s1.addr.should == ["AF_UNIX", ""] + @s2.addr.should == ["AF_UNIX", ""] + end - it "sets the socket addresses to empty Strings" do - @s1.addr.should == ["AF_UNIX", ""] - @s2.addr.should == ["AF_UNIX", ""] + it "sets the socket peer addresses to empty Strings" do + @s1.peeraddr.should == ["AF_UNIX", ""] + @s2.peeraddr.should == ["AF_UNIX", ""] + end end - it "sets the socket peer addresses to empty Strings" do - @s1.peeraddr.should == ["AF_UNIX", ""] - @s2.peeraddr.should == ["AF_UNIX", ""] + platform_is :windows do + it "emulates unnamed sockets with a temporary file with a path" do + @s1.path.match?(/\\AppData\\Local\\Temp\\\d+-\d+\.\(\$\)\z/).should be_true + @s1.addr.should == ["AF_UNIX", @s1.path] + @s2.peeraddr.should == ["AF_UNIX", @s1.path] + end + + it "sets the peer address of first socket to an empty string" do + @s1.peeraddr.should == ["AF_UNIX", ""] + end + + it "sets the address and path of second socket to an empty string" do + @s2.addr.should == ["AF_UNIX", ""] + @s2.path.should == "" + end end end diff --git a/library/socket/unixsocket/socketpair_spec.rb b/library/socket/unixsocket/socketpair_spec.rb index 5f34008df3..c61fc00be4 100644 --- a/library/socket/unixsocket/socketpair_spec.rb +++ b/library/socket/unixsocket/socketpair_spec.rb @@ -3,18 +3,16 @@ require_relative '../shared/partially_closable_sockets' require_relative 'shared/pair' -with_feature :unix_socket do - describe "UNIXSocket.socketpair" do - it_should_behave_like :unixsocket_pair - it_should_behave_like :partially_closable_sockets +describe "UNIXSocket.socketpair" do + it_should_behave_like :unixsocket_pair + it_should_behave_like :partially_closable_sockets - before :each do - @s1, @s2 = UNIXSocket.socketpair - end + before :each do + @s1, @s2 = UNIXSocket.socketpair + end - after :each do - @s1.close - @s2.close - end + after :each do + @s1.close + @s2.close end end diff --git a/shared/file/socket.rb b/shared/file/socket.rb index 55a1cfd284..ef6c482d1c 100644 --- a/shared/file/socket.rb +++ b/shared/file/socket.rb @@ -1,3 +1,33 @@ describe :file_socket, shared: true do - it "accepts an object that has a #to_path method" + it "returns false if the file is not a socket" do + filename = tmp("i_exist") + touch(filename) + + @object.send(@method, filename).should == false + + rm_r filename + end + + it "returns true if the file is a socket" do + require 'socket' + + # We need a really short name here. + # On Linux the path length is limited to 107, see unix(7). + name = tmp("s") + server = UNIXServer.new(name) + + @object.send(@method, name).should == true + + server.close + rm_r name + end + + it "accepts an object that has a #to_path method" do + obj = Object.new + def obj.to_path + __FILE__ + end + + @object.send(@method, obj).should == false + end end