diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
commit | b53cf149ad8d7c46572e4567ca949b4f82ebb22c (patch) | |
tree | ee5032bcb38573dade8ba2c46acbcc0d5f3ddfe3 /spec/ruby/library/socket/shared/socketpair.rb | |
parent | aeeaadaad08038217440c1e9e7c5ca126d7dc633 (diff) |
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/socket/shared/socketpair.rb')
-rw-r--r-- | spec/ruby/library/socket/shared/socketpair.rb | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/spec/ruby/library/socket/shared/socketpair.rb b/spec/ruby/library/socket/shared/socketpair.rb index 03ee0e1a52..1e08deccc2 100644 --- a/spec/ruby/library/socket/shared/socketpair.rb +++ b/spec/ruby/library/socket/shared/socketpair.rb @@ -19,5 +19,120 @@ describe :socket_socketpair, shared: true do s2.close end end + + describe 'using a Fixnum as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, Socket::SOCK_STREAM) + + s1.should be_an_instance_of(Socket) + s2.should be_an_instance_of(Socket) + s1.close + s2.close + end + end + + describe 'using a Symbol as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.public_send(@method, :UNIX, :STREAM) + + s1.should be_an_instance_of(Socket) + s2.should be_an_instance_of(Socket) + s1.close + s2.close + end + + it 'raises SocketError for an unknown address family' do + lambda { Socket.public_send(@method, :CATS, :STREAM) }.should raise_error(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + lambda { Socket.public_send(@method, :UNIX, :CATS) }.should raise_error(SocketError) + end + end + + describe 'using a String as the 1st and 2nd argument' do + it 'returns two Socket objects' do + s1, s2 = Socket.public_send(@method, 'UNIX', 'STREAM') + + s1.should be_an_instance_of(Socket) + s2.should be_an_instance_of(Socket) + s1.close + s2.close + end + + it 'raises SocketError for an unknown address family' do + lambda { Socket.public_send(@method, 'CATS', 'STREAM') }.should raise_error(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + lambda { Socket.public_send(@method, 'UNIX', 'CATS') }.should raise_error(SocketError) + end + end + + describe 'using an object that responds to #to_str as the 1st and 2nd argument' do + it 'returns two Socket objects' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('UNIX') + type.stub!(:to_str).and_return('STREAM') + + s1, s2 = Socket.public_send(@method, family, type) + + s1.should be_an_instance_of(Socket) + s2.should be_an_instance_of(Socket) + s1.close + s2.close + end + + it 'raises TypeError when #to_str does not return a String' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return(Socket::AF_UNIX) + type.stub!(:to_str).and_return(Socket::SOCK_STREAM) + + lambda { Socket.public_send(@method, family, type) }.should raise_error(TypeError) + end + + it 'raises SocketError for an unknown address family' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('CATS') + type.stub!(:to_str).and_return('STREAM') + + lambda { Socket.public_send(@method, family, type) }.should raise_error(SocketError) + end + + it 'raises SocketError for an unknown socket type' do + family = mock(:family) + type = mock(:type) + + family.stub!(:to_str).and_return('UNIX') + type.stub!(:to_str).and_return('CATS') + + lambda { Socket.public_send(@method, family, type) }.should raise_error(SocketError) + end + end + + it 'accepts a custom protocol as a Fixnum as the 3rd argument' do + s1, s2 = Socket.public_send(@method, :UNIX, :STREAM, Socket::IPPROTO_IP) + s1.should be_an_instance_of(Socket) + s2.should be_an_instance_of(Socket) + s1.close + s2.close + end + + it 'connects the returned Socket objects' do + s1, s2 = Socket.public_send(@method, :UNIX, :STREAM) + begin + s1.write('hello') + s2.recv(5).should == 'hello' + ensure + s1.close + s2.close + end + end end end |