summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/addrinfo
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket/addrinfo')
-rw-r--r--spec/ruby/library/socket/addrinfo/afamily_spec.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/bind_spec.rb28
-rw-r--r--spec/ruby/library/socket/addrinfo/canonname_spec.rb27
-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.rb113
-rw-r--r--spec/ruby/library/socket/addrinfo/foreach_spec.rb9
-rw-r--r--spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb87
-rw-r--r--spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb40
-rw-r--r--spec/ruby/library/socket/addrinfo/initialize_spec.rb589
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb48
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_spec.rb63
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb64
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_port_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_spec.rb62
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb41
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb27
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb45
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb43
-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.rb46
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_spec.rb33
-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.rb80
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_load_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/pfamily_spec.rb41
-rw-r--r--spec/ruby/library/socket/addrinfo/protocol_spec.rb22
-rw-r--r--spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb47
-rw-r--r--spec/ruby/library/socket/addrinfo/socktype_spec.rb21
-rw-r--r--spec/ruby/library/socket/addrinfo/tcp_spec.rb34
-rw-r--r--spec/ruby/library/socket/addrinfo/to_s_spec.rb6
-rw-r--r--spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb6
-rw-r--r--spec/ruby/library/socket/addrinfo/udp_spec.rb34
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_path_spec.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_spec.rb69
49 files changed, 2429 insertions, 0 deletions
diff --git a/spec/ruby/library/socket/addrinfo/afamily_spec.rb b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
new file mode 100644
index 0000000000..5d075be057
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#afamily" do
+ describe "for an ipv4 socket" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns Socket::AF_INET" do
+ @addrinfo.afamily.should == Socket::AF_INET
+ end
+
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns Socket::AF_INET6" do
+ @addrinfo.afamily.should == Socket::AF_INET6
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns Socket::AF_UNIX" do
+ @addrinfo.afamily.should == Socket::AF_UNIX
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/bind_spec.rb b/spec/ruby/library/socket/addrinfo/bind_spec.rb
new file mode 100644
index 0000000000..cdd187771f
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/bind_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+describe "Addrinfo#bind" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 0)
+ end
+
+ after :each do
+ @socket.close unless @socket.closed?
+ end
+
+ it "returns a bound socket when no block is given" do
+ @socket = @addrinfo.bind
+ @socket.should.is_a?(Socket)
+ @socket.closed?.should == false
+ end
+
+ it "yields the socket if a block is given" do
+ @addrinfo.bind do |sock|
+ @socket = sock
+ sock.should.is_a?(Socket)
+ end
+ @socket.closed?.should == true
+ end
+
+end
diff --git a/spec/ruby/library/socket/addrinfo/canonname_spec.rb b/spec/ruby/library/socket/addrinfo/canonname_spec.rb
new file mode 100644
index 0000000000..efd3147125
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/canonname_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+describe "Addrinfo#canonname" do
+
+ before :each do
+ @addrinfos = Addrinfo.getaddrinfo("localhost", 80, :INET, :STREAM, nil, Socket::AI_CANONNAME)
+ end
+
+ it "returns the canonical name for a host" do
+ canonname = @addrinfos.map { |a| a.canonname }.find { |name| name and name.include?("localhost") }
+ if canonname
+ canonname.should.include?("localhost")
+ else
+ 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 == 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
new file mode 100644
index 0000000000..b1f6caa174
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/connect_from_spec.rb
@@ -0,0 +1,75 @@
+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.instance_of?(Socket)
+ end
+
+ it 'yields the Socket when a block is given' do
+ @addr.connect_from(ip_address, 0) do |socket|
+ socket.should.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.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.instance_of?(Socket)
+ end
+
+ it 'yields the Socket when a block is given' do
+ @addr.connect_from(@from_addr) do |socket|
+ socket.should.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.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
new file mode 100644
index 0000000000..a8494b5501
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/connect_spec.rb
@@ -0,0 +1,35 @@
+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.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.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.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
new file mode 100644
index 0000000000..2bf49a38e8
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/connect_to_spec.rb
@@ -0,0 +1,75 @@
+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.instance_of?(Socket)
+ end
+
+ it 'yields the Socket when a block is given' do
+ @addr.connect_to(ip_address, @port) do |socket|
+ socket.should.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.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.instance_of?(Socket)
+ end
+
+ it 'yields the Socket when a block is given' do
+ @addr.connect_to(@to_addr) do |socket|
+ socket.should.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.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
new file mode 100644
index 0000000000..38834ade91
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
@@ -0,0 +1,113 @@
+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(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(ArgumentError)
+ end
+
+ it 'raises ArgumentError if more than 2 arguments are given' do
+ -> { @source.family_addrinfo('127.0.0.1', 0, 666) }.should.raise(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.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
+
+ 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(ArgumentError)
+ end
+
+ it 'returns an Addrinfo when a UNIX socket path is given' do
+ addr = @source.family_addrinfo('dogs')
+
+ addr.should.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
+
+ 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(ArgumentError)
+ end
+
+ it "raises ArgumentError if the protocol families don't match" do
+ input = Addrinfo.tcp('::1', 0)
+ -> { @source.family_addrinfo(input) }.should.raise(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(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/foreach_spec.rb b/spec/ruby/library/socket/addrinfo/foreach_spec.rb
new file mode 100644
index 0000000000..8cbbddb8f0
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/foreach_spec.rb
@@ -0,0 +1,9 @@
+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.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
new file mode 100644
index 0000000000..47393ee167
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb
@@ -0,0 +1,87 @@
+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.instance_of?(Array)
+ array[0].should.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
+
+ 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
+
+ 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.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
new file mode 100644
index 0000000000..43b5a2000a
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
@@ -0,0 +1,40 @@
+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
+ 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
diff --git a/spec/ruby/library/socket/addrinfo/initialize_spec.rb b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
new file mode 100644
index 0000000000..f33255e38b
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
@@ -0,0 +1,589 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#initialize" do
+
+ describe "with a sockaddr string" do
+
+ describe "without a family" do
+ before :each do
+ @addrinfo = Addrinfo.new(Socket.sockaddr_in("smtp", "2001:DB8::1"))
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "2001:db8::1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 25
+ end
+
+ it "returns the UNSPEC pfamily" 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
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == 0
+ end
+
+ it "returns the 0 protocol" do
+ @addrinfo.protocol.should == 0
+ end
+ end
+
+ describe "with a family given" do
+ before :each do
+ @addrinfo = Addrinfo.new(Socket.sockaddr_in("smtp", "2001:DB8::1"), Socket::PF_INET6)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "2001:db8::1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 25
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET6
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET6
+ end
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == 0
+ end
+
+ it "returns the 0 protocol" do
+ @addrinfo.protocol.should == 0
+ end
+ end
+
+ describe "with a family and socket type" do
+ before :each do
+ @addrinfo = Addrinfo.new(Socket.sockaddr_in("smtp", "2001:DB8::1"), Socket::PF_INET6, Socket::SOCK_STREAM)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "2001:db8::1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 25
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET6
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET6
+ end
+
+ it "returns the specified socket type" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it "returns the 0 protocol" do
+ @addrinfo.protocol.should == 0
+ end
+ end
+
+ describe "with a family, socket type and protocol" do
+ before :each do
+ @addrinfo = Addrinfo.new(Socket.sockaddr_in("smtp", "2001:DB8::1"), Socket::PF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "2001:db8::1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 25
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET6
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET6
+ end
+
+ it "returns the specified socket type" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it "returns the specified protocol" do
+ @addrinfo.protocol.should == Socket::IPPROTO_TCP
+ end
+ end
+
+ end
+
+ describe "with a sockaddr array" do
+
+ describe "without a family" do
+ before :each do
+ @addrinfo = Addrinfo.new(["AF_INET", 46102, "localhost", "127.0.0.1"])
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "127.0.0.1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 46102
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET
+ end
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == 0
+ end
+
+ it "returns the 0 protocol" do
+ @addrinfo.protocol.should == 0
+ 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(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)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "127.0.0.1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 46102
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET
+ end
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == 0
+ end
+
+ it "returns the 0 protocol" do
+ @addrinfo.protocol.should == 0
+ end
+ end
+
+ describe "with a family and socket type" do
+ before :each do
+ @addrinfo = Addrinfo.new(["AF_INET", 46102, "localhost", "127.0.0.1"], Socket::PF_INET, Socket::SOCK_STREAM)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "127.0.0.1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 46102
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET
+ end
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+
+ 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(SocketError)
+ end
+ end
+
+ describe "with a family, socket type and protocol" do
+ before :each do
+ @addrinfo = Addrinfo.new(["AF_INET", 46102, "localhost", "127.0.0.1"], Socket::PF_INET, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)
+ end
+
+ it "stores the ip address from the sockaddr" do
+ @addrinfo.ip_address.should == "127.0.0.1"
+ end
+
+ it "stores the port number from the sockaddr" do
+ @addrinfo.ip_port.should == 46102
+ end
+
+ it "returns the specified pfamily" do
+ @addrinfo.pfamily.should == Socket::PF_INET
+ end
+
+ it "returns the specified afamily" do
+ @addrinfo.afamily.should == Socket::AF_INET
+ end
+
+ it "returns the 0 socket type" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it "returns the specified protocol" do
+ @addrinfo.protocol.should == Socket::IPPROTO_TCP
+ end
+ 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(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 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(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 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(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(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(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(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 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(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 the specified pfamily for :PF_INET' do
+ addr = Addrinfo.new(@sockaddr, :PF_INET)
+
+ addr.pfamily.should == Socket::PF_INET
+ end
+
+ it 'returns an Addrinfo with the specified pfamily for :INET' 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 the specified pfamily for PF_INET' do
+ addr = Addrinfo.new(@sockaddr, 'PF_INET')
+
+ addr.pfamily.should == Socket::PF_INET
+ end
+
+ it 'returns an Addrinfo with the specified pfamily for INET' 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 '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
diff --git a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
new file mode 100644
index 0000000000..6b18c79469
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../spec_helper'
+
+
+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
+ 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
+ end
+
+ 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
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/inspect_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_spec.rb
new file mode 100644
index 0000000000..1442af6162
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/inspect_spec.rb
@@ -0,0 +1,63 @@
+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
+
+ 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
diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
new file mode 100644
index 0000000000..9a0ede4eeb
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
@@ -0,0 +1,64 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ip_address" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns the ip address" do
+ @addrinfo.ip_address.should == "127.0.0.1"
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns the ip address" do
+ @addrinfo.ip_address.should == "::1"
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "raises an exception" do
+ -> { @addrinfo.ip_address }.should.raise(SocketError)
+ 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
new file mode 100644
index 0000000000..00f74cdd46
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ip_port" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns the port" do
+ @addrinfo.ip_port.should == 80
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns the port" do
+ @addrinfo.ip_port.should == 80
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "raises an exception" do
+ -> { @addrinfo.ip_port }.should.raise(SocketError)
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ip_spec.rb b/spec/ruby/library/socket/addrinfo/ip_spec.rb
new file mode 100644
index 0000000000..2237eca263
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ip_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+describe "Addrinfo#ip?" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns true" do
+ @addrinfo.ip?.should == true
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns true" do
+ @addrinfo.ip?.should == true
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ip?.should == false
+ 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.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
new file mode 100644
index 0000000000..b48ca062ee
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ip_unpack" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns the ip address and port pair" do
+ @addrinfo.ip_unpack.should == ["127.0.0.1", 80]
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns the ip address and port pair" do
+ @addrinfo.ip_unpack.should == ["::1", 80]
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "raises an exception" do
+ -> { @addrinfo.ip_unpack }.should.raise(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
new file mode 100644
index 0000000000..266281ce7a
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv4_loopback?" do
+ describe "for an ipv4 socket" do
+ 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?
+ end
+
+ it "returns false for another address" do
+ Addrinfo.ip('255.255.255.0').ipv4_loopback?.should == false
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @loopback = Addrinfo.tcp("::1", 80)
+ @other = Addrinfo.tcp("::", 80)
+ end
+
+ it "returns false for the loopback address" do
+ @loopback.ipv4_loopback?.should == false
+ end
+
+ it "returns false for another address" do
+ @other.ipv4_loopback?.should == false
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4_loopback?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
new file mode 100644
index 0000000000..bc8a31dfa8
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../spec_helper'
+
+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
+
+ it 'returns false for a regular address' do
+ Addrinfo.ip('8.8.8.8').should_not.ipv4_multicast?
+ end
+
+ it 'returns false for an IPv6 address' do
+ Addrinfo.ip('::1').should_not.ipv4_multicast?
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4_multicast?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
new file mode 100644
index 0000000000..8cfbf0a25e
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv4_private?" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @private = Addrinfo.tcp("10.0.0.1", 80)
+ @other = Addrinfo.tcp("0.0.0.0", 80)
+ 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?
+ end
+
+ it "returns false for a public address" do
+ @other.ipv4_private?.should == false
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @other = Addrinfo.tcp("::", 80)
+ end
+
+ it "returns false" do
+ @other.ipv4_private?.should == false
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4_private?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
new file mode 100644
index 0000000000..8fef94a8e8
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv4?" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("10.0.0.1", 80)
+ end
+
+ it "returns true" do
+ @addrinfo.ipv4?.should == true
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4?.should == false
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb
new file mode 100644
index 0000000000..bfef396381
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb
@@ -0,0 +1,23 @@
+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
new file mode 100644
index 0000000000..2e8241e336
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
@@ -0,0 +1,43 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv6_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 false for the loopback address" do
+ @loopback.ipv6_loopback?.should == false
+ end
+
+ it "returns false for another address" do
+ @other.ipv6_loopback?.should == false
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @loopback = Addrinfo.tcp("::1", 80)
+ @other = Addrinfo.tcp("::", 80)
+ end
+
+ it "returns true for the loopback address" do
+ @loopback.ipv6_loopback?.should == true
+ end
+
+ it "returns false for another address" do
+ @other.ipv6_loopback?.should == false
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6_loopback?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb
new file mode 100644
index 0000000000..01fa0992ba
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb
@@ -0,0 +1,20 @@
+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
new file mode 100644
index 0000000000..a1298919eb
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb
@@ -0,0 +1,19 @@
+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
new file mode 100644
index 0000000000..0aee952d88
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000000..2977a98d30
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000000..58e5976a40
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000000..52787e5e53
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
@@ -0,0 +1,46 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv6_multicast?" do
+ 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 true for a multicast address" do
+ @multicast.ipv6_multicast?.should == false
+ end
+
+ it "returns false for another address" do
+ @other.ipv6_multicast?.should == false
+ end
+ 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?
+ end
+
+ it "returns false for another address" do
+ Addrinfo.ip('::1').should_not.ipv6_multicast?
+ Addrinfo.ip('fe80::').should_not.ipv6_multicast?
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6_multicast?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb
new file mode 100644
index 0000000000..9158eb5809
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb
@@ -0,0 +1,23 @@
+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
new file mode 100644
index 0000000000..9fa8e9bd0c
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#ipv6?" do
+ describe "for an ipv4 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("10.0.0.1", 80)
+ end
+
+ it "returns true" do
+ @addrinfo.ipv6?.should == false
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6?.should == true
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
new file mode 100644
index 0000000000..d1436d4527
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
@@ -0,0 +1,71 @@
+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.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.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.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.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.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 == nil
+ end
+
+ it 'returns nil for a pure IPv6 Addrinfo' do
+ Addrinfo.ip('::1').ipv6_to_ipv4.should == nil
+ end
+
+ it 'returns nil for an IPv4 Addrinfo' do
+ Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should == nil
+ end
+
+ describe 'for a unix socket' do
+ it 'returns nil for a UNIX Addrinfo' do
+ Addrinfo.unix('foo').ipv6_to_ipv4.should == 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
new file mode 100644
index 0000000000..22f0fa3b75
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000000..d63979ceda
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb
@@ -0,0 +1,15 @@
+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
new file mode 100644
index 0000000000..21ca85af99
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb
@@ -0,0 +1,20 @@
+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
new file mode 100644
index 0000000000..7dac0e75db
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb
@@ -0,0 +1,20 @@
+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
new file mode 100644
index 0000000000..80bcdc7f83
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/listen_spec.rb
@@ -0,0 +1,34 @@
+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.instance_of?(Socket)
+ end
+
+ it 'yields the Socket if a block is given' do
+ @addr.listen do |socket|
+ socket.should.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
new file mode 100644
index 0000000000..438b04a99c
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
@@ -0,0 +1,80 @@
+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.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
+
+ it 'includes the protocol as the 5th value' do
+ @array[4].should == 'IPPROTO_TCP'
+ end
+
+ it 'includes the canonical name as the 6th value' do
+ @array[5].should == @addr.canonname
+ end
+ end
+ end
+
+ describe 'using a UNIX Addrinfo' do
+ before do
+ @addr = Addrinfo.unix('foo')
+ end
+
+ it 'returns an Array' do
+ @addr.marshal_dump.should.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
diff --git a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
new file mode 100644
index 0000000000..02cef90115
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
@@ -0,0 +1,33 @@
+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
+
+ 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
diff --git a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
new file mode 100644
index 0000000000..da530b7fdc
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../spec_helper'
+
+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
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns Socket::PF_INET" do
+ @addrinfo.pfamily.should == Socket::PF_INET
+ end
+
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns Socket::PF_INET6" do
+ @addrinfo.pfamily.should == Socket::PF_INET6
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns Socket::PF_UNIX" do
+ @addrinfo.pfamily.should == Socket::PF_UNIX
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/protocol_spec.rb b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
new file mode 100644
index 0000000000..f6ffc9acf9
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#protocol" do
+ it 'returns 0 by default' do
+ Addrinfo.ip('127.0.0.1').protocol.should == 0
+ 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
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns 0" do
+ @addrinfo.protocol.should == 0
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
new file mode 100644
index 0000000000..70d6bfbbfe
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
@@ -0,0 +1,47 @@
+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')
+ end
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns a sockaddr packed structure" do
+ @addrinfo.send(@method).should == Socket.sockaddr_in(80, '::1')
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns a sockaddr packed structure" do
+ @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock')
+ end
+ end
+
+ 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
new file mode 100644
index 0000000000..e5f02cd759
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/socktype_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#socktype" do
+ it 'returns 0 by default' do
+ Addrinfo.ip('127.0.0.1').socktype.should == 0
+ end
+
+ it 'returns the socket type when given' do
+ Addrinfo.tcp('127.0.0.1', 80).socktype.should == Socket::SOCK_STREAM
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns Socket::SOCK_STREAM" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/tcp_spec.rb b/spec/ruby/library/socket/addrinfo/tcp_spec.rb
new file mode 100644
index 0000000000..0669de16a6
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/tcp_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+describe 'Addrinfo.tcp' do
+ SocketSpecs.each_ip_protocol do |family, ip_address|
+ it 'returns an Addrinfo instance' do
+ Addrinfo.tcp(ip_address, 80).should.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
+
+ it 'sets the socket type' do
+ Addrinfo.tcp(ip_address, 80).socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'sets the socket protocol' do
+ Addrinfo.tcp(ip_address, 80).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
new file mode 100644
index 0000000000..ddf994e051
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/to_s_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../spec_helper'
+require_relative 'shared/to_sockaddr'
+
+describe "Addrinfo#to_s" do
+ 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
new file mode 100644
index 0000000000..b9f75454bd
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../spec_helper'
+require_relative 'shared/to_sockaddr'
+
+describe "Addrinfo#to_sockaddr" do
+ 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
new file mode 100644
index 0000000000..51d7f5588e
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/udp_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../spec_helper'
+require_relative '../fixtures/classes'
+
+describe 'Addrinfo.udp' do
+ SocketSpecs.each_ip_protocol do |family, ip_address|
+ it 'returns an Addrinfo instance' do
+ Addrinfo.udp(ip_address, 80).should.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
+
+ it 'sets the socket type' do
+ Addrinfo.udp(ip_address, 80).socktype.should == Socket::SOCK_DGRAM
+ end
+
+ it 'sets the socket protocol' do
+ Addrinfo.udp(ip_address, 80).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
new file mode 100644
index 0000000000..c15075bce3
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../spec_helper'
+
+describe "Addrinfo#unix_path" do
+ describe "for an ipv4 socket" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "raises an exception" do
+ -> { @addrinfo.unix_path }.should.raise(SocketError)
+ end
+
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "raises an exception" do
+ -> { @addrinfo.unix_path }.should.raise(SocketError)
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns the socket path" do
+ @addrinfo.unix_path.should == "/tmp/sock"
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/addrinfo/unix_spec.rb b/spec/ruby/library/socket/addrinfo/unix_spec.rb
new file mode 100644
index 0000000000..da65e13efb
--- /dev/null
+++ b/spec/ruby/library/socket/addrinfo/unix_spec.rb
@@ -0,0 +1,69 @@
+require_relative '../spec_helper'
+
+describe 'Addrinfo.unix' do
+ it 'returns an Addrinfo instance' do
+ Addrinfo.unix('socket').should.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
+
+ it 'sets a custom socket type' do
+ addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM)
+
+ addr.socktype.should == Socket::SOCK_DGRAM
+ end
+
+ it 'sets the socket protocol to 0' do
+ Addrinfo.unix('socket').protocol.should == 0
+ end
+end
+
+describe "Addrinfo#unix?" do
+ describe "for an ipv4 socket" do
+
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+
+ it "returns false" do
+ @addrinfo.unix?.should == false
+ end
+
+ end
+
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
+ end
+
+ it "returns false" do
+ @addrinfo.unix?.should == false
+ end
+ end
+
+ platform_is_not :windows do
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns true" do
+ @addrinfo.unix?.should == true
+ end
+ end
+ end
+end