summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket')
-rw-r--r--spec/ruby/library/socket/addrinfo/afamily_spec.rb5
-rw-r--r--spec/ruby/library/socket/addrinfo/bind_spec.rb5
-rw-r--r--spec/ruby/library/socket/addrinfo/canonname_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_from_spec.rb75
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_spec.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_to_spec.rb75
-rw-r--r--spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb115
-rw-r--r--spec/ruby/library/socket/addrinfo/foreach_spec.rb9
-rw-r--r--spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb91
-rw-r--r--spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/initialize_spec.rb346
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb55
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_spec.rb65
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb38
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_port_spec.rb7
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_spec.rb36
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb7
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb17
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb39
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_spec.rb5
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb9
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb19
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb26
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_spec.rb5
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb71
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb15
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/listen_spec.rb34
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb84
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_load_spec.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/pfamily_spec.rb11
-rw-r--r--spec/ruby/library/socket/addrinfo/protocol_spec.rb28
-rw-r--r--spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb26
-rw-r--r--spec/ruby/library/socket/addrinfo/socktype_spec.rb27
-rw-r--r--spec/ruby/library/socket/addrinfo/tcp_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/to_s_spec.rb7
-rw-r--r--spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb7
-rw-r--r--spec/ruby/library/socket/addrinfo/udp_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_path_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_spec.rb39
-rw-r--r--spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb33
-rw-r--r--spec/ruby/library/socket/ancillarydata/data_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/family_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/initialize_spec.rb284
-rw-r--r--spec/ruby/library/socket/ancillarydata/int_spec.rb43
-rw-r--r--spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb145
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb11
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_ifindex_spec.rb11
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb89
-rw-r--r--spec/ruby/library/socket/ancillarydata/level_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/type_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb61
-rw-r--r--spec/ruby/library/socket/basicsocket/close_read_spec.rb18
-rw-r--r--spec/ruby/library/socket/basicsocket/close_write_spec.rb18
-rw-r--r--spec/ruby/library/socket/basicsocket/connect_address_spec.rb154
-rw-r--r--spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb68
-rw-r--r--spec/ruby/library/socket/basicsocket/for_fd_spec.rb25
-rw-r--r--spec/ruby/library/socket/basicsocket/getpeereid_spec.rb36
-rw-r--r--spec/ruby/library/socket/basicsocket/getpeername_spec.rb9
-rw-r--r--spec/ruby/library/socket/basicsocket/getsockname_spec.rb8
-rw-r--r--spec/ruby/library/socket/basicsocket/getsockopt_spec.rb148
-rw-r--r--spec/ruby/library/socket/basicsocket/ioctl_spec.rb3
-rw-r--r--spec/ruby/library/socket/basicsocket/local_address_spec.rb10
-rw-r--r--spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb74
-rw-r--r--spec/ruby/library/socket/basicsocket/read_spec.rb47
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb102
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_spec.rb126
-rw-r--r--spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb224
-rw-r--r--spec/ruby/library/socket/basicsocket/recvmsg_spec.rb197
-rw-r--r--spec/ruby/library/socket/basicsocket/remote_address_spec.rb10
-rw-r--r--spec/ruby/library/socket/basicsocket/send_spec.rb181
-rw-r--r--spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb118
-rw-r--r--spec/ruby/library/socket/basicsocket/sendmsg_spec.rb111
-rw-r--r--spec/ruby/library/socket/basicsocket/setsockopt_spec.rb149
-rw-r--r--spec/ruby/library/socket/basicsocket/shutdown_spec.rb155
-rw-r--r--spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb43
-rw-r--r--spec/ruby/library/socket/constants/constants_spec.rb26
-rw-r--r--spec/ruby/library/socket/fixtures/classes.rb91
-rw-r--r--spec/ruby/library/socket/ipsocket/addr_spec.rb67
-rw-r--r--spec/ruby/library/socket/ipsocket/getaddress_spec.rb21
-rw-r--r--spec/ruby/library/socket/ipsocket/peeraddr_spec.rb72
-rw-r--r--spec/ruby/library/socket/ipsocket/recvfrom_spec.rb59
-rw-r--r--spec/ruby/library/socket/option/bool_spec.rb12
-rw-r--r--spec/ruby/library/socket/option/initialize_spec.rb83
-rw-r--r--spec/ruby/library/socket/option/inspect_spec.rb5
-rw-r--r--spec/ruby/library/socket/option/int_spec.rb25
-rw-r--r--spec/ruby/library/socket/option/linger_spec.rb22
-rw-r--r--spec/ruby/library/socket/option/new_spec.rb10
-rw-r--r--spec/ruby/library/socket/shared/address.rb249
-rw-r--r--spec/ruby/library/socket/shared/pack_sockaddr.rb67
-rw-r--r--spec/ruby/library/socket/shared/partially_closable_sockets.rb2
-rw-r--r--spec/ruby/library/socket/shared/recv_nonblock.rb54
-rw-r--r--spec/ruby/library/socket/shared/socketpair.rb115
-rw-r--r--spec/ruby/library/socket/socket/accept_loop_spec.rb84
-rw-r--r--spec/ruby/library/socket/socket/accept_nonblock_spec.rb120
-rw-r--r--spec/ruby/library/socket/socket/accept_spec.rb123
-rw-r--r--spec/ruby/library/socket/socket/bind_spec.rb107
-rw-r--r--spec/ruby/library/socket/socket/connect_nonblock_spec.rb146
-rw-r--r--spec/ruby/library/socket/socket/connect_spec.rb76
-rw-r--r--spec/ruby/library/socket/socket/for_fd_spec.rb5
-rw-r--r--spec/ruby/library/socket/socket/getaddrinfo_spec.rb279
-rw-r--r--spec/ruby/library/socket/socket/gethostbyaddr_spec.rb126
-rw-r--r--spec/ruby/library/socket/socket/gethostbyname_spec.rb136
-rw-r--r--spec/ruby/library/socket/socket/gethostname_spec.rb14
-rw-r--r--spec/ruby/library/socket/socket/getifaddrs_spec.rb117
-rw-r--r--spec/ruby/library/socket/socket/getnameinfo_spec.rb89
-rw-r--r--spec/ruby/library/socket/socket/getservbyname_spec.rb14
-rw-r--r--spec/ruby/library/socket/socket/getservbyport_spec.rb23
-rw-r--r--spec/ruby/library/socket/socket/initialize_spec.rb87
-rw-r--r--spec/ruby/library/socket/socket/ip_address_list_spec.rb50
-rw-r--r--spec/ruby/library/socket/socket/ipv6only_bang_spec.rb20
-rw-r--r--spec/ruby/library/socket/socket/listen_spec.rb54
-rw-r--r--spec/ruby/library/socket/socket/local_address_spec.rb43
-rw-r--r--spec/ruby/library/socket/socket/new_spec.rb2
-rw-r--r--spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb8
-rw-r--r--spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb6
-rw-r--r--spec/ruby/library/socket/socket/pair_spec.rb8
-rw-r--r--spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb141
-rw-r--r--spec/ruby/library/socket/socket/recvfrom_spec.rb94
-rw-r--r--spec/ruby/library/socket/socket/remote_address_spec.rb54
-rw-r--r--spec/ruby/library/socket/socket/sockaddr_in_spec.rb6
-rw-r--r--spec/ruby/library/socket/socket/sockaddr_un_spec.rb6
-rw-r--r--spec/ruby/library/socket/socket/socket_spec.rb4
-rw-r--r--spec/ruby/library/socket/socket/socketpair_spec.rb8
-rw-r--r--spec/ruby/library/socket/socket/sysaccept_spec.rb93
-rw-r--r--spec/ruby/library/socket/socket/tcp_server_loop_spec.rb54
-rw-r--r--spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb39
-rw-r--r--spec/ruby/library/socket/socket/tcp_spec.rb70
-rw-r--r--spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb47
-rw-r--r--spec/ruby/library/socket/socket/udp_server_loop_spec.rb59
-rw-r--r--spec/ruby/library/socket/socket/udp_server_recv_spec.rb35
-rw-r--r--spec/ruby/library/socket/socket/udp_server_sockets_spec.rb39
-rw-r--r--spec/ruby/library/socket/socket/unix_server_loop_spec.rb58
-rw-r--r--spec/ruby/library/socket/socket/unix_server_socket_spec.rb48
-rw-r--r--spec/ruby/library/socket/socket/unix_spec.rb45
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb33
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb14
-rw-r--r--spec/ruby/library/socket/spec_helper.rb13
-rw-r--r--spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb53
-rw-r--r--spec/ruby/library/socket/tcpserver/accept_spec.rb74
-rw-r--r--spec/ruby/library/socket/tcpserver/gets_spec.rb6
-rw-r--r--spec/ruby/library/socket/tcpserver/initialize_spec.rb101
-rw-r--r--spec/ruby/library/socket/tcpserver/listen_spec.rb28
-rw-r--r--spec/ruby/library/socket/tcpserver/new_spec.rb67
-rw-r--r--spec/ruby/library/socket/tcpserver/sysaccept_spec.rb46
-rw-r--r--spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb74
-rw-r--r--spec/ruby/library/socket/tcpsocket/initialize_spec.rb100
-rw-r--r--spec/ruby/library/socket/tcpsocket/local_address_spec.rb73
-rw-r--r--spec/ruby/library/socket/tcpsocket/new_spec.rb5
-rw-r--r--spec/ruby/library/socket/tcpsocket/open_spec.rb3
-rw-r--r--spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb8
-rw-r--r--spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb26
-rw-r--r--spec/ruby/library/socket/tcpsocket/recv_spec.rb28
-rw-r--r--spec/ruby/library/socket/tcpsocket/remote_address_spec.rb72
-rw-r--r--spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb4
-rw-r--r--spec/ruby/library/socket/tcpsocket/shared/new.rb37
-rw-r--r--spec/ruby/library/socket/udpsocket/bind_spec.rb53
-rw-r--r--spec/ruby/library/socket/udpsocket/connect_spec.rb35
-rw-r--r--spec/ruby/library/socket/udpsocket/initialize_spec.rb53
-rw-r--r--spec/ruby/library/socket/udpsocket/inspect_spec.rb17
-rw-r--r--spec/ruby/library/socket/udpsocket/local_address_spec.rb80
-rw-r--r--spec/ruby/library/socket/udpsocket/new_spec.rb14
-rw-r--r--spec/ruby/library/socket/udpsocket/open_spec.rb4
-rw-r--r--spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb111
-rw-r--r--spec/ruby/library/socket/udpsocket/remote_address_spec.rb79
-rw-r--r--spec/ruby/library/socket/udpsocket/send_spec.rb92
-rw-r--r--spec/ruby/library/socket/udpsocket/write_spec.rb6
-rw-r--r--spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb67
-rw-r--r--spec/ruby/library/socket/unixserver/accept_spec.rb73
-rw-r--r--spec/ruby/library/socket/unixserver/for_fd_spec.rb8
-rw-r--r--spec/ruby/library/socket/unixserver/initialize_spec.rb28
-rw-r--r--spec/ruby/library/socket/unixserver/listen_spec.rb21
-rw-r--r--spec/ruby/library/socket/unixserver/new_spec.rb16
-rw-r--r--spec/ruby/library/socket/unixserver/open_spec.rb11
-rw-r--r--spec/ruby/library/socket/unixserver/shared/new.rb31
-rw-r--r--spec/ruby/library/socket/unixserver/sysaccept_spec.rb52
-rw-r--r--spec/ruby/library/socket/unixsocket/addr_spec.rb19
-rw-r--r--spec/ruby/library/socket/unixsocket/initialize_spec.rb48
-rw-r--r--spec/ruby/library/socket/unixsocket/inspect_spec.rb8
-rw-r--r--spec/ruby/library/socket/unixsocket/local_address_spec.rb94
-rw-r--r--spec/ruby/library/socket/unixsocket/new_spec.rb16
-rw-r--r--spec/ruby/library/socket/unixsocket/open_spec.rb19
-rw-r--r--spec/ruby/library/socket/unixsocket/pair_spec.rb35
-rw-r--r--spec/ruby/library/socket/unixsocket/partially_closable_spec.rb12
-rw-r--r--spec/ruby/library/socket/unixsocket/path_spec.rb10
-rw-r--r--spec/ruby/library/socket/unixsocket/peeraddr_spec.rb14
-rw-r--r--spec/ruby/library/socket/unixsocket/recv_io_spec.rb52
-rw-r--r--spec/ruby/library/socket/unixsocket/recvfrom_spec.rb81
-rw-r--r--spec/ruby/library/socket/unixsocket/remote_address_spec.rb45
-rw-r--r--spec/ruby/library/socket/unixsocket/send_io_spec.rb30
-rw-r--r--spec/ruby/library/socket/unixsocket/shared/new.rb32
-rw-r--r--spec/ruby/library/socket/unixsocket/shared/pair.rb29
-rw-r--r--spec/ruby/library/socket/unixsocket/socketpair_spec.rb20
202 files changed, 823 insertions, 9644 deletions
diff --git a/spec/ruby/library/socket/addrinfo/afamily_spec.rb b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
index 7229dab9de..1845ab5e04 100644
--- a/spec/ruby/library/socket/addrinfo/afamily_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#afamily" do
describe "for an ipv4 socket" do
@@ -23,7 +24,7 @@ describe "Addrinfo#afamily" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/bind_spec.rb b/spec/ruby/library/socket/addrinfo/bind_spec.rb
index 6f78890a4d..c892b05756 100644
--- a/spec/ruby/library/socket/addrinfo/bind_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/bind_spec.rb
@@ -1,5 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require 'socket'
describe "Addrinfo#bind" do
diff --git a/spec/ruby/library/socket/addrinfo/canonname_spec.rb b/spec/ruby/library/socket/addrinfo/canonname_spec.rb
index a1cc8b3980..15dfe86467 100644
--- a/spec/ruby/library/socket/addrinfo/canonname_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/canonname_spec.rb
@@ -1,5 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require 'socket'
describe "Addrinfo#canonname" do
@@ -15,13 +16,4 @@ describe "Addrinfo#canonname" do
canonname.should == nil
end
end
-
- describe 'when the canonical name is not available' do
- it 'returns nil' do
- addr = Addrinfo.new(Socket.sockaddr_in(0, '127.0.0.1'))
-
- addr.canonname.should be_nil
- end
- end
-
end
diff --git a/spec/ruby/library/socket/addrinfo/connect_from_spec.rb b/spec/ruby/library/socket/addrinfo/connect_from_spec.rb
deleted file mode 100644
index 55fce2e159..0000000000
--- a/spec/ruby/library/socket/addrinfo/connect_from_spec.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Addrinfo#connect_from' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- @addr = Addrinfo.tcp(ip_address, @port)
- end
-
- after do
- @socket.close if @socket
- @server.close
- end
-
- describe 'using separate arguments' do
- it 'returns a Socket when no block is given' do
- @socket = @addr.connect_from(ip_address, 0)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket when a block is given' do
- @addr.connect_from(ip_address, 0) do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'treats the last argument as a set of options if it is a Hash' do
- @socket = @addr.connect_from(ip_address, 0, timeout: 2)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'binds the socket to the local address' do
- @socket = @addr.connect_from(ip_address, 0)
-
- @socket.local_address.ip_address.should == ip_address
-
- @socket.local_address.ip_port.should > 0
- @socket.local_address.ip_port.should_not == @port
- end
- end
-
- describe 'using an Addrinfo as the 1st argument' do
- before do
- @from_addr = Addrinfo.tcp(ip_address, 0)
- end
-
- it 'returns a Socket when no block is given' do
- @socket = @addr.connect_from(@from_addr)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket when a block is given' do
- @addr.connect_from(@from_addr) do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'treats the last argument as a set of options if it is a Hash' do
- @socket = @addr.connect_from(@from_addr, timeout: 2)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'binds the socket to the local address' do
- @socket = @addr.connect_from(@from_addr)
-
- @socket.local_address.ip_address.should == ip_address
-
- @socket.local_address.ip_port.should > 0
- @socket.local_address.ip_port.should_not == @port
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/connect_spec.rb b/spec/ruby/library/socket/addrinfo/connect_spec.rb
deleted file mode 100644
index 1c2dc609ca..0000000000
--- a/spec/ruby/library/socket/addrinfo/connect_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Addrinfo#connect' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- end
-
- after do
- @socket.close if @socket
- @server.close
- end
-
- it 'returns a Socket when no block is given' do
- addr = Addrinfo.tcp(ip_address, @port)
- @socket = addr.connect
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields a Socket when a block is given' do
- addr = Addrinfo.tcp(ip_address, @port)
- addr.connect do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'accepts a Hash of options' do
- addr = Addrinfo.tcp(ip_address, @port)
- @socket = addr.connect(timeout: 2)
- @socket.should be_an_instance_of(Socket)
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/connect_to_spec.rb b/spec/ruby/library/socket/addrinfo/connect_to_spec.rb
deleted file mode 100644
index 69666da19b..0000000000
--- a/spec/ruby/library/socket/addrinfo/connect_to_spec.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Addrinfo#connect_to' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- @addr = Addrinfo.tcp(ip_address, 0)
- end
-
- after do
- @socket.close if @socket
- @server.close
- end
-
- describe 'using separate arguments' do
- it 'returns a Socket when no block is given' do
- @socket = @addr.connect_to(ip_address, @port)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket when a block is given' do
- @addr.connect_to(ip_address, @port) do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'treats the last argument as a set of options if it is a Hash' do
- @socket = @addr.connect_to(ip_address, @port, timeout: 2)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'binds the Addrinfo to the local address' do
- @socket = @addr.connect_to(ip_address, @port)
-
- @socket.local_address.ip_address.should == ip_address
-
- @socket.local_address.ip_port.should > 0
- @socket.local_address.ip_port.should_not == @port
- end
- end
-
- describe 'using an Addrinfo as the 1st argument' do
- before do
- @to_addr = Addrinfo.tcp(ip_address, @port)
- end
-
- it 'returns a Socket when no block is given' do
- @socket = @addr.connect_to(@to_addr)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket when a block is given' do
- @addr.connect_to(@to_addr) do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'treats the last argument as a set of options if it is a Hash' do
- @socket = @addr.connect_to(@to_addr, timeout: 2)
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'binds the socket to the local address' do
- @socket = @addr.connect_to(@to_addr)
-
- @socket.local_address.ip_address.should == ip_address
-
- @socket.local_address.ip_port.should > 0
- @socket.local_address.ip_port.should_not == @port
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
deleted file mode 100644
index 2bc3b6a2e3..0000000000
--- a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#family_addrinfo' do
- it 'raises ArgumentError if no arguments are given' do
- addr = Addrinfo.tcp('127.0.0.1', 0)
-
- -> { addr.family_addrinfo }.should raise_error(ArgumentError)
- end
-
- describe 'using multiple arguments' do
- describe 'with an IP Addrinfo' do
- before do
- @source = Addrinfo.tcp('127.0.0.1', 0)
- end
-
- it 'raises ArgumentError if only 1 argument is given' do
- -> { @source.family_addrinfo('127.0.0.1') }.should raise_error(ArgumentError)
- end
-
- it 'raises ArgumentError if more than 2 arguments are given' do
- -> { @source.family_addrinfo('127.0.0.1', 0, 666) }.should raise_error(ArgumentError)
- end
-
- it 'returns an Addrinfo when a host and port are given' do
- addr = @source.family_addrinfo('127.0.0.1', 0)
-
- addr.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @source.family_addrinfo('127.0.0.1', 0)
- end
-
- it 'uses the same address family as the source Addrinfo' do
- @addr.afamily.should == @source.afamily
- end
-
- it 'uses the same protocol family as the source Addrinfo' do
- @addr.pfamily.should == @source.pfamily
- end
-
- it 'uses the same socket type as the source Addrinfo' do
- @addr.socktype.should == @source.socktype
- end
-
- it 'uses the same protocol as the source Addrinfo' do
- @addr.protocol.should == @source.protocol
- end
- end
- end
-
- with_feature :unix_socket do
- 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 'returns an Addrinfo when a UNIX socket path is given' do
- addr = @source.family_addrinfo('dogs')
-
- addr.should be_an_instance_of(Addrinfo)
- 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 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
- end
- end
- end
- end
-
- describe 'using an Addrinfo as the 1st argument' do
- before do
- @source = Addrinfo.tcp('127.0.0.1', 0)
- end
-
- it 'returns the input Addrinfo' do
- input = Addrinfo.tcp('127.0.0.2', 0)
- @source.family_addrinfo(input).should == input
- end
-
- it 'raises ArgumentError if more than 1 argument is given' do
- input = Addrinfo.tcp('127.0.0.2', 0)
- -> { @source.family_addrinfo(input, 666) }.should raise_error(ArgumentError)
- end
-
- it "raises ArgumentError if the protocol families don't match" do
- input = Addrinfo.tcp('::1', 0)
- -> { @source.family_addrinfo(input) }.should raise_error(ArgumentError)
- end
-
- it "raises ArgumentError if the socket types don't match" do
- input = Addrinfo.udp('127.0.0.1', 0)
- -> { @source.family_addrinfo(input) }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/foreach_spec.rb b/spec/ruby/library/socket/addrinfo/foreach_spec.rb
deleted file mode 100644
index 6ec8fab905..0000000000
--- a/spec/ruby/library/socket/addrinfo/foreach_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo.foreach' do
- it 'yields Addrinfo instances to the supplied block' do
- Addrinfo.foreach('127.0.0.1', 80) do |addr|
- addr.should be_an_instance_of(Addrinfo)
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb
deleted file mode 100644
index 67fad73815..0000000000
--- a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Addrinfo.getaddrinfo' do
- it 'returns an Array of Addrinfo instances' do
- array = Addrinfo.getaddrinfo('127.0.0.1', 80)
-
- array.should be_an_instance_of(Array)
- array[0].should be_an_instance_of(Addrinfo)
- end
-
- SocketSpecs.each_ip_protocol do |family, ip_address|
- it 'sets the IP address of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo(ip_address, 80)
-
- array[0].ip_address.should == ip_address
- end
-
- it 'sets the port of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo(ip_address, 80)
-
- array[0].ip_port.should == 80
- end
-
- it 'sets the address family of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo(ip_address, 80)
-
- array[0].afamily.should == family
- end
-
- it 'sets the protocol family of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo(ip_address, 80)
-
- array[0].pfamily.should == family
- end
- end
-
- guard -> { SocketSpecs.ipv6_available? } do
- it 'sets a custom protocol family of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo('::1', 80, Socket::PF_INET6)
-
- array[0].pfamily.should == Socket::PF_INET6
- end
-
- it 'sets a corresponding address family based on a custom protocol family' do
- array = Addrinfo.getaddrinfo('::1', 80, Socket::PF_INET6)
-
- array[0].afamily.should == Socket::AF_INET6
- end
- end
-
- platform_is_not :windows do
- it 'sets the default socket type of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo('127.0.0.1', 80)
- possible = [Socket::SOCK_STREAM, Socket::SOCK_DGRAM]
-
- possible.should include(array[0].socktype)
- end
- end
-
- it 'sets a custom socket type of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, Socket::SOCK_DGRAM)
-
- array[0].socktype.should == Socket::SOCK_DGRAM
- end
-
- platform_is_not :windows do
- it 'sets the default socket protocol of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo('127.0.0.1', 80)
- possible = [Socket::IPPROTO_TCP, Socket::IPPROTO_UDP]
-
- possible.should include(array[0].protocol)
- end
- end
-
- platform_is_not :'solaris2.10' do # i386-solaris
- it 'sets a custom socket protocol of the Addrinfo instances' do
- array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, nil, Socket::IPPROTO_UDP)
-
- array[0].protocol.should == Socket::IPPROTO_UDP
- end
- end
-
- platform_is_not :solaris do
- it 'sets the canonical name when AI_CANONNAME is given as a flag' do
- array = Addrinfo.getaddrinfo('localhost', 80, nil, nil, nil, Socket::AI_CANONNAME)
-
- array[0].canonname.should be_an_instance_of(String)
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
deleted file mode 100644
index 76579de74c..0000000000
--- a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Addrinfo#getnameinfo' do
- describe 'using an IP Addrinfo' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @addr = Addrinfo.tcp(ip_address, 21)
- end
-
- it 'returns the node and service names' do
- host, service = @addr.getnameinfo
- service.should == 'ftp'
- end
-
- it 'accepts flags as an Integer as the first argument' do
- host, service = @addr.getnameinfo(Socket::NI_NUMERICSERV)
- service.should == '21'
- end
- end
- end
-
- 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
-
- it 'returns the hostname and UNIX socket path' do
- host, path = @addr.getnameinfo
-
- host.should == @host
- path.should == 'cats'
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/initialize_spec.rb b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
index d8885c5d62..254539f95e 100644
--- a/spec/ruby/library/socket/addrinfo/initialize_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#initialize" do
@@ -21,12 +22,6 @@ describe "Addrinfo#initialize" do
@addrinfo.pfamily.should == Socket::PF_UNSPEC
end
- it 'returns AF_INET as the default address family' do
- addr = Addrinfo.new(Socket.sockaddr_in(80, '127.0.0.1'))
-
- addr.afamily.should == Socket::AF_INET
- end
-
it "returns the INET6 afamily" do
@addrinfo.afamily.should == Socket::AF_INET6
end
@@ -91,7 +86,7 @@ describe "Addrinfo#initialize" do
@addrinfo.afamily.should == Socket::AF_INET6
end
- it "returns the specified socket type" do
+ it "returns the 0 socket type" do
@addrinfo.socktype.should == Socket::SOCK_STREAM
end
@@ -147,7 +142,7 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 46102
end
- it "returns the Socket::PF_INET pfamily" do
+ it "returns the Socket::UNSPEC pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET
end
@@ -164,46 +159,6 @@ describe "Addrinfo#initialize" do
end
end
- describe 'with a valid IP address' do
- # Uses AF_INET6 since AF_INET is the default, making it a better test
- # that Addrinfo actually sets the family correctly.
- before do
- @sockaddr = ['AF_INET6', 80, 'hostname', '::1']
- end
-
- it 'returns an Addrinfo with the correct IP' do
- addr = Addrinfo.new(@sockaddr)
-
- addr.ip_address.should == '::1'
- end
-
- it 'returns an Addrinfo with the correct address family' do
- addr = Addrinfo.new(@sockaddr)
-
- addr.afamily.should == Socket::AF_INET6
- end
-
- it 'returns an Addrinfo with the correct protocol family' do
- addr = Addrinfo.new(@sockaddr)
-
- addr.pfamily.should == Socket::PF_INET6
- end
-
- it 'returns an Addrinfo with the correct port' do
- addr = Addrinfo.new(@sockaddr)
-
- addr.ip_port.should == 80
- end
- end
-
- describe 'with an invalid IP address' do
- it 'raises SocketError' do
- block = -> { Addrinfo.new(['AF_INET6', 80, 'hostname', '127.0.0.1']) }
-
- block.should raise_error(SocketError)
- end
- end
-
describe "with a family given" do
before :each do
@addrinfo = Addrinfo.new(["AF_INET", 46102, "localhost", "127.0.0.1"], Socket::PF_INET)
@@ -262,40 +217,6 @@ describe "Addrinfo#initialize" do
it "returns the 0 protocol" do
@addrinfo.protocol.should == 0
end
-
- [:SOCK_STREAM, :SOCK_DGRAM, :SOCK_RAW].each do |type|
- it "overwrites the socket type #{type}" do
- sockaddr = ['AF_INET', 80, 'hostname', '127.0.0.1']
-
- value = Socket.const_get(type)
- addr = Addrinfo.new(sockaddr, nil, value)
-
- addr.socktype.should == value
- end
- end
-
- platform_is_not :android do
- with_feature :sock_packet do
- [:SOCK_SEQPACKET].each do |type|
- it "overwrites the socket type #{type}" do
- sockaddr = ['AF_INET', 80, 'hostname', '127.0.0.1']
-
- value = Socket.const_get(type)
- addr = Addrinfo.new(sockaddr, nil, value)
-
- addr.socktype.should == value
- end
- end
- end
- end
-
- it "raises SocketError when using SOCK_RDM" do
- sockaddr = ['AF_INET', 80, 'hostname', '127.0.0.1']
- value = Socket::SOCK_RDM
- block = -> { Addrinfo.new(sockaddr, nil, value) }
-
- block.should raise_error(SocketError)
- end
end
describe "with a family, socket type and protocol" do
@@ -329,263 +250,4 @@ describe "Addrinfo#initialize" do
end
end
- describe 'using an Array with extra arguments' do
- describe 'with the AF_INET6 address family and an explicit protocol family' do
- before do
- @sockaddr = ['AF_INET6', 80, 'hostname', '127.0.0.1']
- end
-
- it "raises SocketError when using any Socket constant except AF_INET(6)/PF_INET(6)" do
- Socket.constants.grep(/(^AF_|^PF_)(?!INET)/).each do |constant|
- value = Socket.const_get(constant)
- -> {
- Addrinfo.new(@sockaddr, value)
- }.should raise_error(SocketError)
- end
- end
- end
-
- describe 'with the AF_INET address family and an explicit socket protocol' do
- before do
- @sockaddr = ['AF_INET', 80, 'hostname', '127.0.0.1']
- end
-
- describe 'and no socket type is given' do
- valid = [:IPPROTO_IP, :IPPROTO_UDP, :IPPROTO_HOPOPTS]
-
- valid.each do |type|
- it "overwrites the protocol when using #{type}" do
- value = Socket.const_get(type)
- addr = Addrinfo.new(@sockaddr, nil, nil, value)
-
- addr.protocol.should == value
- end
- end
-
- platform_is_not :windows, :aix, :solaris do
- (Socket.constants.grep(/^IPPROTO/) - valid).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, nil, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
- end
-
- describe 'and the socket type is set to SOCK_DGRAM' do
- before do
- @socktype = Socket::SOCK_DGRAM
- end
-
- valid = [:IPPROTO_IP, :IPPROTO_UDP, :IPPROTO_HOPOPTS]
-
- valid.each do |type|
- it "overwrites the protocol when using #{type}" do
- value = Socket.const_get(type)
- addr = Addrinfo.new(@sockaddr, nil, @socktype, value)
-
- addr.protocol.should == value
- end
- end
-
- platform_is_not :windows, :aix, :solaris do
- (Socket.constants.grep(/^IPPROTO/) - valid).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
- end
-
- with_feature :sock_packet do
- describe 'and the socket type is set to SOCK_PACKET' do
- before do
- @socktype = Socket::SOCK_PACKET
- end
-
- Socket.constants.grep(/^IPPROTO/).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
- end
-
- describe 'and the socket type is set to SOCK_RAW' do
- before do
- @socktype = Socket::SOCK_RAW
- end
-
- Socket.constants.grep(/^IPPROTO/).each do |type|
- it "overwrites the protocol when using #{type}" do
- value = Socket.const_get(type)
- addr = Addrinfo.new(@sockaddr, nil, @socktype, value)
-
- addr.protocol.should == value
- end
- end
- end
-
- describe 'and the socket type is set to SOCK_RDM' do
- before do
- @socktype = Socket::SOCK_RDM
- end
-
- Socket.constants.grep(/^IPPROTO/).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
-
- platform_is :linux do
- platform_is_not :android do
- describe 'and the socket type is set to SOCK_SEQPACKET' do
- before do
- @socktype = Socket::SOCK_SEQPACKET
- end
-
- valid = [:IPPROTO_IP, :IPPROTO_HOPOPTS]
-
- valid.each do |type|
- it "overwrites the protocol when using #{type}" do
- value = Socket.const_get(type)
- addr = Addrinfo.new(@sockaddr, nil, @socktype, value)
-
- addr.protocol.should == value
- end
- end
-
- (Socket.constants.grep(/^IPPROTO/) - valid).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
- end
- end
-
- describe 'and the socket type is set to SOCK_STREAM' do
- before do
- @socktype = Socket::SOCK_STREAM
- end
-
- valid = [:IPPROTO_IP, :IPPROTO_TCP, :IPPROTO_HOPOPTS]
-
- valid.each do |type|
- it "overwrites the protocol when using #{type}" do
- value = Socket.const_get(type)
- addr = Addrinfo.new(@sockaddr, nil, @socktype, value)
-
- addr.protocol.should == value
- end
- end
-
- platform_is_not :windows, :aix, :solaris do
- (Socket.constants.grep(/^IPPROTO/) - valid).each do |type|
- it "raises SocketError when using #{type}" do
- value = Socket.const_get(type)
- block = -> { Addrinfo.new(@sockaddr, nil, @socktype, value) }
-
- block.should raise_error(SocketError)
- end
- end
- end
- end
- end
- end
-
- describe 'with Symbols' do
- before do
- @sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
- end
-
- it 'returns an Addrinfo with :PF_INET family' do
- addr = Addrinfo.new(@sockaddr, :PF_INET)
-
- addr.pfamily.should == Socket::PF_INET
- end
-
- it 'returns an Addrinfo with :INET family' do
- addr = Addrinfo.new(@sockaddr, :INET)
-
- addr.pfamily.should == Socket::PF_INET
- end
-
- it 'returns an Addrinfo with :SOCK_STREAM as the socket type' do
- addr = Addrinfo.new(@sockaddr, nil, :SOCK_STREAM)
-
- addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'returns an Addrinfo with :STREAM as the socket type' do
- addr = Addrinfo.new(@sockaddr, nil, :STREAM)
-
- addr.socktype.should == Socket::SOCK_STREAM
- end
- end
-
- describe 'with Strings' do
- before do
- @sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
- end
-
- it 'returns an Addrinfo with "PF_INET" family' do
- addr = Addrinfo.new(@sockaddr, 'PF_INET')
-
- addr.pfamily.should == Socket::PF_INET
- end
-
- it 'returns an Addrinfo with "INET" family' do
- addr = Addrinfo.new(@sockaddr, 'INET')
-
- addr.pfamily.should == Socket::PF_INET
- end
-
- it 'returns an Addrinfo with "SOCK_STREAM" as the socket type' do
- addr = Addrinfo.new(@sockaddr, nil, 'SOCK_STREAM')
-
- addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'returns an Addrinfo with "STREAM" as the socket type' do
- addr = Addrinfo.new(@sockaddr, nil, 'STREAM')
-
- addr.socktype.should == Socket::SOCK_STREAM
- 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
-
- 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 address family' do
- Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
index 70ca4dd4d7..c7d69db760 100644
--- a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
@@ -1,50 +1,25 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe 'Addrinfo#inspect_sockaddr' do
- describe 'using an IPv4 address' do
- it 'returns a String containing the IP address and port number' do
- addr = Addrinfo.tcp('127.0.0.1', 80)
-
- addr.inspect_sockaddr.should == '127.0.0.1:80'
- end
-
- it 'returns a String containing just the IP address when no port is given' do
- addr = Addrinfo.tcp('127.0.0.1', 0)
-
- addr.inspect_sockaddr.should == '127.0.0.1'
- end
+ it 'IPv4' do
+ Addrinfo.tcp('127.0.0.1', 80).inspect_sockaddr.should == '127.0.0.1:80'
+ Addrinfo.tcp('127.0.0.1', 0).inspect_sockaddr.should == '127.0.0.1'
end
- describe 'using an IPv6 address' do
- before :each do
- @ip = '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
- end
-
- it 'returns a String containing the IP address and port number' do
- Addrinfo.tcp('::1', 80).inspect_sockaddr.should == '[::1]:80'
- Addrinfo.tcp(@ip, 80).inspect_sockaddr.should == '[2001:db8:85a3::8a2e:370:7334]:80'
- end
-
- it 'returns a String containing just the IP address when no port is given' do
- Addrinfo.tcp('::1', 0).inspect_sockaddr.should == '::1'
- Addrinfo.tcp(@ip, 0).inspect_sockaddr.should == '2001:db8:85a3::8a2e:370:7334'
- end
+ it 'IPv6' do
+ Addrinfo.tcp('::1', 80).inspect_sockaddr.should == '[::1]:80'
+ Addrinfo.tcp('::1', 0).inspect_sockaddr.should == '::1'
+ ip = '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
+ Addrinfo.tcp(ip, 80).inspect_sockaddr.should == '[2001:db8:85a3::8a2e:370:7334]:80'
+ Addrinfo.tcp(ip, 0).inspect_sockaddr.should == '2001:db8:85a3::8a2e:370:7334'
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')
-
- 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')
-
- addr.inspect_sockaddr.should == 'UNIX foo'
- end
+ platform_is_not :windows do
+ it 'UNIX' do
+ Addrinfo.unix('/tmp/sock').inspect_sockaddr.should == '/tmp/sock'
+ Addrinfo.unix('rel').inspect_sockaddr.should == 'UNIX rel'
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/inspect_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_spec.rb
deleted file mode 100644
index 98e1e83ffa..0000000000
--- a/spec/ruby/library/socket/addrinfo/inspect_spec.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#inspect' do
- describe 'using an IPv4 Addrinfo' do
- it 'returns a String when using a TCP Addrinfo' do
- addr = Addrinfo.tcp('127.0.0.1', 80)
-
- addr.inspect.should == '#<Addrinfo: 127.0.0.1:80 TCP>'
- end
-
- it 'returns a String when using an UDP Addrinfo' do
- addr = Addrinfo.udp('127.0.0.1', 80)
-
- addr.inspect.should == '#<Addrinfo: 127.0.0.1:80 UDP>'
- end
-
- it 'returns a String when using an Addrinfo without a port' do
- addr = Addrinfo.ip('127.0.0.1')
-
- addr.inspect.should == '#<Addrinfo: 127.0.0.1>'
- end
- end
-
- describe 'using an IPv6 Addrinfo' do
- it 'returns a String when using a TCP Addrinfo' do
- addr = Addrinfo.tcp('::1', 80)
-
- addr.inspect.should == '#<Addrinfo: [::1]:80 TCP>'
- end
-
- it 'returns a String when using an UDP Addrinfo' do
- addr = Addrinfo.udp('::1', 80)
-
- addr.inspect.should == '#<Addrinfo: [::1]:80 UDP>'
- end
-
- it 'returns a String when using an Addrinfo without a port' do
- addr = Addrinfo.ip('::1')
-
- addr.inspect.should == '#<Addrinfo: ::1>'
- end
- end
-
- with_feature :unix_socket do
- describe 'using a UNIX Addrinfo' do
- it 'returns a String' do
- addr = Addrinfo.unix('/foo')
-
- addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>'
- end
-
- it 'returns a String when using a relative UNIX path' do
- addr = Addrinfo.unix('foo')
-
- addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>'
- end
-
- it 'returns a String when using a DGRAM socket' do
- addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM)
-
- addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>'
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
index 4522cf5cfd..f82cef0812 100644
--- a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ip_address" do
describe "for an ipv4 socket" do
@@ -21,46 +22,15 @@ describe "Addrinfo#ip_address" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
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)
+ lambda { @addrinfo.ip_address }.should raise_error(SocketError)
end
end
end
-
- describe 'with an Array as the socket address' do
- it 'returns the IP as a String' do
- sockaddr = ['AF_INET', 80, 'localhost', '127.0.0.1']
- addr = Addrinfo.new(sockaddr)
-
- addr.ip_address.should == '127.0.0.1'
- end
- end
-
- describe 'without an IP address' do
- before do
- @ips = ['127.0.0.1', '0.0.0.0', '::1']
- end
-
- # Both these cases seem to return different values at times on MRI. Since
- # this is network dependent we can't rely on an exact IP being returned.
- it 'returns the local IP address when using an empty String as the IP' do
- sockaddr = Socket.sockaddr_in(80, '')
- addr = Addrinfo.new(sockaddr)
-
- @ips.include?(addr.ip_address).should == true
- end
-
- it 'returns the local IP address when using nil as the IP' do
- sockaddr = Socket.sockaddr_in(80, nil)
- addr = Addrinfo.new(sockaddr)
-
- @ips.include?(addr.ip_address).should == true
- end
- end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
index 4118607db0..e437b88ca1 100644
--- a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ip_port" do
describe "for an ipv4 socket" do
@@ -21,14 +22,14 @@ describe "Addrinfo#ip_port" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
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)
+ lambda { @addrinfo.ip_port }.should raise_error(SocketError)
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_spec.rb b/spec/ruby/library/socket/addrinfo/ip_spec.rb
index 80e7a62df7..2e4b613ae5 100644
--- a/spec/ruby/library/socket/addrinfo/ip_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ip?" do
describe "for an ipv4 socket" do
@@ -22,43 +22,15 @@ describe "Addrinfo#ip?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
end
- it "returns false" do
+ it "returns Socket::AF_INET6" do
@addrinfo.ip?.should be_false
end
end
end
end
-
-describe 'Addrinfo.ip' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- it 'returns an Addrinfo instance' do
- Addrinfo.ip(ip_address).should be_an_instance_of(Addrinfo)
- end
-
- it 'sets the IP address' do
- Addrinfo.ip(ip_address).ip_address.should == ip_address
- end
-
- it 'sets the port to 0' do
- Addrinfo.ip(ip_address).ip_port.should == 0
- end
-
- it 'sets the address family' do
- Addrinfo.ip(ip_address).afamily.should == family
- end
-
- it 'sets the protocol family' do
- Addrinfo.ip(ip_address).pfamily.should == family
- end
-
- it 'sets the socket type to 0' do
- Addrinfo.ip(ip_address).socktype.should == 0
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
index 6c81c48d1c..2b4a9372cc 100644
--- a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ip_unpack" do
describe "for an ipv4 socket" do
@@ -21,14 +22,14 @@ describe "Addrinfo#ip_unpack" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
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)
+ lambda { @addrinfo.ip_unpack }.should raise_error(SocketError)
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
index 10ad084fc9..457bd7cebf 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
@@ -1,16 +1,19 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv4_loopback?" do
describe "for an ipv4 socket" do
+ before :each do
+ @loopback = Addrinfo.tcp("127.0.0.1", 80)
+ @other = Addrinfo.tcp("0.0.0.0", 80)
+ end
+
it "returns true for the loopback address" do
- Addrinfo.ip('127.0.0.1').should.ipv4_loopback?
- Addrinfo.ip('127.0.0.2').should.ipv4_loopback?
- Addrinfo.ip('127.255.0.1').should.ipv4_loopback?
- Addrinfo.ip('127.255.255.255').should.ipv4_loopback?
+ @loopback.ipv4_loopback?.should be_true
end
it "returns false for another address" do
- Addrinfo.ip('255.255.255.0').ipv4_loopback?.should be_false
+ @other.ipv4_loopback?.should be_false
end
end
@@ -29,7 +32,7 @@ describe "Addrinfo#ipv4_loopback?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
index f7fead8640..01f6a6ebf7 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
@@ -1,21 +1,38 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv4_multicast?" do
- it 'returns true for a multicast address' do
- Addrinfo.ip('224.0.0.0').should.ipv4_multicast?
- Addrinfo.ip('224.0.0.9').should.ipv4_multicast?
- Addrinfo.ip('239.255.255.250').should.ipv4_multicast?
- end
+ describe "for an ipv4 socket" do
+ before :each do
+ @multicast = Addrinfo.tcp("224.0.0.1", 80)
+ @other = Addrinfo.tcp("0.0.0.0", 80)
+ end
- it 'returns false for a regular address' do
- Addrinfo.ip('8.8.8.8').should_not.ipv4_multicast?
+ it "returns true for the loopback address" do
+ @multicast.ipv4_multicast?.should be_true
+ end
+
+ it "returns false for another address" do
+ @other.ipv4_multicast?.should be_false
+ end
end
- it 'returns false for an IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv4_multicast?
+ describe "for an ipv6 socket" do
+ before :each do
+ @multicast = Addrinfo.tcp("ff02::1", 80)
+ @other = Addrinfo.tcp("::", 80)
+ end
+
+ it "returns false for the loopback address" do
+ @multicast.ipv4_multicast?.should be_false
+ end
+
+ it "returns false for another address" do
+ @other.ipv4_multicast?.should be_false
+ end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
index e5a33b4953..cf8bd8c1aa 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv4_private?" do
describe "for an ipv4 socket" do
@@ -8,14 +9,7 @@ describe "Addrinfo#ipv4_private?" do
end
it "returns true for a private address" do
- Addrinfo.ip('10.0.0.0').should.ipv4_private?
- Addrinfo.ip('10.0.0.5').should.ipv4_private?
-
- Addrinfo.ip('172.16.0.0').should.ipv4_private?
- Addrinfo.ip('172.16.0.5').should.ipv4_private?
-
- Addrinfo.ip('192.168.0.0').should.ipv4_private?
- Addrinfo.ip('192.168.0.5').should.ipv4_private?
+ @private.ipv4_private?.should be_true
end
it "returns false for a public address" do
@@ -33,7 +27,7 @@ describe "Addrinfo#ipv4_private?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
index 7cba8209b6..3d4560532e 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv4?" do
describe "for an ipv4 socket" do
@@ -21,7 +22,7 @@ describe "Addrinfo#ipv4?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb
deleted file mode 100644
index bfef396381..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-guard -> { SocketSpecs.ipv6_available? } do
- describe 'Addrinfo#ipv6_linklocal?' do
- platform_is_not :aix do
- it 'returns true for a link-local address' do
- Addrinfo.ip('fe80::').should.ipv6_linklocal?
- Addrinfo.ip('fe81::').should.ipv6_linklocal?
- Addrinfo.ip('fe8f::').should.ipv6_linklocal?
- Addrinfo.ip('fe80::1').should.ipv6_linklocal?
- end
- end
-
- it 'returns false for a regular address' do
- Addrinfo.ip('::1').should_not.ipv6_linklocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_linklocal?
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
index 9ff8f107bf..b0060378e6 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv6_loopback?" do
describe "for an ipv4 socket" do
@@ -7,7 +8,7 @@ describe "Addrinfo#ipv6_loopback?" do
@other = Addrinfo.tcp("0.0.0.0", 80)
end
- it "returns false for the loopback address" do
+ it "returns true for the loopback address" do
@loopback.ipv6_loopback?.should be_false
end
@@ -22,7 +23,7 @@ describe "Addrinfo#ipv6_loopback?" do
@other = Addrinfo.tcp("::", 80)
end
- it "returns true for the loopback address" do
+ it "returns false for the loopback address" do
@loopback.ipv6_loopback?.should be_true
end
@@ -31,7 +32,7 @@ describe "Addrinfo#ipv6_loopback?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb
deleted file mode 100644
index 01fa0992ba..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_mc_global?' do
- it 'returns true for a multi-cast address in the global scope' do
- Addrinfo.ip('ff1e::').should.ipv6_mc_global?
- Addrinfo.ip('fffe::').should.ipv6_mc_global?
- Addrinfo.ip('ff0e::').should.ipv6_mc_global?
- Addrinfo.ip('ff1e::1').should.ipv6_mc_global?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_mc_global?
- Addrinfo.ip('ff1a::').should_not.ipv6_mc_global?
- Addrinfo.ip('ff1f::1').should_not.ipv6_mc_global?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_global?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb
deleted file mode 100644
index a1298919eb..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_mc_linklocal?' do
- it 'returns true for a multi-cast link-local address' do
- Addrinfo.ip('ff12::').should.ipv6_mc_linklocal?
- Addrinfo.ip('ff02::').should.ipv6_mc_linklocal?
- Addrinfo.ip('fff2::').should.ipv6_mc_linklocal?
- Addrinfo.ip('ff12::1').should.ipv6_mc_linklocal?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_mc_linklocal?
- Addrinfo.ip('fff1::').should_not.ipv6_mc_linklocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_linklocal?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb
deleted file mode 100644
index 0aee952d88..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_mc_nodelocal?' do
- it 'returns true for a multi-cast node-local address' do
- Addrinfo.ip('ff11::').should.ipv6_mc_nodelocal?
- Addrinfo.ip('ff01::').should.ipv6_mc_nodelocal?
- Addrinfo.ip('fff1::').should.ipv6_mc_nodelocal?
- Addrinfo.ip('ff11::1').should.ipv6_mc_nodelocal?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_mc_nodelocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_nodelocal?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb
deleted file mode 100644
index 2977a98d30..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_mc_orglocal?' do
- it 'returns true for a multi-cast org-local address' do
- Addrinfo.ip('ff18::').should.ipv6_mc_orglocal?
- Addrinfo.ip('ff08::').should.ipv6_mc_orglocal?
- Addrinfo.ip('fff8::').should.ipv6_mc_orglocal?
- Addrinfo.ip('ff18::1').should.ipv6_mc_orglocal?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_mc_orglocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_orglocal?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb
deleted file mode 100644
index 58e5976a40..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_mc_sitelocal?' do
- it 'returns true for a multi-cast site-local address' do
- Addrinfo.ip('ff15::').should.ipv6_mc_sitelocal?
- Addrinfo.ip('ff05::').should.ipv6_mc_sitelocal?
- Addrinfo.ip('fff5::').should.ipv6_mc_sitelocal?
- Addrinfo.ip('ff15::1').should.ipv6_mc_sitelocal?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_mc_sitelocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_sitelocal?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
index 2c987b5921..d8b3a96ebb 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv6_multicast?" do
describe "for an ipv4 socket" do
@@ -7,7 +8,7 @@ describe "Addrinfo#ipv6_multicast?" do
@other = Addrinfo.tcp("0.0.0.0", 80)
end
- it "returns true for a multicast address" do
+ it "returns true for the loopback address" do
@multicast.ipv6_multicast?.should be_false
end
@@ -17,24 +18,21 @@ describe "Addrinfo#ipv6_multicast?" do
end
describe "for an ipv6 socket" do
- it "returns true for a multicast address" do
- Addrinfo.ip('ff00::').should.ipv6_multicast?
- Addrinfo.ip('ff00::1').should.ipv6_multicast?
- Addrinfo.ip('ff08::1').should.ipv6_multicast?
- Addrinfo.ip('fff8::1').should.ipv6_multicast?
-
- Addrinfo.ip('ff02::').should.ipv6_multicast?
- Addrinfo.ip('ff02::1').should.ipv6_multicast?
- Addrinfo.ip('ff0f::').should.ipv6_multicast?
+ before :each do
+ @multicast = Addrinfo.tcp("ff02::1", 80)
+ @other = Addrinfo.tcp("::", 80)
+ end
+
+ it "returns false for the loopback address" do
+ @multicast.ipv6_multicast?.should be_true
end
it "returns false for another address" do
- Addrinfo.ip('::1').should_not.ipv6_multicast?
- Addrinfo.ip('fe80::').should_not.ipv6_multicast?
+ @other.ipv6_multicast?.should be_false
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb
deleted file mode 100644
index 9158eb5809..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-guard -> { SocketSpecs.ipv6_available? } do
- describe 'Addrinfo#ipv6_sitelocal?' do
- platform_is_not :aix do
- it 'returns true for a site-local address' do
- Addrinfo.ip('feef::').should.ipv6_sitelocal?
- Addrinfo.ip('fee0::').should.ipv6_sitelocal?
- Addrinfo.ip('fee2::').should.ipv6_sitelocal?
- Addrinfo.ip('feef::1').should.ipv6_sitelocal?
- end
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_sitelocal?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_sitelocal?
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
index 131e38849c..b66bc0d70b 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#ipv6?" do
describe "for an ipv4 socket" do
@@ -21,7 +22,7 @@ describe "Addrinfo#ipv6?" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
deleted file mode 100644
index 6dfaf531ae..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-guard -> { SocketSpecs.ipv6_available? } do
- describe 'Addrinfo#ipv6_to_ipv4' do
- it 'returns an Addrinfo for ::192.168.1.1' do
- addr = Addrinfo.ip('::192.168.1.1').ipv6_to_ipv4
-
- addr.should be_an_instance_of(Addrinfo)
-
- addr.afamily.should == Socket::AF_INET
- addr.ip_address.should == '192.168.1.1'
- end
-
- platform_is_not :aix do
- it 'returns an Addrinfo for ::0.0.1.1' do
- addr = Addrinfo.ip('::0.0.1.1').ipv6_to_ipv4
-
- addr.should be_an_instance_of(Addrinfo)
-
- addr.afamily.should == Socket::AF_INET
- addr.ip_address.should == '0.0.1.1'
- end
-
- it 'returns an Addrinfo for ::0.0.1.0' do
- addr = Addrinfo.ip('::0.0.1.0').ipv6_to_ipv4
-
- addr.should be_an_instance_of(Addrinfo)
-
- addr.afamily.should == Socket::AF_INET
- addr.ip_address.should == '0.0.1.0'
- end
-
- it 'returns an Addrinfo for ::0.1.0.0' do
- addr = Addrinfo.ip('::0.1.0.0').ipv6_to_ipv4
-
- addr.should be_an_instance_of(Addrinfo)
-
- addr.afamily.should == Socket::AF_INET
- addr.ip_address.should == '0.1.0.0'
- end
- end
-
- it 'returns an Addrinfo for ::ffff:192.168.1.1' do
- addr = Addrinfo.ip('::ffff:192.168.1.1').ipv6_to_ipv4
-
- addr.should be_an_instance_of(Addrinfo)
-
- addr.afamily.should == Socket::AF_INET
- addr.ip_address.should == '192.168.1.1'
- end
-
- it 'returns nil for ::0.0.0.1' do
- Addrinfo.ip('::0.0.0.1').ipv6_to_ipv4.should be_nil
- end
-
- it 'returns nil for a pure IPv6 Addrinfo' do
- Addrinfo.ip('::1').ipv6_to_ipv4.should be_nil
- end
-
- it 'returns nil for an IPv4 Addrinfo' do
- Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should be_nil
- end
-
- with_feature :unix_socket do
- it 'returns nil for a UNIX Addrinfo' do
- Addrinfo.unix('foo').ipv6_to_ipv4.should be_nil
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb
deleted file mode 100644
index 22f0fa3b75..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_unique_local?' do
- it 'returns true for an unique local IPv6 address' do
- Addrinfo.ip('fc00::').should.ipv6_unique_local?
- Addrinfo.ip('fd00::').should.ipv6_unique_local?
- Addrinfo.ip('fcff::').should.ipv6_unique_local?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_unique_local?
- Addrinfo.ip('fe00::').should_not.ipv6_unique_local?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_unique_local?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb
deleted file mode 100644
index d63979ceda..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_unspecified?' do
- it 'returns true for an unspecified IPv6 address' do
- Addrinfo.ip('::').should.ipv6_unspecified?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_unspecified?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_unspecified?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb
deleted file mode 100644
index 21ca85af99..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_v4compat?' do
- it 'returns true for an IPv4 compatible address' do
- Addrinfo.ip('::127.0.0.1').should.ipv6_v4compat?
- Addrinfo.ip('::192.168.1.1').should.ipv6_v4compat?
- end
-
- it 'returns false for an IPv4 mapped address' do
- Addrinfo.ip('::ffff:192.168.1.1').should_not.ipv6_v4compat?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_v4compat?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_v4compat?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb
deleted file mode 100644
index 7dac0e75db..0000000000
--- a/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#ipv6_v4mapped?' do
- it 'returns true for an IPv4 compatible address' do
- Addrinfo.ip('::ffff:192.168.1.1').should.ipv6_v4mapped?
- end
-
- it 'returns false for an IPv4 compatible address' do
- Addrinfo.ip('::192.168.1.1').should_not.ipv6_v4mapped?
- Addrinfo.ip('::127.0.0.1').should_not.ipv6_v4mapped?
- end
-
- it 'returns false for a regular IPv6 address' do
- Addrinfo.ip('::1').should_not.ipv6_v4mapped?
- end
-
- it 'returns false for an IPv4 address' do
- Addrinfo.ip('127.0.0.1').should_not.ipv6_v4mapped?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/listen_spec.rb b/spec/ruby/library/socket/addrinfo/listen_spec.rb
deleted file mode 100644
index 931093f732..0000000000
--- a/spec/ruby/library/socket/addrinfo/listen_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#listen' do
- before do
- @addr = Addrinfo.tcp('127.0.0.1', 0)
- @socket = nil
- end
-
- after do
- @socket.close if @socket
- end
-
- it 'returns a Socket when no block is given' do
- @socket = @addr.listen
-
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket if a block is given' do
- @addr.listen do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'closes the socket if a block is given' do
- socket = nil
-
- @addr.listen do |sock|
- socket = sock
- end
-
- socket.should.closed?
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
deleted file mode 100644
index c4220a6f3e..0000000000
--- a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#marshal_dump' do
- describe 'using an IP Addrinfo' do
- before do
- @addr = Addrinfo.getaddrinfo('localhost', 80, :INET, :STREAM,
- Socket::IPPROTO_TCP, Socket::AI_CANONNAME)[0]
- end
-
- it 'returns an Array' do
- @addr.marshal_dump.should be_an_instance_of(Array)
- 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_INET'
- end
-
- it 'includes the IP address as the 2nd value' do
- @array[1].should == [@addr.ip_address, @addr.ip_port.to_s]
- end
-
- it 'includes the protocol family as the 3rd value' do
- @array[2].should == 'PF_INET'
- end
-
- it 'includes the socket type as the 4th value' do
- @array[3].should == 'SOCK_STREAM'
- end
-
- platform_is_not :'solaris2.10' do # i386-solaris
- it 'includes the protocol as the 5th value' do
- @array[4].should == 'IPPROTO_TCP'
- end
- end
-
- it 'includes the canonical name as the 6th value' do
- @array[5].should == @addr.canonname
- end
- end
- end
-
- with_feature :unix_socket 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
- @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 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 protocol as the 5th value' do
- @array[4].should == 0
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
deleted file mode 100644
index aa20865224..0000000000
--- a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Addrinfo#marshal_load' do
- describe 'using an IP address' do
- it 'returns a new Addrinfo' do
- source = Addrinfo.getaddrinfo('localhost', 80, :INET, :STREAM,
- Socket::IPPROTO_TCP, Socket::AI_CANONNAME)[0]
-
- 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.ip_address.should == source.ip_address
- addr.ip_port.should == source.ip_port
- addr.canonname.should == source.canonname
- 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))
-
- 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
-end
diff --git a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
index 984744a964..d37ed73e1e 100644
--- a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
@@ -1,12 +1,7 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#pfamily" do
- it 'returns PF_UNSPEC as the default socket family' do
- sockaddr = Socket.pack_sockaddr_in(80, 'localhost')
-
- Addrinfo.new(sockaddr).pfamily.should == Socket::PF_UNSPEC
- end
-
describe "for an ipv4 socket" do
before :each do
@@ -29,7 +24,7 @@ describe "Addrinfo#pfamily" do
end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/protocol_spec.rb b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
index ea143fc4a8..4ff11dc017 100644
--- a/spec/ruby/library/socket/addrinfo/protocol_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
@@ -1,16 +1,30 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#protocol" do
- it 'returns 0 by default' do
- Addrinfo.ip('127.0.0.1').protocol.should == 0
+ describe "for an ipv4 socket" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns Socket::IPPROTO_TCP" do
+ @addrinfo.protocol.should == Socket::IPPROTO_TCP
+ end
+
end
- it 'returns a custom protocol when given' do
- Addrinfo.tcp('127.0.0.1', 80).protocol.should == Socket::IPPROTO_TCP
- Addrinfo.tcp('::1', 80).protocol.should == Socket::IPPROTO_TCP
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns Socket::IPPROTO_TCP" do
+ @addrinfo.protocol.should == Socket::IPPROTO_TCP
+ end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
index 4f7cf439a0..86819a31b0 100644
--- a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
+++ b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
@@ -1,11 +1,12 @@
-describe :socket_addrinfo_to_sockaddr, shared: true do
+describe :socket_addrinfo_to_sockaddr, :shared => true do
+
describe "for an ipv4 socket" do
before :each do
@addrinfo = Addrinfo.tcp("127.0.0.1", 80)
end
it "returns a sockaddr packed structure" do
- @addrinfo.send(@method).should == Socket.sockaddr_in(80, '127.0.0.1')
+ @addrinfo.send(@method).should be_kind_of(String)
end
end
@@ -15,35 +16,20 @@ describe :socket_addrinfo_to_sockaddr, shared: true do
end
it "returns a sockaddr packed structure" do
- @addrinfo.send(@method).should == Socket.sockaddr_in(80, '::1')
+ @addrinfo.send(@method).should be_kind_of(String)
end
end
- with_feature :unix_socket do
+ platform_is_not :windows 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')
+ @addrinfo.send(@method).should be_kind_of(String)
end
end
end
- describe 'using a Addrinfo with just an IP address' do
- it 'returns a String' do
- addr = Addrinfo.ip('127.0.0.1')
-
- addr.send(@method).should == Socket.sockaddr_in(0, '127.0.0.1')
- end
- end
-
- describe 'using a Addrinfo without an IP and port' do
- it 'returns a String' do
- addr = Addrinfo.new(['AF_INET', 0, '', ''])
-
- addr.send(@method).should == Socket.sockaddr_in(0, '')
- end
- end
end
diff --git a/spec/ruby/library/socket/addrinfo/socktype_spec.rb b/spec/ruby/library/socket/addrinfo/socktype_spec.rb
index b994bea140..e1c8c0f3f5 100644
--- a/spec/ruby/library/socket/addrinfo/socktype_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/socktype_spec.rb
@@ -1,15 +1,30 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Addrinfo#socktype" do
- it 'returns 0 by default' do
- Addrinfo.ip('127.0.0.1').socktype.should == 0
+ describe "for an ipv4 socket" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns Socket::SOCK_STREAM" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+
end
- it 'returns the socket type when given' do
- Addrinfo.tcp('127.0.0.1', 80).socktype.should == Socket::SOCK_STREAM
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns Socket::SOCK_STREAM" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
end
- with_feature :unix_socket do
+ platform_is_not :windows do
describe "for a unix socket" do
before :each do
@addrinfo = Addrinfo.unix("/tmp/sock")
diff --git a/spec/ruby/library/socket/addrinfo/tcp_spec.rb b/spec/ruby/library/socket/addrinfo/tcp_spec.rb
index c74c9c21c2..b5c18cefea 100644
--- a/spec/ruby/library/socket/addrinfo/tcp_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/tcp_spec.rb
@@ -1,34 +1,20 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
-describe 'Addrinfo.tcp' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- it 'returns an Addrinfo instance' do
- Addrinfo.tcp(ip_address, 80).should be_an_instance_of(Addrinfo)
- end
-
- it 'sets the IP address' do
- Addrinfo.tcp(ip_address, 80).ip_address.should == ip_address
- end
-
- it 'sets the port' do
- Addrinfo.tcp(ip_address, 80).ip_port.should == 80
- end
-
- it 'sets the address family' do
- Addrinfo.tcp(ip_address, 80).afamily.should == family
- end
-
- it 'sets the protocol family' do
- Addrinfo.tcp(ip_address, 80).pfamily.should == family
- end
+describe "Addrinfo.tcp" do
- it 'sets the socket type' do
- Addrinfo.tcp(ip_address, 80).socktype.should == Socket::SOCK_STREAM
- end
+ before :each do
+ @addrinfo = Addrinfo.tcp("localhost", "smtp")
+ end
- it 'sets the socket protocol' do
- Addrinfo.tcp(ip_address, 80).protocol.should == Socket::IPPROTO_TCP
+ it "creates a addrinfo for a tcp socket" do
+ ["::1", "127.0.0.1"].should include(@addrinfo.ip_address)
+ [Socket::PF_INET, Socket::PF_INET6].should include(@addrinfo.pfamily)
+ @addrinfo.ip_port.should == 25
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ platform_is_not :solaris do
+ @addrinfo.protocol.should == Socket::IPPROTO_TCP
end
end
+
end
diff --git a/spec/ruby/library/socket/addrinfo/to_s_spec.rb b/spec/ruby/library/socket/addrinfo/to_s_spec.rb
index ddf994e051..7205bdc823 100644
--- a/spec/ruby/library/socket/addrinfo/to_s_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/to_s_spec.rb
@@ -1,6 +1,7 @@
-require_relative '../spec_helper'
-require_relative 'shared/to_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/to_sockaddr', __FILE__)
+require 'socket'
describe "Addrinfo#to_s" do
- it_behaves_like :socket_addrinfo_to_sockaddr, :to_s
+ it_behaves_like(:socket_addrinfo_to_sockaddr, :to_s)
end
diff --git a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
index b9f75454bd..f3f926c2b6 100644
--- a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
@@ -1,6 +1,7 @@
-require_relative '../spec_helper'
-require_relative 'shared/to_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/to_sockaddr', __FILE__)
+require 'socket'
describe "Addrinfo#to_sockaddr" do
- it_behaves_like :socket_addrinfo_to_sockaddr, :to_sockaddr
+ it_behaves_like(:socket_addrinfo_to_sockaddr, :to_sockaddr)
end
diff --git a/spec/ruby/library/socket/addrinfo/udp_spec.rb b/spec/ruby/library/socket/addrinfo/udp_spec.rb
index b05cbf9b0b..712d730e05 100644
--- a/spec/ruby/library/socket/addrinfo/udp_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/udp_spec.rb
@@ -1,36 +1,20 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
-describe 'Addrinfo.udp' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- it 'returns an Addrinfo instance' do
- Addrinfo.udp(ip_address, 80).should be_an_instance_of(Addrinfo)
- end
-
- it 'sets the IP address' do
- Addrinfo.udp(ip_address, 80).ip_address.should == ip_address
- end
-
- it 'sets the port' do
- Addrinfo.udp(ip_address, 80).ip_port.should == 80
- end
-
- it 'sets the address family' do
- Addrinfo.udp(ip_address, 80).afamily.should == family
- end
-
- it 'sets the protocol family' do
- Addrinfo.udp(ip_address, 80).pfamily.should == family
- end
+describe "Addrinfo.udp" do
- it 'sets the socket type' do
- Addrinfo.udp(ip_address, 80).socktype.should == Socket::SOCK_DGRAM
- end
+ before :each do
+ @addrinfo = Addrinfo.udp("localhost", "daytime")
+ end
+ it "creates a addrinfo for a tcp socket" do
+ ["::1", "127.0.0.1"].should include(@addrinfo.ip_address)
+ [Socket::PF_INET, Socket::PF_INET6].should include(@addrinfo.pfamily)
+ @addrinfo.ip_port.should == 13
+ @addrinfo.socktype.should == Socket::SOCK_DGRAM
platform_is_not :solaris do
- it 'sets the socket protocol' do
- Addrinfo.udp(ip_address, 80).protocol.should == Socket::IPPROTO_UDP
- end
+ @addrinfo.protocol.should == Socket::IPPROTO_UDP
end
end
+
end
diff --git a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
index 6bfb56a4ac..3f7e03dd7b 100644
--- a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
@@ -1,6 +1,7 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
-with_feature :unix_socket do
+platform_is_not :windows do
describe "Addrinfo#unix_path" do
describe "for an ipv4 socket" do
@@ -9,7 +10,7 @@ with_feature :unix_socket do
end
it "raises an exception" do
- -> { @addrinfo.unix_path }.should raise_error(SocketError)
+ lambda { @addrinfo.unix_path }.should raise_error(SocketError)
end
end
@@ -20,17 +21,19 @@ with_feature :unix_socket do
end
it "raises an exception" do
- -> { @addrinfo.unix_path }.should raise_error(SocketError)
+ lambda { @addrinfo.unix_path }.should raise_error(SocketError)
end
end
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ platform_is_not :windows do
+ 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"
+ it "returns the socket path" do
+ @addrinfo.unix_path.should == "/tmp/sock"
+ end
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/unix_spec.rb b/spec/ruby/library/socket/addrinfo/unix_spec.rb
index 4596ece17e..00eedc96e7 100644
--- a/spec/ruby/library/socket/addrinfo/unix_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/unix_spec.rb
@@ -1,35 +1,18 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
-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
-
- 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 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
+describe "Addrinfo.unix" do
- it 'sets a custom socket type' do
- addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM)
-
- addr.socktype.should == Socket::SOCK_DGRAM
+ platform_is_not :windows do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
end
- it 'sets the socket protocol to 0' do
- Addrinfo.unix('socket').protocol.should == 0
+ it "creates a addrinfo for a unix socket" do
+ @addrinfo.pfamily.should == Socket::PF_UNIX
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ @addrinfo.protocol.should == 0
+ @addrinfo.unix_path.should == "/tmp/sock"
end
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb b/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
deleted file mode 100644
index c54ee29825..0000000000
--- a/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#cmsg_is?' do
- describe 'using :INET, :IP, :TTL as the family, level, and type' do
- before do
- @data = Socket::AncillaryData.new(:INET, :IP, :TTL, '')
- end
-
- it 'returns true when comparing with IPPROTO_IP and IP_TTL' do
- @data.cmsg_is?(Socket::IPPROTO_IP, Socket::IP_TTL).should == true
- end
-
- it 'returns true when comparing with :IP and :TTL' do
- @data.cmsg_is?(:IP, :TTL).should == true
- end
-
- with_feature :pktinfo do
- it 'returns false when comparing with :IP and :PKTINFO' do
- @data.cmsg_is?(:IP, :PKTINFO).should == false
- end
- end
-
- it 'returns false when comparing with :SOCKET and :RIGHTS' do
- @data.cmsg_is?(:SOCKET, :RIGHTS).should == false
- end
-
- it 'raises SocketError when comparing with :IPV6 and :RIGHTS' do
- -> { @data.cmsg_is?(:IPV6, :RIGHTS) }.should raise_error(SocketError)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/data_spec.rb b/spec/ruby/library/socket/ancillarydata/data_spec.rb
deleted file mode 100644
index 5a1a446dd5..0000000000
--- a/spec/ruby/library/socket/ancillarydata/data_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#data' do
- it 'returns the data as a String' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, 'ugh').data.should == 'ugh'
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/family_spec.rb b/spec/ruby/library/socket/ancillarydata/family_spec.rb
deleted file mode 100644
index 975f0d2538..0000000000
--- a/spec/ruby/library/socket/ancillarydata/family_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#family' do
- it 'returns the family as an Integer' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').family.should == Socket::AF_INET
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb
deleted file mode 100644
index 344d1485c5..0000000000
--- a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb
+++ /dev/null
@@ -1,284 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#initialize' do
- describe 'using Integers for the family, level, and type' do
- before do
- @data = Socket::AncillaryData
- .new(Socket::AF_INET, Socket::IPPROTO_IP, Socket::IP_RECVTTL, 'ugh')
- end
-
- it 'sets the address family' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the message level' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the message type' do
- @data.type.should == Socket::IP_RECVTTL
- end
-
- it 'sets the data' do
- @data.data.should == 'ugh'
- end
- end
-
- describe 'using Symbols for the family, level, and type' do
- before do
- @data = Socket::AncillaryData.new(:INET, :IPPROTO_IP, :RECVTTL, 'ugh')
- end
-
- it 'sets the address family' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the message level' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the message type' do
- @data.type.should == Socket::IP_RECVTTL
- end
-
- it 'sets the data' do
- @data.data.should == 'ugh'
- end
- end
-
- describe 'using Strings for the family, level, and type' do
- before do
- @data = Socket::AncillaryData.new('INET', 'IPPROTO_IP', 'RECVTTL', 'ugh')
- end
-
- it 'sets the address family' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the message level' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the message type' do
- @data.type.should == Socket::IP_RECVTTL
- end
-
- it 'sets the data' do
- @data.data.should == 'ugh'
- end
- end
-
- describe 'using custom objects with a to_str method for the family, level, and type' do
- before do
- fmock = mock(:family)
- lmock = mock(:level)
- tmock = mock(:type)
- dmock = mock(:data)
-
- fmock.stub!(:to_str).and_return('INET')
- lmock.stub!(:to_str).and_return('IP')
- tmock.stub!(:to_str).and_return('RECVTTL')
- dmock.stub!(:to_str).and_return('ugh')
-
- @data = Socket::AncillaryData.new(fmock, lmock, tmock, dmock)
- end
-
- it 'sets the address family' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the message level' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the message type' do
- @data.type.should == Socket::IP_RECVTTL
- end
-
- it 'sets the data' do
- @data.data.should == 'ugh'
- end
- end
-
- describe 'using :AF_INET as the family and :SOCKET as the level' do
- it 'sets the type to SCM_RIGHTS when using :RIGHTS as the type argument' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
- end
-
- platform_is_not :"solaris2.10", :aix do
- it 'sets the type to SCM_TIMESTAMP when using :TIMESTAMP as the type argument' do
- Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '').type.should == Socket::SCM_TIMESTAMP
- end
- end
-
- it 'raises TypeError when using a numeric string as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :IGMP, Socket::SCM_RIGHTS.to_s, '')
- }.should raise_error(TypeError)
- end
-
- it 'raises SocketError when using :RECVTTL as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :SOCKET, :RECVTTL, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :MOO as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :SOCKET, :MOO, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :IP_RECVTTL as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :SOCKET, :IP_RECVTTL, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_INET as the family and :SOCKET as the level' do
- it 'sets the type to SCM_RIGHTS when using :RIGHTS as the type argument' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
- end
- end
-
- describe 'using :AF_INET as the family and :IP as the level' do
- it 'sets the type to IP_RECVTTL when using :RECVTTL as the type argument' do
- Socket::AncillaryData.new(:INET, :IP, :RECVTTL, '').type.should == Socket::IP_RECVTTL
- end
-
- with_feature :ip_mtu do
- it 'sets the type to IP_MTU when using :MTU as the type argument' do
- Socket::AncillaryData.new(:INET, :IP, :MTU, '').type.should == Socket::IP_MTU
- end
- end
-
- it 'raises SocketError when using :RIGHTS as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :IP, :RIGHTS, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :MOO as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :IP, :MOO, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_INET as the family and :IPV6 as the level' do
- it 'sets the type to IPV6_CHECKSUM when using :CHECKSUM as the type argument' do
- Socket::AncillaryData.new(:INET, :IPV6, :CHECKSUM, '').type.should == Socket::IPV6_CHECKSUM
- end
-
- with_feature :ipv6_nexthop do
- it 'sets the type to IPV6_NEXTHOP when using :NEXTHOP as the type argument' do
- Socket::AncillaryData.new(:INET, :IPV6, :NEXTHOP, '').type.should == Socket::IPV6_NEXTHOP
- end
- end
-
- it 'raises SocketError when using :RIGHTS as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :IPV6, :RIGHTS, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :MOO as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :IPV6, :MOO, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_INET as the family and :TCP as the level' do
- with_feature :tcp_cork do
- it 'sets the type to TCP_CORK when using :CORK as the type argument' do
- Socket::AncillaryData.new(:INET, :TCP, :CORK, '').type.should == Socket::TCP_CORK
- end
- end
-
- with_feature :tcp_info do
- it 'sets the type to TCP_INFO when using :INFO as the type argument' do
- Socket::AncillaryData.new(:INET, :TCP, :INFO, '').type.should == Socket::TCP_INFO
- end
- end
-
- it 'raises SocketError when using :RIGHTS as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :TCP, :RIGHTS, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :MOO as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :TCP, :MOO, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_INET as the family and :UDP as the level' do
- with_feature :udp_cork do
- it 'sets the type to UDP_CORK when using :CORK as the type argument' do
- Socket::AncillaryData.new(:INET, :UDP, :CORK, '').type.should == Socket::UDP_CORK
- end
- end
-
- it 'raises SocketError when using :RIGHTS as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :UDP, :RIGHTS, '')
- }.should raise_error(SocketError)
- end
-
- it 'raises SocketError when using :MOO as the type argument' do
- -> {
- Socket::AncillaryData.new(:INET, :UDP, :MOO, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_UNIX as the family and :SOCKET as the level' do
- it 'sets the type to SCM_RIGHTS when using :RIGHTS as the type argument' do
- Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
- end
-
- it 'raises SocketError when using :CORK sa the type argument' do
- -> {
- Socket::AncillaryData.new(:UNIX, :SOCKET, :CORK, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_UNIX as the family and :IP as the level' do
- it 'raises SocketError' do
- -> {
- Socket::AncillaryData.new(:UNIX, :IP, :RECVTTL, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_UNIX as the family and :IPV6 as the level' do
- it 'raises SocketError' do
- -> {
- Socket::AncillaryData.new(:UNIX, :IPV6, :NEXTHOP, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_UNIX as the family and :TCP as the level' do
- it 'raises SocketError' do
- -> {
- Socket::AncillaryData.new(:UNIX, :TCP, :CORK, '')
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using :AF_UNIX as the family and :UDP as the level' do
- it 'raises SocketError' do
- -> {
- Socket::AncillaryData.new(:UNIX, :UDP, :CORK, '')
- }.should raise_error(SocketError)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/int_spec.rb b/spec/ruby/library/socket/ancillarydata/int_spec.rb
deleted file mode 100644
index fe41a30a1a..0000000000
--- a/spec/ruby/library/socket/ancillarydata/int_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData.int' do
- before do
- @data = Socket::AncillaryData.int(:INET, :SOCKET, :RIGHTS, 4)
- end
-
- it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
- end
-
- it 'sets the family to AF_INET' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the level SOL_SOCKET' do
- @data.level.should == Socket::SOL_SOCKET
- end
-
- it 'sets the type SCM_RIGHTS' do
- @data.type.should == Socket::SCM_RIGHTS
- end
-
- it 'sets the data to a packed String' do
- @data.data.should == [4].pack('I')
- end
- end
-
- describe 'Socket::AncillaryData#int' do
- it 'returns the data as an Integer' do
- data = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, 4)
-
- data.int.should == 4
- end
-
- it 'raises when the data is not an Integer' do
- data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, 'ugh')
-
- -> { data.int }.should raise_error(TypeError)
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
deleted file mode 100644
index 84910a038a..0000000000
--- a/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
+++ /dev/null
@@ -1,145 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data, :pktinfo do
- describe 'Socket::AncillaryData.ip_pktinfo' do
- describe 'with a source address and index' do
- before do
- @data = Socket::AncillaryData.ip_pktinfo(Addrinfo.ip('127.0.0.1'), 4)
- end
-
- it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
- end
-
- it 'sets the family to AF_INET' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the level to IPPROTO_IP' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the type to IP_PKTINFO' do
- @data.type.should == Socket::IP_PKTINFO
- end
- end
-
- describe 'with a source address, index, and destination address' do
- before do
- source = Addrinfo.ip('127.0.0.1')
- dest = Addrinfo.ip('127.0.0.5')
- @data = Socket::AncillaryData.ip_pktinfo(source, 4, dest)
- end
-
- it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
- end
-
- it 'sets the family to AF_INET' do
- @data.family.should == Socket::AF_INET
- end
-
- it 'sets the level to IPPROTO_IP' do
- @data.level.should == Socket::IPPROTO_IP
- end
-
- it 'sets the type to IP_PKTINFO' do
- @data.type.should == Socket::IP_PKTINFO
- end
- end
- end
-
- describe 'Socket::AncillaryData#ip_pktinfo' do
- describe 'using an Addrinfo without a port number' do
- before do
- @source = Addrinfo.ip('127.0.0.1')
- @dest = Addrinfo.ip('127.0.0.5')
- @data = Socket::AncillaryData.ip_pktinfo(@source, 4, @dest)
- end
-
- it 'returns an Array' do
- @data.ip_pktinfo.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @info = @data.ip_pktinfo
- end
-
- it 'stores an Addrinfo at index 0' do
- @info[0].should be_an_instance_of(Addrinfo)
- end
-
- it 'stores the ifindex at index 1' do
- @info[1].should be_kind_of(Integer)
- end
-
- it 'stores an Addrinfo at index 2' do
- @info[2].should be_an_instance_of(Addrinfo)
- end
- end
-
- describe 'the source Addrinfo' do
- before do
- @addr = @data.ip_pktinfo[0]
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '127.0.0.1'
- end
-
- it 'is not the same object as the input Addrinfo' do
- @addr.should_not equal @source
- end
- end
-
- describe 'the ifindex' do
- it 'is an Integer' do
- @data.ip_pktinfo[1].should == 4
- end
- end
-
- describe 'the destination Addrinfo' do
- before do
- @addr = @data.ip_pktinfo[2]
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '127.0.0.5'
- end
-
- it 'is not the same object as the input Addrinfo' do
- @addr.should_not equal @dest
- end
- end
- end
-
- describe 'using an Addrinfo with a port number' do
- before do
- @source = Addrinfo.tcp('127.0.0.1', 80)
- @dest = Addrinfo.tcp('127.0.0.5', 85)
- @data = Socket::AncillaryData.ip_pktinfo(@source, 4, @dest)
- end
-
- describe 'the source Addrinfo' do
- before do
- @addr = @data.ip_pktinfo[0]
- end
-
- it 'does not contain a port number' do
- @addr.ip_port.should == 0
- end
- end
-
- describe 'the destination Addrinfo' do
- before do
- @addr = @data.ip_pktinfo[2]
- end
-
- it 'does not contain a port number' do
- @addr.ip_port.should == 0
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb
deleted file mode 100644
index f70fe27d6a..0000000000
--- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data, :ipv6_pktinfo do
- describe 'Socket::AncillaryData#ipv6_pktinfo_addr' do
- it 'returns an Addrinfo' do
- data = Socket::AncillaryData.ipv6_pktinfo(Addrinfo.ip('::1'), 4)
-
- data.ipv6_pktinfo_addr.should be_an_instance_of(Addrinfo)
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_ifindex_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_ifindex_spec.rb
deleted file mode 100644
index bda37eec98..0000000000
--- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_ifindex_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data, :ipv6_pktinfo do
- describe 'Socket::AncillaryData#ipv6_pktinfo_ifindex' do
- it 'returns an Addrinfo' do
- data = Socket::AncillaryData.ipv6_pktinfo(Addrinfo.ip('::1'), 4)
-
- data.ipv6_pktinfo_ifindex.should == 4
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
deleted file mode 100644
index 0fffc720dc..0000000000
--- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data, :ipv6_pktinfo do
- describe 'Socket::AncillaryData.ipv6_pktinfo' do
- before do
- @data = Socket::AncillaryData.ipv6_pktinfo(Addrinfo.ip('::1'), 4)
- end
-
- it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
- end
-
- it 'sets the family to AF_INET' do
- @data.family.should == Socket::AF_INET6
- end
-
- it 'sets the level to IPPROTO_IP' do
- @data.level.should == Socket::IPPROTO_IPV6
- end
-
- it 'sets the type to IP_PKTINFO' do
- @data.type.should == Socket::IPV6_PKTINFO
- end
- end
-
- describe 'Socket::AncillaryData#ipv6_pktinfo' do
- describe 'using an Addrinfo without a port number' do
- before do
- @source = Addrinfo.ip('::1')
- @data = Socket::AncillaryData.ipv6_pktinfo(@source, 4)
- end
-
- it 'returns an Array' do
- @data.ipv6_pktinfo.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @info = @data.ipv6_pktinfo
- end
-
- it 'stores an Addrinfo at index 0' do
- @info[0].should be_an_instance_of(Addrinfo)
- end
-
- it 'stores the ifindex at index 1' do
- @info[1].should be_kind_of(Integer)
- end
- end
-
- describe 'the source Addrinfo' do
- before do
- @addr = @data.ipv6_pktinfo[0]
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '::1'
- end
-
- it 'is not the same object as the input Addrinfo' do
- @addr.should_not equal @source
- end
- end
-
- describe 'the ifindex' do
- it 'is an Integer' do
- @data.ipv6_pktinfo[1].should == 4
- end
- end
- end
-
- describe 'using an Addrinfo with a port number' do
- before do
- @source = Addrinfo.tcp('::1', 80)
- @data = Socket::AncillaryData.ipv6_pktinfo(@source, 4)
- end
-
- describe 'the source Addrinfo' do
- before do
- @addr = @data.ipv6_pktinfo[0]
- end
-
- it 'does not contain a port number' do
- @addr.ip_port.should == 0
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/level_spec.rb b/spec/ruby/library/socket/ancillarydata/level_spec.rb
deleted file mode 100644
index a2ff216f9d..0000000000
--- a/spec/ruby/library/socket/ancillarydata/level_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#level' do
- it 'returns the level as an Integer' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').level.should == Socket::SOL_SOCKET
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/type_spec.rb b/spec/ruby/library/socket/ancillarydata/type_spec.rb
deleted file mode 100644
index 972beeeca0..0000000000
--- a/spec/ruby/library/socket/ancillarydata/type_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData#type' do
- it 'returns the type as an Integer' do
- Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
- end
- end
-end
diff --git a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
deleted file mode 100644
index 65ffcb01af..0000000000
--- a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require_relative '../spec_helper'
-
-with_feature :ancillary_data do
- describe 'Socket::AncillaryData.unix_rights' do
- describe 'using a list of IO objects' do
- before do
- @data = Socket::AncillaryData.unix_rights(STDOUT, STDERR)
- end
-
- it 'sets the family to AF_UNIX' do
- @data.family.should == Socket::AF_UNIX
- end
-
- it 'sets the level to SOL_SOCKET' do
- @data.level.should == Socket::SOL_SOCKET
- end
-
- it 'sets the type to SCM_RIGHTS' do
- @data.type.should == Socket::SCM_RIGHTS
- end
-
- it 'sets the data to a String containing the file descriptors' do
- @data.data.unpack('I*').should == [STDOUT.fileno, STDERR.fileno]
- end
- end
-
- describe 'using non IO objects' do
- it 'raises TypeError' do
- -> { Socket::AncillaryData.unix_rights(10) }.should raise_error(TypeError)
- end
- end
- end
-
- describe 'Socket::AncillaryData#unix_rights' do
- it 'returns the data as an Array of IO objects' do
- data = Socket::AncillaryData.unix_rights(STDOUT, STDERR)
-
- data.unix_rights.should == [STDOUT, STDERR]
- end
-
- it 'returns nil when the data is not a list of file descriptors' do
- data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, '')
-
- data.unix_rights.should be_nil
- end
-
- it 'raises TypeError when the level is not SOL_SOCKET' do
- data = Socket::AncillaryData.new(:INET, :IP, :RECVTTL, '')
-
- -> { data.unix_rights }.should raise_error(TypeError)
- end
-
- platform_is_not :"solaris2.10", :aix do
- it 'raises TypeError when the type is not SCM_RIGHTS' do
- data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '')
-
- -> { data.unix_rights }.should raise_error(TypeError)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/close_read_spec.rb b/spec/ruby/library/socket/basicsocket/close_read_spec.rb
index f317b34955..c71e1acaf9 100644
--- a/spec/ruby/library/socket/basicsocket/close_read_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/close_read_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#close_read" do
before :each do
@@ -12,16 +12,16 @@ describe "Socket::BasicSocket#close_read" do
it "closes the reading end of the socket" do
@server.close_read
- -> { @server.read }.should raise_error(IOError)
+ lambda { @server.read }.should raise_error(IOError)
end
- it 'does not raise when called on a socket already closed for reading' do
+ it "it works on sockets with closed ends" do
@server.close_read
- @server.close_read
- -> { @server.read }.should raise_error(IOError)
+ lambda { @server.close_read }.should_not raise_error(Exception)
+ lambda { @server.read }.should raise_error(IOError)
end
- it 'does not fully close the socket' do
+ it "does not close the socket" do
@server.close_read
@server.closed?.should be_false
end
@@ -32,9 +32,9 @@ describe "Socket::BasicSocket#close_read" do
@server.closed?.should be_true
end
- it 'raises IOError when called on a fully closed socket' do
+ it "raises IOError on closed socket" do
@server.close
- -> { @server.close_read }.should raise_error(IOError)
+ lambda { @server.close_read }.should raise_error(IOError)
end
it "returns nil" do
diff --git a/spec/ruby/library/socket/basicsocket/close_write_spec.rb b/spec/ruby/library/socket/basicsocket/close_write_spec.rb
index 232cfbb7c6..a00f5d5870 100644
--- a/spec/ruby/library/socket/basicsocket/close_write_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/close_write_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#close_write" do
before :each do
@@ -12,16 +12,16 @@ describe "Socket::BasicSocket#close_write" do
it "closes the writing end of the socket" do
@server.close_write
- -> { @server.write("foo") }.should raise_error(IOError)
+ lambda { @server.write("foo") }.should raise_error(IOError)
end
- it 'does not raise when called on a socket already closed for writing' do
+ it "works on sockets with closed write ends" do
@server.close_write
- @server.close_write
- -> { @server.write("foo") }.should raise_error(IOError)
+ lambda { @server.close_write }.should_not raise_error(Exception)
+ lambda { @server.write("foo") }.should raise_error(IOError)
end
- it 'does not fully close the socket' do
+ it "does not close the socket" do
@server.close_write
@server.closed?.should be_false
end
@@ -37,9 +37,9 @@ describe "Socket::BasicSocket#close_write" do
@server.closed?.should be_true
end
- it 'raises IOError when called on a fully closed socket' do
+ it "raises IOError on closed socket" do
@server.close
- -> { @server.close_write }.should raise_error(IOError)
+ lambda { @server.close_write }.should raise_error(IOError)
end
it "returns nil" do
diff --git a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb
deleted file mode 100644
index 1a1c9982d9..0000000000
--- a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#connect_address' do
- describe 'using an unbound socket' do
- after do
- @sock.close
- end
-
- it 'raises SocketError' do
- @sock = Socket.new(:INET, :STREAM)
-
- -> { @sock.connect_address }.should raise_error(SocketError)
- end
- end
-
- describe 'using a socket bound to 0.0.0.0' do
- before do
- @sock = Socket.new(:INET, :STREAM)
- @sock.bind(Socket.sockaddr_in(0, '0.0.0.0'))
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.connect_address.should be_an_instance_of(Addrinfo)
- end
-
- it 'uses 127.0.0.1 as the IP address' do
- @sock.connect_address.ip_address.should == '127.0.0.1'
- end
-
- it 'uses the correct port number' do
- @sock.connect_address.ip_port.should > 0
- end
-
- it 'uses AF_INET as the address family' do
- @sock.connect_address.afamily.should == Socket::AF_INET
- end
-
- it 'uses PF_INET as the address family' do
- @sock.connect_address.pfamily.should == Socket::PF_INET
- 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
-
- guard -> { SocketSpecs.ipv6_available? } do
- describe 'using a socket bound to ::' do
- before do
- @sock = Socket.new(:INET6, :STREAM)
- @sock.bind(Socket.sockaddr_in(0, '::'))
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.connect_address.should be_an_instance_of(Addrinfo)
- end
-
- it 'uses ::1 as the IP address' do
- @sock.connect_address.ip_address.should == '::1'
- end
-
- it 'uses the correct port number' do
- @sock.connect_address.ip_port.should > 0
- end
-
- it 'uses AF_INET6 as the address family' do
- @sock.connect_address.afamily.should == Socket::AF_INET6
- end
-
- it 'uses PF_INET6 as the address family' do
- @sock.connect_address.pfamily.should == Socket::PF_INET6
- 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
-
- 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
- before do
- @path = SocketSpecs.socket_path
- @sock = UNIXServer.new(@path)
- end
-
- after do
- @sock.close
- rm_r(@path)
- end
-
- it 'returns an Addrinfo' do
- @sock.connect_address.should be_an_instance_of(Addrinfo)
- end
-
- it 'uses the correct socket path' do
- @sock.connect_address.unix_path.should == @path
- 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
-end
diff --git a/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb b/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb
index a8800a8493..3ef3a686e2 100644
--- a/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "BasicSocket.do_not_reverse_lookup" do
before :each do
@@ -37,67 +37,3 @@ describe "BasicSocket.do_not_reverse_lookup" do
@socket.peeraddr[2].should == "127.0.0.1"
end
end
-
-describe :socket_do_not_reverse_lookup, shared: true do
- it "inherits from BasicSocket.do_not_reverse_lookup when the socket is created" do
- @socket = @method.call
- reverse = BasicSocket.do_not_reverse_lookup
- @socket.do_not_reverse_lookup.should == reverse
-
- BasicSocket.do_not_reverse_lookup = !reverse
- @socket.do_not_reverse_lookup.should == reverse
- end
-
- it "is true when BasicSocket.do_not_reverse_lookup is true" do
- BasicSocket.do_not_reverse_lookup = true
- @socket = @method.call
- @socket.do_not_reverse_lookup.should == true
- end
-
- it "is false when BasicSocket.do_not_reverse_lookup is false" do
- BasicSocket.do_not_reverse_lookup = false
- @socket = @method.call
- @socket.do_not_reverse_lookup.should == false
- end
-
- it "can be changed with #do_not_reverse_lookup=" do
- @socket = @method.call
- reverse = @socket.do_not_reverse_lookup
- @socket.do_not_reverse_lookup = !reverse
- @socket.do_not_reverse_lookup.should == !reverse
- end
-end
-
-describe "BasicSocket#do_not_reverse_lookup" do
- before :each do
- @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
- @server = TCPServer.new('127.0.0.1', 0)
- @port = @server.addr[1]
- end
-
- after :each do
- @server.close unless @server.closed?
- @socket.close if @socket && !@socket.closed?
- BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
- end
-
- describe "for an TCPSocket.new socket" do
- it_behaves_like :socket_do_not_reverse_lookup, -> {
- TCPSocket.new('127.0.0.1', @port)
- }
- end
-
- describe "for an TCPServer#accept socket" do
- before :each do
- @client = TCPSocket.new('127.0.0.1', @port)
- end
-
- after :each do
- @client.close if @client && !@client.closed?
- end
-
- it_behaves_like :socket_do_not_reverse_lookup, -> {
- @server.accept
- }
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/for_fd_spec.rb b/spec/ruby/library/socket/basicsocket/for_fd_spec.rb
index 9c9e6a8b55..164e4dc93c 100644
--- a/spec/ruby/library/socket/basicsocket/for_fd_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/for_fd_spec.rb
@@ -1,14 +1,14 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-describe "BasicSocket.for_fd" do
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+describe "BasicSocket#for_fd" do
before :each do
@server = TCPServer.new(0)
@s2 = nil
end
after :each do
- @socket1.close if @socket1
@server.close if @server
end
@@ -18,21 +18,4 @@ describe "BasicSocket.for_fd" do
@s2.should be_kind_of(TCPServer)
@s2.fileno.should == @server.fileno
end
-
- it 'returns a new socket for a file descriptor' do
- @socket1 = Socket.new(:INET, :DGRAM)
- socket2 = Socket.for_fd(@socket1.fileno)
- socket2.autoclose = false
-
- socket2.should be_an_instance_of(Socket)
- socket2.fileno.should == @socket1.fileno
- end
-
- it 'sets the socket into binary mode' do
- @socket1 = Socket.new(:INET, :DGRAM)
- socket2 = Socket.for_fd(@socket1.fileno)
- socket2.autoclose = false
-
- socket2.binmode?.should be_true
- end
end
diff --git a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb
deleted file mode 100644
index 6179211d96..0000000000
--- a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'BasicSocket#getpeereid' do
- with_feature :unix_socket do
- describe 'using a UNIXSocket' 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 'returns an Array with the user and group ID' do
- @client.getpeereid.should == [Process.euid, Process.egid]
- end
- end
- end
-
- describe 'using an IPSocket' do
- after do
- @sock.close
- end
-
- it 'raises NoMethodError' do
- @sock = TCPServer.new('127.0.0.1', 0)
- -> { @sock.getpeereid }.should raise_error(NoMethodError)
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/getpeername_spec.rb b/spec/ruby/library/socket/basicsocket/getpeername_spec.rb
index 0b93f02eef..cecf590092 100644
--- a/spec/ruby/library/socket/basicsocket/getpeername_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/getpeername_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#getpeername" do
@@ -19,7 +19,8 @@ describe "Socket::BasicSocket#getpeername" do
@client.getpeername.should == server_sockaddr
end
- it 'raises Errno::ENOTCONN for a disconnected socket' do
- -> { @server.getpeername }.should raise_error(Errno::ENOTCONN)
+ # Catch general exceptions to prevent NotImplementedError
+ it "raises an error if socket's not connected" do
+ lambda { @server.getpeername }.should raise_error(Exception)
end
end
diff --git a/spec/ruby/library/socket/basicsocket/getsockname_spec.rb b/spec/ruby/library/socket/basicsocket/getsockname_spec.rb
index b33db088b6..cb3a45eb5f 100644
--- a/spec/ruby/library/socket/basicsocket/getsockname_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/getsockname_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#getsockname" do
after :each do
@@ -7,7 +7,7 @@ describe "Socket::BasicSocket#getsockname" do
@socket.close
end
- it "returns the sockaddr associated with the socket" do
+ it "returns the sockaddr associacted with the socket" do
@socket = TCPServer.new("127.0.0.1", 0)
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
sockaddr.should == [@socket.addr[1], "127.0.0.1"]
@@ -20,7 +20,7 @@ describe "Socket::BasicSocket#getsockname" do
sockaddr[0].should == @socket.addr[1]
end
- it 'returns a default socket address for a disconnected socket' do
+ it "returns empty sockaddr for unbinded sockets" do
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
sockaddr.should == [0, "0.0.0.0"]
diff --git a/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb
index ce65d6c92b..dc4fffa5c1 100644
--- a/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "BasicSocket#getsockopt" do
before :each do
@@ -41,148 +41,6 @@ describe "BasicSocket#getsockopt" do
end
it "raises a SystemCallError with an invalid socket option" do
- -> { @sock.getsockopt Socket::SOL_SOCKET, -1 }.should raise_error(Errno::ENOPROTOOPT)
- end
-
- it 'returns a Socket::Option using a constant' do
- opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE)
-
- opt.should be_an_instance_of(Socket::Option)
- end
-
- it 'returns a Socket::Option for a boolean option' do
- opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR)
-
- opt.bool.should == false
- end
-
- it 'returns a Socket::Option for a numeric option' do
- opt = @sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL)
-
- opt.int.should be_kind_of(Integer)
- end
-
- it 'returns a Socket::Option for a struct option' do
- opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER)
-
- opt.linger.should == [false, 0]
- end
-
- it 'raises Errno::ENOPROTOOPT when requesting an invalid option' do
- -> { @sock.getsockopt(Socket::SOL_SOCKET, -1) }.should raise_error(Errno::ENOPROTOOPT)
- end
-
- describe 'using Symbols as arguments' do
- it 'returns a Socket::Option for arguments :SOCKET and :TYPE' do
- opt = @sock.getsockopt(:SOCKET, :TYPE)
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_TYPE
- end
-
- it 'returns a Socket::Option for arguments :IP and :TTL' do
- opt = @sock.getsockopt(:IP, :TTL)
-
- opt.level.should == Socket::IPPROTO_IP
- opt.optname.should == Socket::IP_TTL
- end
-
- it 'returns a Socket::Option for arguments :SOCKET and :REUSEADDR' do
- opt = @sock.getsockopt(:SOCKET, :REUSEADDR)
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_REUSEADDR
- end
-
- it 'returns a Socket::Option for arguments :SOCKET and :LINGER' do
- opt = @sock.getsockopt(:SOCKET, :LINGER)
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_LINGER
- end
-
- with_feature :udp_cork do
- it 'returns a Socket::Option for arguments :UDP and :CORK' do
- sock = Socket.new(:INET, :DGRAM)
- begin
- opt = sock.getsockopt(:UDP, :CORK)
-
- opt.level.should == Socket::IPPROTO_UDP
- opt.optname.should == Socket::UDP_CORK
- ensure
- sock.close
- end
- end
- end
- end
-
- describe 'using Strings as arguments' do
- it 'returns a Socket::Option for arguments "SOCKET" and "TYPE"' do
- opt = @sock.getsockopt("SOCKET", "TYPE")
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_TYPE
- end
-
- it 'returns a Socket::Option for arguments "IP" and "TTL"' do
- opt = @sock.getsockopt("IP", "TTL")
-
- opt.level.should == Socket::IPPROTO_IP
- opt.optname.should == Socket::IP_TTL
- end
-
- it 'returns a Socket::Option for arguments "SOCKET" and "REUSEADDR"' do
- opt = @sock.getsockopt("SOCKET", "REUSEADDR")
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_REUSEADDR
- end
-
- it 'returns a Socket::Option for arguments "SOCKET" and "LINGER"' do
- opt = @sock.getsockopt("SOCKET", "LINGER")
-
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_LINGER
- end
-
- with_feature :udp_cork do
- it 'returns a Socket::Option for arguments "UDP" and "CORK"' do
- sock = Socket.new("INET", "DGRAM")
- begin
- opt = sock.getsockopt("UDP", "CORK")
-
- opt.level.should == Socket::IPPROTO_UDP
- opt.optname.should == Socket::UDP_CORK
- ensure
- sock.close
- end
- end
- end
- end
-
- describe 'using a String based option' do
- it 'allows unpacking of a boolean option' do
- opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR).to_s
-
- opt.unpack('i').should == [0]
- end
-
- it 'allows unpacking of a numeric option' do
- opt = @sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL).to_s
- array = opt.unpack('i')
-
- array[0].should be_kind_of(Integer)
- array[0].should > 0
- end
-
- it 'allows unpacking of a struct option' do
- opt = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER).to_s
-
- if opt.bytesize == 8
- opt.unpack('ii').should == [0, 0]
- else
- opt.unpack('i').should == [0]
- end
- end
+ lambda { @sock.getsockopt Socket::SOL_SOCKET, -1 }.should raise_error(Errno::ENOPROTOOPT)
end
end
diff --git a/spec/ruby/library/socket/basicsocket/ioctl_spec.rb b/spec/ruby/library/socket/basicsocket/ioctl_spec.rb
index 615d92bea8..9a7f535317 100644
--- a/spec/ruby/library/socket/basicsocket/ioctl_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/ioctl_spec.rb
@@ -1,4 +1,5 @@
-require_relative '../spec_helper'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'socket'
describe "Socket::BasicSocket#ioctl" do
platform_is :linux do
diff --git a/spec/ruby/library/socket/basicsocket/local_address_spec.rb b/spec/ruby/library/socket/basicsocket/local_address_spec.rb
deleted file mode 100644
index 0bd60a44cd..0000000000
--- a/spec/ruby/library/socket/basicsocket/local_address_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../shared/address'
-
-describe 'BasicSocket#local_address' do
- it_behaves_like :socket_local_remote_address, :local_address, -> socket {
- a2 = BasicSocket.for_fd(socket.fileno)
- a2.autoclose = false
- a2.local_address
- }
-end
diff --git a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb
deleted file mode 100644
index ea5e65da5c..0000000000
--- a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe "BasicSocket#read_nonblock" do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before :each do
- @r = Socket.new(family, :DGRAM)
- @w = Socket.new(family, :DGRAM)
-
- @r.bind(Socket.pack_sockaddr_in(0, ip_address))
- @w.send("aaa", 0, @r.getsockname)
- end
-
- after :each do
- @r.close unless @r.closed?
- @w.close unless @w.closed?
- end
-
- it "receives data after it's ready" do
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(5).should == "aaa"
- end
-
- platform_is_not :windows do
- it 'returned data is binary encoded regardless of the external encoding' do
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(1).encoding.should == Encoding::BINARY
-
- @w.send("bbb", 0, @r.getsockname)
- @r.set_encoding(Encoding::ISO_8859_1)
- IO.select([@r], nil, nil, 2)
- buffer = @r.read_nonblock(3)
- buffer.should == "bbb"
- buffer.encoding.should == Encoding::BINARY
- end
- end
-
- it 'replaces the content of the provided buffer without changing its encoding' do
- buffer = "initial data".dup.force_encoding(Encoding::UTF_8)
-
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(3, buffer)
- buffer.should == "aaa"
- buffer.encoding.should == Encoding::UTF_8
-
- @w.send("bbb", 0, @r.getsockname)
- @r.set_encoding(Encoding::ISO_8859_1)
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(3, buffer)
- buffer.should == "bbb"
- buffer.encoding.should == Encoding::UTF_8
- end
-
- platform_is :linux do
- it 'does not set the IO in nonblock mode' do
- require 'io/nonblock'
- @r.nonblock = false
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(3).should == "aaa"
- @r.should_not.nonblock?
- end
- end
-
- platform_is_not :linux, :windows do
- it 'sets the IO in nonblock mode' do
- require 'io/nonblock'
- @r.nonblock = false
- IO.select([@r], nil, nil, 2)
- @r.read_nonblock(3).should == "aaa"
- @r.should.nonblock?
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/read_spec.rb b/spec/ruby/library/socket/basicsocket/read_spec.rb
deleted file mode 100644
index ba9de7d5cf..0000000000
--- a/spec/ruby/library/socket/basicsocket/read_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe "BasicSocket#read" do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before :each do
- @r = Socket.new(family, :DGRAM)
- @w = Socket.new(family, :DGRAM)
-
- @r.bind(Socket.pack_sockaddr_in(0, ip_address))
- @w.send("aaa", 0, @r.getsockname)
- end
-
- after :each do
- @r.close unless @r.closed?
- @w.close unless @w.closed?
- end
-
- it "receives data after it's ready" do
- @r.read(3).should == "aaa"
- end
-
- it 'returned data is binary encoded regardless of the external encoding' do
- @r.read(3).encoding.should == Encoding::BINARY
-
- @w.send("bbb", 0, @r.getsockname)
- @r.set_encoding(Encoding::UTF_8)
- buffer = @r.read(3)
- buffer.should == "bbb"
- buffer.encoding.should == Encoding::BINARY
- end
-
- it 'replaces the content of the provided buffer without changing its encoding' do
- buffer = "initial data".dup.force_encoding(Encoding::UTF_8)
-
- @r.read(3, buffer)
- buffer.should == "aaa"
- buffer.encoding.should == Encoding::UTF_8
-
- @w.send("bbb", 0, @r.getsockname)
- @r.set_encoding(Encoding::ISO_8859_1)
- @r.read(3, buffer)
- buffer.should == "bbb"
- buffer.encoding.should == Encoding::UTF_8
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb
index df42c116fb..2c948eaa2f 100644
--- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb
@@ -1,101 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../shared/recv_nonblock', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::BasicSocket#recv_nonblock" do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before :each do
- @s1 = Socket.new(family, :DGRAM)
- @s2 = Socket.new(family, :DGRAM)
- end
-
- after :each do
- @s1.close unless @s1.closed?
- @s2.close unless @s2.closed?
- end
-
- platform_is_not :windows do
- describe 'using an unbound socket' do
- it 'raises an exception extending IO::WaitReadable' do
- -> { @s1.recv_nonblock(1) }.should raise_error(IO::WaitReadable)
- end
- end
- end
-
- it "raises an exception extending IO::WaitReadable if there's no data available" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- -> {
- @s1.recv_nonblock(5)
- }.should raise_error(IO::WaitReadable) { |e|
- platform_is_not :windows do
- e.should be_kind_of(Errno::EAGAIN)
- end
- platform_is :windows do
- e.should be_kind_of(Errno::EWOULDBLOCK)
- end
- }
- end
-
- it "returns :wait_readable with exception: false" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- @s1.recv_nonblock(5, exception: false).should == :wait_readable
- end
-
- it "receives data after it's ready" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- @s2.send("aaa", 0, @s1.getsockname)
- IO.select([@s1], nil, nil, 2)
- @s1.recv_nonblock(5).should == "aaa"
- end
-
- it "allows an output buffer as third argument" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- @s2.send("data", 0, @s1.getsockname)
- IO.select([@s1], nil, nil, 2)
-
- buffer = +"foo"
- @s1.recv_nonblock(5, 0, buffer).should.equal?(buffer)
- buffer.should == "data"
- end
-
- it "preserves the encoding of the given buffer" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- @s2.send("data", 0, @s1.getsockname)
- IO.select([@s1], nil, nil, 2)
-
- buffer = ''.encode(Encoding::ISO_8859_1)
- @s1.recv_nonblock(5, 0, buffer)
- buffer.encoding.should == Encoding::ISO_8859_1
- end
-
- it "does not block if there's no data available" do
- @s1.bind(Socket.pack_sockaddr_in(0, ip_address))
- @s2.send("a", 0, @s1.getsockname)
- IO.select([@s1], nil, nil, 2)
- @s1.recv_nonblock(1).should == "a"
- -> {
- @s1.recv_nonblock(5)
- }.should raise_error(IO::WaitReadable)
- end
- end
-
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a connected but not bound socket' do
- before do
- @server = Socket.new(family, :STREAM)
- end
-
- after do
- @server.close
- end
-
- it "raises Errno::ENOTCONN" do
- -> { @server.recv_nonblock(1) }.should raise_error { |e|
- [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class)
- }
- -> { @server.recv_nonblock(1, exception: false) }.should raise_error { |e|
- [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class)
- }
- end
- end
- end
+ it_behaves_like :socket_recv_nonblock, :recv_nonblock
end
diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb
index e82a357d3d..5891bf9c87 100644
--- a/spec/ruby/library/socket/basicsocket/recv_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: binary -*-
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "BasicSocket#recv" do
@@ -32,25 +32,6 @@ describe "BasicSocket#recv" do
ScratchPad.recorded.should == 'hello'
end
- ruby_version_is "3.3" do
- it "returns nil on a closed stream socket" do
- t = Thread.new do
- client = @server.accept
- packet = client.recv(10)
- client.close
- packet
- end
-
- Thread.pass while t.status and t.status != "sleep"
- t.status.should_not be_nil
-
- socket = TCPSocket.new('127.0.0.1', @port)
- socket.close
-
- t.value.should be_nil
- end
- end
-
platform_is_not :solaris do
it "accepts flags to specify unusual receiving behaviour" do
t = Thread.new do
@@ -95,100 +76,21 @@ describe "BasicSocket#recv" do
ScratchPad.recorded.should == "firstline\377"
end
- it "allows an output buffer as third argument" do
- socket = TCPSocket.new('127.0.0.1', @port)
- socket.write("data")
-
- client = @server.accept
- buffer = +"foo"
- begin
- client.recv(4, 0, buffer).should.equal?(buffer)
- ensure
- client.close
- end
- buffer.should == "data"
-
- socket.close
- end
-
- it "preserves the encoding of the given buffer" do
- socket = TCPSocket.new('127.0.0.1', @port)
- socket.write("data")
-
- client = @server.accept
- buffer = ''.encode(Encoding::ISO_8859_1)
- begin
- client.recv(4, 0, buffer)
- ensure
- client.close
- end
- buffer.encoding.should == Encoding::ISO_8859_1
-
- socket.close
- end
-end
-
-describe 'BasicSocket#recv' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :DGRAM)
- @client = Socket.new(family, :DGRAM)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'using an unbound socket' do
- it 'blocks the caller' do
- -> { @server.recv(4) }.should block_caller
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
+ ruby_version_is "2.3" do
+ it "allows an output buffer as third argument" do
+ socket = TCPSocket.new('127.0.0.1', @port)
+ socket.write("data")
- describe 'without any data available' do
- it 'blocks the caller' do
- -> { @server.recv(4) }.should block_caller
- end
+ client = @server.accept
+ buf = "foo"
+ begin
+ client.recv(4, 0, buf)
+ ensure
+ client.close
end
+ buf.should == "data"
- describe 'with data available' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'reads the given amount of bytes' do
- @client.write('hello')
-
- @server.recv(2).should == 'he'
- end
-
- it 'reads the given amount of bytes when it exceeds the data size' do
- @client.write('he')
-
- @server.recv(6).should == 'he'
- end
-
- it 'blocks the caller when called twice without new data being available' do
- @client.write('hello')
-
- @server.recv(2).should == 'he'
-
- -> { @server.recv(4) }.should block_caller
- end
-
- it 'takes a peek at the data when using the MSG_PEEK flag' do
- @client.write('hello')
-
- @server.recv(2, Socket::MSG_PEEK).should == 'he'
- @server.recv(2).should == 'he'
- end
- end
+ socket.close
end
end
end
diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb
deleted file mode 100644
index cc4275c417..0000000000
--- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb
+++ /dev/null
@@ -1,224 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'BasicSocket#recvmsg_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a disconnected socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- describe 'using an unbound socket' do
- it 'raises an exception extending IO::WaitReadable' do
- -> { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable)
- end
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- describe 'without any data available' do
- it 'raises an exception extending IO::WaitReadable' do
- -> { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable)
- end
-
- it 'returns :wait_readable with exception: false' do
- @server.recvmsg_nonblock(exception: false).should == :wait_readable
- end
- end
-
- describe 'with data available' do
- before do
- @client.connect(@server.getsockname)
-
- @client.write('hello')
-
- IO.select([@server], nil, nil, 5)
- end
-
- it 'returns an Array containing the data, an Addrinfo and the flags' do
- @server.recvmsg_nonblock.should be_an_instance_of(Array)
- end
-
- describe 'without a maximum message length' do
- it 'reads all the available data' do
- @server.recvmsg_nonblock[0].should == 'hello'
- end
- end
-
- describe 'with a maximum message length' do
- platform_is_not :windows do
- it 'reads up to the maximum amount of bytes' do
- @server.recvmsg_nonblock(2)[0].should == 'he'
- end
- end
- end
-
- describe 'the returned Array' do
- before do
- @array = @server.recvmsg_nonblock
- end
-
- it 'stores the message at index 0' do
- @array[0].should == 'hello'
- end
-
- it 'stores an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
-
- platform_is_not :windows do
- it 'stores the flags at index 2' do
- @array[2].should be_kind_of(Integer)
- end
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @array[1]
- end
-
- it 'uses the IP address of the client' do
- @addr.ip_address.should == @client.local_address.ip_address
- end
-
- it 'uses the correct address family' do
- @addr.afamily.should == family
- end
-
- it 'uses the correct protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses the correct socket type' do
- @addr.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses the port number of the client' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
- end
- end
-
- platform_is_not :windows do
- describe 'using a connected but not bound socket' do
- before do
- @server = Socket.new(family, :STREAM)
- end
-
- after do
- @server.close
- end
-
- it "raises Errno::ENOTCONN" do
- -> { @server.recvmsg_nonblock }.should raise_error(Errno::ENOTCONN)
- -> { @server.recvmsg_nonblock(exception: false) }.should raise_error(Errno::ENOTCONN)
- end
- end
-
- describe 'using a connected socket' do
- before do
- @client = Socket.new(family, :STREAM)
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without any data available' do
- it 'raises IO::WaitReadable' do
- -> {
- socket, _ = @server.accept
- begin
- socket.recvmsg_nonblock
- ensure
- socket.close
- end
- }.should raise_error(IO::WaitReadable)
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
-
- @socket, _ = @server.accept
- IO.select([@socket])
- end
-
- after do
- @socket.close
- end
-
- it 'returns an Array containing the data, an Addrinfo and the flags' do
- @socket.recvmsg_nonblock.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = @socket.recvmsg_nonblock
- end
-
- it 'stores the message at index 0' do
- @array[0].should == 'hello'
- end
-
- it 'stores an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
-
- it 'stores the flags at index 2' do
- @array[2].should be_kind_of(Integer)
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @array[1]
- end
-
- it 'raises when receiving the ip_address message' do
- -> { @addr.ip_address }.should raise_error(SocketError)
- end
-
- it 'uses the correct address family' do
- @addr.afamily.should == Socket::AF_UNSPEC
- end
-
- it 'uses 0 for the protocol family' do
- @addr.pfamily.should == 0
- end
-
- it 'uses the correct socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'raises when receiving the ip_port message' do
- -> { @addr.ip_port }.should raise_error(SocketError)
- end
- end
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb
deleted file mode 100644
index 8063723701..0000000000
--- a/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb
+++ /dev/null
@@ -1,197 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'BasicSocket#recvmsg' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a disconnected socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- describe 'using an unbound socket' do
- it 'blocks the caller' do
- -> { @server.recvmsg }.should block_caller
- end
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- describe 'without any data available' do
- it 'blocks the caller' do
- -> { @server.recvmsg }.should block_caller
- end
- end
-
- describe 'with data available' do
- before do
- @client.connect(@server.getsockname)
-
- @client.write('hello')
- end
-
- it 'returns an Array containing the data, an Addrinfo and the flags' do
- @server.recvmsg.should be_an_instance_of(Array)
- end
-
- describe 'without a maximum message length' do
- it 'reads all the available data' do
- @server.recvmsg[0].should == 'hello'
- end
- end
-
- describe 'with a maximum message length' do
- it 'reads up to the maximum amount of bytes' do
- @server.recvmsg(2)[0].should == 'he'
- end
- end
-
- describe 'the returned Array' do
- before do
- @array = @server.recvmsg
- end
-
- it 'stores the message at index 0' do
- @array[0].should == 'hello'
- end
-
- it 'stores an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
-
- platform_is_not :windows do
- it 'stores the flags at index 2' do
- @array[2].should be_kind_of(Integer)
- end
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @array[1]
- end
-
- it 'uses the IP address of the client' do
- @addr.ip_address.should == @client.local_address.ip_address
- end
-
- it 'uses the correct address family' do
- @addr.afamily.should == family
- end
-
- it 'uses the correct protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses the correct socket type' do
- @addr.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses the port number of the client' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
- end
- end
-
- platform_is_not :windows do
- describe 'using a connected socket' do
- before do
- @client = Socket.new(family, :STREAM)
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without any data available' do
- it 'blocks the caller' do
- socket, _ = @server.accept
- begin
- -> { socket.recvmsg }.should block_caller
- ensure
- socket.close
- end
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
- @socket, _ = @server.accept
- end
-
- after do
- @socket.close
- end
-
- it 'returns an Array containing the data, an Addrinfo and the flags' do
- @socket.recvmsg.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = @socket.recvmsg
- end
-
- it 'stores the message at index 0' do
- @array[0].should == 'hello'
- end
-
- it 'stores an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
-
- it 'stores the flags at index 2' do
- @array[2].should be_kind_of(Integer)
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @array[1]
- end
-
- it 'raises when receiving the ip_address message' do
- -> { @addr.ip_address }.should raise_error(SocketError)
- end
-
- it 'uses the correct address family' do
- @addr.afamily.should == Socket::AF_UNSPEC
- end
-
- it 'returns 0 for the protocol family' do
- @addr.pfamily.should == 0
- end
-
- it 'uses the correct socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'raises when receiving the ip_port message' do
- -> { @addr.ip_port }.should raise_error(SocketError)
- end
- end
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/remote_address_spec.rb b/spec/ruby/library/socket/basicsocket/remote_address_spec.rb
deleted file mode 100644
index 439bf31592..0000000000
--- a/spec/ruby/library/socket/basicsocket/remote_address_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../shared/address'
-
-describe 'BasicSocket#remote_address' do
- it_behaves_like :socket_local_remote_address, :remote_address, -> socket {
- a2 = BasicSocket.for_fd(socket.fileno)
- a2.autoclose = false
- a2.remote_address
- }
-end
diff --git a/spec/ruby/library/socket/basicsocket/send_spec.rb b/spec/ruby/library/socket/basicsocket/send_spec.rb
index 1c028480e3..4df0d04a10 100644
--- a/spec/ruby/library/socket/basicsocket/send_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/send_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "BasicSocket#send" do
before :each do
@@ -16,27 +16,27 @@ describe "BasicSocket#send" do
@socket.close
end
- it "sends a message to another socket and returns the number of bytes sent" do
- data = +""
- t = Thread.new do
- client = @server.accept
- loop do
- got = client.recv(5)
- break if got.nil? || got.empty?
- data << got
- end
- client.close
- end
- Thread.pass while t.status and t.status != "sleep"
- t.status.should_not be_nil
+ it "sends a message to another socket and returns the number of bytes sent" do
+ data = ""
+ t = Thread.new do
+ client = @server.accept
+ loop do
+ got = client.recv(5)
+ break if got.empty?
+ data << got
+ end
+ client.close
+ end
+ Thread.pass while t.status and t.status != "sleep"
+ t.status.should_not be_nil
- @socket.send('hello', 0).should == 5
- @socket.shutdown(1) # indicate, that we are done sending
- @socket.recv(10)
+ @socket.send('hello', 0).should == 5
+ @socket.shutdown(1) # indicate, that we are done sending
+ @socket.recv(10)
- t.join
- data.should == 'hello'
- end
+ t.join
+ data.should == 'hello'
+ end
platform_is_not :solaris, :windows do
it "accepts flags to specify unusual sending behaviour" do
@@ -62,12 +62,12 @@ describe "BasicSocket#send" do
end
it "accepts a sockaddr as recipient address" do
- data = +""
+ data = ""
t = Thread.new do
client = @server.accept
loop do
got = client.recv(5)
- break if got.nil? || got.empty?
+ break if got.empty?
data << got
end
client.close
@@ -83,138 +83,3 @@ describe "BasicSocket#send" do
data.should == 'hello'
end
end
-
-describe 'BasicSocket#send' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a disconnected socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'with an object implementing #to_str' do
- it 'returns the amount of sent bytes' do
- data = mock('message')
- data.should_receive(:to_str).and_return('hello')
- @client.send(data, 0, @server.getsockname).should == 5
- end
- end
-
- describe 'without a destination address' do
- it "raises #{SocketSpecs.dest_addr_req_error}" do
- -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
-
- describe 'with a destination address as a String' do
- it 'returns the amount of sent bytes' do
- @client.send('hello', 0, @server.getsockname).should == 5
- end
-
- it 'does not persist the connection after writing to the socket' do
- @client.send('hello', 0, @server.getsockname)
-
- -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
-
- describe 'with a destination address as an Addrinfo' do
- it 'returns the amount of sent bytes' do
- @client.send('hello', 0, @server.connect_address).should == 5
- end
- end
- end
-
- describe 'using a connected UDP socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without a destination address argument' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'returns the amount of bytes written' do
- @client.send('hello', 0).should == 5
- end
- end
-
- describe 'with a destination address argument' do
- before do
- @alt_server = Socket.new(family, :DGRAM)
-
- @alt_server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @alt_server.close
- end
-
- it 'sends the message to the given address instead' do
- @client.send('hello', 0, @alt_server.getsockname).should == 5
-
- -> { @server.recv(5) }.should block_caller
-
- @alt_server.recv(5).should == 'hello'
- end
-
- it 'does not persist the alternative connection after writing to the socket' do
- @client.send('hello', 0, @alt_server.getsockname)
-
- @client.connect(@server.getsockname)
- @client.send('world', 0)
-
- @server.recv(5).should == 'world'
- end
- end
- end
-
- platform_is_not :darwin, :windows do
- describe 'using a connected TCP socket' do
- before do
- @client = Socket.new(family, :STREAM)
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'using the MSG_OOB flag' do
- it 'sends an out-of-band message' do
- socket, _ = @server.accept
- socket.setsockopt(:SOCKET, :OOBINLINE, true)
- @client.send('a', Socket::MSG_OOB).should == 1
- begin
- socket.recv(10).should == 'a'
- ensure
- socket.close
- end
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb
deleted file mode 100644
index 7acfc659bd..0000000000
--- a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'BasicSocket#sendmsg_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a disconnected socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without a destination address' do
- it "raises #{SocketSpecs.dest_addr_req_error}" do
- -> {
- @client.sendmsg_nonblock('hello')
- }.should raise_error(SocketSpecs.dest_addr_req_error)
- -> {
- @client.sendmsg_nonblock('hello', exception: false)
- }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
-
- describe 'with a destination address as a String' do
- it 'returns the amount of sent bytes' do
- @client.sendmsg_nonblock('hello', 0, @server.getsockname).should == 5
- end
- end
-
- describe 'with a destination address as an Addrinfo' do
- it 'returns the amount of sent bytes' do
- @client.sendmsg_nonblock('hello', 0, @server.connect_address).should == 5
- end
- end
- end
-
- describe 'using a connected UDP socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without a destination address argument' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'returns the amount of bytes written' do
- @client.sendmsg_nonblock('hello').should == 5
- end
- end
-
- describe 'with a destination address argument' do
- before do
- @alt_server = Socket.new(family, :DGRAM)
- @alt_server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @alt_server.close
- end
-
- it 'sends the message to the given address instead' do
- @client.sendmsg_nonblock('hello', 0, @alt_server.getsockname).should == 5
- -> { @server.recv(5) }.should block_caller
- @alt_server.recv(5).should == 'hello'
- end
- end
- end
-
- platform_is_not :windows do
- describe 'using a connected TCP socket' do
- before do
- @client = Socket.new(family, :STREAM)
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'raises IO::WaitWritable when the underlying buffer is full' do
- -> {
- 10.times { @client.sendmsg_nonblock('hello' * 1_000_000) }
- }.should raise_error(IO::WaitWritable)
- end
-
- it 'returns :wait_writable when the underlying buffer is full with exception: false' do
- ret = nil
- 10.times {
- ret = @client.sendmsg_nonblock('hello' * 1_000_000, exception: false)
- break unless ret.is_a?(Integer)
- }
- ret.should == :wait_writable
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb
deleted file mode 100644
index 7ff336c0b7..0000000000
--- a/spec/ruby/library/socket/basicsocket/sendmsg_spec.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'BasicSocket#sendmsg' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a disconnected socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- describe 'without a destination address' do
- it "raises #{SocketSpecs.dest_addr_req_error}" do
- -> { @client.sendmsg('hello') }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
- end
-
- describe 'with a destination address as a String' do
- it 'returns the amount of sent bytes' do
- @client.sendmsg('hello', 0, @server.getsockname).should == 5
- end
- end
-
- describe 'with a destination address as an Addrinfo' do
- it 'returns the amount of sent bytes' do
- @client.sendmsg('hello', 0, @server.connect_address).should == 5
- end
- end
- end
-
- describe 'using a connected UDP socket' do
- before do
- @client = Socket.new(family, :DGRAM)
- @server = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without a destination address argument' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'returns the amount of bytes written' do
- @client.sendmsg('hello').should == 5
- end
- end
-
- describe 'with a destination address argument' do
- before do
- @alt_server = Socket.new(family, :DGRAM)
-
- @alt_server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @alt_server.close
- end
-
- it 'sends the message to the given address instead' do
- @client.sendmsg('hello', 0, @alt_server.getsockname).should == 5
-
- -> { @server.recv(5) }.should block_caller
-
- @alt_server.recv(5).should == 'hello'
- end
- end
- end
-
- platform_is_not :windows do # spurious
- describe 'using a connected TCP socket' do
- before do
- @client = Socket.new(family, :STREAM)
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'blocks when the underlying buffer is full' do
- # Buffer sizes may differ per platform, so sadly this is the only
- # reliable way of testing blocking behaviour.
- -> do
- 10.times { @client.sendmsg('hello' * 1_000_000) }
- end.should block_caller
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
index 1e8d84e1c9..523a22d957 100644
--- a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "BasicSocket#setsockopt" do
@@ -38,7 +38,7 @@ describe "BasicSocket#setsockopt" do
platform_is_not :windows do
it "raises EINVAL if passed wrong linger value" do
- -> do
+ lambda do
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, 0)
end.should raise_error(Errno::EINVAL)
end
@@ -70,7 +70,7 @@ describe "BasicSocket#setsockopt" do
n.should_not == [0].pack("i")
platform_is_not :windows do
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "")
}.should raise_error(SystemCallError)
end
@@ -80,7 +80,7 @@ describe "BasicSocket#setsockopt" do
n.should_not == [0].pack("i")
platform_is_not :windows do
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "0")
}.should raise_error(SystemCallError)
end
@@ -90,13 +90,13 @@ describe "BasicSocket#setsockopt" do
n.should == [0].pack("i")
platform_is_not :windows do
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "1")
}.should raise_error(SystemCallError)
end
platform_is_not :windows do
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, "\x00\x00\x00")
}.should raise_error(SystemCallError)
end
@@ -125,7 +125,7 @@ describe "BasicSocket#setsockopt" do
n = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).to_s
n.unpack('i')[0].should >= 1
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, nil).should == 0
}.should raise_error(TypeError)
@@ -137,23 +137,23 @@ describe "BasicSocket#setsockopt" do
n = @sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).to_s
n.unpack('i')[0].should >= 2
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "")
}.should raise_error(SystemCallError)
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "bla")
}.should raise_error(SystemCallError)
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "0")
}.should raise_error(SystemCallError)
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "1")
}.should raise_error(SystemCallError)
- -> {
+ lambda {
@sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, "\x00\x00\x00")
}.should raise_error(SystemCallError)
@@ -211,126 +211,3 @@ describe "BasicSocket#setsockopt" do
end
end
end
-
-describe 'BasicSocket#setsockopt' do
- describe 'using a STREAM socket' do
- before do
- @socket = Socket.new(:INET, :STREAM)
- end
-
- after do
- @socket.close
- end
-
- describe 'using separate arguments with Symbols' do
- it 'raises TypeError when the first argument is nil' do
- -> { @socket.setsockopt(nil, :REUSEADDR, true) }.should raise_error(TypeError)
- end
-
- it 'sets a boolean option' do
- @socket.setsockopt(:SOCKET, :REUSEADDR, true).should == 0
- @socket.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
-
- it 'sets an integer option' do
- @socket.setsockopt(:IP, :TTL, 255).should == 0
- @socket.getsockopt(:IP, :TTL).int.should == 255
- end
-
- guard -> { SocketSpecs.ipv6_available? } do
- it 'sets an IPv6 boolean option' do
- socket = Socket.new(:INET6, :STREAM)
- begin
- socket.setsockopt(:IPV6, :V6ONLY, true).should == 0
- socket.getsockopt(:IPV6, :V6ONLY).bool.should == true
- ensure
- socket.close
- end
- end
- end
-
- platform_is_not :windows do
- it 'raises Errno::EINVAL when setting an invalid option value' do
- -> { @socket.setsockopt(:SOCKET, :OOBINLINE, 'bla') }.should raise_error(Errno::EINVAL)
- end
- end
- end
-
- describe 'using separate arguments with Symbols' do
- it 'sets a boolean option' do
- @socket.setsockopt('SOCKET', 'REUSEADDR', true).should == 0
- @socket.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
-
- it 'sets an integer option' do
- @socket.setsockopt('IP', 'TTL', 255).should == 0
- @socket.getsockopt(:IP, :TTL).int.should == 255
- end
- end
-
- describe 'using separate arguments with constants' do
- it 'sets a boolean option' do
- @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true).should == 0
- @socket.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
-
- it 'sets an integer option' do
- @socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, 255).should == 0
- @socket.getsockopt(:IP, :TTL).int.should == 255
- end
- end
-
- describe 'using separate arguments with custom objects' do
- it 'sets a boolean option' do
- level = mock(:level)
- name = mock(:name)
-
- level.stub!(:to_str).and_return('SOCKET')
- name.stub!(:to_str).and_return('REUSEADDR')
-
- @socket.setsockopt(level, name, true).should == 0
- end
- end
-
- describe 'using a Socket::Option as the first argument' do
- it 'sets a boolean option' do
- @socket.setsockopt(Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true)).should == 0
- @socket.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
-
- it 'sets an integer option' do
- @socket.setsockopt(Socket::Option.int(:INET, :IP, :TTL, 255)).should == 0
- @socket.getsockopt(:IP, :TTL).int.should == 255
- end
-
- it 'raises ArgumentError when passing 2 arguments' do
- option = Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true)
- -> { @socket.setsockopt(option, :REUSEADDR) }.should raise_error(ArgumentError)
- end
-
- it 'raises TypeError when passing 3 arguments' do
- option = Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true)
- -> { @socket.setsockopt(option, :REUSEADDR, true) }.should raise_error(TypeError)
- end
- end
- end
-
- with_feature :unix_socket do
- 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
-
- it 'sets a boolean option' do
- @server.setsockopt(:SOCKET, :REUSEADDR, true)
- @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/basicsocket/shutdown_spec.rb b/spec/ruby/library/socket/basicsocket/shutdown_spec.rb
index c78b32de38..c874f08697 100644
--- a/spec/ruby/library/socket/basicsocket/shutdown_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/shutdown_spec.rb
@@ -1,155 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-platform_is_not :windows do # hangs
- describe "Socket::BasicSocket#shutdown" do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM)
- @client = Socket.new(family, :STREAM)
+describe "Socket::BasicSocket#shutdown" do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'using an Integer' do
- it 'shuts down a socket for reading' do
- @client.shutdown(Socket::SHUT_RD)
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for writing' do
- @client.shutdown(Socket::SHUT_WR)
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'shuts down a socket for reading and writing' do
- @client.shutdown(Socket::SHUT_RDWR)
-
- @client.recv(1).to_s.should be_empty
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'raises ArgumentError when using an invalid option' do
- -> { @server.shutdown(666) }.should raise_error(ArgumentError)
- end
- end
-
- describe 'using a Symbol' do
- it 'shuts down a socket for reading using :RD' do
- @client.shutdown(:RD)
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for reading using :SHUT_RD' do
- @client.shutdown(:SHUT_RD)
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for writing using :WR' do
- @client.shutdown(:WR)
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'shuts down a socket for writing using :SHUT_WR' do
- @client.shutdown(:SHUT_WR)
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'shuts down a socket for reading and writing' do
- @client.shutdown(:RDWR)
-
- @client.recv(1).to_s.should be_empty
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'raises ArgumentError when using an invalid option' do
- -> { @server.shutdown(:Nope) }.should raise_error(SocketError)
- end
- end
-
- describe 'using a String' do
- it 'shuts down a socket for reading using "RD"' do
- @client.shutdown('RD')
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for reading using "SHUT_RD"' do
- @client.shutdown('SHUT_RD')
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for writing using "WR"' do
- @client.shutdown('WR')
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'shuts down a socket for writing using "SHUT_WR"' do
- @client.shutdown('SHUT_WR')
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
-
- it 'raises ArgumentError when using an invalid option' do
- -> { @server.shutdown('Nope') }.should raise_error(SocketError)
- end
- end
-
- describe 'using an object that responds to #to_str' do
- before do
- @dummy = mock(:dummy)
- end
-
- it 'shuts down a socket for reading using "RD"' do
- @dummy.stub!(:to_str).and_return('RD')
-
- @client.shutdown(@dummy)
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for reading using "SHUT_RD"' do
- @dummy.stub!(:to_str).and_return('SHUT_RD')
-
- @client.shutdown(@dummy)
-
- @client.recv(1).to_s.should be_empty
- end
-
- it 'shuts down a socket for reading and writing' do
- @dummy.stub!(:to_str).and_return('RDWR')
-
- @client.shutdown(@dummy)
-
- @client.recv(1).to_s.should be_empty
-
- -> { @client.write('hello') }.should raise_error(Errno::EPIPE)
- end
- end
-
- describe 'using an object that does not respond to #to_str' do
- it 'raises TypeError' do
- -> { @server.shutdown(mock(:dummy)) }.should raise_error(TypeError)
- end
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb
deleted file mode 100644
index 523e732959..0000000000
--- a/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe "BasicSocket#write_nonblock" do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before :each do
- @r = Socket.new(family, :DGRAM)
- @w = Socket.new(family, :DGRAM)
-
- @r.bind(Socket.pack_sockaddr_in(0, ip_address))
- @w.connect(@r.getsockname)
- end
-
- after :each do
- @r.close unless @r.closed?
- @w.close unless @w.closed?
- end
-
- it "sends data" do
- @w.write_nonblock("aaa").should == 3
- IO.select([@r], nil, nil, 2)
- @r.recv_nonblock(5).should == "aaa"
- end
-
- platform_is :linux do
- it 'does not set the IO in nonblock mode' do
- require 'io/nonblock'
- @w.nonblock = false
- @w.write_nonblock("aaa").should == 3
- @w.should_not.nonblock?
- end
- end
-
- platform_is_not :linux, :windows do
- it 'sets the IO in nonblock mode' do
- require 'io/nonblock'
- @w.nonblock = false
- @w.write_nonblock("aaa").should == 3
- @w.should.nonblock?
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/constants/constants_spec.rb b/spec/ruby/library/socket/constants/constants_spec.rb
index 637bc6740a..9b8a0e55b3 100644
--- a/spec/ruby/library/socket/constants/constants_spec.rb
+++ b/spec/ruby/library/socket/constants/constants_spec.rb
@@ -1,5 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+include Socket::Constants
describe "Socket::Constants" do
it "defines socket types" do
@@ -68,7 +69,7 @@ describe "Socket::Constants" do
end
end
- platform_is_not :solaris, :windows, :aix, :android do
+ platform_is_not :solaris, :windows, :aix do
it "defines multicast options" do
consts = ["IP_MAX_MEMBERSHIPS"]
consts.each do |c|
@@ -86,23 +87,4 @@ describe "Socket::Constants" do
Socket::Constants.should have_constant(c)
end
end
-
- platform_is_not :windows do
- it 'defines SCM options' do
- Socket::Constants.should have_constant('SCM_RIGHTS')
- end
-
- it 'defines error options' do
- consts = ["EAI_ADDRFAMILY", "EAI_NODATA"]
-
- # FreeBSD (11.1, at least) obsoletes EAI_ADDRFAMILY and EAI_NODATA
- platform_is :freebsd do
- consts = %w(EAI_MEMORY)
- end
-
- consts.each do |c|
- Socket::Constants.should have_constant(c)
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/fixtures/classes.rb b/spec/ruby/library/socket/fixtures/classes.rb
index 786629d2ef..b8e5d2a38d 100644
--- a/spec/ruby/library/socket/fixtures/classes.rb
+++ b/spec/ruby/library/socket/fixtures/classes.rb
@@ -1,16 +1,16 @@
require 'socket'
module SocketSpecs
- # helper to get the hostname associated to 127.0.0.1 or the given ip
- def self.hostname(ip = "127.0.0.1")
+ # helper to get the hostname associated to 127.0.0.1
+ def self.hostname
# Calculate each time, without caching, since the result might
# depend on things like do_not_reverse_lookup mode, which is
# changing from test to test
- Socket.getaddrinfo(ip, nil)[0][2]
+ Socket.getaddrinfo("127.0.0.1", nil)[0][2]
end
- def self.hostname_reverse_lookup(ip = "127.0.0.1")
- Socket.getaddrinfo(ip, nil, 0, 0, 0, 0, true)[0][2]
+ def self.hostnamev6
+ Socket.getaddrinfo("::1", nil)[0][2]
end
def self.addr(which=:ipv4)
@@ -34,12 +34,10 @@ module SocketSpecs
def self.socket_path
path = tmp("unix.sock", false)
- # Check for too long unix socket path (max 104 bytes on macOS)
+ # Check for too long unix socket path (max 108 bytes including \0 => 107)
# Note that Linux accepts not null-terminated paths but the man page advises against it.
- if path.bytesize > 104
- # rm_r in spec/mspec/lib/mspec/helpers/fs.rb fails against
- # "/tmp/unix_server_spec.socket"
- skip "too long unix socket path: #{path}"
+ if path.bytesize > 107
+ path = "/tmp/unix_server_spec.socket"
end
rm_socket(path)
path
@@ -49,48 +47,6 @@ module SocketSpecs
File.delete(path) if File.exist?(path)
end
- def self.ipv6_available?
- @ipv6_available ||= begin
- server = TCPServer.new('::1', 0)
- rescue Errno::EAFNOSUPPORT, Errno::EADDRNOTAVAIL, SocketError
- :no
- else
- server.close
- :yes
- end
- @ipv6_available == :yes
- end
-
- def self.each_ip_protocol
- describe 'using IPv4' do
- yield Socket::AF_INET, '127.0.0.1', 'AF_INET'
- end
-
- guard -> { SocketSpecs.ipv6_available? } do
- describe 'using IPv6' do
- yield Socket::AF_INET6, '::1', 'AF_INET6'
- end
- end
- end
-
- def self.loop_with_timeout(timeout = TIME_TOLERANCE)
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
-
- while yield == :retry
- if Process.clock_gettime(Process::CLOCK_MONOTONIC) - start >= timeout
- raise RuntimeError, "Did not succeed within #{timeout} seconds"
- end
- end
- end
-
- def self.dest_addr_req_error
- error = Errno::EDESTADDRREQ
- platform_is :windows do
- error = Errno::ENOTCONN
- end
- error
- end
-
# TCPServer echo server accepting one connection
class SpecTCPServer
attr_reader :hostname, :port
@@ -113,7 +69,7 @@ module SocketSpecs
begin
data = socket.recv(1024)
- return if data.nil? || data.empty?
+ return if data.empty?
log "SpecTCPServer received: #{data.inspect}"
return if data == "QUIT"
@@ -134,33 +90,4 @@ module SocketSpecs
@logger.puts message if @logger
end
end
-
- # We need to find a free port for Socket.tcp_server_loop and Socket.udp_server_loop,
- # and the only reliable way to do that is to pass 0 as the port, but then we need to
- # find out which one was chosen and the API doesn't let us find what it is. So we
- # intercept one of the public API methods called by these methods.
- class ServerLoopPortFinder < Socket
- def self.tcp_server_sockets(*args)
- super(*args) { |sockets|
- @port = sockets.first.local_address.ip_port
- yield(sockets)
- }
- end
-
- def self.udp_server_sockets(*args, &block)
- super(*args) { |sockets|
- @port = sockets.first.local_address.ip_port
- yield(sockets)
- }
- end
-
- def self.cleanup
- @port = nil
- end
-
- def self.port
- sleep 0.001 until @port
- @port
- end
- end
end
diff --git a/spec/ruby/library/socket/ipsocket/addr_spec.rb b/spec/ruby/library/socket/ipsocket/addr_spec.rb
index 199eb85ab7..2184082c51 100644
--- a/spec/ruby/library/socket/ipsocket/addr_spec.rb
+++ b/spec/ruby/library/socket/ipsocket/addr_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#addr" do
before :each do
@@ -40,66 +40,3 @@ describe "Socket::IPSocket#addr" do
addrinfo[3].should == "127.0.0.1"
end
end
-
-describe 'Socket::IPSocket#addr' do
- SocketSpecs.each_ip_protocol do |family, ip_address, family_name|
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- end
-
- after do
- @server.close
- end
-
- describe 'without reverse lookups' do
- before do
- @hostname = Socket.getaddrinfo(ip_address, nil)[0][2]
- end
-
- it 'returns an Array containing address information' do
- @server.addr.should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'with reverse lookups' do
- before do
- @hostname = Socket.getaddrinfo(ip_address, nil, nil, 0, 0, 0, true)[0][2]
- end
-
- describe 'using true as the argument' do
- it 'returns an Array containing address information' do
- @server.addr(true).should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'using :hostname as the argument' do
- it 'returns an Array containing address information' do
- @server.addr(:hostname).should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'using :cats as the argument' do
- it 'raises ArgumentError' do
- -> { @server.addr(:cats) }.should raise_error(ArgumentError)
- end
- end
- end
-
- describe 'with do_not_reverse_lookup disabled on socket level' do
- before do
- @server.do_not_reverse_lookup = false
-
- @hostname = Socket.getaddrinfo(ip_address, nil, nil, 0, 0, 0, true)[0][2]
- end
-
- after do
- @server.do_not_reverse_lookup = true
- end
-
- it 'returns an Array containing address information' do
- @server.addr.should == [family_name, @port, @hostname, ip_address]
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb
index 329f8267d3..c574c7d267 100644
--- a/spec/ruby/library/socket/ipsocket/getaddress_spec.rb
+++ b/spec/ruby/library/socket/ipsocket/getaddress_spec.rb
@@ -1,7 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#getaddress" do
+
it "returns the IP address of hostname" do
addr_local = IPSocket.getaddress(SocketSpecs.hostname)
["127.0.0.1", "::1"].include?(addr_local).should == true
@@ -10,19 +11,17 @@ describe "Socket::IPSocket#getaddress" do
it "returns the IP address when passed an IP" do
IPSocket.getaddress("127.0.0.1").should == "127.0.0.1"
IPSocket.getaddress("0.0.0.0").should == "0.0.0.0"
- IPSocket.getaddress('::1').should == '::1'
- end
-
- it 'returns IPv4 compatible IPv6 addresses' do
- IPSocket.getaddress('::ffff:192.168.1.1').should == '::ffff:192.168.1.1'
end
# There is no way to make this fail-proof on all machines, because
# DNS servers like opendns return A records for ANY host, including
# traditionally invalidly named ones.
- it "raises an error on unknown hostnames" do
- -> {
- IPSocket.getaddress("rubyspecdoesntexist.ruby-lang.org")
- }.should raise_error(SocketError)
+ quarantine! do
+ it "raises an error on unknown hostnames" do
+ lambda {
+ IPSocket.getaddress("rubyspecdoesntexist.fallingsnow.net")
+ }.should raise_error(SocketError)
+ end
end
+
end
diff --git a/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb b/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb
index 702650940b..27529c3d1c 100644
--- a/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb
+++ b/spec/ruby/library/socket/ipsocket/peeraddr_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#peeraddr" do
before :each do
@@ -16,7 +16,7 @@ describe "Socket::IPSocket#peeraddr" do
end
it "raises error if socket is not connected" do
- -> {
+ lambda {
@server.peeraddr
}.should raise_error(Errno::ENOTCONN)
end
@@ -49,69 +49,3 @@ describe "Socket::IPSocket#peeraddr" do
addrinfo[3].should == "127.0.0.1"
end
end
-
-describe 'Socket::IPSocket#peeraddr' do
- SocketSpecs.each_ip_protocol do |family, ip_address, family_name|
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- @client = TCPSocket.new(ip_address, @port)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'without reverse lookups' do
- before do
- @hostname = Socket.getaddrinfo(ip_address, nil)[0][2]
- end
-
- it 'returns an Array containing address information' do
- @client.peeraddr.should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'with reverse lookups' do
- before do
- @hostname = Socket.getaddrinfo(ip_address, nil, nil, 0, 0, 0, true)[0][2]
- end
-
- describe 'using true as the argument' do
- it 'returns an Array containing address information' do
- @client.peeraddr(true).should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'using :hostname as the argument' do
- it 'returns an Array containing address information' do
- @client.peeraddr(:hostname).should == [family_name, @port, @hostname, ip_address]
- end
- end
-
- describe 'using :cats as the argument' do
- it 'raises ArgumentError' do
- -> { @client.peeraddr(:cats) }.should raise_error(ArgumentError)
- end
- end
- end
-
- describe 'with do_not_reverse_lookup disabled on socket level' do
- before do
- @client.do_not_reverse_lookup = false
-
- @hostname = Socket.getaddrinfo(ip_address, nil, nil, 0, 0, 0, true)[0][2]
- @port = @client.local_address.ip_port
- end
-
- after do
- @client.do_not_reverse_lookup = true
- end
-
- it 'returns an Array containing address information' do
- @client.addr.should == [family_name, @port, @hostname, ip_address]
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb
index 2af86ea70d..54f150decf 100644
--- a/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb
+++ b/spec/ruby/library/socket/ipsocket/recvfrom_spec.rb
@@ -1,7 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#recvfrom" do
+
before :each do
@server = TCPServer.new("127.0.0.1", 0)
@port = @server.addr[1]
@@ -64,60 +65,8 @@ describe "Socket::IPSocket#recvfrom" do
data.size.should == 2
data.first.should == "hel"
- # This does not apply to every platform, dependent on recvfrom(2)
+ # This does not apply to every platform, dependant on recvfrom(2)
# data.last.should == nil
end
-end
-
-describe 'Socket::IPSocket#recvfrom' do
- SocketSpecs.each_ip_protocol do |family, ip_address, family_name|
- before do
- @server = UDPSocket.new(family)
- @client = UDPSocket.new(family)
-
- @server.bind(ip_address, 0)
- @client.connect(ip_address, @server.connect_address.ip_port)
-
- @hostname = Socket.getaddrinfo(ip_address, nil)[0][2]
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns an Array containing up to N bytes and address information' do
- @client.write('hello')
-
- port = @client.local_address.ip_port
- ret = @server.recvfrom(2)
-
- ret.should == ['he', [family_name, port, @hostname, ip_address]]
- end
- it 'allows specifying of flags when receiving data' do
- @client.write('hello')
-
- @server.recvfrom(2, Socket::MSG_PEEK)[0].should == 'he'
-
- @server.recvfrom(2)[0].should == 'he'
- end
-
- describe 'using reverse lookups' do
- before do
- @server.do_not_reverse_lookup = false
-
- @hostname = Socket.getaddrinfo(ip_address, nil, 0, 0, 0, 0, true)[0][2]
- end
-
- it 'includes the hostname in the address Array' do
- @client.write('hello')
-
- port = @client.local_address.ip_port
- ret = @server.recvfrom(2)
-
- ret.should == ['he', [family_name, port, @hostname, ip_address]]
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/option/bool_spec.rb b/spec/ruby/library/socket/option/bool_spec.rb
index 144a78043d..74c832a0ad 100644
--- a/spec/ruby/library/socket/option/bool_spec.rb
+++ b/spec/ruby/library/socket/option/bool_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::Option.bool" do
it "creates a new Socket::Option" do
@@ -18,10 +18,8 @@ describe "Socket::Option#bool" do
Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false).bool.should == false
end
- platform_is_not :windows do
- it 'raises TypeError when called on a non boolean option' do
- opt = Socket::Option.linger(1, 4)
- -> { opt.bool }.should raise_error(TypeError)
- end
+ it "raises TypeError if option has not good size" do
+ so = Socket::Option.new(:UNSPEC, :SOCKET, :SO_LINGER, [0, 0].pack('i*'))
+ lambda { so.bool }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/library/socket/option/initialize_spec.rb b/spec/ruby/library/socket/option/initialize_spec.rb
deleted file mode 100644
index 8071ad7ef0..0000000000
--- a/spec/ruby/library/socket/option/initialize_spec.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket::Option#initialize' do
- before do
- @bool = [0].pack('i')
- end
-
- describe 'using Integers' do
- it 'returns a Socket::Option' do
- opt = Socket::Option
- .new(Socket::AF_INET, Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, @bool)
-
- opt.should be_an_instance_of(Socket::Option)
-
- opt.family.should == Socket::AF_INET
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_KEEPALIVE
- opt.data.should == @bool
- end
- end
-
- describe 'using Symbols' do
- it 'returns a Socket::Option' do
- opt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, @bool)
-
- opt.should be_an_instance_of(Socket::Option)
-
- opt.family.should == Socket::AF_INET
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_KEEPALIVE
- opt.data.should == @bool
- end
-
- it 'raises when using an invalid address family' do
- -> {
- Socket::Option.new(:INET2, :SOCKET, :KEEPALIVE, @bool)
- }.should raise_error(SocketError)
- end
-
- it 'raises when using an invalid level' do
- -> {
- Socket::Option.new(:INET, :CATS, :KEEPALIVE, @bool)
- }.should raise_error(SocketError)
- end
-
- it 'raises when using an invalid option name' do
- -> {
- Socket::Option.new(:INET, :SOCKET, :CATS, @bool)
- }.should raise_error(SocketError)
- end
- end
-
- describe 'using Strings' do
- it 'returns a Socket::Option' do
- opt = Socket::Option.new('INET', 'SOCKET', 'KEEPALIVE', @bool)
-
- opt.should be_an_instance_of(Socket::Option)
-
- opt.family.should == Socket::AF_INET
- opt.level.should == Socket::SOL_SOCKET
- opt.optname.should == Socket::SO_KEEPALIVE
- opt.data.should == @bool
- end
-
- it 'raises when using an invalid address family' do
- -> {
- Socket::Option.new('INET2', 'SOCKET', 'KEEPALIVE', @bool)
- }.should raise_error(SocketError)
- end
-
- it 'raises when using an invalid level' do
- -> {
- Socket::Option.new('INET', 'CATS', 'KEEPALIVE', @bool)
- }.should raise_error(SocketError)
- end
-
- it 'raises when using an invalid option name' do
- -> {
- Socket::Option.new('INET', 'SOCKET', 'CATS', @bool)
- }.should raise_error(SocketError)
- end
- end
-end
diff --git a/spec/ruby/library/socket/option/inspect_spec.rb b/spec/ruby/library/socket/option/inspect_spec.rb
index ebea940d2f..df72f227a9 100644
--- a/spec/ruby/library/socket/option/inspect_spec.rb
+++ b/spec/ruby/library/socket/option/inspect_spec.rb
@@ -1,6 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require 'socket'
describe 'Socket::Option#inspect' do
it 'correctly returns SO_LINGER value' do
diff --git a/spec/ruby/library/socket/option/int_spec.rb b/spec/ruby/library/socket/option/int_spec.rb
index 8c69ef6cbd..f926ff7968 100644
--- a/spec/ruby/library/socket/option/int_spec.rb
+++ b/spec/ruby/library/socket/option/int_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::Option.int" do
it "creates a new Socket::Option" do
@@ -10,17 +10,6 @@ describe "Socket::Option.int" do
so.optname.should == Socket::Constants::SO_KEEPALIVE
so.data.should == [5].pack('i')
end
-
- it 'returns a Socket::Option' do
- opt = Socket::Option.int(:INET, :IP, :TTL, 4)
-
- opt.should be_an_instance_of(Socket::Option)
-
- opt.family.should == Socket::AF_INET
- opt.level.should == Socket::IPPROTO_IP
- opt.optname.should == Socket::IP_TTL
- opt.data.should == [4].pack('i')
- end
end
describe "Socket::Option#int" do
@@ -30,14 +19,10 @@ describe "Socket::Option#int" do
so = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 32765)
so.int.should == 32765
-
- Socket::Option.int(:INET, :IP, :TTL, 4).int.should == 4
end
- platform_is_not :windows do
- it 'raises TypeError when called on a non integer option' do
- opt = Socket::Option.linger(1, 4)
- -> { opt.int }.should raise_error(TypeError)
- end
+ it "raises TypeError if option has not good size" do
+ so = Socket::Option.new(:UNSPEC, :SOCKET, :SO_LINGER, [0, 0].pack('i*'))
+ lambda { so.int }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/library/socket/option/linger_spec.rb b/spec/ruby/library/socket/option/linger_spec.rb
index ee987db85b..687d421af3 100644
--- a/spec/ruby/library/socket/option/linger_spec.rb
+++ b/spec/ruby/library/socket/option/linger_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
option_pack = 'i*'
platform_is :windows do
@@ -10,11 +10,9 @@ describe "Socket::Option.linger" do
it "creates a new Socket::Option for SO_LINGER" do
so = Socket::Option.linger(1, 10)
so.should be_an_instance_of(Socket::Option)
-
so.family.should == Socket::Constants::AF_UNSPEC
so.level.should == Socket::Constants::SOL_SOCKET
so.optname.should == Socket::Constants::SO_LINGER
-
so.data.should == [1, 10].pack(option_pack)
end
@@ -52,25 +50,13 @@ describe "Socket::Option#linger" do
it "raises TypeError if not a SO_LINGER" do
so = Socket::Option.int(:AF_UNSPEC, :SOL_SOCKET, :KEEPALIVE, 1)
- -> { so.linger }.should raise_error(TypeError)
- end
-
- it 'raises TypeError when called on a non SOL_SOCKET/SO_LINGER option' do
- opt = Socket::Option.int(:INET, :IP, :TTL, 4)
-
- -> { opt.linger }.should raise_error(TypeError)
+ lambda { so.linger }.should raise_error(TypeError)
end
platform_is_not :windows do
it "raises TypeError if option has not good size" do
so = Socket::Option.int(:AF_UNSPEC, :SOL_SOCKET, :LINGER, 1)
- -> { so.linger }.should raise_error(TypeError)
+ lambda { so.linger }.should raise_error(TypeError)
end
end
-
- it 'raises TypeError when called on a non linger option' do
- opt = Socket::Option.new(:INET, :SOCKET, :LINGER, '')
-
- -> { opt.linger }.should raise_error(TypeError)
- end
end
diff --git a/spec/ruby/library/socket/option/new_spec.rb b/spec/ruby/library/socket/option/new_spec.rb
index a9e6f09097..4f2d0c5386 100644
--- a/spec/ruby/library/socket/option/new_spec.rb
+++ b/spec/ruby/library/socket/option/new_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::Option.new" do
it "should accept integers" do
@@ -22,14 +22,14 @@ describe "Socket::Option.new" do
end
it "should raise error on unknown family" do
- -> { Socket::Option.new(:INET4, :SOCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
+ lambda { Socket::Option.new(:INET4, :SOCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
end
it "should raise error on unknown level" do
- -> { Socket::Option.new(:INET, :ROCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
+ lambda { Socket::Option.new(:INET, :ROCKET, :KEEPALIVE, [0].pack('i')) }.should raise_error(SocketError)
end
it "should raise error on unknown option name" do
- -> { Socket::Option.new(:INET, :SOCKET, :ALIVE, [0].pack('i')) }.should raise_error(SocketError)
+ lambda { Socket::Option.new(:INET, :SOCKET, :ALIVE, [0].pack('i')) }.should raise_error(SocketError)
end
end
diff --git a/spec/ruby/library/socket/shared/address.rb b/spec/ruby/library/socket/shared/address.rb
deleted file mode 100644
index f3be9cfb99..0000000000
--- a/spec/ruby/library/socket/shared/address.rb
+++ /dev/null
@@ -1,249 +0,0 @@
-require_relative '../fixtures/classes'
-
-describe :socket_local_remote_address, shared: true do
- describe 'using TCPSocket' do
- before :each do
- @s = TCPServer.new('127.0.0.1', 0)
- @a = TCPSocket.new('127.0.0.1', @s.addr[1])
- @b = @s.accept
- @addr = @object.call(@a)
- end
-
- after :each do
- [@b, @a, @s].each(&:close)
- end
-
- it 'uses AF_INET as the address family' do
- @addr.afamily.should == Socket::AF_INET
- end
-
- it 'uses PF_INET as the protocol family' do
- @addr.pfamily.should == Socket::PF_INET
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '127.0.0.1'
- end
-
- it 'uses the correct port' do
- if @method == :local_address
- @addr.ip_port.should != @s.addr[1]
- else
- @addr.ip_port.should == @s.addr[1]
- end
- end
-
- it 'equals address of peer socket' do
- if @method == :local_address
- @addr.to_s.should == @b.remote_address.to_s
- else
- @addr.to_s.should == @b.local_address.to_s
- end
- 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 '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
-
- guard -> { SocketSpecs.ipv6_available? } do
- describe 'using IPv6' do
- before :each do
- @s = TCPServer.new('::1', 0)
- @a = TCPSocket.new('::1', @s.addr[1])
- @b = @s.accept
- @addr = @object.call(@a)
- end
-
- after :each do
- [@b, @a, @s].each(&:close)
- end
-
- it 'uses AF_INET6 as the address family' do
- @addr.afamily.should == Socket::AF_INET6
- end
-
- it 'uses PF_INET6 as the protocol family' do
- @addr.pfamily.should == Socket::PF_INET6
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '::1'
- end
-
- it 'uses the correct port' do
- if @method == :local_address
- @addr.ip_port.should != @s.addr[1]
- else
- @addr.ip_port.should == @s.addr[1]
- end
- end
-
- it 'equals address of peer socket' do
- if @method == :local_address
- @addr.to_s.should == @b.remote_address.to_s
- else
- @addr.to_s.should == @b.local_address.to_s
- end
- 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 '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
- 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
-
- 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 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
- 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 'equals address of peer socket' do
- if @method == :local_address
- @addr.to_s.should == @b.remote_address.to_s
- else
- @addr.to_s.should == @b.local_address.to_s
- end
- 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 '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
- end
-
- describe 'using UDPSocket' do
- before :each do
- @s = UDPSocket.new
- @s.bind("127.0.0.1", 0)
- @a = UDPSocket.new
- @a.connect("127.0.0.1", @s.addr[1])
- @addr = @object.call(@a)
- end
-
- after :each do
- [@a, @s].each(&:close)
- end
-
- it 'uses the correct address family' do
- @addr.afamily.should == Socket::AF_INET
- end
-
- it 'uses the correct protocol family' do
- @addr.pfamily.should == Socket::PF_INET
- end
-
- it 'uses SOCK_DGRAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses the correct IP address' do
- @addr.ip_address.should == '127.0.0.1'
- end
-
- it 'uses the correct port' do
- if @method == :local_address
- @addr.ip_port.should != @s.addr[1]
- else
- @addr.ip_port.should == @s.addr[1]
- end
- 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 'can be used to connect to the peer' do
- b = @addr.connect
- begin
- b.remote_address.to_s.should == @addr.to_s
- ensure
- b.close
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb
index 26fdf682b1..4ffa02a8d8 100644
--- a/spec/ruby/library/socket/shared/pack_sockaddr.rb
+++ b/spec/ruby/library/socket/shared/pack_sockaddr.rb
@@ -17,52 +17,11 @@ describe :socket_pack_sockaddr_in, shared: true do
sockaddr_in = Socket.public_send(@method, nil, '127.0.0.1')
Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '127.0.0.1']
-
- sockaddr_in = Socket.public_send(@method, 80, Socket::INADDR_ANY)
- Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0']
- end
-
- platform_is_not :solaris do
- it 'resolves the service name to a port' do
- sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1')
- Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1']
- end
- end
-
- describe 'using an IPv4 address' do
- it 'returns a String of 16 bytes' do
- str = Socket.public_send(@method, 80, '127.0.0.1')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 16
- end
- end
-
- platform_is_not :solaris do
- describe 'using an IPv6 address' do
- it 'returns a String of 28 bytes' do
- str = Socket.public_send(@method, 80, '::1')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 28
- end
- end
- end
-
- platform_is :solaris do
- describe 'using an IPv6 address' do
- it 'returns a String of 32 bytes' do
- str = Socket.public_send(@method, 80, '::1')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 32
- end
- end
end
end
describe :socket_pack_sockaddr_un, shared: true do
- with_feature :unix_socket do
+ platform_is_not :windows 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]
@@ -81,29 +40,11 @@ describe :socket_pack_sockaddr_un, shared: true do
end
end
- platform_is :linux do
- it 'returns a String of 110 bytes' do
- str = Socket.public_send(@method, '/tmp/test.sock')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 110
- end
- end
-
- platform_is :bsd do
- it 'returns a String of 106 bytes' do
- str = Socket.public_send(@method, '/tmp/test.sock')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 106
- end
- end
-
platform_is_not :windows, :aix do
- it "raises ArgumentError for paths that are too long" do
+ it "raises if path length exceeds max size" do
# AIX doesn't raise error
- long_path = 'a' * 110
- -> { Socket.public_send(@method, long_path) }.should raise_error(ArgumentError)
+ long_path = Array.new(512, 0).join
+ lambda { Socket.public_send(@method, long_path) }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/ruby/library/socket/shared/partially_closable_sockets.rb b/spec/ruby/library/socket/shared/partially_closable_sockets.rb
index b1c2ebabe1..1bdff08bf6 100644
--- a/spec/ruby/library/socket/shared/partially_closable_sockets.rb
+++ b/spec/ruby/library/socket/shared/partially_closable_sockets.rb
@@ -1,4 +1,4 @@
-describe :partially_closable_sockets, shared: true do
+describe "partially closable sockets", shared: true do
it "if the write end is closed then the other side can read past EOF without blocking" do
@s1.write("foo")
@s1.close_write
diff --git a/spec/ruby/library/socket/shared/recv_nonblock.rb b/spec/ruby/library/socket/shared/recv_nonblock.rb
new file mode 100644
index 0000000000..a5f6c6812e
--- /dev/null
+++ b/spec/ruby/library/socket/shared/recv_nonblock.rb
@@ -0,0 +1,54 @@
+describe :socket_recv_nonblock, shared: true do
+ before :each do
+ @s1 = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
+ @s2 = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
+ end
+
+ after :each do
+ @s1.close unless @s1.closed?
+ @s2.close unless @s2.closed?
+ end
+
+ it "raises an exception extending IO::WaitReadable if there's no data available" do
+ @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
+ lambda {
+ @s1.recv_nonblock(5)
+ }.should raise_error(IO::WaitReadable) { |e|
+ platform_is_not :windows do
+ e.should be_kind_of(Errno::EAGAIN)
+ end
+ platform_is :windows do
+ e.should be_kind_of(Errno::EWOULDBLOCK)
+ end
+ }
+ end
+
+ it "receives data after it's ready" do
+ @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
+ @s2.send("aaa", 0, @s1.getsockname)
+ IO.select([@s1], nil, nil, 2)
+ @s1.recv_nonblock(5).should == "aaa"
+ end
+
+ ruby_version_is "2.3" do
+ it "allows an output buffer as third argument" do
+ @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
+ @s2.send("data", 0, @s1.getsockname)
+ IO.select([@s1], nil, nil, 2)
+
+ buf = "foo"
+ @s1.recv_nonblock(5, 0, buf)
+ buf.should == "data"
+ end
+ end
+
+ it "does not block if there's no data available" do
+ @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
+ @s2.send("a", 0, @s1.getsockname)
+ IO.select([@s1], nil, nil, 2)
+ @s1.recv_nonblock(1).should == "a"
+ lambda {
+ @s1.recv_nonblock(5)
+ }.should raise_error(IO::WaitReadable)
+ end
+end
diff --git a/spec/ruby/library/socket/shared/socketpair.rb b/spec/ruby/library/socket/shared/socketpair.rb
index 25146cfff6..03ee0e1a52 100644
--- a/spec/ruby/library/socket/shared/socketpair.rb
+++ b/spec/ruby/library/socket/shared/socketpair.rb
@@ -19,120 +19,5 @@ describe :socket_socketpair, shared: true do
s2.close
end
end
-
- describe 'using an Integer as the 1st and 2nd argument' do
- it 'returns two Socket objects' do
- s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, Socket::SOCK_STREAM)
-
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
- s1.close
- s2.close
- end
- end
-
- describe 'using a Symbol as the 1st and 2nd argument' do
- it 'returns two Socket objects' do
- s1, s2 = Socket.public_send(@method, :UNIX, :STREAM)
-
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
- s1.close
- s2.close
- end
-
- it 'raises SocketError for an unknown address family' do
- -> { Socket.public_send(@method, :CATS, :STREAM) }.should raise_error(SocketError)
- end
-
- it 'raises SocketError for an unknown socket type' do
- -> { Socket.public_send(@method, :UNIX, :CATS) }.should raise_error(SocketError)
- end
- end
-
- describe 'using a String as the 1st and 2nd argument' do
- it 'returns two Socket objects' do
- s1, s2 = Socket.public_send(@method, 'UNIX', 'STREAM')
-
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
- s1.close
- s2.close
- end
-
- it 'raises SocketError for an unknown address family' do
- -> { Socket.public_send(@method, 'CATS', 'STREAM') }.should raise_error(SocketError)
- end
-
- it 'raises SocketError for an unknown socket type' do
- -> { Socket.public_send(@method, 'UNIX', 'CATS') }.should raise_error(SocketError)
- end
- end
-
- describe 'using an object that responds to #to_str as the 1st and 2nd argument' do
- it 'returns two Socket objects' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return('UNIX')
- type.stub!(:to_str).and_return('STREAM')
-
- s1, s2 = Socket.public_send(@method, family, type)
-
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
- s1.close
- s2.close
- end
-
- it 'raises TypeError when #to_str does not return a String' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return(Socket::AF_UNIX)
- type.stub!(:to_str).and_return(Socket::SOCK_STREAM)
-
- -> { Socket.public_send(@method, family, type) }.should raise_error(TypeError)
- end
-
- it 'raises SocketError for an unknown address family' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return('CATS')
- type.stub!(:to_str).and_return('STREAM')
-
- -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError)
- end
-
- it 'raises SocketError for an unknown socket type' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return('UNIX')
- type.stub!(:to_str).and_return('CATS')
-
- -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError)
- end
- end
-
- it 'accepts a custom protocol as an Integer as the 3rd argument' do
- s1, s2 = Socket.public_send(@method, :UNIX, :STREAM, Socket::IPPROTO_IP)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
- s1.close
- s2.close
- end
-
- it 'connects the returned Socket objects' do
- s1, s2 = Socket.public_send(@method, :UNIX, :STREAM)
- begin
- s1.write('hello')
- s2.recv(5).should == 'hello'
- ensure
- s1.close
- s2.close
- end
- end
end
end
diff --git a/spec/ruby/library/socket/socket/accept_loop_spec.rb b/spec/ruby/library/socket/socket/accept_loop_spec.rb
deleted file mode 100644
index 78e8c3fa4a..0000000000
--- a/spec/ruby/library/socket/socket/accept_loop_spec.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.accept_loop' do
- before do
- @server = Socket.new(:INET, :STREAM)
- @client = Socket.new(:INET, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
- @server.listen(1)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'using an Array of Sockets' do
- describe 'without any available connections' do
- # FIXME windows randomly hangs here forever
- # https://ci.appveyor.com/project/ruby/ruby/builds/20817932/job/dor2ipny7ru4erpa
- platform_is_not :windows do
- it 'blocks the caller' do
- -> { Socket.accept_loop([@server]) }.should block_caller
- end
- end
- end
-
- describe 'with available connections' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'yields a Socket and an Addrinfo' do
- conn = nil
- addr = nil
-
- Socket.accept_loop([@server]) do |connection, address|
- conn = connection
- addr = address
- break
- end
-
- begin
- conn.should be_an_instance_of(Socket)
- addr.should be_an_instance_of(Addrinfo)
- ensure
- conn.close
- end
- end
- end
- end
-
- describe 'using separate Socket arguments' do
- describe 'without any available connections' do
- it 'blocks the caller' do
- -> { Socket.accept_loop(@server) }.should block_caller
- end
- end
-
- describe 'with available connections' do
- before do
- @client.connect(@server.getsockname)
- end
-
- it 'yields a Socket and an Addrinfo' do
- conn = nil
- addr = nil
-
- Socket.accept_loop(@server) do |connection, address|
- conn = connection
- addr = address
- break
- end
-
- begin
- conn.should be_an_instance_of(Socket)
- addr.should be_an_instance_of(Addrinfo)
- ensure
- conn.close
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb
index 011622988c..be0bbf5f03 100644
--- a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb
+++ b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb
@@ -1,5 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+require 'socket'
describe "Socket#accept_nonblock" do
before :each do
@@ -15,7 +17,7 @@ describe "Socket#accept_nonblock" do
end
it "raises IO::WaitReadable if the connection is not accepted yet" do
- -> {
+ lambda {
@socket.accept_nonblock
}.should raise_error(IO::WaitReadable) { |e|
platform_is_not :windows do
@@ -27,115 +29,9 @@ describe "Socket#accept_nonblock" do
}
end
- it 'returns :wait_readable in exceptionless mode' do
- @socket.accept_nonblock(exception: false).should == :wait_readable
- end
-end
-
-describe 'Socket#accept_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM, 0)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
- end
-
- after do
- @server.close unless @server.closed?
- end
-
- describe 'using an unbound socket' do
- it 'raises Errno::EINVAL' do
- -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL)
- -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL)
- end
- end
-
- describe "using a bound socket that's not listening" do
- before do
- @server.bind(@sockaddr)
- end
-
- it 'raises Errno::EINVAL' do
- -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL)
- -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL)
- end
- end
-
- describe 'using a closed socket' do
- it 'raises IOError' do
- @server.close
-
- -> { @server.accept_nonblock }.should raise_error(IOError)
- -> { @server.accept_nonblock(exception: false) }.should raise_error(IOError)
- end
- end
-
- describe "using a bound socket that's listening" do
- before do
- @server.bind(@sockaddr)
- @server.listen(1)
- end
-
- describe 'without a connected client' do
- it 'raises IO::WaitReadable' do
- -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
- end
- end
-
- platform_is_not :windows do
- describe 'with a connected client' do
- before do
- addr = Socket.sockaddr_in(@server.local_address.ip_port, ip_address)
- @client = Socket.new(family, :STREAM, 0)
-
- @client.connect(addr)
- end
-
- after do
- @socket.close if @socket
- @client.close
- end
-
- it 'returns an Array containing a Socket and an Addrinfo' do
- IO.select([@server])
- @socket, addrinfo = @server.accept_nonblock
-
- @socket.should be_an_instance_of(Socket)
- addrinfo.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- before do
- IO.select([@server])
- @socket, @addr = @server.accept_nonblock
- end
-
- it 'uses AF_INET as the address family' do
- @addr.afamily.should == family
- end
-
- it 'uses PF_INET as the protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
-
- it 'uses the same IP address as the client Socket' do
- @addr.ip_address.should == @client.local_address.ip_address
- end
-
- it 'uses the same port as the client Socket' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
+ ruby_version_is '2.3' do
+ it 'returns :wait_readable in exceptionless mode' do
+ @socket.accept_nonblock(exception: false).should == :wait_readable
end
end
end
diff --git a/spec/ruby/library/socket/socket/accept_spec.rb b/spec/ruby/library/socket/socket/accept_spec.rb
index 417f996c55..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/accept_spec.rb
+++ b/spec/ruby/library/socket/socket/accept_spec.rb
@@ -1,121 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#accept' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM, 0)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
- end
-
- after do
- @server.close unless @server.closed?
- end
-
- platform_is :linux do # hangs on other platforms
- describe 'using an unbound socket' do
- it 'raises Errno::EINVAL' do
- -> { @server.accept }.should raise_error(Errno::EINVAL)
- end
- end
-
- describe "using a bound socket that's not listening" do
- before do
- @server.bind(@sockaddr)
- end
-
- it 'raises Errno::EINVAL' do
- -> { @server.accept }.should raise_error(Errno::EINVAL)
- end
- end
- end
-
- describe 'using a closed socket' do
- it 'raises IOError' do
- @server.close
-
- -> { @server.accept }.should raise_error(IOError)
- end
- end
-
- describe "using a bound socket that's listening" do
- before do
- @server.bind(@sockaddr)
- @server.listen(1)
-
- server_ip = @server.local_address.ip_port
- @server_addr = Socket.sockaddr_in(server_ip, ip_address)
- end
-
- describe 'without a connected client' do
- it 'blocks the caller until a connection is available' do
- client = Socket.new(family, :STREAM, 0)
- thread = Thread.new do
- @server.accept
- end
-
- client.connect(@server_addr)
-
- value = thread.value
- begin
- value.should be_an_instance_of(Array)
- ensure
- client.close
- value[0].close
- end
- end
- end
-
- describe 'with a connected client' do
- before do
- addr = Socket.sockaddr_in(@server.local_address.ip_port, ip_address)
- @client = Socket.new(family, :STREAM, 0)
-
- @client.connect(addr)
- end
-
- after do
- @socket.close if @socket
- @client.close
- end
-
- it 'returns an Array containing a Socket and an Addrinfo' do
- @socket, addrinfo = @server.accept
-
- @socket.should be_an_instance_of(Socket)
- addrinfo.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- before do
- @socket, @addr = @server.accept
- end
-
- it 'uses AF_INET as the address family' do
- @addr.afamily.should == family
- end
-
- it 'uses PF_INET as the protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
-
- it 'uses the same IP address as the client Socket' do
- @addr.ip_address.should == @client.local_address.ip_address
- end
-
- it 'uses the same port as the client Socket' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/bind_spec.rb b/spec/ruby/library/socket/socket/bind_spec.rb
index 4465a3dafa..399c988b32 100644
--- a/spec/ruby/library/socket/socket/bind_spec.rb
+++ b/spec/ruby/library/socket/socket/bind_spec.rb
@@ -1,9 +1,11 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+include Socket::Constants
describe "Socket#bind on SOCK_DGRAM socket" do
before :each do
- @sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
+ @sock = Socket.new(AF_INET, SOCK_DGRAM, 0)
@sockaddr = Socket.pack_sockaddr_in(0, "127.0.0.1")
end
@@ -13,7 +15,7 @@ describe "Socket#bind on SOCK_DGRAM socket" do
end
it "binds to a port" do
- -> { @sock.bind(@sockaddr) }.should_not raise_error
+ lambda { @sock.bind(@sockaddr) }.should_not raise_error
end
it "returns 0 if successful" do
@@ -23,29 +25,26 @@ describe "Socket#bind on SOCK_DGRAM socket" do
it "raises Errno::EINVAL when already bound" do
@sock.bind(@sockaddr)
- -> { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL)
+ lambda { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL)
end
it "raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available from the local machine" do
sockaddr1 = Socket.pack_sockaddr_in(0, "4.3.2.1")
- -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL)
+ lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL)
end
platform_is_not :windows, :cygwin do
- as_user do
- break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
- it "raises Errno::EACCES when the current user does not have permission to bind" do
- sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
- -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
- end
+ it "raises Errno::EACCES when the current user does not have permission to bind" do
+ sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
+ lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
end
end
end
describe "Socket#bind on SOCK_STREAM socket" do
before :each do
- @sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
- @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
+ @sock = Socket.new(AF_INET, SOCK_STREAM, 0)
+ @sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, true)
@sockaddr = Socket.pack_sockaddr_in(0, "127.0.0.1")
end
@@ -55,7 +54,7 @@ describe "Socket#bind on SOCK_STREAM socket" do
end
it "binds to a port" do
- -> { @sock.bind(@sockaddr) }.should_not raise_error
+ lambda { @sock.bind(@sockaddr) }.should_not raise_error
end
it "returns 0 if successful" do
@@ -65,86 +64,18 @@ describe "Socket#bind on SOCK_STREAM socket" do
it "raises Errno::EINVAL when already bound" do
@sock.bind(@sockaddr)
- -> { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL)
+ lambda { @sock.bind(@sockaddr) }.should raise_error(Errno::EINVAL)
end
it "raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available from the local machine" do
sockaddr1 = Socket.pack_sockaddr_in(0, "4.3.2.1")
- -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL)
+ lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL)
end
platform_is_not :windows, :cygwin do
- as_user do
- break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
- it "raises Errno::EACCES when the current user does not have permission to bind" do
- sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
- -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
- end
- end
- end
-end
-
-describe 'Socket#bind' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a packed socket address' do
- before do
- @socket = Socket.new(family, :DGRAM)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
- end
-
- after do
- @socket.close
- end
-
- it 'returns 0 when successfully bound' do
- @socket.bind(@sockaddr).should == 0
- end
-
- it 'raises Errno::EINVAL when binding to an already bound port' do
- @socket.bind(@sockaddr)
-
- -> { @socket.bind(@sockaddr) }.should raise_error(Errno::EINVAL)
- end
-
- it 'raises Errno::EADDRNOTAVAIL when the specified sockaddr is not available' do
- ip = family == Socket::AF_INET ? '4.3.2.1' : '::2'
- sockaddr1 = Socket.sockaddr_in(0, ip)
-
- -> { @socket.bind(sockaddr1) }.should raise_error(Errno::EADDRNOTAVAIL)
- end
-
- platform_is_not :windows do
- as_user do
- break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
-
- it 'raises Errno::EACCES when the user is not allowed to bind to the port' do
- sockaddr1 = Socket.pack_sockaddr_in(1, ip_address)
-
- -> { @socket.bind(sockaddr1) }.should raise_error(Errno::EACCES)
- end
- end
- end
- end
-
- describe 'using an Addrinfo' do
- before do
- @addr = Addrinfo.udp(ip_address, 0)
- @socket = Socket.new(@addr.afamily, @addr.socktype)
- end
-
- after do
- @socket.close
- end
-
- it 'binds to an Addrinfo' do
- @socket.bind(@addr).should == 0
- @socket.local_address.should be_an_instance_of(Addrinfo)
- end
-
- it 'uses a new Addrinfo for the local address' do
- @socket.bind(@addr)
- @socket.local_address.should_not == @addr
- end
+ it "raises Errno::EACCES when the current user does not have permission to bind" do
+ sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
+ lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
end
end
end
diff --git a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb
index 3cf667fc4a..26bceabb51 100644
--- a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb
+++ b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb
@@ -1,5 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+require 'socket'
describe "Socket#connect_nonblock" do
before :each do
@@ -16,133 +18,55 @@ describe "Socket#connect_nonblock" do
@thread.join if @thread
end
- platform_is_not :solaris do
- it "connects the socket to the remote side" do
- port = nil
- accept = false
- @thread = Thread.new do
- server = TCPServer.new(@hostname, 0)
- port = server.addr[1]
- Thread.pass until accept
- conn = server.accept
- conn << "hello!"
- conn.close
- server.close
- end
-
- Thread.pass until port
+ it "connects the socket to the remote side" do
+ port = nil
+ accept = false
+ @thread = Thread.new do
+ server = TCPServer.new(@hostname, 0)
+ port = server.addr[1]
+ Thread.pass until accept
+ conn = server.accept
+ conn << "hello!"
+ conn.close
+ server.close
+ end
- addr = Socket.sockaddr_in(port, @hostname)
- begin
- @socket.connect_nonblock(addr)
- rescue Errno::EINPROGRESS
- end
+ Thread.pass until port
- accept = true
- IO.select nil, [@socket]
+ addr = Socket.sockaddr_in(port, @hostname)
+ begin
+ @socket.connect_nonblock(addr)
+ rescue Errno::EINPROGRESS
+ end
- begin
- @socket.connect_nonblock(addr)
- rescue Errno::EISCONN
- # Not all OS's use this errno, so we trap and ignore it
- end
+ accept = true
+ IO.select nil, [@socket]
- @socket.read(6).should == "hello!"
+ begin
+ @socket.connect_nonblock(addr)
+ rescue Errno::EISCONN
+ # Not all OS's use this errno, so we trap and ignore it
end
+
+ @socket.read(6).should == "hello!"
end
platform_is_not :freebsd, :solaris, :aix do
it "raises Errno::EINPROGRESS when the connect would block" do
- -> do
+ lambda do
@socket.connect_nonblock(@addr)
end.should raise_error(Errno::EINPROGRESS)
end
it "raises Errno::EINPROGRESS with IO::WaitWritable mixed in when the connect would block" do
- -> do
+ lambda do
@socket.connect_nonblock(@addr)
end.should raise_error(IO::WaitWritable)
end
- it "returns :wait_writable in exceptionless mode when the connect would block" do
- @socket.connect_nonblock(@addr, exception: false).should == :wait_writable
- end
- end
-end
-
-describe 'Socket#connect_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a DGRAM socket' do
- before do
- @server = Socket.new(family, :DGRAM)
- @client = Socket.new(family, :DGRAM)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
-
- @server.bind(@sockaddr)
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns 0 when successfully connected using a String' do
- @client.connect_nonblock(@server.getsockname).should == 0
- end
-
- it 'returns 0 when successfully connected using an Addrinfo' do
- @client.connect_nonblock(@server.connect_address).should == 0
- end
-
- it 'raises TypeError when passed an Integer' do
- -> { @client.connect_nonblock(666) }.should raise_error(TypeError)
- end
- end
-
- describe 'using a STREAM socket' do
- before do
- @server = Socket.new(family, :STREAM)
- @client = Socket.new(family, :STREAM)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- it 'raises Errno::EISCONN when already connected' do
- @server.listen(1)
- @client.connect(@server.connect_address).should == 0
-
- -> {
- @client.connect_nonblock(@server.connect_address)
-
- # A second call needed if non-blocking sockets become default
- # XXX honestly I don't expect any real code to care about this spec
- # as it's too implementation-dependent and checking for connect()
- # errors is futile anyways because of TOCTOU
- @client.connect_nonblock(@server.connect_address)
- }.should raise_error(Errno::EISCONN)
- end
-
- it 'returns 0 when already connected in exceptionless mode' do
- @server.listen(1)
- @client.connect(@server.connect_address).should == 0
-
- @client.connect_nonblock(@server.connect_address, exception: false).should == 0
- end
- end
-
- platform_is_not :freebsd, :solaris do
- it 'raises IO:EINPROGRESSWaitWritable when the connection would block' do
- @server.bind(@sockaddr)
-
- -> {
- @client.connect_nonblock(@server.connect_address)
- }.should raise_error(IO::EINPROGRESSWaitWritable)
- end
+ ruby_version_is "2.3" do
+ it "returns :wait_writable in exceptionless mode when the connect would block" do
+ @socket.connect_nonblock(@addr, exception: false).should == :wait_writable
end
end
end
diff --git a/spec/ruby/library/socket/socket/connect_spec.rb b/spec/ruby/library/socket/socket/connect_spec.rb
index 7fceb47b00..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/connect_spec.rb
+++ b/spec/ruby/library/socket/socket/connect_spec.rb
@@ -1,74 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#connect' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM)
- @client = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns 0 when connected successfully using a String' do
- @server.listen(1)
-
- @client.connect(@server.getsockname).should == 0
- end
-
- it 'returns 0 when connected successfully using an Addrinfo' do
- @server.listen(1)
-
- @client.connect(@server.connect_address).should == 0
- end
-
- it 'raises Errno::EISCONN when already connected' do
- @server.listen(1)
-
- @client.connect(@server.getsockname).should == 0
-
- -> {
- @client.connect(@server.getsockname)
-
- # A second call needed if non-blocking sockets become default
- # XXX honestly I don't expect any real code to care about this spec
- # as it's too implementation-dependent and checking for connect()
- # errors is futile anyways because of TOCTOU
- @client.connect(@server.getsockname)
- }.should raise_error(Errno::EISCONN)
- end
-
- platform_is_not :darwin do
- it 'raises Errno::ECONNREFUSED or Errno::ETIMEDOUT when the connection failed' do
- begin
- @client.connect(@server.getsockname)
- rescue => e
- [Errno::ECONNREFUSED, Errno::ETIMEDOUT].include?(e.class).should == true
- end
- end
- end
- end
-
- ruby_version_is "3.4" do
- it "fails with timeout" do
- # TEST-NET-1 IP address are reserved for documentation and example purposes.
- address = Socket.pack_sockaddr_in(1, "192.0.2.1")
-
- client = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
- client.timeout = 0
-
- -> {
- begin
- client.connect(address)
- rescue Errno::ECONNREFUSED
- skip "Outgoing packets may be filtered"
- end
- }.should raise_error(IO::TimeoutError)
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/for_fd_spec.rb b/spec/ruby/library/socket/socket/for_fd_spec.rb
index e89228d436..6688988448 100644
--- a/spec/ruby/library/socket/socket/for_fd_spec.rb
+++ b/spec/ruby/library/socket/socket/for_fd_spec.rb
@@ -1,5 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require 'socket'
describe "Socket.for_fd" do
before :each do
diff --git a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
index e0eff3cef4..fa8112c010 100644
--- a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
+++ b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
@@ -1,7 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-describe "Socket.getaddrinfo" do
+require 'socket'
+
+describe "Socket#getaddrinfo" do
before :each do
@do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
BasicSocket.do_not_reverse_lookup = true
@@ -51,10 +53,10 @@ describe "Socket.getaddrinfo" do
end
end
- # #getaddrinfo will return a INADDR_ANY address (0.0.0.0 or "::")
- # if it's a passive socket. In the case of non-passive
+ # #getaddrinfo will return a INADDR_ANY address (0.0.0.0
+ # or "::") if it's a passive socket. In the case of non-passive
# sockets (AI_PASSIVE not set) it should return the loopback
- # address (127.0.0.1 or "::1").
+ # address (127.0.0.1 or "::1".
it "accepts empty addresses for IPv4 passive sockets" do
res = Socket.getaddrinfo(nil, "discard",
@@ -90,7 +92,7 @@ describe "Socket.getaddrinfo" do
["AF_INET6", 9, "::", "::", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP],
["AF_INET6", 9, "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0:0", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP]
]
- res.each { |a| expected.should include(a) }
+ res.each { |a| expected.should include (a) }
end
it "accepts empty addresses for IPv6 non-passive sockets" do
@@ -108,266 +110,3 @@ describe "Socket.getaddrinfo" do
end
end
end
-
-describe 'Socket.getaddrinfo' do
- describe 'without global reverse lookups' do
- it 'returns an Array' do
- Socket.getaddrinfo(nil, 'ftp').should be_an_instance_of(Array)
- end
-
- it 'accepts an Integer as the address family' do
- array = Socket.getaddrinfo(nil, 'ftp', Socket::AF_INET)[0]
-
- array[0].should == 'AF_INET'
- array[1].should == 21
- array[2].should == '127.0.0.1'
- array[3].should == '127.0.0.1'
- array[4].should == Socket::AF_INET
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts an Integer as the address family using IPv6' do
- array = Socket.getaddrinfo(nil, 'ftp', Socket::AF_INET6)[0]
-
- array[0].should == 'AF_INET6'
- array[1].should == 21
- array[2].should == '::1'
- array[3].should == '::1'
- array[4].should == Socket::AF_INET6
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts a Symbol as the address family' do
- array = Socket.getaddrinfo(nil, 'ftp', :INET)[0]
-
- array[0].should == 'AF_INET'
- array[1].should == 21
- array[2].should == '127.0.0.1'
- array[3].should == '127.0.0.1'
- array[4].should == Socket::AF_INET
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts a Symbol as the address family using IPv6' do
- array = Socket.getaddrinfo(nil, 'ftp', :INET6)[0]
-
- array[0].should == 'AF_INET6'
- array[1].should == 21
- array[2].should == '::1'
- array[3].should == '::1'
- array[4].should == Socket::AF_INET6
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts a String as the address family' do
- array = Socket.getaddrinfo(nil, 'ftp', 'INET')[0]
-
- array[0].should == 'AF_INET'
- array[1].should == 21
- array[2].should == '127.0.0.1'
- array[3].should == '127.0.0.1'
- array[4].should == Socket::AF_INET
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts a String as the address family using IPv6' do
- array = Socket.getaddrinfo(nil, 'ftp', 'INET6')[0]
-
- array[0].should == 'AF_INET6'
- array[1].should == 21
- array[2].should == '::1'
- array[3].should == '::1'
- array[4].should == Socket::AF_INET6
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts an object responding to #to_str as the host' do
- dummy = mock(:dummy)
-
- dummy.stub!(:to_str).and_return('127.0.0.1')
-
- array = Socket.getaddrinfo(dummy, 'ftp')[0]
-
- array[0].should == 'AF_INET'
- array[1].should == 21
- array[2].should == '127.0.0.1'
- array[3].should == '127.0.0.1'
- array[4].should == Socket::AF_INET
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts an object responding to #to_str as the address family' do
- dummy = mock(:dummy)
-
- dummy.stub!(:to_str).and_return('INET')
-
- array = Socket.getaddrinfo(nil, 'ftp', dummy)[0]
-
- array[0].should == 'AF_INET'
- array[1].should == 21
- array[2].should == '127.0.0.1'
- array[3].should == '127.0.0.1'
- array[4].should == Socket::AF_INET
- array[5].should be_kind_of(Integer)
- array[6].should be_kind_of(Integer)
- end
-
- it 'accepts an Integer as the socket type' do
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0]
- array.should == [
- 'AF_INET',
- 21,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
-
- it 'accepts a Symbol as the socket type' do
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0]
- array.should == [
- 'AF_INET',
- 21,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
-
- it 'accepts a String as the socket type' do
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0]
- array.should == [
- 'AF_INET',
- 21,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
-
- it 'accepts an object responding to #to_str as the socket type' do
- dummy = mock(:dummy)
-
- dummy.stub!(:to_str).and_return('STREAM')
-
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0]
- array.should == [
- 'AF_INET',
- 21,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
-
- platform_is_not :windows do
- it 'accepts an Integer as the protocol family' do
- *array, proto = Socket.getaddrinfo(nil, 'discard', :INET, :DGRAM, Socket::IPPROTO_UDP)[0]
- array.should == [
- 'AF_INET',
- 9,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_DGRAM,
- ]
- [0, Socket::IPPROTO_UDP].should include(proto)
- end
- end
-
- it 'accepts an Integer as the flags' do
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
- Socket::IPPROTO_TCP, Socket::AI_PASSIVE)[0]
- array.should == [
- 'AF_INET',
- 21,
- '0.0.0.0',
- '0.0.0.0',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
-
- it 'performs a reverse lookup when the reverse_lookup argument is true' do
- addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
- Socket::IPPROTO_TCP, 0, true)[0]
-
- addr[0].should == 'AF_INET'
- addr[1].should == 21
-
- addr[2].should be_an_instance_of(String)
- addr[2].should_not == addr[3]
-
- addr[3].should == '127.0.0.1'
- end
-
- it 'performs a reverse lookup when the reverse_lookup argument is :hostname' do
- addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
- Socket::IPPROTO_TCP, 0, :hostname)[0]
-
- addr[0].should == 'AF_INET'
- addr[1].should == 21
-
- addr[2].should be_an_instance_of(String)
- addr[2].should_not == addr[3]
-
- addr[3].should == '127.0.0.1'
- end
-
- it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do
- *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
- Socket::IPPROTO_TCP, 0, :numeric)[0]
- array.should == [
- 'AF_INET',
- 21,
- '127.0.0.1',
- '127.0.0.1',
- Socket::AF_INET,
- Socket::SOCK_STREAM,
- ]
- [0, Socket::IPPROTO_TCP].should include(proto)
- end
- end
-
- describe 'with global reverse lookups' do
- before do
- @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
- BasicSocket.do_not_reverse_lookup = false
- end
-
- after do
- BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
- end
-
- it 'returns an address honoring the global lookup option' do
- addr = Socket.getaddrinfo(nil, 'ftp', :INET)[0]
-
- addr[0].should == 'AF_INET'
- addr[1].should == 21
-
- # We don't have control over this value and there's no way to test this
- # without relying on Socket.getaddrinfo()'s own behaviour (meaning this
- # test would faily any way of the method was not implemented correctly).
- addr[2].should be_an_instance_of(String)
- addr[2].should_not == addr[3]
-
- addr[3].should == '127.0.0.1'
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
index a4c8355520..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
+++ b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
@@ -1,124 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require 'ipaddr'
-
-describe 'Socket.gethostbyaddr' do
- describe 'using an IPv4 address' do
- before do
- @addr = IPAddr.new('127.0.0.1').hton
- end
-
- describe 'without an explicit address family' do
- it 'returns an Array' do
- suppress_warning { Socket.gethostbyaddr(@addr) }.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = suppress_warning { Socket.gethostbyaddr(@addr) }
- end
-
- # RubyCI Solaris 11x defines 127.0.0.1 as unstable11x
- platform_is_not :"solaris2.11" do
- it 'includes the hostname as the first value' do
- @array[0].should == SocketSpecs.hostname_reverse_lookup
- end
- end
-
- it 'includes the aliases as the 2nd value' do
- @array[1].should be_an_instance_of(Array)
-
- @array[1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
-
- it 'includes the address type as the 3rd value' do
- @array[2].should == Socket::AF_INET
- end
-
- it 'includes all address strings as the remaining values' do
- @array[3].should == @addr
-
- @array[4..-1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
- end
- end
-
- describe 'with an explicit address family' do
- it 'returns an Array when using an Integer as the address family' do
- suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET) }.should be_an_instance_of(Array)
- end
-
- it 'returns an Array when using a Symbol as the address family' do
- suppress_warning { Socket.gethostbyaddr(@addr, :INET) }.should be_an_instance_of(Array)
- end
-
- it 'raises SocketError when the address is not supported by the family' do
- -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET6) } }.should raise_error(SocketError)
- end
- end
- end
-
- guard -> { SocketSpecs.ipv6_available? && platform_is_not(:aix) } do
- describe 'using an IPv6 address' do
- before do
- @addr = IPAddr.new('::1').hton
- end
-
- describe 'without an explicit address family' do
- it 'returns an Array' do
- suppress_warning { Socket.gethostbyaddr(@addr) }.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = suppress_warning { Socket.gethostbyaddr(@addr) }
- end
-
- it 'includes the hostname as the first value' do
- @array[0].should == SocketSpecs.hostname_reverse_lookup("::1")
- end
-
- it 'includes the aliases as the 2nd value' do
- @array[1].should be_an_instance_of(Array)
-
- @array[1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
-
- it 'includes the address type as the 3rd value' do
- @array[2].should == Socket::AF_INET6
- end
-
- it 'includes all address strings as the remaining values' do
- @array[3].should be_an_instance_of(String)
-
- @array[4..-1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
- end
- end
-
- describe 'with an explicit address family' do
- it 'returns an Array when using an Integer as the address family' do
- suppress_warning { Socket.gethostbyaddr(@addr, Socket::AF_INET6) }.should be_an_instance_of(Array)
- end
-
- it 'returns an Array when using a Symbol as the address family' do
- suppress_warning { Socket.gethostbyaddr(@addr, :INET6) }.should be_an_instance_of(Array)
- end
-
- platform_is_not :windows, :wsl do
- it 'raises SocketError when the address is not supported by the family' do
- -> { suppress_warning { Socket.gethostbyaddr(@addr, :INET) } }.should raise_error(SocketError)
- end
- end
- end
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb
index 0858e255e4..a93c9ffb98 100644
--- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb
@@ -1,135 +1,17 @@
# -*- encoding: binary -*-
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-describe "Socket.gethostbyname" do
+require 'socket'
+
+describe "Socket#gethostbyname" do
it "returns broadcast address info for '<broadcast>'" do
- addr = suppress_warning { Socket.gethostbyname('<broadcast>') }
- addr.should == ["255.255.255.255", [], 2, "\xFF\xFF\xFF\xFF"]
+ addr = Socket.gethostbyname('<broadcast>');
+ addr.should == ["255.255.255.255", [], 2, "\377\377\377\377"]
end
it "returns broadcast address info for '<any>'" do
- addr = suppress_warning { Socket.gethostbyname('<any>') }
- addr.should == ["0.0.0.0", [], 2, "\x00\x00\x00\x00"]
- end
-end
-
-describe 'Socket.gethostbyname' do
- it 'returns an Array' do
- suppress_warning { Socket.gethostbyname('127.0.0.1') }.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = suppress_warning { Socket.gethostbyname('127.0.0.1') }
- end
-
- it 'includes the hostname as the first value' do
- @array[0].should == '127.0.0.1'
- end
-
- it 'includes the aliases as the 2nd value' do
- @array[1].should be_an_instance_of(Array)
-
- @array[1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
-
- it 'includes the address type as the 3rd value' do
- possible = [Socket::AF_INET, Socket::AF_INET6]
-
- possible.include?(@array[2]).should == true
- end
-
- it 'includes the address strings as the remaining values' do
- @array[3].should be_an_instance_of(String)
-
- @array[4..-1].each do |val|
- val.should be_an_instance_of(String)
- end
- end
- end
-
- describe 'using <broadcast> as the input address' do
- describe 'the returned Array' do
- before do
- @addr = suppress_warning { Socket.gethostbyname('<broadcast>') }
- end
-
- it 'includes the broadcast address as the first value' do
- @addr[0].should == '255.255.255.255'
- end
-
- it 'includes the address type as the 3rd value' do
- @addr[2].should == Socket::AF_INET
- end
-
- it 'includes the address string as the 4th value' do
- @addr[3].should == [255, 255, 255, 255].pack('C4')
- end
- end
- end
-
- describe 'using <any> as the input address' do
- describe 'the returned Array' do
- before do
- @addr = suppress_warning { Socket.gethostbyname('<any>') }
- end
-
- it 'includes the wildcard address as the first value' do
- @addr[0].should == '0.0.0.0'
- end
-
- it 'includes the address type as the 3rd value' do
- @addr[2].should == Socket::AF_INET
- end
-
- it 'includes the address string as the 4th value' do
- @addr[3].should == [0, 0, 0, 0].pack('C4')
- end
- end
- end
-
- describe 'using an IPv4 address' do
- describe 'the returned Array' do
- before do
- @addr = suppress_warning { Socket.gethostbyname('127.0.0.1') }
- end
-
- it 'includes the IP address as the first value' do
- @addr[0].should == '127.0.0.1'
- end
-
- it 'includes the address type as the 3rd value' do
- @addr[2].should == Socket::AF_INET
- end
-
- it 'includes the address string as the 4th value' do
- @addr[3].should == [127, 0, 0, 1].pack('C4')
- end
- end
- end
-
- guard -> { SocketSpecs.ipv6_available? } do
- describe 'using an IPv6 address' do
- describe 'the returned Array' do
- before do
- @addr = suppress_warning { Socket.gethostbyname('::1') }
- end
-
- it 'includes the IP address as the first value' do
- @addr[0].should == '::1'
- end
-
- it 'includes the address type as the 3rd value' do
- @addr[2].should == Socket::AF_INET6
- end
-
- it 'includes the address string as the 4th value' do
- @addr[3].should == [0, 0, 0, 0, 0, 0, 0, 1].pack('n8')
- end
- end
- end
+ addr = Socket.gethostbyname('<any>');
+ addr.should == ["0.0.0.0", [], 2, "\000\000\000\000"]
end
end
diff --git a/spec/ruby/library/socket/socket/gethostname_spec.rb b/spec/ruby/library/socket/socket/gethostname_spec.rb
index 89e1ed496f..c61e6b3eb4 100644
--- a/spec/ruby/library/socket/socket/gethostname_spec.rb
+++ b/spec/ruby/library/socket/socket/gethostname_spec.rb
@@ -1,16 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket.gethostname" do
- def system_hostname
- # Most platforms implement this POSIX standard:
- `uname -n`.strip
- rescue
- # Only really required for Windows without MSYS/MinGW/Cygwin etc:
- `hostname`.strip
- end
-
it "returns the host name" do
- Socket.gethostname.should == system_hostname
+ Socket.gethostname.should == `hostname`.strip
end
end
diff --git a/spec/ruby/library/socket/socket/getifaddrs_spec.rb b/spec/ruby/library/socket/socket/getifaddrs_spec.rb
deleted file mode 100644
index 7df542abe6..0000000000
--- a/spec/ruby/library/socket/socket/getifaddrs_spec.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-require_relative '../spec_helper'
-
-platform_is_not :aix, :"solaris2.10" do
-describe 'Socket.getifaddrs' do
- before do
- @ifaddrs = Socket.getifaddrs
- end
-
- it 'returns an Array' do
- @ifaddrs.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- it 'should not be empty' do
- @ifaddrs.should_not be_empty
- end
-
- it 'contains instances of Socket::Ifaddr' do
- @ifaddrs.each do |ifaddr|
- ifaddr.should be_an_instance_of(Socket::Ifaddr)
- end
- end
- end
-
- describe 'each returned Socket::Ifaddr' do
- it 'has an interface index' do
- @ifaddrs.each do |ifaddr|
- ifaddr.ifindex.should be_kind_of(Integer)
- end
- end
-
- it 'has an interface name' do
- @ifaddrs.each do |ifaddr|
- ifaddr.name.should be_an_instance_of(String)
- end
- end
-
- it 'has a set of flags' do
- @ifaddrs.each do |ifaddr|
- ifaddr.flags.should be_kind_of(Integer)
- end
- end
- end
-
- describe 'the Socket::Ifaddr address' do
- before do
- @addrs = @ifaddrs.map(&:addr).compact
- end
-
- it 'is an Addrinfo' do
- @addrs.all? do |addr|
- addr.should be_an_instance_of(Addrinfo)
- true
- end.should be_true
- end
-
- it 'has an address family' do
- @addrs.all? do |addr|
- addr.afamily.should be_kind_of(Integer)
- addr.afamily.should_not == Socket::AF_UNSPEC
- true
- end.should be_true
- end
- end
-
- platform_is_not :windows do
- describe 'the Socket::Ifaddr broadcast address' do
- before do
- @addrs = @ifaddrs.map(&:broadaddr).compact
- end
-
- it 'is an Addrinfo' do
- @addrs.all? do |addr|
- addr.should be_an_instance_of(Addrinfo)
- true
- end.should be_true
- end
-
- it 'has an address family' do
- @addrs.all? do |addr|
- addr.afamily.should be_kind_of(Integer)
- addr.afamily.should_not == Socket::AF_UNSPEC
- true
- end.should be_true
- end
- end
-
- describe 'the Socket::Ifaddr netmask address' do
- before do
- @addrs = @ifaddrs.map(&:netmask).compact.select(&:ip?)
- end
-
- it 'is an Addrinfo' do
- @addrs.all? do |addr|
- addr.should be_an_instance_of(Addrinfo)
- true
- end.should be_true
- end
-
- it 'has an address family' do
- @addrs.all? do |addr|
- addr.afamily.should be_kind_of(Integer)
- addr.afamily.should_not == Socket::AF_UNSPEC
- true
- end.should be_true
- end
-
- it 'has an IP address' do
- @addrs.all? do |addr|
- addr.ip_address.should be_an_instance_of(String)
- true
- end.should be_true
- end
- end
- end
-end
-end
diff --git a/spec/ruby/library/socket/socket/getnameinfo_spec.rb b/spec/ruby/library/socket/socket/getnameinfo_spec.rb
index 4f13bf484d..9fc55dd61b 100644
--- a/spec/ruby/library/socket/socket/getnameinfo_spec.rb
+++ b/spec/ruby/library/socket/socket/getnameinfo_spec.rb
@@ -1,5 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+require 'socket'
describe "Socket.getnameinfo" do
before :each do
@@ -60,88 +62,5 @@ describe "Socket.getnameinfo" do
name_info = Socket.getnameinfo ["AF_INET", 9, 'foo', '127.0.0.1']
name_info[1].should == 'discard'
end
-end
-
-describe 'Socket.getnameinfo' do
- describe 'using a String as the first argument' do
- before do
- @addr = Socket.sockaddr_in(21, '127.0.0.1')
- end
-
- it 'raises SocketError or TypeError when using an invalid String' do
- -> { Socket.getnameinfo('cats') }.should raise_error(Exception) { |e|
- (e.is_a?(SocketError) || e.is_a?(TypeError)).should == true
- }
- end
-
- describe 'without custom flags' do
- it 'returns an Array containing the hostname and service name' do
- Socket.getnameinfo(@addr).should == [SocketSpecs.hostname_reverse_lookup, 'ftp']
- end
- end
-
- describe 'using NI_NUMERICHOST as the flag' do
- it 'returns an Array containing the numeric hostname and service name' do
- array = Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST)
-
- %w{127.0.0.1 ::1}.include?(array[0]).should == true
-
- array[1].should == 'ftp'
- end
- end
- end
- SocketSpecs.each_ip_protocol do |family, ip_address, family_name|
- before do
- @hostname = SocketSpecs.hostname_reverse_lookup(ip_address)
- end
-
- describe 'using a 3 element Array as the first argument' do
- before do
- @addr = [family_name, 21, @hostname]
- end
-
- it 'raises ArgumentError when using an invalid Array' do
- -> { Socket.getnameinfo([family_name]) }.should raise_error(ArgumentError)
- end
-
- platform_is_not :windows do
- describe 'using NI_NUMERICHOST as the flag' do
- it 'returns an Array containing the numeric hostname and service name' do
- Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'ftp']
- end
- end
- end
- end
-
- describe 'using a 4 element Array as the first argument' do
- before do
- @addr = [family_name, 21, ip_address, ip_address]
- end
-
- describe 'without custom flags' do
- it 'returns an Array containing the hostname and service name' do
- array = Socket.getnameinfo(@addr)
- array.should be_an_instance_of(Array)
- array[0].should == @hostname
- array[1].should == 'ftp'
- end
-
- it 'uses the 3rd value as the hostname if the 4th is not present' do
- addr = [family_name, 21, ip_address, nil]
-
- array = Socket.getnameinfo(addr)
- array.should be_an_instance_of(Array)
- array[0].should == @hostname
- array[1].should == 'ftp'
- end
- end
-
- describe 'using NI_NUMERICHOST as the flag' do
- it 'returns an Array containing the numeric hostname and service name' do
- Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'ftp']
- end
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/socket/getservbyname_spec.rb b/spec/ruby/library/socket/socket/getservbyname_spec.rb
index d361e619f2..a48b5753b4 100644
--- a/spec/ruby/library/socket/socket/getservbyname_spec.rb
+++ b/spec/ruby/library/socket/socket/getservbyname_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket#getservbyname" do
it "returns the port for service 'discard'" do
@@ -10,14 +10,6 @@ describe "Socket#getservbyname" do
Socket.getservbyname('discard', 'tcp').should == 9
end
- it 'returns the port for service "ftp"' do
- Socket.getservbyname('ftp').should == 21
- end
-
- it 'returns the port for service "ftp" with protocol "tcp"' do
- Socket.getservbyname('ftp', 'tcp').should == 21
- end
-
it "returns the port for service 'domain' with protocol 'udp'" do
Socket.getservbyname('domain', 'udp').should == 53
end
@@ -27,6 +19,6 @@ describe "Socket#getservbyname" do
end
it "raises a SocketError when the service or port is invalid" do
- -> { Socket.getservbyname('invalid') }.should raise_error(SocketError)
+ lambda { Socket.getservbyname('invalid') }.should raise_error(SocketError)
end
end
diff --git a/spec/ruby/library/socket/socket/getservbyport_spec.rb b/spec/ruby/library/socket/socket/getservbyport_spec.rb
deleted file mode 100644
index 563c592b54..0000000000
--- a/spec/ruby/library/socket/socket/getservbyport_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.getservbyport' do
- platform_is_not :windows do
- it 'returns the service name as a String' do
- Socket.getservbyport(514).should == 'shell'
- end
- end
-
- platform_is :windows do
- it 'returns the service name as a String' do
- Socket.getservbyport(514).should == 'cmd'
- end
- end
-
- it 'returns the service name when using a custom protocol name' do
- Socket.getservbyport(514, 'udp').should == 'syslog'
- end
-
- it 'raises SocketError for an unknown port number' do
- -> { Socket.getservbyport(0) }.should raise_error(SocketError)
- end
-end
diff --git a/spec/ruby/library/socket/socket/initialize_spec.rb b/spec/ruby/library/socket/socket/initialize_spec.rb
deleted file mode 100644
index f8337bcaa5..0000000000
--- a/spec/ruby/library/socket/socket/initialize_spec.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket#initialize' do
- before do
- @socket = nil
- end
-
- after do
- @socket.close if @socket
- end
-
- describe 'using an Integer as the 1st and 2nd arguments' do
- it 'returns a Socket' do
- @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
-
- @socket.should be_an_instance_of(Socket)
- end
- end
-
- describe 'using Symbols as the 1st and 2nd arguments' do
- it 'returns a Socket' do
- @socket = Socket.new(:INET, :STREAM)
-
- @socket.should be_an_instance_of(Socket)
- end
- end
-
- describe 'using Strings as the 1st and 2nd arguments' do
- it 'returns a Socket' do
- @socket = Socket.new('INET', 'STREAM')
-
- @socket.should be_an_instance_of(Socket)
- end
- end
-
- describe 'using objects that respond to #to_str' do
- it 'returns a Socket' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return('AF_INET')
- type.stub!(:to_str).and_return('STREAM')
-
- @socket = Socket.new(family, type)
-
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'raises TypeError when the #to_str method does not return a String' do
- family = mock(:family)
- type = mock(:type)
-
- family.stub!(:to_str).and_return(Socket::AF_INET)
- type.stub!(:to_str).and_return(Socket::SOCK_STREAM)
-
- -> { Socket.new(family, type) }.should raise_error(TypeError)
- end
- end
-
- describe 'using a custom protocol' do
- it 'returns a Socket when using an Integer' do
- @socket = Socket.new(:INET, :STREAM, Socket::IPPROTO_TCP)
-
- @socket.should be_an_instance_of(Socket)
- end
-
- it 'raises TypeError when using a Symbol' do
- -> { Socket.new(:INET, :STREAM, :TCP) }.should raise_error(TypeError)
- end
- end
-
- it 'sets the do_not_reverse_lookup option' do
- @socket = Socket.new(:INET, :STREAM)
-
- @socket.do_not_reverse_lookup.should == Socket.do_not_reverse_lookup
- end
-
- it "sets basic IO accessors" do
- @socket = Socket.new(:INET, :STREAM)
- @socket.lineno.should == 0
- end
-
- it "sets the socket to binary mode" do
- @socket = Socket.new(:INET, :STREAM)
- @socket.binmode?.should be_true
- end
-end
diff --git a/spec/ruby/library/socket/socket/ip_address_list_spec.rb b/spec/ruby/library/socket/socket/ip_address_list_spec.rb
deleted file mode 100644
index f97c2d7f85..0000000000
--- a/spec/ruby/library/socket/socket/ip_address_list_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.ip_address_list' do
- it 'returns an Array' do
- Socket.ip_address_list.should be_an_instance_of(Array)
- end
-
- describe 'the returned Array' do
- before do
- @array = Socket.ip_address_list
- end
-
- it 'is not empty' do
- @array.should_not be_empty
- end
-
- it 'contains Addrinfo objects' do
- @array.each do |klass|
- klass.should be_an_instance_of(Addrinfo)
- end
- end
- end
-
- describe 'each returned Addrinfo' do
- before do
- @array = Socket.ip_address_list
- end
-
- it 'has a non-empty IP address' do
- @array.each do |addr|
- addr.ip_address.should be_an_instance_of(String)
- addr.ip_address.should_not be_empty
- end
- end
-
- it 'has an address family' do
- families = [Socket::AF_INET, Socket::AF_INET6]
-
- @array.each do |addr|
- families.include?(addr.afamily).should == true
- end
- end
-
- it 'uses 0 as the port number' do
- @array.each do |addr|
- addr.ip_port.should == 0
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb b/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb
deleted file mode 100644
index 4f429c089e..0000000000
--- a/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-guard -> { SocketSpecs.ipv6_available? } do
- describe 'Socket#ipv6only!' do
- before do
- @socket = Socket.new(:INET6, :DGRAM)
- end
-
- after do
- @socket.close
- end
-
- it 'enables IPv6 only mode' do
- @socket.ipv6only!
-
- @socket.getsockopt(:IPV6, :V6ONLY).bool.should == true
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/listen_spec.rb b/spec/ruby/library/socket/socket/listen_spec.rb
index 4d2aedab19..bea87f4ec5 100644
--- a/spec/ruby/library/socket/socket/listen_spec.rb
+++ b/spec/ruby/library/socket/socket/listen_spec.rb
@@ -1,9 +1,11 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+include Socket::Constants
describe "Socket#listen" do
before :each do
- @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
+ @socket = Socket.new(AF_INET, SOCK_STREAM, 0)
end
after :each do
@@ -18,49 +20,3 @@ describe "Socket#listen" do
@socket.listen(1).should == 0
end
end
-
-describe 'Socket#listen' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'using a DGRAM socket' do
- before do
- @server = Socket.new(family, :DGRAM)
- @client = Socket.new(family, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'raises Errno::EOPNOTSUPP or Errno::EACCES' do
- -> { @server.listen(1) }.should raise_error { |e|
- [Errno::EOPNOTSUPP, Errno::EACCES].should.include?(e.class)
- }
- end
- end
-
- describe 'using a STREAM socket' do
- before do
- @server = Socket.new(family, :STREAM)
- @client = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns 0' do
- @server.listen(1).should == 0
- end
-
- it "raises when the given argument can't be coerced to an Integer" do
- -> { @server.listen('cats') }.should raise_error(TypeError)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/local_address_spec.rb b/spec/ruby/library/socket/socket/local_address_spec.rb
deleted file mode 100644
index 3687f93a0c..0000000000
--- a/spec/ruby/library/socket/socket/local_address_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket#local_address' do
- before do
- @sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses AF_INET as the address family' do
- @sock.local_address.afamily.should == Socket::AF_INET
- end
-
- it 'uses PF_INET as the protocol family' do
- @sock.local_address.pfamily.should == Socket::PF_INET
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @sock.local_address.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses 0.0.0.0 as the IP address' do
- @sock.local_address.ip_address.should == '0.0.0.0'
- end
-
- platform_is_not :windows do
- it 'uses 0 as the port' do
- @sock.local_address.ip_port.should == 0
- end
- end
-
- it 'uses 0 as the protocol' do
- @sock.local_address.protocol.should == 0
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/new_spec.rb b/spec/ruby/library/socket/socket/new_spec.rb
new file mode 100644
index 0000000000..fcd29e1257
--- /dev/null
+++ b/spec/ruby/library/socket/socket/new_spec.rb
@@ -0,0 +1,2 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb
index ef2a2d4ba9..8c95b948dc 100644
--- a/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb
+++ b/spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/pack_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/pack_sockaddr', __FILE__)
-describe "Socket.pack_sockaddr_in" do
+describe "Socket#pack_sockaddr_in" do
it_behaves_like :socket_pack_sockaddr_in, :pack_sockaddr_in
end
diff --git a/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb
index 1ee0bc6157..aacb6d54dc 100644
--- a/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb
+++ b/spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/pack_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/pack_sockaddr', __FILE__)
describe "Socket#pack_sockaddr_un" do
it_behaves_like :socket_pack_sockaddr_un, :pack_sockaddr_un
diff --git a/spec/ruby/library/socket/socket/pair_spec.rb b/spec/ruby/library/socket/socket/pair_spec.rb
index 8dd470a95e..663ca3f183 100644
--- a/spec/ruby/library/socket/socket/pair_spec.rb
+++ b/spec/ruby/library/socket/socket/pair_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/socketpair'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/socketpair', __FILE__)
-describe "Socket.pair" do
+describe "Socket#pair" do
it_behaves_like :socket_socketpair, :pair
end
diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb
index 5596f91bb8..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb
+++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb
@@ -1,139 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#recvfrom_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :DGRAM)
- @client = Socket.new(family, :DGRAM)
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- describe 'using an unbound socket' do
- it 'raises IO::WaitReadable' do
- -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
- end
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @client.connect(@server.getsockname)
- end
-
- describe 'without any data available' do
- it 'raises IO::WaitReadable' do
- -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
- end
-
- it 'returns :wait_readable with exception: false' do
- @server.recvfrom_nonblock(1, exception: false).should == :wait_readable
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- platform_is_not :windows do
- it 'returns an Array containing the data and an Addrinfo' do
- IO.select([@server])
- ret = @server.recvfrom_nonblock(1)
-
- ret.should be_an_instance_of(Array)
- ret.length.should == 2
- end
- end
-
- it "allows an output buffer as third argument" do
- @client.write('hello')
-
- IO.select([@server])
- buffer = +''
- message, = @server.recvfrom_nonblock(5, 0, buffer)
-
- message.should.equal?(buffer)
- buffer.should == 'hello'
- end
-
- it "preserves the encoding of the given buffer" do
- @client.write('hello')
-
- IO.select([@server])
- buffer = ''.encode(Encoding::ISO_8859_1)
- @server.recvfrom_nonblock(5, 0, buffer)
-
- buffer.encoding.should == Encoding::ISO_8859_1
- end
-
- describe 'the returned data' do
- it 'is the same as the sent data' do
- 5.times do
- @client.write('hello')
-
- IO.select([@server])
- msg, _ = @server.recvfrom_nonblock(5)
-
- msg.should == 'hello'
- end
- end
- end
-
- platform_is_not :windows do
- describe 'the returned Array' do
- before do
- IO.select([@server])
- @array = @server.recvfrom_nonblock(1)
- end
-
- it 'contains the data at index 0' do
- @array[0].should == 'h'
- end
-
- it 'contains an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
- end
-
- describe 'the returned Addrinfo' do
- before do
- IO.select([@server])
- @addr = @server.recvfrom_nonblock(1)[1]
- end
-
- it 'uses AF_INET as the address family' do
- @addr.afamily.should == family
- end
-
- it 'uses SOCK_DGRAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses PF_INET as the protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
-
- it 'uses the IP address of the client' do
- @addr.ip_address.should == ip_address
- end
-
- it 'uses the port of the client' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/recvfrom_spec.rb b/spec/ruby/library/socket/socket/recvfrom_spec.rb
index faf161e4a5..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/recvfrom_spec.rb
+++ b/spec/ruby/library/socket/socket/recvfrom_spec.rb
@@ -1,92 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#recvfrom' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :DGRAM)
- @client = Socket.new(family, :DGRAM)
- end
-
- after do
- @client.close
- @server.close
- end
-
- describe 'using an unbound socket' do
- it 'blocks the caller' do
- -> { @server.recvfrom(1) }.should block_caller
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @client.connect(@server.getsockname)
- end
-
- describe 'without any data available' do
- it 'blocks the caller' do
- -> { @server.recvfrom(1) }.should block_caller
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns an Array containing the data and an Addrinfo' do
- ret = @server.recvfrom(1)
-
- ret.should be_an_instance_of(Array)
- ret.length.should == 2
- end
-
- describe 'the returned Array' do
- before do
- @array = @server.recvfrom(1)
- end
-
- it 'contains the data at index 0' do
- @array[0].should == 'h'
- end
-
- it 'contains an Addrinfo at index 1' do
- @array[1].should be_an_instance_of(Addrinfo)
- end
- end
-
- describe 'the returned Addrinfo' do
- before do
- @addr = @server.recvfrom(1)[1]
- end
-
- it 'uses AF_INET as the address family' do
- @addr.afamily.should == family
- end
-
- it 'uses SOCK_DGRAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses PF_INET as the protocol family' do
- @addr.pfamily.should == family
- end
-
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
-
- it 'uses the IP address of the client' do
- @addr.ip_address.should == ip_address
- end
-
- it 'uses the port of the client' do
- @addr.ip_port.should == @client.local_address.ip_port
- end
- end
- end
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/remote_address_spec.rb b/spec/ruby/library/socket/socket/remote_address_spec.rb
deleted file mode 100644
index 24d60d7f58..0000000000
--- a/spec/ruby/library/socket/socket/remote_address_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#remote_address' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
- @server.listen(1)
-
- @host = @server.local_address.ip_address
- @port = @server.local_address.ip_port
- @client = Socket.new(family, :STREAM, Socket::IPPROTO_TCP)
-
- @client.connect(Socket.sockaddr_in(@port, @host))
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns an Addrinfo' do
- @client.remote_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses AF_INET as the address family' do
- @client.remote_address.afamily.should == family
- end
-
- it 'uses PF_INET as the protocol family' do
- @client.remote_address.pfamily.should == family
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @client.remote_address.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses the correct IP address' do
- @client.remote_address.ip_address.should == @host
- end
-
- it 'uses the correct port' do
- @client.remote_address.ip_port.should == @port
- end
-
- it 'uses 0 as the protocol' do
- @client.remote_address.protocol.should == 0
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/sockaddr_in_spec.rb
index 8ee956ac26..59e0318fda 100644
--- a/spec/ruby/library/socket/socket/sockaddr_in_spec.rb
+++ b/spec/ruby/library/socket/socket/sockaddr_in_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/pack_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/pack_sockaddr', __FILE__)
describe "Socket#sockaddr_in" do
it_behaves_like :socket_pack_sockaddr_in, :sockaddr_in
diff --git a/spec/ruby/library/socket/socket/sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/sockaddr_un_spec.rb
index 8922ff4d6d..fa233587d9 100644
--- a/spec/ruby/library/socket/socket/sockaddr_un_spec.rb
+++ b/spec/ruby/library/socket/socket/sockaddr_un_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/pack_sockaddr'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/pack_sockaddr', __FILE__)
describe "Socket#sockaddr_un" do
it_behaves_like :socket_pack_sockaddr_un, :sockaddr_un
diff --git a/spec/ruby/library/socket/socket/socket_spec.rb b/spec/ruby/library/socket/socket/socket_spec.rb
index 5a3d6733e0..dbaed17af4 100644
--- a/spec/ruby/library/socket/socket/socket_spec.rb
+++ b/spec/ruby/library/socket/socket/socket_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket" do
it "inherits from BasicSocket and IO" do
diff --git a/spec/ruby/library/socket/socket/socketpair_spec.rb b/spec/ruby/library/socket/socket/socketpair_spec.rb
index 551c376d49..80b07170a6 100644
--- a/spec/ruby/library/socket/socket/socketpair_spec.rb
+++ b/spec/ruby/library/socket/socket/socketpair_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/socketpair'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/socketpair', __FILE__)
-describe "Socket.socketpair" do
+describe "Socket#socketpair" do
it_behaves_like :socket_socketpair, :socketpair
end
diff --git a/spec/ruby/library/socket/socket/sysaccept_spec.rb b/spec/ruby/library/socket/socket/sysaccept_spec.rb
index 92ac21124e..fcd29e1257 100644
--- a/spec/ruby/library/socket/socket/sysaccept_spec.rb
+++ b/spec/ruby/library/socket/socket/sysaccept_spec.rb
@@ -1,91 +1,2 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket#sysaccept' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :STREAM)
- @sockaddr = Socket.sockaddr_in(0, ip_address)
- end
-
- after do
- @server.close
- end
-
- platform_is :linux do # hangs on other platforms
- describe 'using an unbound socket' do
- it 'raises Errno::EINVAL' do
- -> { @server.sysaccept }.should raise_error(Errno::EINVAL)
- end
- end
-
- describe "using a bound socket that's not listening" do
- before do
- @server.bind(@sockaddr)
- end
-
- it 'raises Errno::EINVAL' do
- -> { @server.sysaccept }.should raise_error(Errno::EINVAL)
- end
- end
- end
-
- describe "using a bound socket that's listening" do
- before do
- @server.bind(@sockaddr)
- @server.listen(1)
-
- server_ip = @server.local_address.ip_port
- @server_addr = Socket.sockaddr_in(server_ip, ip_address)
- end
-
- after do
- Socket.for_fd(@fd).close if @fd
- end
-
- describe 'without a connected client' do
- before do
- @client = Socket.new(family, :STREAM)
- end
-
- after do
- @client.close
- end
-
- it 'blocks the caller until a connection is available' do
- thread = Thread.new do
- @fd, _ = @server.sysaccept
- end
-
- @client.connect(@server_addr)
-
- thread.value.should be_an_instance_of(Array)
- end
- end
-
- describe 'with a connected client' do
- before do
- @client = Socket.new(family, :STREAM)
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- end
-
- it 'returns an Array containing an Integer and an Addrinfo' do
- @fd, addrinfo = @server.sysaccept
-
- @fd.should be_kind_of(Integer)
- addrinfo.should be_an_instance_of(Addrinfo)
- end
-
- it 'returns a new file descriptor' do
- @fd, _ = @server.sysaccept
-
- @fd.should_not == @client.fileno
- end
- end
- end
- end
-end
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
diff --git a/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb b/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb
deleted file mode 100644
index a46c6df5c6..0000000000
--- a/spec/ruby/library/socket/socket/tcp_server_loop_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket.tcp_server_loop' do
- describe 'when no connections are available' do
- it 'blocks the caller' do
- -> { Socket.tcp_server_loop('127.0.0.1', 0) }.should block_caller
- end
- end
-
- describe 'when a connection is available' do
- before do
- @client = Socket.new(:INET, :STREAM)
- SocketSpecs::ServerLoopPortFinder.cleanup
- end
-
- after do
- @sock.close if @sock
- @client.close
- end
-
- it 'yields a Socket and an Addrinfo' do
- @sock, addr = nil
-
- thread = Thread.new do
- SocketSpecs::ServerLoopPortFinder.tcp_server_loop('127.0.0.1', 0) do |socket, addrinfo|
- @sock = socket
- addr = addrinfo
-
- break
- end
- end
-
- port = SocketSpecs::ServerLoopPortFinder.port
-
- SocketSpecs.loop_with_timeout do
- begin
- @client.connect(Socket.sockaddr_in(port, '127.0.0.1'))
- rescue SystemCallError
- sleep 0.01
- :retry
- end
- end
-
- # At this point the connection has been set up but the thread may not yet
- # have returned, thus we'll need to wait a little longer for it to
- # complete.
- thread.join
-
- @sock.should be_an_instance_of(Socket)
- addr.should be_an_instance_of(Addrinfo)
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb
deleted file mode 100644
index bd496d3015..0000000000
--- a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.tcp_server_sockets' do
- describe 'without a block' do
- before do
- @sockets = nil
- end
-
- after do
- @sockets.each(&:close)
- end
-
- it 'returns an Array of Socket objects' do
- @sockets = Socket.tcp_server_sockets(0)
-
- @sockets.should be_an_instance_of(Array)
- @sockets[0].should be_an_instance_of(Socket)
- end
- end
-
- describe 'with a block' do
- it 'yields the sockets to the supplied block' do
- Socket.tcp_server_sockets(0) do |sockets|
- sockets.should be_an_instance_of(Array)
- sockets[0].should be_an_instance_of(Socket)
- end
- end
-
- it 'closes all sockets after the block returns' do
- sockets = nil
-
- Socket.tcp_server_sockets(0) { |socks| sockets = socks }
-
- sockets.each do |socket|
- socket.should.closed?
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/tcp_spec.rb b/spec/ruby/library/socket/socket/tcp_spec.rb
deleted file mode 100644
index faf020b1ea..0000000000
--- a/spec/ruby/library/socket/socket/tcp_spec.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.tcp' do
- before do
- @server = Socket.new(:INET, :STREAM)
- @client = nil
-
- @server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
- @server.listen(1)
-
- @host = @server.connect_address.ip_address
- @port = @server.connect_address.ip_port
- end
-
- after do
- @client.close if @client && !@client.closed?
- @client = nil
-
- @server.close
- end
-
- it 'returns a Socket when no block is given' do
- @client = Socket.tcp(@host, @port)
-
- @client.should be_an_instance_of(Socket)
- end
-
- it 'yields the Socket when a block is given' do
- Socket.tcp(@host, @port) do |socket|
- socket.should be_an_instance_of(Socket)
- end
- end
-
- it 'closes the Socket automatically when a block is given' do
- Socket.tcp(@host, @port) do |socket|
- @socket = socket
- end
-
- @socket.should.closed?
- end
-
- it 'binds to a local address and port when specified' do
- @client = Socket.tcp(@host, @port, @host, 0)
-
- @client.local_address.ip_address.should == @host
-
- @client.local_address.ip_port.should > 0
- @client.local_address.ip_port.should_not == @port
- end
-
- it 'raises ArgumentError when 6 arguments are provided' do
- -> {
- Socket.tcp(@host, @port, @host, 0, {:connect_timeout => 1}, 10)
- }.should raise_error(ArgumentError)
- end
-
- it 'connects to the server' do
- @client = Socket.tcp(@host, @port)
-
- @client.write('hello')
-
- connection, _ = @server.accept
-
- begin
- connection.recv(5).should == 'hello'
- ensure
- connection.close
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb b/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb
deleted file mode 100644
index cb8c5c5587..0000000000
--- a/spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.udp_server_loop_on' do
- before do
- @server = Socket.new(:INET, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
- end
-
- after do
- @server.close
- end
-
- describe 'when no connections are available' do
- it 'blocks the caller' do
- -> { Socket.udp_server_loop_on([@server]) }.should block_caller
- end
- end
-
- describe 'when a connection is available' do
- before do
- @client = Socket.new(:INET, :DGRAM)
- end
-
- after do
- @client.close
- end
-
- it 'yields the message and a Socket::UDPSource' do
- msg = nil
- src = nil
-
- @client.connect(@server.getsockname)
- @client.write('hello')
-
- Socket.udp_server_loop_on([@server]) do |message, source|
- msg = message
- src = source
-
- break
- end
-
- msg.should == 'hello'
- src.should be_an_instance_of(Socket::UDPSource)
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb
deleted file mode 100644
index fc030e75b9..0000000000
--- a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'Socket.udp_server_loop' do
- describe 'when no connections are available' do
- it 'blocks the caller' do
- -> { Socket.udp_server_loop('127.0.0.1', 0) }.should block_caller
- end
- end
-
- describe 'when a connection is available' do
- before do
- @client = Socket.new(:INET, :DGRAM)
- SocketSpecs::ServerLoopPortFinder.cleanup
- end
-
- after do
- @client.close
- end
-
- it 'yields the message and a Socket::UDPSource' do
- msg, src = nil
-
- thread = Thread.new do
- SocketSpecs::ServerLoopPortFinder.udp_server_loop('127.0.0.1', 0) do |message, source|
- msg = message
- src = source
-
- break
- end
- end
-
- port = SocketSpecs::ServerLoopPortFinder.port
-
- # Because this will return even if the server is up and running (it's UDP
- # after all) we'll have to write and wait until "msg" is set.
- @client.connect(Socket.sockaddr_in(port, '127.0.0.1'))
-
- SocketSpecs.loop_with_timeout do
- begin
- @client.write('hello')
- rescue SystemCallError
- sleep 0.01
- :retry
- else
- unless msg
- sleep 0.001
- :retry
- end
- end
- end
-
- msg.should == 'hello'
- src.should be_an_instance_of(Socket::UDPSource)
-
- thread.join
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/udp_server_recv_spec.rb b/spec/ruby/library/socket/socket/udp_server_recv_spec.rb
deleted file mode 100644
index 47ed74bc03..0000000000
--- a/spec/ruby/library/socket/socket/udp_server_recv_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.udp_server_recv' do
- before do
- @server = Socket.new(:INET, :DGRAM)
- @client = Socket.new(:INET, :DGRAM)
-
- @server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
- @client.connect(@server.getsockname)
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'yields the message and a Socket::UDPSource' do
- msg = :unset
- src = :unset
-
- @client.write('hello')
-
- readable, _, _ = IO.select([@server])
- readable.size.should == 1
-
- Socket.udp_server_recv(readable) do |message, source|
- msg = message
- src = source
- break
- end
-
- msg.should == 'hello'
- src.should be_an_instance_of(Socket::UDPSource)
- end
-end
diff --git a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb
deleted file mode 100644
index f8be672612..0000000000
--- a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'Socket.udp_server_sockets' do
- describe 'without a block' do
- before do
- @sockets = nil
- end
-
- after do
- @sockets.each(&:close)
- end
-
- it 'returns an Array of Socket objects' do
- @sockets = Socket.udp_server_sockets(0)
-
- @sockets.should be_an_instance_of(Array)
- @sockets[0].should be_an_instance_of(Socket)
- end
- end
-
- describe 'with a block' do
- it 'yields the sockets to the supplied block' do
- Socket.udp_server_sockets(0) do |sockets|
- sockets.should be_an_instance_of(Array)
- sockets[0].should be_an_instance_of(Socket)
- end
- end
-
- it 'closes all sockets after the block returns' do
- sockets = nil
-
- Socket.udp_server_sockets(0) { |socks| sockets = socks }
-
- sockets.each do |socket|
- socket.should.closed?
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb b/spec/ruby/library/socket/socket/unix_server_loop_spec.rb
deleted file mode 100644
index 0f34d4a50b..0000000000
--- a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-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
-
- 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
- end
-
- describe 'when a connection is available' do
- before do
- @client = nil
- end
-
- after do
- @sock.close if @sock
- @client.close if @client
- end
-
- 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
-
- break
- end
- end
-
- SocketSpecs.loop_with_timeout do
- begin
- @client = Socket.unix(@path)
- rescue SystemCallError
- sleep 0.01
- :retry
- end
- end
-
- thread.join
-
- @sock.should be_an_instance_of(Socket)
- addr.should be_an_instance_of(Addrinfo)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb b/spec/ruby/library/socket/socket/unix_server_socket_spec.rb
deleted file mode 100644
index fc357740fa..0000000000
--- a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-with_feature :unix_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
- @socket = nil
- end
-
- after do
- @socket.close
- end
-
- it 'returns a Socket' do
- @socket = Socket.unix_server_socket(@path)
-
- @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
- end
-
- it 'closes the Socket when the block returns' do
- socket = nil
-
- Socket.unix_server_socket(@path) do |sock|
- socket = sock
- end
-
- socket.should be_an_instance_of(Socket)
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/unix_spec.rb b/spec/ruby/library/socket/socket/unix_spec.rb
deleted file mode 100644
index 4bff59bd4b..0000000000
--- a/spec/ruby/library/socket/socket/unix_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-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
-
- after do
- @server.close
- @socket.close if @socket
-
- rm_r(@path)
- end
-
- describe 'when no block is given' do
- it 'returns a Socket' do
- @socket = Socket.unix(@path)
-
- @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
- end
-
- it 'closes the Socket when the block returns' do
- socket = nil
-
- Socket.unix(@path) do |sock|
- socket = sock
- end
-
- socket.should.closed?
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
index 79ec68cd18..91d2b947a1 100644
--- a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
+++ b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
@@ -1,7 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require 'socket'
describe "Socket.unpack_sockaddr_in" do
+
it "decodes the host name and port number of a packed sockaddr_in" do
sockaddr = Socket.sockaddr_in 3333, '127.0.0.1'
Socket.unpack_sockaddr_in(sockaddr).should == [3333, '127.0.0.1']
@@ -12,35 +14,16 @@ describe "Socket.unpack_sockaddr_in" do
Socket.unpack_sockaddr_in(addrinfo).should == [3333, '127.0.0.1']
end
- describe 'using an IPv4 address' do
- it 'returns an Array containing the port and IP address' do
- port = 80
- ip = '127.0.0.1'
- addr = Socket.pack_sockaddr_in(port, ip)
-
- Socket.unpack_sockaddr_in(addr).should == [port, ip]
- end
- end
-
- describe 'using an IPv6 address' do
- it 'returns an Array containing the port and IP address' do
- port = 80
- ip = '::1'
- addr = Socket.pack_sockaddr_in(port, ip)
-
- Socket.unpack_sockaddr_in(addr).should == [port, ip]
- end
- end
-
- with_feature :unix_socket do
+ platform_is_not :windows 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)
+ lambda { 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)
+ lambda { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError)
end
end
+
end
diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
index 12f970f89b..f81d36f7e9 100644
--- a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
+++ b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
@@ -1,8 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe 'Socket.unpack_sockaddr_un' do
+describe 'Socket.unpack_sockaddr_un' do
+ platform_is_not :windows do
it 'decodes sockaddr to unix path' do
sockaddr = Socket.sockaddr_un('/tmp/sock')
Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock'
@@ -13,14 +13,14 @@ with_feature :unix_socket do
Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock'
end
- it 'raises an ArgumentError when the sa_family is not AF_UNIX' do
+ it 'raises an ArgumentError when the sin_family is not AF_UNIX' do
sockaddr = Socket.sockaddr_in(0, '127.0.0.1')
- -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError)
+ lambda { 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)
+ lambda { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb
deleted file mode 100644
index 1121542dd5..0000000000
--- a/spec/ruby/library/socket/spec_helper.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require_relative '../../spec_helper'
-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)
-MSpec.enable_feature :ipv6_pktinfo if Socket.const_defined?(:IPV6_PKTINFO)
-MSpec.enable_feature :ip_mtu if Socket.const_defined?(:IP_MTU)
-MSpec.enable_feature :ipv6_nexthop if Socket.const_defined?(:IPV6_NEXTHOP)
-MSpec.enable_feature :tcp_info if Socket.const_defined?(:TCP_INFO)
-MSpec.enable_feature :ancillary_data if Socket.const_defined?(:AncillaryData)
diff --git a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb
index 91f6a327f0..d6f7448084 100644
--- a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::TCPServer.accept_nonblock" do
before :each do
@@ -13,12 +13,12 @@ describe "Socket::TCPServer.accept_nonblock" do
it "accepts non blocking connections" do
@server.listen(5)
- -> {
+ lambda {
@server.accept_nonblock
}.should raise_error(IO::WaitReadable)
c = TCPSocket.new("127.0.0.1", @port)
- IO.select([@server])
+ sleep 0.1
s = @server.accept_nonblock
port, address = Socket.unpack_sockaddr_in(s.getsockname)
@@ -33,52 +33,17 @@ describe "Socket::TCPServer.accept_nonblock" do
it "raises an IOError if the socket is closed" do
@server.close
- -> { @server.accept }.should raise_error(IOError)
+ lambda { @server.accept }.should raise_error(IOError)
end
describe 'without a connected client' do
it 'raises error' do
- -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
+ lambda { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
end
- it 'returns :wait_readable in exceptionless mode' do
- @server.accept_nonblock(exception: false).should == :wait_readable
- end
- end
-end
-
-describe 'TCPServer#accept_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- end
-
- after do
- @server.close
- end
-
- describe 'without a connected client' do
- it 'raises IO::WaitReadable' do
- -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
- end
- end
-
- platform_is_not :windows do # spurious
- describe 'with a connected client' do
- before do
- @client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
- end
-
- after do
- @socket.close if @socket
- @client.close
- end
-
- it 'returns a TCPSocket' do
- IO.select([@server])
- @socket = @server.accept_nonblock
- @socket.should be_an_instance_of(TCPSocket)
- end
+ ruby_version_is '2.3' do
+ it 'returns :wait_readable in exceptionless mode' do
+ @server.accept_nonblock(exception: false).should == :wait_readable
end
end
end
diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb
index d8892cd5f0..e7a1d87dbe 100644
--- a/spec/ruby/library/socket/tcpserver/accept_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb
@@ -1,5 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
describe "TCPServer#accept" do
before :each do
@@ -58,75 +59,8 @@ describe "TCPServer#accept" do
t.join
end
- it "is automatically retried when interrupted by SIGVTALRM" do
- t = Thread.new do
- client = @server.accept
- value = client.read(2)
- client.close
- value
- end
-
- Thread.pass while t.status and t.status != "sleep"
- # Thread#backtrace uses SIGVTALRM on TruffleRuby and potentially other implementations.
- # Sending a signal to a thread is not possible with Ruby APIs.
- t.backtrace.join("\n").should =~ /in [`'](?:TCPServer#)?accept'/
-
- socket = TCPSocket.new('127.0.0.1', @port)
- socket.write("OK")
- socket.close
-
- t.value.should == "OK"
- end
-
it "raises an IOError if the socket is closed" do
@server.close
- -> { @server.accept }.should raise_error(IOError)
- end
-end
-
-describe 'TCPServer#accept' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- end
-
- after do
- @server.close
- end
-
- describe 'without a connected client' do
- it 'blocks the caller' do
- -> { @server.accept }.should block_caller
- end
- end
-
- describe 'with a connected client' do
- before do
- @client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
- end
-
- after do
- @socket.close if @socket
- @client.close
- end
-
- it 'returns a TCPSocket' do
- @socket = @server.accept
- @socket.should be_an_instance_of(TCPSocket)
- end
-
- platform_is_not :windows do
- it "returns a TCPSocket which is set to nonblocking" do
- require 'io/nonblock'
- @socket = @server.accept
- @socket.should.nonblock?
- end
- end
-
- it "returns a TCPSocket which is set to close on exec" do
- @socket = @server.accept
- @socket.should.close_on_exec?
- end
- end
+ lambda { @server.accept }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/socket/tcpserver/gets_spec.rb b/spec/ruby/library/socket/tcpserver/gets_spec.rb
index 417976d737..86ba65eae2 100644
--- a/spec/ruby/library/socket/tcpserver/gets_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/gets_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "TCPServer#gets" do
before :each do
@@ -11,6 +11,6 @@ describe "TCPServer#gets" do
end
it "raises Errno::ENOTCONN on gets" do
- -> { @server.gets }.should raise_error(Errno::ENOTCONN)
+ lambda { @server.gets }.should raise_error(Errno::ENOTCONN)
end
end
diff --git a/spec/ruby/library/socket/tcpserver/initialize_spec.rb b/spec/ruby/library/socket/tcpserver/initialize_spec.rb
deleted file mode 100644
index 4ddd1f465f..0000000000
--- a/spec/ruby/library/socket/tcpserver/initialize_spec.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'TCPServer#initialize' do
- describe 'with a single Integer argument' do
- before do
- @server = TCPServer.new(0)
- end
-
- after do
- @server.close
- end
-
- it 'sets the port to the given argument' do
- @server.local_address.ip_port.should be_kind_of(Integer)
- @server.local_address.ip_port.should > 0
- end
-
- platform_is_not :windows do
- it 'sets the hostname to 0.0.0.0 or ::' do
- a = @server.local_address
- a.ip_address.should == (a.ipv6? ? '::' : '0.0.0.0')
- end
- end
-
- it "sets the socket to binmode" do
- @server.binmode?.should be_true
- end
- end
-
- describe 'with a single String argument containing a numeric value' do
- before do
- @server = TCPServer.new('0')
- end
-
- after do
- @server.close
- end
-
- it 'sets the port to the given argument' do
- @server.local_address.ip_port.should be_kind_of(Integer)
- @server.local_address.ip_port.should > 0
- end
-
- platform_is_not :windows do
- it 'sets the hostname to 0.0.0.0 or ::' do
- a = @server.local_address
- a.ip_address.should == (a.ipv6? ? '::' : '0.0.0.0')
- end
- end
- end
-
- describe 'with a single String argument containing a non numeric value' do
- it 'raises SocketError' do
- -> { TCPServer.new('cats') }.should raise_error(SocketError)
- end
- end
-
- describe 'with a String and an Integer' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- end
-
- after do
- @server.close
- end
-
- it 'sets the port to the given port argument' do
- @server.local_address.ip_port.should be_kind_of(Integer)
- @server.local_address.ip_port.should > 0
- end
-
- it 'sets the hostname to the given host argument' do
- @server.local_address.ip_address.should == ip_address
- end
- end
- end
-
- describe 'with a String and a custom object' do
- before do
- dummy = mock(:dummy)
- dummy.stub!(:to_str).and_return('0')
-
- @server = TCPServer.new('127.0.0.1', dummy)
- end
-
- after do
- @server.close
- end
-
- it 'sets the port to the given port argument' do
- @server.local_address.ip_port.should be_kind_of(Integer)
- @server.local_address.ip_port.should > 0
- end
-
- it 'sets the hostname to the given host argument' do
- @server.local_address.ip_address.should == '127.0.0.1'
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpserver/listen_spec.rb b/spec/ruby/library/socket/tcpserver/listen_spec.rb
index c877fdced6..d764b4ce70 100644
--- a/spec/ruby/library/socket/tcpserver/listen_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/listen_spec.rb
@@ -1,22 +1,18 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-describe 'TCPServer#listen' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- end
+require 'socket'
- after do
- @server.close
- end
+describe 'TCPServer#listen' do
+ before :each do
+ @server = TCPServer.new(SocketSpecs.hostname, 0)
+ end
- it 'returns 0' do
- @server.listen(1).should == 0
- end
+ after :each do
+ @server.close unless @server.closed?
+ end
- it "raises when the given argument can't be coerced to an Integer" do
- -> { @server.listen('cats') }.should raise_error(TypeError)
- end
+ it 'returns 0' do
+ @server.listen(10).should == 0
end
end
diff --git a/spec/ruby/library/socket/tcpserver/new_spec.rb b/spec/ruby/library/socket/tcpserver/new_spec.rb
index dd1ba676bd..adbc3f303e 100644
--- a/spec/ruby/library/socket/tcpserver/new_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/new_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "TCPServer.new" do
after :each do
@@ -10,7 +10,7 @@ describe "TCPServer.new" do
@server = TCPServer.new('127.0.0.1', 0)
addr = @server.addr
addr[0].should == 'AF_INET'
- addr[1].should be_kind_of(Integer)
+ addr[1].should be_kind_of(Fixnum)
# on some platforms (Mac), MRI
# returns comma at the end.
addr[2].should =~ /^#{SocketSpecs.hostname}\b/
@@ -20,12 +20,12 @@ describe "TCPServer.new" do
it "binds to localhost and a port with either IPv4 or IPv6" do
@server = TCPServer.new(SocketSpecs.hostname, 0)
addr = @server.addr
- addr[1].should be_kind_of(Integer)
+ addr[1].should be_kind_of(Fixnum)
if addr[0] == 'AF_INET'
addr[2].should =~ /^#{SocketSpecs.hostname}\b/
addr[3].should == '127.0.0.1'
else
- addr[2].should =~ /^#{SocketSpecs.hostname('::1')}\b/
+ addr[2].should =~ /^#{SocketSpecs.hostnamev6}\b/
addr[3].should == '::1'
end
end
@@ -34,77 +34,36 @@ describe "TCPServer.new" do
@server = TCPServer.new('', 0)
addr = @server.addr
addr[0].should == 'AF_INET'
- addr[1].should be_kind_of(Integer)
+ addr[1].should be_kind_of(Fixnum)
addr[2].should == '0.0.0.0'
addr[3].should == '0.0.0.0'
end
it "binds to INADDR_ANY if the hostname is empty and the port is a string" do
- @server = TCPServer.new('', '0')
- addr = @server.addr
- addr[0].should == 'AF_INET'
- addr[1].should be_kind_of(Integer)
- addr[2].should == '0.0.0.0'
- addr[3].should == '0.0.0.0'
- end
-
- it "binds to a port if the port is explicitly nil" do
- @server = TCPServer.new('', nil)
- addr = @server.addr
- addr[0].should == 'AF_INET'
- addr[1].should be_kind_of(Integer)
- addr[2].should == '0.0.0.0'
- addr[3].should == '0.0.0.0'
- end
-
- it "binds to a port if the port is an empty string" do
- @server = TCPServer.new('', '')
+ @server = TCPServer.new('', 0)
addr = @server.addr
addr[0].should == 'AF_INET'
- addr[1].should be_kind_of(Integer)
+ addr[1].should be_kind_of(Fixnum)
addr[2].should == '0.0.0.0'
addr[3].should == '0.0.0.0'
end
it "coerces port to string, then determines port from that number or service name" do
- -> { TCPServer.new(SocketSpecs.hostname, Object.new) }.should raise_error(TypeError)
+ lambda { TCPServer.new(SocketSpecs.hostname, Object.new) }.should raise_error(TypeError)
port = Object.new
port.should_receive(:to_str).and_return("0")
@server = TCPServer.new(SocketSpecs.hostname, port)
addr = @server.addr
- addr[1].should be_kind_of(Integer)
+ addr[1].should be_kind_of(Fixnum)
# TODO: This should also accept strings like 'https', but I don't know how to
# pick such a service port that will be able to reliably bind...
end
- it "has a single argument form and treats it as a port number" do
- @server = TCPServer.new(0)
- addr = @server.addr
- addr[1].should be_kind_of(Integer)
- end
-
- it "coerces port to a string when it is the only argument" do
- -> { TCPServer.new(Object.new) }.should raise_error(TypeError)
-
- port = Object.new
- port.should_receive(:to_str).and_return("0")
-
- @server = TCPServer.new(port)
- addr = @server.addr
- addr[1].should be_kind_of(Integer)
- end
-
- it "does not use the given block and warns to use TCPServer::open" do
- -> {
- @server = TCPServer.new(0) { raise }
- }.should complain(/warning: TCPServer::new\(\) does not take block; use TCPServer::open\(\) instead/)
- end
-
it "raises Errno::EADDRNOTAVAIL when the address is unknown" do
- -> { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL)
+ lambda { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL)
end
# There is no way to make this fail-proof on all machines, because
@@ -112,7 +71,7 @@ describe "TCPServer.new" do
# traditionally invalidly named ones.
quarantine! do
it "raises a SocketError when the host is unknown" do
- -> {
+ lambda {
TCPServer.new("--notavalidname", 0)
}.should raise_error(SocketError)
end
@@ -120,7 +79,7 @@ describe "TCPServer.new" do
it "raises Errno::EADDRINUSE when address is already in use" do
@server = TCPServer.new('127.0.0.1', 0)
- -> {
+ lambda {
@server = TCPServer.new('127.0.0.1', @server.addr[1])
}.should raise_error(Errno::EADDRINUSE)
end
diff --git a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb
index bd7d33faf4..93c1ffe152 100644
--- a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb
@@ -1,5 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+require 'socket'
describe "TCPServer#sysaccept" do
before :each do
@@ -12,7 +14,7 @@ describe "TCPServer#sysaccept" do
end
it 'blocks if no connections' do
- -> { @server.sysaccept }.should block_caller
+ lambda { @server.sysaccept }.should block_caller
end
it 'returns file descriptor of an accepted connection' do
@@ -21,46 +23,10 @@ describe "TCPServer#sysaccept" do
fd = @server.sysaccept
- fd.should be_kind_of(Integer)
+ fd.should be_an_instance_of(Fixnum)
ensure
sock.close if sock && !sock.closed?
IO.for_fd(fd).close if fd
end
end
end
-
-describe 'TCPServer#sysaccept' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- end
-
- after do
- @server.close
- end
-
- describe 'without a connected client' do
- it 'blocks the caller' do
- -> { @server.sysaccept }.should block_caller
- end
- end
-
- describe 'with a connected client' do
- before do
- @client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
- end
-
- after do
- Socket.for_fd(@fd).close if @fd
- @client.close
- end
-
- it 'returns a new file descriptor as an Integer' do
- @fd = @server.sysaccept
-
- @fd.should be_kind_of(Integer)
- @fd.should_not == @client.fileno
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
index f0e98778f5..11838aca27 100644
--- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
@@ -1,12 +1,10 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
# TODO: verify these for windows
describe "TCPSocket#gethostbyname" do
before :each do
- suppress_warning do
- @host_info = TCPSocket.gethostbyname(SocketSpecs.hostname)
- end
+ @host_info = TCPSocket.gethostbyname(SocketSpecs.hostname)
end
it "returns an array elements of information on the hostname" do
@@ -51,69 +49,3 @@ describe "TCPSocket#gethostbyname" do
@host_info[1].should be_kind_of(Array)
end
end
-
-describe 'TCPSocket#gethostbyname' do
- it 'returns an Array' do
- suppress_warning do
- TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array)
- end
- end
-
- describe 'using a hostname' do
- describe 'the returned Array' do
- before do
- suppress_warning do
- @array = TCPSocket.gethostbyname('127.0.0.1')
- end
- end
-
- it 'includes the canonical name as the 1st value' do
- @array[0].should == '127.0.0.1'
- end
-
- it 'includes an array of alternative hostnames as the 2nd value' do
- @array[1].should be_an_instance_of(Array)
- end
-
- it 'includes the address family as the 3rd value' do
- @array[2].should be_kind_of(Integer)
- end
-
- it 'includes the IP addresses as all the remaining values' do
- ips = %w{::1 127.0.0.1}
-
- ips.include?(@array[3]).should == true
-
- # Not all machines might have both IPv4 and IPv6 set up, so this value is
- # optional.
- ips.include?(@array[4]).should == true if @array[4]
- end
- end
- end
-
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'the returned Array' do
- before do
- suppress_warning do
- @array = TCPSocket.gethostbyname(ip_address)
- end
- end
-
- it 'includes the IP address as the 1st value' do
- @array[0].should == ip_address
- end
-
- it 'includes an empty list of aliases as the 2nd value' do
- @array[1].should == []
- end
-
- it 'includes the address family as the 3rd value' do
- @array[2].should == family
- end
-
- it 'includes the IP address as the 4th value' do
- @array[3].should == ip_address
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb
deleted file mode 100644
index d7feb9751b..0000000000
--- a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative 'shared/new'
-
-describe 'TCPSocket#initialize' do
- it_behaves_like :tcpsocket_new, :new
-
- describe "with a running server" do
- before :each do
- @server = SocketSpecs::SpecTCPServer.new
- @hostname = @server.hostname
- end
-
- after :each do
- if @socket
- @socket.write "QUIT"
- @socket.close
- end
- @server.shutdown
- end
-
- it "does not use the given block and warns to use TCPSocket::open" do
- -> {
- @socket = TCPSocket.new(@hostname, @server.port, nil) { raise }
- }.should complain(/warning: TCPSocket::new\(\) does not take block; use TCPSocket::open\(\) instead/)
- end
- end
-end
-
-describe 'TCPSocket#initialize' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- describe 'when no server is listening on the given address' do
- it 'raises Errno::ECONNREFUSED' do
- -> { TCPSocket.new(ip_address, 666) }.should raise_error(Errno::ECONNREFUSED)
- end
- end
-
- describe 'when a server is listening on the given address' do
- before do
- @server = TCPServer.new(ip_address, 0)
- @port = @server.connect_address.ip_port
- end
-
- after do
- @client.close if @client
- @server.close
- end
-
- it 'returns a TCPSocket when using an Integer as the port' do
- @client = TCPSocket.new(ip_address, @port)
- @client.should be_an_instance_of(TCPSocket)
- end
-
- it 'returns a TCPSocket when using a String as the port' do
- @client = TCPSocket.new(ip_address, @port.to_s)
- @client.should be_an_instance_of(TCPSocket)
- end
-
- it 'raises SocketError when the port number is a non numeric String' do
- -> { TCPSocket.new(ip_address, 'cats') }.should raise_error(SocketError)
- end
-
- it 'set the socket to binmode' do
- @client = TCPSocket.new(ip_address, @port)
- @client.binmode?.should be_true
- end
-
- it 'connects to the right address' do
- @client = TCPSocket.new(ip_address, @port)
-
- @client.remote_address.ip_address.should == @server.local_address.ip_address
- @client.remote_address.ip_port.should == @server.local_address.ip_port
- end
-
- platform_is_not :windows do
- it "creates a socket which is set to nonblocking" do
- require 'io/nonblock'
- @client = TCPSocket.new(ip_address, @port)
- @client.should.nonblock?
- end
- end
-
- it "creates a socket which is set to close on exec" do
- @client = TCPSocket.new(ip_address, @port)
- @client.should.close_on_exec?
- end
-
- describe 'using a local address and service' do
- it 'binds the client socket to the local address and service' do
- @client = TCPSocket.new(ip_address, @port, ip_address, 0)
-
- @client.local_address.ip_address.should == ip_address
-
- @client.local_address.ip_port.should > 0
- @client.local_address.ip_port.should_not == @port
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb b/spec/ruby/library/socket/tcpsocket/local_address_spec.rb
deleted file mode 100644
index ce66d5ff8f..0000000000
--- a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'TCPSocket#local_address' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @host = @server.connect_address.ip_address
- @port = @server.connect_address.ip_port
- end
-
- after do
- @server.close
- end
-
- describe 'using an explicit hostname' do
- before do
- @sock = TCPSocket.new(@host, @port)
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses AF_INET as the address family' do
- @sock.local_address.afamily.should == family
- end
-
- it 'uses PF_INET as the protocol family' do
- @sock.local_address.pfamily.should == family
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @sock.local_address.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses the correct IP address' do
- @sock.local_address.ip_address.should == @host
- end
-
- it 'uses a randomly assigned local port' do
- @sock.local_address.ip_port.should > 0
- @sock.local_address.ip_port.should_not == @port
- end
-
- it 'uses 0 as the protocol' do
- @sock.local_address.protocol.should == 0
- end
- end
- end
-
- describe 'using an implicit hostname' do
- before do
- @sock = TCPSocket.new(nil, @port)
- end
-
- after do
- @sock.close
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct IP address' do
- @sock.local_address.ip_address.should == @host
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/new_spec.rb b/spec/ruby/library/socket/tcpsocket/new_spec.rb
new file mode 100644
index 0000000000..279576272b
--- /dev/null
+++ b/spec/ruby/library/socket/tcpsocket/new_spec.rb
@@ -0,0 +1,5 @@
+require File.expand_path('../shared/new', __FILE__)
+
+describe "TCPSocket.new" do
+ it_behaves_like :tcpsocket_new, :new
+end
diff --git a/spec/ruby/library/socket/tcpsocket/open_spec.rb b/spec/ruby/library/socket/tcpsocket/open_spec.rb
index 0c0b579064..fb4cc4629a 100644
--- a/spec/ruby/library/socket/tcpsocket/open_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/open_spec.rb
@@ -1,5 +1,4 @@
-require_relative "../../../spec_helper"
-require_relative 'shared/new'
+require File.expand_path('../shared/new', __FILE__)
describe "TCPSocket.open" do
it_behaves_like :tcpsocket_new, :open
diff --git a/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb b/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb
index d365ecd335..6a43eea625 100644
--- a/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/partially_closable_sockets'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
describe "TCPSocket partial closability" do
@@ -16,6 +16,6 @@ describe "TCPSocket partial closability" do
@s2.close
end
- it_should_behave_like :partially_closable_sockets
+ it_should_behave_like "partially closable sockets"
end
diff --git a/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb
index 6ce5a41b58..237ff781a3 100644
--- a/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "TCPSocket#recv_nonblock" do
before :each do
@@ -27,22 +27,10 @@ describe "TCPSocket#recv_nonblock" do
@socket.recv_nonblock(50).should == "TCPSocket#recv_nonblock"
end
- it 'writes the read to a buffer from the socket' do
- @socket = TCPSocket.new @hostname, @server.port
- @socket.write "TCPSocket#recv_nonblock"
-
- # Wait for the server to echo. This spec is testing the return
- # value, not the non-blocking behavior.
- #
- # TODO: Figure out a good way to test non-blocking.
- IO.select([@socket])
- buffer = "".b
- @socket.recv_nonblock(50, 0, buffer)
- buffer.should == 'TCPSocket#recv_nonblock'
- end
-
- it 'returns :wait_readable in exceptionless mode' do
- @socket = TCPSocket.new @hostname, @server.port
- @socket.recv_nonblock(50, exception: false).should == :wait_readable
+ ruby_version_is '2.3' do
+ it 'returns :wait_readable in exceptionless mode' do
+ @socket = TCPSocket.new @hostname, @server.port
+ @socket.recv_nonblock(50, exception: false).should == :wait_readable
+ end
end
end
diff --git a/spec/ruby/library/socket/tcpsocket/recv_spec.rb b/spec/ruby/library/socket/tcpsocket/recv_spec.rb
deleted file mode 100644
index f380db670d..0000000000
--- a/spec/ruby/library/socket/tcpsocket/recv_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'TCPSocket#recv' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
- end
-
- after do
- @client.close
- @server.close
- end
-
- it 'returns the message data' do
- @client.write('hello')
-
- socket = @server.accept
-
- begin
- socket.recv(5).should == 'hello'
- ensure
- socket.close
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb b/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb
deleted file mode 100644
index eb9dabc075..0000000000
--- a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'TCPSocket#remote_address' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = TCPServer.new(ip_address, 0)
- @host = @server.connect_address.ip_address
- @port = @server.connect_address.ip_port
- end
-
- after do
- @server.close
- end
-
- describe 'using an explicit hostname' do
- before do
- @sock = TCPSocket.new(@host, @port)
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.remote_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses AF_INET as the address family' do
- @sock.remote_address.afamily.should == family
- end
-
- it 'uses PF_INET as the protocol family' do
- @sock.remote_address.pfamily.should == family
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @sock.remote_address.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'uses the correct IP address' do
- @sock.remote_address.ip_address.should == @host
- end
-
- it 'uses the correct port' do
- @sock.remote_address.ip_port.should == @port
- end
-
- it 'uses 0 as the protocol' do
- @sock.remote_address.protocol.should == 0
- end
- end
- end
-
- describe 'using an implicit hostname' do
- before do
- @sock = TCPSocket.new(nil, @port)
- end
-
- after do
- @sock.close
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct IP address' do
- @sock.remote_address.ip_address.should == @host
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb b/spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb
index 8b728b7522..8a0cb443b5 100644
--- a/spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "TCPSocket#setsockopt" do
before :each do
diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb
index 90f8d7e6a2..912208c86c 100644
--- a/spec/ruby/library/socket/tcpsocket/shared/new.rb
+++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb
@@ -1,41 +1,19 @@
-require_relative '../../spec_helper'
-require_relative '../../fixtures/classes'
+require File.expand_path('../../../../../spec_helper', __FILE__)
+require File.expand_path('../../../fixtures/classes', __FILE__)
describe :tcpsocket_new, shared: true do
it "requires a hostname and a port as arguments" do
- -> { TCPSocket.send(@method) }.should raise_error(ArgumentError)
+ lambda { TCPSocket.send(@method) }.should raise_error(ArgumentError)
end
it "refuses the connection when there is no server to connect to" do
- -> do
+ lambda do
TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.reserved_unused_port)
end.should raise_error(SystemCallError) {|e|
[Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should include(e.class)
}
end
- ruby_version_is ""..."3.2" do
- it 'raises Errno::ETIMEDOUT with :connect_timeout when no server is listening on the given address' do
- -> {
- TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
- }.should raise_error(Errno::ETIMEDOUT)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
- end
-
- ruby_version_is "3.2" do
- it 'raises IO::TimeoutError with :connect_timeout when no server is listening on the given address' do
- -> {
- TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
- }.should raise_error(IO::TimeoutError)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
- end
-
describe "with a running server" do
before :each do
@server = SocketSpecs::SpecTCPServer.new
@@ -94,13 +72,8 @@ describe :tcpsocket_new, shared: true do
@socket.addr[3].should == SocketSpecs.addr(:ipv6)
end
- @socket.addr[1].should be_kind_of(Integer)
+ @socket.addr[1].should be_kind_of(Fixnum)
@socket.addr[2].should =~ /^#{@hostname}/
end
-
- it "connects to a server when passed connect_timeout argument" do
- @socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1)
- @socket.should be_an_instance_of(TCPSocket)
- end
end
end
diff --git a/spec/ruby/library/socket/udpsocket/bind_spec.rb b/spec/ruby/library/socket/udpsocket/bind_spec.rb
index 08b386e941..bdc3c3d33f 100644
--- a/spec/ruby/library/socket/udpsocket/bind_spec.rb
+++ b/spec/ruby/library/socket/udpsocket/bind_spec.rb
@@ -1,7 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+describe "UDPSocket.bind" do
-describe "UDPSocket#bind" do
before :each do
@socket = UDPSocket.new
end
@@ -18,7 +19,7 @@ describe "UDPSocket#bind" do
it "raises Errno::EINVAL when already bound" do
@socket.bind(SocketSpecs.hostname, 0)
- -> {
+ lambda {
@socket.bind(SocketSpecs.hostname, @socket.addr[1])
}.should raise_error(Errno::EINVAL)
end
@@ -33,51 +34,9 @@ describe "UDPSocket#bind" do
end
it "binds to INADDR_ANY if the hostname is empty" do
- @socket.bind("", 0).should == 0
+ @socket.bind("", 0)
port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
host.should == "0.0.0.0"
port.should == @socket.addr[1]
end
end
-
-describe 'UDPSocket#bind' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @socket = UDPSocket.new(family)
- end
-
- after do
- @socket.close
- end
-
- it 'binds to an address and port' do
- @socket.bind(ip_address, 0).should == 0
-
- @socket.local_address.ip_address.should == ip_address
- @socket.local_address.ip_port.should > 0
- end
-
- it 'binds to an address and port using String arguments' do
- @socket.bind(ip_address, '0').should == 0
-
- @socket.local_address.ip_address.should == ip_address
- @socket.local_address.ip_port.should > 0
- end
-
- it 'can receive data after being bound to an address' do
- @socket.bind(ip_address, 0)
-
- addr = @socket.connect_address
- client = UDPSocket.new(family)
-
- client.connect(addr.ip_address, addr.ip_port)
- client.write('hello')
-
- begin
- @socket.recv(6).should == 'hello'
- ensure
- client.close
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/connect_spec.rb b/spec/ruby/library/socket/udpsocket/connect_spec.rb
deleted file mode 100644
index d92bdeb981..0000000000
--- a/spec/ruby/library/socket/udpsocket/connect_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'UDPSocket#connect' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @socket = UDPSocket.new(family)
- end
-
- after do
- @socket.close
- end
-
- it 'connects to an address even when it is not used' do
- @socket.connect(ip_address, 9996).should == 0
- end
-
- it 'can send data after connecting' do
- receiver = UDPSocket.new(family)
-
- receiver.bind(ip_address, 0)
-
- addr = receiver.connect_address
-
- @socket.connect(addr.ip_address, addr.ip_port)
- @socket.write('hello')
-
- begin
- receiver.recv(6).should == 'hello'
- ensure
- receiver.close
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb
deleted file mode 100644
index ecf0043c10..0000000000
--- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'UDPSocket#initialize' do
- after do
- @socket.close if @socket
- end
-
- it 'initializes a new UDPSocket' do
- @socket = UDPSocket.new
- @socket.should be_an_instance_of(UDPSocket)
- end
-
- it 'initializes a new UDPSocket using an Integer' do
- @socket = UDPSocket.new(Socket::AF_INET)
- @socket.should be_an_instance_of(UDPSocket)
- end
-
- it 'initializes a new UDPSocket using a Symbol' do
- @socket = UDPSocket.new(:INET)
- @socket.should be_an_instance_of(UDPSocket)
- end
-
- it 'initializes a new UDPSocket using a String' do
- @socket = UDPSocket.new('INET')
- @socket.should be_an_instance_of(UDPSocket)
- end
-
- it 'sets the socket to binmode' do
- @socket = UDPSocket.new(:INET)
- @socket.binmode?.should be_true
- end
-
- platform_is_not :windows do
- it 'sets the socket to nonblock' do
- require 'io/nonblock'
- @socket = UDPSocket.new(:INET)
- @socket.should.nonblock?
- end
- end
-
- it 'sets the socket to close on exec' do
- @socket = UDPSocket.new(:INET)
- @socket.should.close_on_exec?
- end
-
- it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do
- -> {
- UDPSocket.new(666)
- }.should raise_error(SystemCallError) { |e|
- [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class)
- }
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/inspect_spec.rb b/spec/ruby/library/socket/udpsocket/inspect_spec.rb
deleted file mode 100644
index e212120b14..0000000000
--- a/spec/ruby/library/socket/udpsocket/inspect_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require_relative '../spec_helper'
-
-describe 'UDPSocket#inspect' do
- before do
- @socket = UDPSocket.new
- @socket.bind('127.0.0.1', 0)
- end
-
- after do
- @socket.close
- end
-
- it 'returns a String with the fd, family, address and port' do
- port = @socket.addr[1]
- @socket.inspect.should == "#<UDPSocket:fd #{@socket.fileno}, AF_INET, 127.0.0.1, #{port}>"
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/local_address_spec.rb b/spec/ruby/library/socket/udpsocket/local_address_spec.rb
deleted file mode 100644
index 92e4cc10c7..0000000000
--- a/spec/ruby/library/socket/udpsocket/local_address_spec.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'UDPSocket#local_address' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :DGRAM, Socket::IPPROTO_UDP)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
-
- @host = @server.connect_address.ip_address
- @port = @server.connect_address.ip_port
- end
-
- after do
- @server.close
- end
-
- describe 'using an explicit hostname' do
- before do
- @sock = UDPSocket.new(family)
-
- @sock.connect(@host, @port)
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct address family' do
- @sock.local_address.afamily.should == family
- end
-
- it 'uses the correct protocol family' do
- @sock.local_address.pfamily.should == family
- end
-
- it 'uses SOCK_DGRAM as the socket type' do
- @sock.local_address.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses the correct IP address' do
- @sock.local_address.ip_address.should == @host
- end
-
- it 'uses a randomly assigned local port' do
- @sock.local_address.ip_port.should > 0
- @sock.local_address.ip_port.should_not == @port
- end
-
- it 'uses 0 as the protocol' do
- @sock.local_address.protocol.should == 0
- end
- end
- end
-
- describe 'using an implicit hostname' do
- before do
- @sock = UDPSocket.new(family)
-
- @sock.connect(nil, @port)
- end
-
- after do
- @sock.close
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct IP address' do
- @sock.local_address.ip_address.should == @host
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/new_spec.rb b/spec/ruby/library/socket/udpsocket/new_spec.rb
index 79bfcb624d..f13e605959 100644
--- a/spec/ruby/library/socket/udpsocket/new_spec.rb
+++ b/spec/ruby/library/socket/udpsocket/new_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe 'UDPSocket.new' do
after :each do
@@ -11,7 +11,7 @@ describe 'UDPSocket.new' do
@socket.should be_an_instance_of(UDPSocket)
end
- it 'using Integer argument' do
+ it 'using Fixnum argument' do
@socket = UDPSocket.new(Socket::AF_INET)
@socket.should be_an_instance_of(UDPSocket)
end
@@ -26,14 +26,8 @@ describe 'UDPSocket.new' do
@socket.should be_an_instance_of(UDPSocket)
end
- it "does not use the given block and warns to use UDPSocket::open" do
- -> {
- @socket = UDPSocket.new { raise }
- }.should complain(/warning: UDPSocket::new\(\) does not take block; use UDPSocket::open\(\) instead/)
- end
-
it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT if unsupported family passed' do
- -> { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e|
+ lambda { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e|
[Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class)
}
end
diff --git a/spec/ruby/library/socket/udpsocket/open_spec.rb b/spec/ruby/library/socket/udpsocket/open_spec.rb
index e4dbb2ee2a..188f879ed1 100644
--- a/spec/ruby/library/socket/udpsocket/open_spec.rb
+++ b/spec/ruby/library/socket/udpsocket/open_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "UDPSocket.open" do
after :each do
diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb
deleted file mode 100644
index b804099589..0000000000
--- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'UDPSocket#recvfrom_nonblock' do
- SocketSpecs.each_ip_protocol do |family, ip_address, family_name|
- before do
- @server = UDPSocket.new(family)
- @client = UDPSocket.new(family)
- end
-
- after do
- @client.close
- @server.close
- end
-
- platform_is_not :windows do
- describe 'using an unbound socket' do
- it 'raises IO::WaitReadable' do
- -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
- end
- end
- end
-
- describe 'using a bound socket' do
- before do
- @server.bind(ip_address, 0)
-
- addr = @server.connect_address
-
- @client.connect(addr.ip_address, addr.ip_port)
- end
-
- describe 'without any data available' do
- it 'raises IO::WaitReadable' do
- -> { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
- end
-
- it 'returns :wait_readable with exception: false' do
- @server.recvfrom_nonblock(1, exception: false).should == :wait_readable
- end
- end
-
- platform_is_not :windows do
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns an Array containing the data and an Array' do
- IO.select([@server])
- @server.recvfrom_nonblock(1).should be_an_instance_of(Array)
- end
-
- it 'writes the data to the buffer when one is present' do
- buffer = "".b
- IO.select([@server])
- @server.recvfrom_nonblock(1, 0, buffer)
- buffer.should == 'h'
- end
-
- it "preserves the encoding of the given buffer" do
- buffer = ''.encode(Encoding::ISO_8859_1)
- IO.select([@server])
- message, = @server.recvfrom_nonblock(1, 0, buffer)
-
- message.should.equal?(buffer)
- buffer.encoding.should == Encoding::ISO_8859_1
- end
-
- describe 'the returned Array' do
- before do
- IO.select([@server])
- @array = @server.recvfrom_nonblock(1)
- end
-
- it 'contains the data at index 0' do
- @array[0].should == 'h'
- end
-
- it 'contains an Array at index 1' do
- @array[1].should be_an_instance_of(Array)
- end
- end
-
- describe 'the returned address Array' do
- before do
- IO.select([@server])
- @addr = @server.recvfrom_nonblock(1)[1]
- end
-
- it 'uses the correct address family' do
- @addr[0].should == family_name
- end
-
- it 'uses the port of the client' do
- @addr[1].should == @client.local_address.ip_port
- end
-
- it 'uses the hostname of the client' do
- @addr[2].should == ip_address
- end
-
- it 'uses the IP address of the client' do
- @addr[3].should == ip_address
- end
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb b/spec/ruby/library/socket/udpsocket/remote_address_spec.rb
deleted file mode 100644
index 94889ce560..0000000000
--- a/spec/ruby/library/socket/udpsocket/remote_address_spec.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-describe 'UDPSocket#remote_address' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = Socket.new(family, :DGRAM, Socket::IPPROTO_UDP)
-
- @server.bind(Socket.sockaddr_in(0, ip_address))
-
- @host = @server.connect_address.ip_address
- @port = @server.connect_address.ip_port
- end
-
- after do
- @server.close
- end
-
- describe 'using an explicit hostname' do
- before do
- @sock = UDPSocket.new(family)
-
- @sock.connect(@host, @port)
- end
-
- after do
- @sock.close
- end
-
- it 'returns an Addrinfo' do
- @sock.remote_address.should be_an_instance_of(Addrinfo)
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct address family' do
- @sock.remote_address.afamily.should == family
- end
-
- it 'uses the correct protocol family' do
- @sock.remote_address.pfamily.should == family
- end
-
- it 'uses SOCK_DGRAM as the socket type' do
- @sock.remote_address.socktype.should == Socket::SOCK_DGRAM
- end
-
- it 'uses the correct IP address' do
- @sock.remote_address.ip_address.should == @host
- end
-
- it 'uses the correct port' do
- @sock.remote_address.ip_port.should == @port
- end
-
- it 'uses 0 as the protocol' do
- @sock.remote_address.protocol.should == 0
- end
- end
- end
-
- describe 'using an implicit hostname' do
- before do
- @sock = UDPSocket.new(family)
-
- @sock.connect(nil, @port)
- end
-
- after do
- @sock.close
- end
-
- describe 'the returned Addrinfo' do
- it 'uses the correct IP address' do
- @sock.remote_address.ip_address.should == @host
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/send_spec.rb b/spec/ruby/library/socket/udpsocket/send_spec.rb
index 6dd5f67bea..1a6f44b26e 100644
--- a/spec/ruby/library/socket/udpsocket/send_spec.rb
+++ b/spec/ruby/library/socket/udpsocket/send_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-describe "UDPSocket#send" do
+describe "UDPSocket.send" do
before :each do
@port = nil
@server_thread = Thread.new do
@@ -34,7 +34,7 @@ describe "UDPSocket#send" do
@msg[0].should == "ad hoc"
@msg[1][0].should == "AF_INET"
- @msg[1][1].should be_kind_of(Integer)
+ @msg[1][1].should be_kind_of(Fixnum)
@msg[1][3].should == "127.0.0.1"
end
@@ -46,7 +46,7 @@ describe "UDPSocket#send" do
@msg[0].should == "ad hoc"
@msg[1][0].should == "AF_INET"
- @msg[1][1].should be_kind_of(Integer)
+ @msg[1][1].should be_kind_of(Fixnum)
@msg[1][3].should == "127.0.0.1"
end
@@ -59,14 +59,14 @@ describe "UDPSocket#send" do
@msg[0].should == "connection-based"
@msg[1][0].should == "AF_INET"
- @msg[1][1].should be_kind_of(Integer)
+ @msg[1][1].should be_kind_of(Fixnum)
@msg[1][3].should == "127.0.0.1"
end
- it "raises EMSGSIZE if data is too big" do
+ it "raises EMSGSIZE if data is too too big" do
@socket = UDPSocket.open
begin
- -> do
+ lambda do
@socket.send('1' * 100_000, 0, SocketSpecs.hostname, @port.to_s)
end.should raise_error(Errno::EMSGSIZE)
ensure
@@ -76,79 +76,3 @@ describe "UDPSocket#send" do
end
end
end
-
-describe 'UDPSocket#send' do
- SocketSpecs.each_ip_protocol do |family, ip_address|
- before do
- @server = UDPSocket.new(family)
- @client = UDPSocket.new(family)
-
- @server.bind(ip_address, 0)
-
- @addr = @server.connect_address
- end
-
- after do
- @server.close
- @client.close
- end
-
- describe 'using a disconnected socket' do
- describe 'without a destination address' do
- it "raises #{SocketSpecs.dest_addr_req_error}" do
- -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
-
- describe 'with a destination address as separate arguments' do
- it 'returns the amount of sent bytes' do
- @client.send('hello', 0, @addr.ip_address, @addr.ip_port).should == 5
- end
-
- it 'does not persist the connection after sending data' do
- @client.send('hello', 0, @addr.ip_address, @addr.ip_port)
-
- -> { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
- end
- end
-
- describe 'with a destination address as a single String argument' do
- it 'returns the amount of sent bytes' do
- @client.send('hello', 0, @server.getsockname).should == 5
- end
- end
- end
-
- describe 'using a connected socket' do
- describe 'without an explicit destination address' do
- before do
- @client.connect(@addr.ip_address, @addr.ip_port)
- end
-
- it 'returns the amount of bytes written' do
- @client.send('hello', 0).should == 5
- end
- end
-
- describe 'with an explicit destination address' do
- before do
- @alt_server = UDPSocket.new(family)
-
- @alt_server.bind(ip_address, 0)
- end
-
- after do
- @alt_server.close
- end
-
- it 'sends the data to the given address instead' do
- @client.send('hello', 0, @alt_server.getsockname).should == 5
-
- -> { @server.recv(5) }.should block_caller
-
- @alt_server.recv(5).should == 'hello'
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/udpsocket/write_spec.rb b/spec/ruby/library/socket/udpsocket/write_spec.rb
index c971f29b62..11e38bb470 100644
--- a/spec/ruby/library/socket/udpsocket/write_spec.rb
+++ b/spec/ruby/library/socket/udpsocket/write_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "UDPSocket#write" do
it "raises EMSGSIZE if msg is too long" do
@@ -10,7 +10,7 @@ describe "UDPSocket#write" do
s2 = UDPSocket.new
s2.connect(host, s1.addr[1])
- -> do
+ lambda do
s2.write('1' * 100_000)
end.should raise_error(Errno::EMSGSIZE)
ensure
diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
index dba3de7359..b94e91e879 100644
--- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXServer#accept_nonblock" do
+describe "UNIXServer#accept_nonblock" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -28,61 +29,9 @@ with_feature :unix_socket 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
-
- 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 'with a client' do
- before do
- @client = UNIXSocket.new(@path)
- end
-
- after do
- @client.close
- @socket.close if @socket
- end
-
- 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 data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns a UNIXSocket' 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
- end
+ ruby_version_is '2.3' do
+ it 'returns :wait_readable in exceptionless mode' do
+ @server.accept_nonblock(exception: false).should == :wait_readable
end
end
end
diff --git a/spec/ruby/library/socket/unixserver/accept_spec.rb b/spec/ruby/library/socket/unixserver/accept_spec.rb
index 1305bc6220..3921dadd9d 100644
--- a/spec/ruby/library/socket/unixserver/accept_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_spec.rb
@@ -1,7 +1,7 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
+platform_is_not :windows do
describe "UNIXServer#accept" do
before :each do
@path = SocketSpecs.socket_path
@@ -59,70 +59,3 @@ with_feature :unix_socket do
end
end
end
-
-with_feature :unix_socket 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
- @client = UNIXSocket.new(@path)
- end
-
- after do
- @client.close
- @socket.close if @socket
- end
-
- describe 'without any data' do
- it 'returns a UNIXSocket' do
- @socket = @server.accept
- @socket.should be_an_instance_of(UNIXSocket)
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns a UNIXSocket' do
- @socket = @server.accept
- @socket.should be_an_instance_of(UNIXSocket)
- end
-
- describe 'the returned UNIXSocket' do
- it 'can read the data written' do
- @socket = @server.accept
- @socket.recv(5).should == 'hello'
- end
-
- it "is set to nonblocking" do
- require 'io/nonblock'
- @socket = @server.accept
- @socket.should.nonblock?
- end
-
- it "is set to close on exec" do
- @socket = @server.accept
- @socket.should.close_on_exec?
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/unixserver/for_fd_spec.rb b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
index 8cc55ef391..c3cfd86a1c 100644
--- a/spec/ruby/library/socket/unixserver/for_fd_spec.rb
+++ b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
@@ -1,8 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXServer.for_fd" do
+platform_is_not :windows do
+ describe "UNIXServer#for_fd" do
before :each do
@unix_path = SocketSpecs.socket_path
@unix = UNIXServer.new(@unix_path)
diff --git a/spec/ruby/library/socket/unixserver/initialize_spec.rb b/spec/ruby/library/socket/unixserver/initialize_spec.rb
deleted file mode 100644
index 0cc49ef1eb..0000000000
--- a/spec/ruby/library/socket/unixserver/initialize_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-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
-
- 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 '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
- end
-end
diff --git a/spec/ruby/library/socket/unixserver/listen_spec.rb b/spec/ruby/library/socket/unixserver/listen_spec.rb
deleted file mode 100644
index b90b3bbb09..0000000000
--- a/spec/ruby/library/socket/unixserver/listen_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-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
-
- after do
- @server.close
-
- rm_r(@path)
- end
-
- it 'returns 0' do
- @server.listen(1).should == 0
- end
- end
-end
diff --git a/spec/ruby/library/socket/unixserver/new_spec.rb b/spec/ruby/library/socket/unixserver/new_spec.rb
index a160e3ce5c..d34aa0ca03 100644
--- a/spec/ruby/library/socket/unixserver/new_spec.rb
+++ b/spec/ruby/library/socket/unixserver/new_spec.rb
@@ -1,14 +1,6 @@
-require_relative '../spec_helper'
-require_relative 'shared/new'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/new', __FILE__)
-with_feature :unix_socket do
- 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
- end
+describe "UNIXServer.new" do
+ it_behaves_like :unixserver_new, :new
end
diff --git a/spec/ruby/library/socket/unixserver/open_spec.rb b/spec/ruby/library/socket/unixserver/open_spec.rb
index 16453dd3bd..47c76eb9b4 100644
--- a/spec/ruby/library/socket/unixserver/open_spec.rb
+++ b/spec/ruby/library/socket/unixserver/open_spec.rb
@@ -1,11 +1,10 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative 'shared/new'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/new', __FILE__)
-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
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
end
diff --git a/spec/ruby/library/socket/unixserver/shared/new.rb b/spec/ruby/library/socket/unixserver/shared/new.rb
index b537f2a871..2018140caa 100644
--- a/spec/ruby/library/socket/unixserver/shared/new.rb
+++ b/spec/ruby/library/socket/unixserver/shared/new.rb
@@ -1,20 +1,23 @@
-require_relative '../../spec_helper'
-require_relative '../../fixtures/classes'
+require File.expand_path('../../../../../spec_helper', __FILE__)
+require File.expand_path('../../../fixtures/classes', __FILE__)
+require 'tempfile'
describe :unixserver_new, shared: true do
- before :each do
- @path = SocketSpecs.socket_path
- end
+ platform_is_not :windows do
+ 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 "creates a new UNIXServer" do
- @server = UNIXServer.send(@method, @path)
- @server.path.should == @path
- @server.addr.should == ["AF_UNIX", @path]
+ it "creates a new UNIXServer" do
+ @server = UNIXServer.send(@method, @path)
+ @server.path.should == @path
+ @server.addr.should == ["AF_UNIX", @path]
+ end
end
end
diff --git a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
deleted file mode 100644
index e59731878a..0000000000
--- a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-with_feature :unix_socket 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
- @client = UNIXSocket.new(@path)
- end
-
- after do
- Socket.for_fd(@fd).close if @fd
- @client.close
- 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
- end
- end
- end
-end
diff --git a/spec/ruby/library/socket/unixsocket/addr_spec.rb b/spec/ruby/library/socket/unixsocket/addr_spec.rb
index d93e061312..34c62e083f 100644
--- a/spec/ruby/library/socket/unixsocket/addr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#addr" do
+describe "UNIXSocket#addr" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -15,13 +16,8 @@ with_feature :unix_socket do
SocketSpecs.rm_socket @path
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 path of the socket in an array if it's a server" do
@@ -31,5 +27,10 @@ with_feature :unix_socket do
it "returns an empty string for path if it's a client" do
@client.addr[1].should == ""
end
+
+ it "returns an array" do
+ @client.addr.should be_kind_of(Array)
+ end
end
+
end
diff --git a/spec/ruby/library/socket/unixsocket/initialize_spec.rb b/spec/ruby/library/socket/unixsocket/initialize_spec.rb
deleted file mode 100644
index bf7896ab0e..0000000000
--- a/spec/ruby/library/socket/unixsocket/initialize_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-
-with_feature :unix_socket do
- describe 'UNIXSocket#initialize' do
- describe 'using a non existing path' 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)
- end
-
- after do
- @socket.close
- @server.close
- rm_r(@path)
- end
-
- it 'returns a new UNIXSocket' do
- @socket.should be_an_instance_of(UNIXSocket)
- 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
-
- it 'sets the socket to nonblock' do
- require 'io/nonblock'
- @socket.should.nonblock?
- end
-
- it 'sets the socket to close on exec' do
- @socket.should.close_on_exec?
- end
-
- end
- end
-end
diff --git a/spec/ruby/library/socket/unixsocket/inspect_spec.rb b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
index a542ba6db5..8ea25ec1e9 100644
--- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
@@ -1,8 +1,8 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#inspect" do
+describe "UNIXSocket#inspect" do
+ platform_is_not :windows do
it "returns sockets fd for unnamed sockets" do
begin
s1, s2 = UNIXSocket.socketpair
diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb
deleted file mode 100644
index 734253e7f5..0000000000
--- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-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
-
- 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
-
- 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 PF_UNIX as the protocol family' do
- @client.local_address.pfamily.should == Socket::PF_UNIX
- end
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @client.local_address.socktype.should == Socket::SOCK_STREAM
- end
-
- platform_is_not :aix do
- it 'uses an empty socket path' do
- @client.local_address.unix_path.should == ''
- end
- end
-
- it 'uses 0 as the protocol' do
- @client.local_address.protocol.should == 0
- 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)
- end
-
- after :each do
- @sock.close
- @sock2.close
- end
-
- it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
- 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 PF_UNIX as the protocol family' do
- @sock.local_address.pfamily.should == Socket::PF_UNIX
- end
-
- it 'uses SOCK_STREAM as the socket type' do
- @sock.local_address.socktype.should == Socket::SOCK_STREAM
- end
-
- it 'raises SocketError for #ip_address' do
- -> {
- @sock.local_address.ip_address
- }.should raise_error(SocketError, "need IPv4 or IPv6 address")
- 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
-end
diff --git a/spec/ruby/library/socket/unixsocket/new_spec.rb b/spec/ruby/library/socket/unixsocket/new_spec.rb
index 6d8ea6dcfe..7db8613b96 100644
--- a/spec/ruby/library/socket/unixsocket/new_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/new_spec.rb
@@ -1,14 +1,6 @@
-require_relative '../spec_helper'
-require_relative 'shared/new'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/new', __FILE__)
-with_feature :unix_socket do
- 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
- end
+describe "UNIXSocket.new" do
+ it_behaves_like :unixsocket_new, :new
end
diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb
index 61def30abb..5b9b19ee33 100644
--- a/spec/ruby/library/socket/unixsocket/open_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/open_spec.rb
@@ -1,13 +1,12 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative 'shared/new'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/new', __FILE__)
-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
+describe "UNIXSocket.open" do
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -19,9 +18,9 @@ with_feature :unix_socket do
end
it "opens a unix socket on the specified file and yields it to the block" do
- UNIXSocket.open(@path) do |client|
+ UNIXSocket.send(@method, @path) do |client|
client.addr[0].should == "AF_UNIX"
- client.should_not.closed?
+ client.closed?.should == false
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/pair_spec.rb b/spec/ruby/library/socket/unixsocket/pair_spec.rb
index b0a3b2af99..5cd75e2906 100644
--- a/spec/ruby/library/socket/unixsocket/pair_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb
@@ -1,12 +1,11 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/partially_closable_sockets'
-require_relative 'shared/pair'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
-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
+ platform_is_not :windows do
+
+ it_should_behave_like "partially closable sockets"
before :each do
@s1, @s2 = UNIXSocket.pair
@@ -16,5 +15,25 @@ with_feature :unix_socket do
@s1.close
@s2.close
end
+
+ it "returns a pair of connected sockets" do
+ @s1.puts "foo"
+ @s2.gets.should == "foo\n"
+ end
+
+ it "returns sockets with no name" do
+ @s1.path.should == @s2.path
+ @s1.path.should == ""
+ end
+
+ it "returns sockets with no address" do
+ @s1.addr.should == ["AF_UNIX", ""]
+ @s2.addr.should == ["AF_UNIX", ""]
+ end
+
+ it "returns sockets with no peeraddr" do
+ @s1.peeraddr.should == ["AF_UNIX", ""]
+ @s2.peeraddr.should == ["AF_UNIX", ""]
+ end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
index ef7d0f0b2a..f43274db2e 100644
--- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
@@ -1,9 +1,10 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-require_relative '../shared/partially_closable_sockets'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
+require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
-with_feature :unix_socket do
+platform_is_not :windows do
describe "UNIXSocket partial closability" do
+
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -18,6 +19,7 @@ with_feature :unix_socket do
SocketSpecs.rm_socket @path
end
- it_should_behave_like :partially_closable_sockets
+ it_should_behave_like "partially closable sockets"
+
end
end
diff --git a/spec/ruby/library/socket/unixsocket/path_spec.rb b/spec/ruby/library/socket/unixsocket/path_spec.rb
index a608378e4f..a2beaffeea 100644
--- a/spec/ruby/library/socket/unixsocket/path_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/path_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#path" do
+describe "UNIXSocket#path" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -23,4 +24,5 @@ with_feature :unix_socket do
@client.path.should == ""
end
end
+
end
diff --git a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
index 72bc96b1fe..dc5a319f4d 100644
--- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#peeraddr" do
+describe "UNIXSocket#peeraddr" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -15,14 +16,15 @@ with_feature :unix_socket do
SocketSpecs.rm_socket @path
end
- it "returns the address family and path of the server end of the connection" do
+ it "returns the address familly 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
- -> {
+ lambda {
@server.peeraddr
}.should raise_error(Errno::ENOTCONN)
end
end
+
end
diff --git a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
index 1dbc4538e3..c7a8946ceb 100644
--- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#recv_io" do
+describe "UNIXSocket#recv_io" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -37,48 +38,7 @@ with_feature :unix_socket do
@socket = @server.accept
@io = @socket.recv_io(File)
- @io.should be_an_instance_of(File)
- end
- end
-
- describe 'UNIXSocket#recv_io' do
- before do
- @file = File.open('/dev/null', 'w')
- @client, @server = UNIXSocket.socketpair
- end
-
- after do
- @client.close
- @server.close
- @io.close if @io
- @file.close
- end
-
- describe 'without a custom class' do
- it 'returns an IO' do
- @client.send_io(@file)
-
- @io = @server.recv_io
- @io.should be_an_instance_of(IO)
- end
- end
-
- describe 'with a custom class' do
- it 'returns an instance of the custom class' do
- @client.send_io(@file)
-
- @io = @server.recv_io(File)
- @io.should be_an_instance_of(File)
- end
- end
-
- describe 'with a custom mode' do
- it 'opens the IO using the given mode' do
- @client.send_io(@file)
-
- @io = @server.recv_io(File, File::WRONLY)
- @io.should be_an_instance_of(File)
- end
+ @io.should be_kind_of(File)
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
index d849fdc302..78e272bfe2 100644
--- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#recvfrom" do
+describe "UNIXSocket#recvfrom" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -31,29 +32,6 @@ with_feature :unix_socket do
sock.close
end
- it "allows an output buffer as third argument" do
- buffer = +''
-
- @client.send("foobar", 0)
- sock = @server.accept
- message, = sock.recvfrom(6, 0, buffer)
- sock.close
-
- message.should.equal?(buffer)
- buffer.should == "foobar"
- end
-
- it "preserves the encoding of the given buffer" do
- buffer = ''.encode(Encoding::ISO_8859_1)
-
- @client.send("foobar", 0)
- sock = @server.accept
- sock.recvfrom(6, 0, buffer)
- sock.close
-
- buffer.encoding.should == Encoding::ISO_8859_1
- end
-
it "uses different message options" do
@client.send("foobar", Socket::MSG_PEEK)
sock = @server.accept
@@ -66,53 +44,4 @@ with_feature :unix_socket do
end
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
- end
-
- it 'returns an Array containing the data and address information' do
- @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']]
- end
- end
-
- # These specs are taken from the rdoc examples on UNIXSocket#recvfrom.
- describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do
- before do
- @path1 = SocketSpecs.socket_path
- @path2 = SocketSpecs.socket_path.chop + '2'
- rm_r(@path2)
-
- @client_raw = Socket.new(:UNIX, :DGRAM)
- @client_raw.bind(Socket.sockaddr_un(@path1))
-
- @server_raw = Socket.new(:UNIX, :DGRAM)
- @server_raw.bind(Socket.sockaddr_un(@path2))
-
- @socket = UNIXSocket.for_fd(@server_raw.fileno)
- @socket.autoclose = false
- end
-
- after do
- @client_raw.close
- @server_raw.close # also closes @socket
-
- rm_r @path1
- rm_r @path2
- end
-
- it 'returns an Array containing the data and address information' do
- @client_raw.send('hello', 0, Socket.sockaddr_un(@path2))
-
- @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]]
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
deleted file mode 100644
index 0b416254d0..0000000000
--- a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-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
-
- after do
- @client.close
- @server.close
-
- rm_r(@path)
- 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
-
- 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 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
- end
- end
-end
diff --git a/spec/ruby/library/socket/unixsocket/send_io_spec.rb b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
index 80f3550c6d..ec8d6b2314 100644
--- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
@@ -1,8 +1,9 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../../fixtures/classes', __FILE__)
-with_feature :unix_socket do
- describe "UNIXSocket#send_io" do
+describe "UNIXSocket#send_io" do
+
+ platform_is_not :windows do
before :each do
@path = SocketSpecs.socket_path
@server = UNIXServer.open(@path)
@@ -31,25 +32,4 @@ with_feature :unix_socket do
@io.read.should == File.read(@send_io_path)
end
end
-
- describe 'UNIXSocket#send_io' do
- before do
- @file = File.open('/dev/null', 'w')
- @client, @server = UNIXSocket.socketpair
- end
-
- after do
- @client.close
- @server.close
- @io.close if @io
- @file.close
- end
-
- it 'sends an IO object' do
- @client.send_io(@file)
-
- @io = @server.recv_io
- @io.should be_an_instance_of(IO)
- end
- end
end
diff --git a/spec/ruby/library/socket/unixsocket/shared/new.rb b/spec/ruby/library/socket/unixsocket/shared/new.rb
index f075b03c5e..76c0d07b83 100644
--- a/spec/ruby/library/socket/unixsocket/shared/new.rb
+++ b/spec/ruby/library/socket/unixsocket/shared/new.rb
@@ -1,22 +1,24 @@
-require_relative '../../spec_helper'
-require_relative '../../fixtures/classes'
+require File.expand_path('../../../../../spec_helper', __FILE__)
+require File.expand_path('../../../fixtures/classes', __FILE__)
describe :unixsocket_new, shared: true do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- end
+ platform_is_not :windows do
+ 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?
+ @client.addr[0].should == "AF_UNIX"
+ @client.closed?.should == false
+ end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/shared/pair.rb b/spec/ruby/library/socket/unixsocket/shared/pair.rb
deleted file mode 100644
index ade7fc9852..0000000000
--- a/spec/ruby/library/socket/unixsocket/shared/pair.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require_relative '../../spec_helper'
-require_relative '../../fixtures/classes'
-
-describe :unixsocket_pair, shared: true do
- it "returns two UNIXSockets" do
- @s1.should be_an_instance_of(UNIXSocket)
- @s2.should be_an_instance_of(UNIXSocket)
- end
-
- it "returns a pair of connected sockets" do
- @s1.puts "foo"
- @s2.gets.should == "foo\n"
- end
-
- 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 peer addresses to empty Strings" do
- @s1.peeraddr.should == ["AF_UNIX", ""]
- @s2.peeraddr.should == ["AF_UNIX", ""]
- end
-end
diff --git a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
deleted file mode 100644
index 5f34008df3..0000000000
--- a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../spec_helper'
-require_relative '../fixtures/classes'
-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
-
- before :each do
- @s1, @s2 = UNIXSocket.socketpair
- end
-
- after :each do
- @s1.close
- @s2.close
- end
- end
-end