summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/ancillarydata
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket/ancillarydata')
-rw-r--r--spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb33
-rw-r--r--spec/ruby/library/socket/ancillarydata/family_spec.rb2
-rw-r--r--spec/ruby/library/socket/ancillarydata/initialize_spec.rb76
-rw-r--r--spec/ruby/library/socket/ancillarydata/int_spec.rb8
-rw-r--r--spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb145
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb2
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb12
-rw-r--r--spec/ruby/library/socket/ancillarydata/level_spec.rb2
-rw-r--r--spec/ruby/library/socket/ancillarydata/type_spec.rb2
-rw-r--r--spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb14
10 files changed, 239 insertions, 57 deletions
diff --git a/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb b/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
new file mode 100644
index 0000000000..c77f3bdbae
--- /dev/null
+++ b/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+with_feature :ancillary_data do
+ describe 'Socket::AncillaryData#cmsg_is?' do
+ describe 'using :INET, :IP, :TTL as the family, level, and type' do
+ before do
+ @data = Socket::AncillaryData.new(:INET, :IP, :TTL, '')
+ end
+
+ it 'returns true when comparing with IPPROTO_IP and IP_TTL' do
+ @data.cmsg_is?(Socket::IPPROTO_IP, Socket::IP_TTL).should == true
+ end
+
+ it 'returns true when comparing with :IP and :TTL' do
+ @data.cmsg_is?(:IP, :TTL).should == true
+ end
+
+ with_feature :pktinfo do
+ it 'returns false when comparing with :IP and :PKTINFO' do
+ @data.cmsg_is?(:IP, :PKTINFO).should == false
+ end
+ end
+
+ it 'returns false when comparing with :SOCKET and :RIGHTS' do
+ @data.cmsg_is?(:SOCKET, :RIGHTS).should == false
+ end
+
+ it 'raises SocketError when comparing with :IPV6 and :RIGHTS' do
+ -> { @data.cmsg_is?(:IPV6, :RIGHTS) }.should.raise(SocketError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/ancillarydata/family_spec.rb b/spec/ruby/library/socket/ancillarydata/family_spec.rb
index b742e0c6db..975f0d2538 100644
--- a/spec/ruby/library/socket/ancillarydata/family_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/family_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
with_feature :ancillary_data do
describe 'Socket::AncillaryData#family' do
- it 'returns the family as a Fixnum' do
+ it 'returns the family as an Integer' do
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').family.should == Socket::AF_INET
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb
index 659a29e24a..60f5ac7a90 100644
--- a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
with_feature :ancillary_data do
describe 'Socket::AncillaryData#initialize' do
- describe 'using Fixnums for the family, level, and type' do
+ describe 'using Integers for the family, level, and type' do
before do
@data = Socket::AncillaryData
.new(Socket::AF_INET, Socket::IPPROTO_IP, Socket::IP_RECVTTL, 'ugh')
@@ -106,32 +106,34 @@ with_feature :ancillary_data 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
+ platform_is_not :aix do
+ it 'sets the type to SCM_TIMESTAMP when using :TIMESTAMP as the type argument' do
+ Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '').type.should == Socket::SCM_TIMESTAMP
+ end
end
it 'raises TypeError when using a numeric string as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :IGMP, Socket::SCM_RIGHTS.to_s, '')
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it 'raises SocketError when using :RECVTTL as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :SOCKET, :RECVTTL, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
it 'raises SocketError when using :MOO as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :SOCKET, :MOO, '')
- }.should raise_error(SocketError)
+ }.should.raise(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)
+ }.should.raise(SocketError)
end
end
@@ -153,15 +155,15 @@ with_feature :ancillary_data do
end
it 'raises SocketError when using :RIGHTS as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :IP, :RIGHTS, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
it 'raises SocketError when using :MOO as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :IP, :MOO, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
end
@@ -177,15 +179,15 @@ with_feature :ancillary_data do
end
it 'raises SocketError when using :RIGHTS as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :IPV6, :RIGHTS, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
it 'raises SocketError when using :MOO as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :IPV6, :MOO, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
end
@@ -203,15 +205,15 @@ with_feature :ancillary_data do
end
it 'raises SocketError when using :RIGHTS as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :TCP, :RIGHTS, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
it 'raises SocketError when using :MOO as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :TCP, :MOO, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
end
@@ -223,15 +225,15 @@ with_feature :ancillary_data do
end
it 'raises SocketError when using :RIGHTS as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :UDP, :RIGHTS, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
it 'raises SocketError when using :MOO as the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:INET, :UDP, :MOO, '')
- }.should raise_error(SocketError)
+ }.should.raise(SocketError)
end
end
@@ -241,41 +243,41 @@ with_feature :ancillary_data do
end
it 'raises SocketError when using :CORK sa the type argument' do
- lambda {
+ -> {
Socket::AncillaryData.new(:UNIX, :SOCKET, :CORK, '')
- }.should raise_error(SocketError)
+ }.should.raise(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)
+ }.should.raise(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)
+ }.should.raise(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)
+ }.should.raise(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)
+ }.should.raise(SocketError)
end
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/int_spec.rb b/spec/ruby/library/socket/ancillarydata/int_spec.rb
index 75608a28b8..10c5dea436 100644
--- a/spec/ruby/library/socket/ancillarydata/int_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/int_spec.rb
@@ -7,7 +7,7 @@ with_feature :ancillary_data do
end
it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
+ @data.should.instance_of?(Socket::AncillaryData)
end
it 'sets the family to AF_INET' do
@@ -28,16 +28,16 @@ with_feature :ancillary_data do
end
describe 'Socket::AncillaryData#int' do
- it 'returns the data as a Fixnum' do
+ it 'returns the data as an Integer' do
data = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, 4)
data.int.should == 4
end
- it 'raises when the data is not a Fixnum' do
+ it 'raises when the data is not an Integer' do
data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, 'ugh')
- lambda { data.int }.should raise_error(TypeError)
+ -> { data.int }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
new file mode 100644
index 0000000000..065bcf1f39
--- /dev/null
+++ b/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb
@@ -0,0 +1,145 @@
+require_relative '../spec_helper'
+
+with_feature :ancillary_data, :pktinfo do
+ describe 'Socket::AncillaryData.ip_pktinfo' do
+ describe 'with a source address and index' do
+ before do
+ @data = Socket::AncillaryData.ip_pktinfo(Addrinfo.ip('127.0.0.1'), 4)
+ end
+
+ it 'returns a Socket::AncillaryData' do
+ @data.should.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.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.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.instance_of?(Addrinfo)
+ end
+
+ it 'stores the ifindex at index 1' do
+ @info[1].should.is_a?(Integer)
+ end
+
+ it 'stores an Addrinfo at index 2' do
+ @info[2].should.instance_of?(Addrinfo)
+ end
+ end
+
+ describe 'the source Addrinfo' do
+ before do
+ @addr = @data.ip_pktinfo[0]
+ end
+
+ it 'uses the correct IP address' do
+ @addr.ip_address.should == '127.0.0.1'
+ end
+
+ it 'is not the same object as the input Addrinfo' do
+ @addr.should_not.equal? @source
+ end
+ end
+
+ describe 'the ifindex' do
+ it 'is an Integer' do
+ @data.ip_pktinfo[1].should == 4
+ end
+ end
+
+ describe 'the destination Addrinfo' do
+ before do
+ @addr = @data.ip_pktinfo[2]
+ end
+
+ it 'uses the correct IP address' do
+ @addr.ip_address.should == '127.0.0.5'
+ end
+
+ it 'is not the same object as the input Addrinfo' do
+ @addr.should_not.equal? @dest
+ end
+ end
+ end
+
+ describe 'using an Addrinfo with a port number' do
+ before do
+ @source = Addrinfo.tcp('127.0.0.1', 80)
+ @dest = Addrinfo.tcp('127.0.0.5', 85)
+ @data = Socket::AncillaryData.ip_pktinfo(@source, 4, @dest)
+ end
+
+ describe 'the source Addrinfo' do
+ before do
+ @addr = @data.ip_pktinfo[0]
+ end
+
+ it 'does not contain a port number' do
+ @addr.ip_port.should == 0
+ end
+ end
+
+ describe 'the destination Addrinfo' do
+ before do
+ @addr = @data.ip_pktinfo[2]
+ end
+
+ it 'does not contain a port number' do
+ @addr.ip_port.should == 0
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb
index f70fe27d6a..7c630218d1 100644
--- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb
@@ -5,7 +5,7 @@ with_feature :ancillary_data, :ipv6_pktinfo 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)
+ data.ipv6_pktinfo_addr.should.instance_of?(Addrinfo)
end
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
index 6315aba89c..b5b779c36e 100644
--- a/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb
@@ -7,7 +7,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do
end
it 'returns a Socket::AncillaryData' do
- @data.should be_an_instance_of(Socket::AncillaryData)
+ @data.should.instance_of?(Socket::AncillaryData)
end
it 'sets the family to AF_INET' do
@@ -31,7 +31,7 @@ with_feature :ancillary_data, :ipv6_pktinfo do
end
it 'returns an Array' do
- @data.ipv6_pktinfo.should be_an_instance_of(Array)
+ @data.ipv6_pktinfo.should.instance_of?(Array)
end
describe 'the returned Array' do
@@ -40,11 +40,11 @@ with_feature :ancillary_data, :ipv6_pktinfo do
end
it 'stores an Addrinfo at index 0' do
- @info[0].should be_an_instance_of(Addrinfo)
+ @info[0].should.instance_of?(Addrinfo)
end
it 'stores the ifindex at index 1' do
- @info[1].should be_an_instance_of(Fixnum)
+ @info[1].should.is_a?(Integer)
end
end
@@ -58,12 +58,12 @@ with_feature :ancillary_data, :ipv6_pktinfo do
end
it 'is not the same object as the input Addrinfo' do
- @addr.should_not == @source
+ @addr.should_not.equal? @source
end
end
describe 'the ifindex' do
- it 'is a Fixnum' do
+ it 'is an Integer' do
@data.ipv6_pktinfo[1].should == 4
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/level_spec.rb b/spec/ruby/library/socket/ancillarydata/level_spec.rb
index 40b070a6d8..a2ff216f9d 100644
--- a/spec/ruby/library/socket/ancillarydata/level_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/level_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
with_feature :ancillary_data do
describe 'Socket::AncillaryData#level' do
- it 'returns the level as a Fixnum' do
+ it 'returns the level as an Integer' do
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').level.should == Socket::SOL_SOCKET
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/type_spec.rb b/spec/ruby/library/socket/ancillarydata/type_spec.rb
index 1a4b04ed57..972beeeca0 100644
--- a/spec/ruby/library/socket/ancillarydata/type_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/type_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
with_feature :ancillary_data do
describe 'Socket::AncillaryData#type' do
- it 'returns the type as a Fixnum' do
+ it 'returns the type as an Integer' do
Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS
end
end
diff --git a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
index 0bbef4c08d..6dd144ba5a 100644
--- a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
+++ b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb
@@ -26,7 +26,7 @@ with_feature :ancillary_data do
describe 'using non IO objects' do
it 'raises TypeError' do
- lambda { Socket::AncillaryData.unix_rights(10) }.should raise_error(TypeError)
+ -> { Socket::AncillaryData.unix_rights(10) }.should.raise(TypeError)
end
end
end
@@ -41,19 +41,21 @@ with_feature :ancillary_data do
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
+ data.unix_rights.should == 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)
+ -> { data.unix_rights }.should.raise(TypeError)
end
- it 'raises TypeError when the type is not SCM_RIGHTS' do
- data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '')
+ platform_is_not :aix do
+ 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)
+ -> { data.unix_rights }.should.raise(TypeError)
+ end
end
end
end