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
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#addr" do
|
||||
|
@ -16,8 +16,13 @@ describe "UNIXSocket#addr" do
|
|||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "returns an array" do
|
||||
@client.addr.should be_kind_of(Array)
|
||||
end
|
||||
|
||||
it "returns the address family of this socket in an array" do
|
||||
@client.addr[0].should == "AF_UNIX"
|
||||
@server.addr[0].should == "AF_UNIX"
|
||||
end
|
||||
|
||||
it "returns the path of the socket in an array if it's a server" do
|
||||
|
@ -27,10 +32,5 @@ describe "UNIXSocket#addr" do
|
|||
it "returns an empty string for path if it's a client" do
|
||||
@client.addr[1].should == ""
|
||||
end
|
||||
|
||||
it "returns an array" do
|
||||
@client.addr.should be_kind_of(Array)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
38
spec/ruby/library/socket/unixsocket/initialize_spec.rb
Normal file
38
spec/ruby/library/socket/unixsocket/initialize_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#initialize' do
|
||||
describe 'using a non existing path' do
|
||||
it 'raises Errno::ENOENT' do
|
||||
lambda { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'using an existing socket path' do
|
||||
before do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.new(@path)
|
||||
@socket = UNIXSocket.new(@path)
|
||||
end
|
||||
|
||||
after do
|
||||
@socket.close
|
||||
@server.close
|
||||
rm_r(@path)
|
||||
end
|
||||
|
||||
it 'returns a new UNIXSocket' do
|
||||
@socket.should be_an_instance_of(UNIXSocket)
|
||||
end
|
||||
|
||||
it 'sets the socket path to an empty String' do
|
||||
@socket.path.should == ''
|
||||
end
|
||||
|
||||
it 'sets the socket to binmode' do
|
||||
@socket.binmode?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#inspect" do
|
||||
|
|
45
spec/ruby/library/socket/unixsocket/local_address_spec.rb
Normal file
45
spec/ruby/library/socket/unixsocket/local_address_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#local_address' do
|
||||
before do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.new(@path)
|
||||
@client = UNIXSocket.new(@path)
|
||||
end
|
||||
|
||||
after do
|
||||
@client.close
|
||||
@server.close
|
||||
|
||||
rm_r(@path)
|
||||
end
|
||||
|
||||
it 'returns an Addrinfo' do
|
||||
@client.local_address.should be_an_instance_of(Addrinfo)
|
||||
end
|
||||
|
||||
describe 'the returned Addrinfo' do
|
||||
it 'uses AF_UNIX as the address family' do
|
||||
@client.local_address.afamily.should == Socket::AF_UNIX
|
||||
end
|
||||
|
||||
it 'uses PF_UNIX as the protocol family' do
|
||||
@client.local_address.pfamily.should == Socket::PF_UNIX
|
||||
end
|
||||
|
||||
it 'uses SOCK_STREAM as the socket type' do
|
||||
@client.local_address.socktype.should == Socket::SOCK_STREAM
|
||||
end
|
||||
|
||||
it 'uses an empty socket path' do
|
||||
@client.local_address.unix_path.should == ''
|
||||
end
|
||||
|
||||
it 'uses 0 as the protocol' do
|
||||
@client.local_address.protocol.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative 'shared/new'
|
||||
|
||||
describe "UNIXSocket.new" do
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/new'
|
||||
|
||||
describe "UNIXSocket.open" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative '../shared/partially_closable_sockets'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative '../shared/partially_closable_sockets'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#path" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#peeraddr" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#recv_io" do
|
||||
|
@ -38,7 +38,50 @@ describe "UNIXSocket#recv_io" do
|
|||
@socket = @server.accept
|
||||
@io = @socket.recv_io(File)
|
||||
|
||||
@io.should be_kind_of(File)
|
||||
@io.should be_an_instance_of(File)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#recv_io' do
|
||||
before do
|
||||
@file = File.open('/dev/null', 'w')
|
||||
@client, @server = UNIXSocket.socketpair
|
||||
end
|
||||
|
||||
after do
|
||||
@client.close
|
||||
@server.close
|
||||
@io.close if @io
|
||||
@file.close
|
||||
end
|
||||
|
||||
describe 'without a custom class' do
|
||||
it 'returns an IO' do
|
||||
@client.send_io(@file)
|
||||
|
||||
@io = @server.recv_io
|
||||
@io.should be_an_instance_of(IO)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a custom class' do
|
||||
it 'returns an instance of the custom class' do
|
||||
@client.send_io(@file)
|
||||
|
||||
@io = @server.recv_io(File)
|
||||
@io.should be_an_instance_of(File)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a custom mode' do
|
||||
it 'opens the IO using the given mode' do
|
||||
@client.send_io(@file)
|
||||
|
||||
@io = @server.recv_io(File, File::WRONLY)
|
||||
@io.should be_an_instance_of(File)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#recvfrom" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
|
@ -43,5 +42,56 @@ describe "UNIXSocket#recvfrom" do
|
|||
sock.close
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#recvfrom' do
|
||||
describe 'using a socket pair' do
|
||||
before do
|
||||
@client, @server = UNIXSocket.socketpair
|
||||
@client.write('hello')
|
||||
end
|
||||
|
||||
after do
|
||||
@client.close
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'returns an Array containing the data and address information' do
|
||||
@server.recvfrom(5).should == ['hello', ['AF_UNIX', '']]
|
||||
end
|
||||
end
|
||||
|
||||
# These specs are taken from the rdoc examples on UNIXSocket#recvfrom.
|
||||
describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do
|
||||
before do
|
||||
@path1 = SocketSpecs.socket_path
|
||||
@path2 = SocketSpecs.socket_path + '2'
|
||||
rm_r(@path2)
|
||||
|
||||
@client_raw = Socket.new(:UNIX, :DGRAM)
|
||||
@client_raw.bind(Socket.sockaddr_un(@path1))
|
||||
|
||||
@server_raw = Socket.new(:UNIX, :DGRAM)
|
||||
@server_raw.bind(Socket.sockaddr_un(@path2))
|
||||
|
||||
@socket = UNIXSocket.for_fd(@server_raw.fileno)
|
||||
end
|
||||
|
||||
after do
|
||||
@client_raw.close
|
||||
@server_raw.close # also closes @socket
|
||||
|
||||
rm_r @path1
|
||||
rm_r @path2
|
||||
end
|
||||
|
||||
it 'returns an Array containing the data and address information' do
|
||||
@client_raw.send('hello', 0, Socket.sockaddr_un(@path2))
|
||||
|
||||
@socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
45
spec/ruby/library/socket/unixsocket/remote_address_spec.rb
Normal file
45
spec/ruby/library/socket/unixsocket/remote_address_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#remote_address' do
|
||||
before do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.new(@path)
|
||||
@client = UNIXSocket.new(@path)
|
||||
end
|
||||
|
||||
after do
|
||||
@client.close
|
||||
@server.close
|
||||
|
||||
rm_r(@path)
|
||||
end
|
||||
|
||||
it 'returns an Addrinfo' do
|
||||
@client.remote_address.should be_an_instance_of(Addrinfo)
|
||||
end
|
||||
|
||||
describe 'the returned Addrinfo' do
|
||||
it 'uses AF_UNIX as the address family' do
|
||||
@client.remote_address.afamily.should == Socket::AF_UNIX
|
||||
end
|
||||
|
||||
it 'uses PF_UNIX as the protocol family' do
|
||||
@client.remote_address.pfamily.should == Socket::PF_UNIX
|
||||
end
|
||||
|
||||
it 'uses SOCK_STREAM as the socket type' do
|
||||
@client.remote_address.socktype.should == Socket::SOCK_STREAM
|
||||
end
|
||||
|
||||
it 'uses the correct socket path' do
|
||||
@client.remote_address.unix_path.should == @path
|
||||
end
|
||||
|
||||
it 'uses 0 as the protocol' do
|
||||
@client.remote_address.protocol.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "UNIXSocket#send_io" do
|
||||
|
@ -33,3 +33,26 @@ describe "UNIXSocket#send_io" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket#send_io' do
|
||||
before do
|
||||
@file = File.open('/dev/null', 'w')
|
||||
@client, @server = UNIXSocket.socketpair
|
||||
end
|
||||
|
||||
after do
|
||||
@client.close
|
||||
@server.close
|
||||
@io.close if @io
|
||||
@file.close
|
||||
end
|
||||
|
||||
it 'sends an IO object' do
|
||||
@client.send_io(@file)
|
||||
|
||||
@io = @server.recv_io
|
||||
@io.should be_an_instance_of(IO)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../../spec_helper'
|
||||
require_relative '../../spec_helper'
|
||||
require_relative '../../fixtures/classes'
|
||||
|
||||
describe :unixsocket_new, shared: true do
|
||||
|
|
40
spec/ruby/library/socket/unixsocket/socketpair_spec.rb
Normal file
40
spec/ruby/library/socket/unixsocket/socketpair_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
with_feature :unix_socket do
|
||||
describe 'UNIXSocket.socketpair' do
|
||||
before do
|
||||
@s1, @s2 = UNIXSocket.socketpair
|
||||
end
|
||||
|
||||
after do
|
||||
@s1.close
|
||||
@s2.close
|
||||
end
|
||||
|
||||
it 'returns two UNIXSockets' do
|
||||
@s1.should be_an_instance_of(UNIXSocket)
|
||||
@s2.should be_an_instance_of(UNIXSocket)
|
||||
end
|
||||
|
||||
it 'connects the sockets to each other' do
|
||||
@s1.write('hello')
|
||||
|
||||
@s2.recv(5).should == 'hello'
|
||||
end
|
||||
|
||||
it 'sets the socket paths to empty Strings' do
|
||||
@s1.path.should == ''
|
||||
@s2.path.should == ''
|
||||
end
|
||||
|
||||
it 'sets the socket addresses to empty Strings' do
|
||||
@s1.addr.should == ['AF_UNIX', '']
|
||||
@s2.addr.should == ['AF_UNIX', '']
|
||||
end
|
||||
|
||||
it 'sets the socket peer addresses to empty Strings' do
|
||||
@s1.peeraddr.should == ['AF_UNIX', '']
|
||||
@s2.peeraddr.should == ['AF_UNIX', '']
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue