1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
require_relative '../spec_helper'
with_feature :ancillary_data do
describe 'Socket::AncillaryData.unix_rights' do
describe 'using a list of IO objects' do
before do
@data = Socket::AncillaryData.unix_rights(STDOUT, STDERR)
end
it 'sets the family to AF_UNIX' do
@data.family.should == Socket::AF_UNIX
end
it 'sets the level to SOL_SOCKET' do
@data.level.should == Socket::SOL_SOCKET
end
it 'sets the type to SCM_RIGHTS' do
@data.type.should == Socket::SCM_RIGHTS
end
it 'sets the data to a String containing the file descriptors' do
@data.data.unpack('I*').should == [STDOUT.fileno, STDERR.fileno]
end
end
describe 'using non IO objects' do
it 'raises TypeError' do
-> { Socket::AncillaryData.unix_rights(10) }.should raise_error(TypeError)
end
end
end
describe 'Socket::AncillaryData#unix_rights' do
it 'returns the data as an Array of IO objects' do
data = Socket::AncillaryData.unix_rights(STDOUT, STDERR)
data.unix_rights.should == [STDOUT, STDERR]
end
it 'returns nil when the data is not a list of file descriptors' do
data = Socket::AncillaryData.new(:UNIX, :SOCKET, :RIGHTS, '')
data.unix_rights.should be_nil
end
it 'raises TypeError when the level is not SOL_SOCKET' do
data = Socket::AncillaryData.new(:INET, :IP, :RECVTTL, '')
-> { data.unix_rights }.should raise_error(TypeError)
end
platform_is_not :"solaris2.10", :aix do
it 'raises TypeError when the type is not SCM_RIGHTS' do
data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '')
-> { data.unix_rights }.should raise_error(TypeError)
end
end
end
end
|