mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aeeaadaad0
commit
b53cf149ad
246 changed files with 9108 additions and 548 deletions
31
spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
Normal file
31
spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
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
|
||||
|
||||
it 'returns false when comparing with :IP and :PKTINFO' do
|
||||
@data.cmsg_is?(:IP, :PKTINFO).should == false
|
||||
end
|
||||
|
||||
it 'returns false when comparing with :SOCKET and :RIGHTS' do
|
||||
@data.cmsg_is?(:SOCKET, :RIGHTS).should == false
|
||||
end
|
||||
|
||||
it 'raises SocketError when comparign with :IPV6 and :RIGHTS' do
|
||||
lambda { @data.cmsg_is?(:IPV6, :RIGHTS) }.should raise_error(SocketError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
9
spec/ruby/library/socket/ancillarydata/data_spec.rb
Normal file
9
spec/ruby/library/socket/ancillarydata/data_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
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
|
9
spec/ruby/library/socket/ancillarydata/family_spec.rb
Normal file
9
spec/ruby/library/socket/ancillarydata/family_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :ancillary_data do
|
||||
describe 'Socket::AncillaryData#family' do
|
||||
it 'returns the family as a Fixnum' do
|
||||
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').family.should == Socket::AF_INET
|
||||
end
|
||||
end
|
||||
end
|
282
spec/ruby/library/socket/ancillarydata/initialize_spec.rb
Normal file
282
spec/ruby/library/socket/ancillarydata/initialize_spec.rb
Normal file
|
@ -0,0 +1,282 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :ancillary_data do
|
||||
describe 'Socket::AncillaryData#initialize' do
|
||||
describe 'using Fixnums 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
|
||||
|
||||
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
|
||||
|
||||
it 'raises TypeError when using a numeric string as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :SOCKET, :RECVTTL, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :MOO as the type argument' do
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :SOCKET, :MOO, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :IP_RECVTTL as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :IP, :RIGHTS, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :MOO as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :IPV6, :RIGHTS, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :MOO as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :TCP, :RIGHTS, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :MOO as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:INET, :UDP, :RIGHTS, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises SocketError when using :MOO as the type argument' do
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
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
|
||||
lambda {
|
||||
Socket::AncillaryData.new(:UNIX, :UDP, :CORK, '')
|
||||
}.should raise_error(SocketError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
43
spec/ruby/library/socket/ancillarydata/int_spec.rb
Normal file
43
spec/ruby/library/socket/ancillarydata/int_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
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 a Fixnum' do
|
||||
data = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, 4)
|
||||
|
||||
data.int.should == 4
|
||||
end
|
||||
|
||||
it 'raises when the data is not a Fixnum' do
|
||||
data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, 'ugh')
|
||||
|
||||
lambda { data.int }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
145
spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
Normal file
145
spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
Normal file
|
@ -0,0 +1,145 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :ancillary_data 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_an_instance_of(Fixnum)
|
||||
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 == @source
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the ifindex' do
|
||||
it 'is a Fixnum' 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 == @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
|
|
@ -0,0 +1,11 @@
|
|||
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
|
|
@ -0,0 +1,11 @@
|
|||
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
|
89
spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
Normal file
89
spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
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_an_instance_of(Fixnum)
|
||||
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 == @source
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the ifindex' do
|
||||
it 'is a Fixnum' 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
|
9
spec/ruby/library/socket/ancillarydata/level_spec.rb
Normal file
9
spec/ruby/library/socket/ancillarydata/level_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :ancillary_data do
|
||||
describe 'Socket::AncillaryData#level' do
|
||||
it 'returns the level as a Fixnum' do
|
||||
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').level.should == Socket::SOL_SOCKET
|
||||
end
|
||||
end
|
||||
end
|
9
spec/ruby/library/socket/ancillarydata/type_spec.rb
Normal file
9
spec/ruby/library/socket/ancillarydata/type_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :ancillary_data do
|
||||
describe 'Socket::AncillaryData#type' do
|
||||
it 'returns the type as a Fixnum' do
|
||||
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
|
||||
end
|
||||
end
|
||||
end
|
59
spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
Normal file
59
spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
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
|
||||
lambda { 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, '')
|
||||
|
||||
lambda { data.unix_rights }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it 'raises TypeError when the type is not SCM_RIGHTS' do
|
||||
data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '')
|
||||
|
||||
lambda { data.unix_rights }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue