mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
36
spec/ruby/library/socket/unixsocket/addr_spec.rb
Normal file
36
spec/ruby/library/socket/unixsocket/addr_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#addr" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "returns the address family of this socket in an array" do
|
||||
@client.addr[0].should == "AF_UNIX"
|
||||
end
|
||||
|
||||
it "returns the path of the socket in an array if it's a server" do
|
||||
@server.addr[1].should == @path
|
||||
end
|
||||
|
||||
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
|
17
spec/ruby/library/socket/unixsocket/inspect_spec.rb
Normal file
17
spec/ruby/library/socket/unixsocket/inspect_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#inspect" do
|
||||
platform_is_not :windows do
|
||||
it "returns sockets fd for unnamed sockets" do
|
||||
begin
|
||||
s1, s2 = UNIXSocket.socketpair
|
||||
s1.inspect.should == "#<UNIXSocket:fd #{s1.fileno}>"
|
||||
s2.inspect.should == "#<UNIXSocket:fd #{s2.fileno}>"
|
||||
ensure
|
||||
s1.close
|
||||
s2.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
6
spec/ruby/library/socket/unixsocket/new_spec.rb
Normal file
6
spec/ruby/library/socket/unixsocket/new_spec.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/new', __FILE__)
|
||||
|
||||
describe "UNIXSocket.new" do
|
||||
it_behaves_like :unixsocket_new, :new
|
||||
end
|
27
spec/ruby/library/socket/unixsocket/open_spec.rb
Normal file
27
spec/ruby/library/socket/unixsocket/open_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/new', __FILE__)
|
||||
|
||||
describe "UNIXSocket.open" do
|
||||
it_behaves_like :unixsocket_new, :open
|
||||
end
|
||||
|
||||
describe "UNIXSocket.open" do
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "opens a unix socket on the specified file and yields it to the block" do
|
||||
UNIXSocket.send(@method, @path) do |client|
|
||||
client.addr[0].should == "AF_UNIX"
|
||||
client.closed?.should == false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
39
spec/ruby/library/socket/unixsocket/pair_spec.rb
Normal file
39
spec/ruby/library/socket/unixsocket/pair_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
|
||||
|
||||
describe "UNIXSocket#pair" do
|
||||
platform_is_not :windows do
|
||||
|
||||
it_should_behave_like "partially closable sockets"
|
||||
|
||||
before :each do
|
||||
@s1, @s2 = UNIXSocket.pair
|
||||
end
|
||||
|
||||
after :each do
|
||||
@s1.close
|
||||
@s2.close
|
||||
end
|
||||
|
||||
it "returns a pair of connected sockets" do
|
||||
@s1.puts "foo"
|
||||
@s2.gets.should == "foo\n"
|
||||
end
|
||||
|
||||
it "returns sockets with no name" do
|
||||
@s1.path.should == @s2.path
|
||||
@s1.path.should == ""
|
||||
end
|
||||
|
||||
it "returns sockets with no address" do
|
||||
@s1.addr.should == ["AF_UNIX", ""]
|
||||
@s2.addr.should == ["AF_UNIX", ""]
|
||||
end
|
||||
|
||||
it "returns sockets with no peeraddr" do
|
||||
@s1.peeraddr.should == ["AF_UNIX", ""]
|
||||
@s2.peeraddr.should == ["AF_UNIX", ""]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
require File.expand_path('../../shared/partially_closable_sockets', __FILE__)
|
||||
|
||||
platform_is_not :windows do
|
||||
describe "UNIXSocket partial closability" do
|
||||
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@s1 = UNIXSocket.new(@path)
|
||||
@s2 = @server.accept
|
||||
end
|
||||
|
||||
after :each do
|
||||
@server.close
|
||||
@s1.close
|
||||
@s2.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it_should_behave_like "partially closable sockets"
|
||||
|
||||
end
|
||||
end
|
28
spec/ruby/library/socket/unixsocket/path_spec.rb
Normal file
28
spec/ruby/library/socket/unixsocket/path_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#path" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "returns the path of the socket if it's a server" do
|
||||
@server.path.should == @path
|
||||
end
|
||||
|
||||
it "returns an empty string for path if it's a client" do
|
||||
@client.path.should == ""
|
||||
end
|
||||
end
|
||||
|
||||
end
|
28
spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
Normal file
28
spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#peeraddr" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "returns the address familly and path of the server end of the connection" do
|
||||
@client.peeraddr.should == ["AF_UNIX", @path]
|
||||
end
|
||||
|
||||
it "raises an error in server sockets" do
|
||||
lambda { @server.peeraddr }.should raise_error
|
||||
end
|
||||
end
|
||||
|
||||
end
|
44
spec/ruby/library/socket/unixsocket/recv_io_spec.rb
Normal file
44
spec/ruby/library/socket/unixsocket/recv_io_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#recv_io" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
|
||||
@send_io_path = File.expand_path('../../fixtures/send_io.txt', __FILE__)
|
||||
@file = File.open(@send_io_path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@io.close if @io
|
||||
@socket.close if @socket
|
||||
|
||||
@file.close
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "reads an IO object across the socket" do
|
||||
@client.send_io(@file)
|
||||
|
||||
@socket = @server.accept
|
||||
@io = @socket.recv_io
|
||||
|
||||
@io.read.should == File.read(@send_io_path)
|
||||
end
|
||||
|
||||
it "takes an optional class to use" do
|
||||
@client.send_io(@file)
|
||||
|
||||
@socket = @server.accept
|
||||
@io = @socket.recv_io(File)
|
||||
|
||||
@io.should be_kind_of(File)
|
||||
end
|
||||
end
|
||||
end
|
47
spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
Normal file
47
spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#recvfrom" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "receives len bytes from sock" do
|
||||
@client.send("foobar", 0)
|
||||
sock = @server.accept
|
||||
sock.recvfrom(6).first.should == "foobar"
|
||||
sock.close
|
||||
end
|
||||
|
||||
it "returns an array with data and information on the sender" do
|
||||
@client.send("foobar", 0)
|
||||
sock = @server.accept
|
||||
data = sock.recvfrom(6)
|
||||
data.first.should == "foobar"
|
||||
data.last.should == ["AF_UNIX", ""]
|
||||
sock.close
|
||||
end
|
||||
|
||||
it "uses different message options" do
|
||||
@client.send("foobar", Socket::MSG_PEEK)
|
||||
sock = @server.accept
|
||||
peek_data = sock.recvfrom(6, Socket::MSG_PEEK) # Does not retrieve the message
|
||||
real_data = sock.recvfrom(6)
|
||||
|
||||
real_data.should == peek_data
|
||||
peek_data.should == ["foobar", ["AF_UNIX", ""]]
|
||||
sock.close
|
||||
end
|
||||
end
|
||||
|
||||
end
|
35
spec/ruby/library/socket/unixsocket/send_io_spec.rb
Normal file
35
spec/ruby/library/socket/unixsocket/send_io_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UNIXSocket#send_io" do
|
||||
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
@client = UNIXSocket.open(@path)
|
||||
|
||||
@send_io_path = File.expand_path('../../fixtures/send_io.txt', __FILE__)
|
||||
@file = File.open(@send_io_path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@io.close if @io
|
||||
@socket.close if @socket
|
||||
|
||||
@file.close
|
||||
@client.close
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "sends the fd for an IO object across the socket" do
|
||||
@client.send_io(@file)
|
||||
|
||||
@socket = @server.accept
|
||||
@io = @socket.recv_io
|
||||
|
||||
@io.read.should == File.read(@send_io_path)
|
||||
end
|
||||
end
|
||||
end
|
24
spec/ruby/library/socket/unixsocket/shared/new.rb
Normal file
24
spec/ruby/library/socket/unixsocket/shared/new.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../../fixtures/classes', __FILE__)
|
||||
|
||||
describe :unixsocket_new, shared: true do
|
||||
platform_is_not :windows do
|
||||
before :each do
|
||||
@path = SocketSpecs.socket_path
|
||||
@server = UNIXServer.open(@path)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@client.close if @client
|
||||
@server.close
|
||||
SocketSpecs.rm_socket @path
|
||||
end
|
||||
|
||||
it "opens a unix socket on the specified file" do
|
||||
@client = UNIXSocket.send(@method, @path)
|
||||
|
||||
@client.addr[0].should == "AF_UNIX"
|
||||
@client.closed?.should == false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue