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 "Socket::TCPServer.accept_nonblock" do
|
||||
|
@ -46,3 +46,39 @@ describe "Socket::TCPServer.accept_nonblock" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'TCPServer#accept_nonblock' do
|
||||
SocketSpecs.each_ip_protocol do |family, ip_address|
|
||||
before do
|
||||
@server = TCPServer.new(ip_address, 0)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
describe 'without a connected client' do
|
||||
it 'raises IO::WaitReadable' do
|
||||
lambda { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
|
||||
end
|
||||
end
|
||||
|
||||
platform_is_not :windows do # spurious
|
||||
describe 'with a connected client' do
|
||||
before do
|
||||
@client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
|
||||
end
|
||||
|
||||
after do
|
||||
@socket.close if @socket
|
||||
@client.close
|
||||
end
|
||||
|
||||
it 'returns a TCPSocket' do
|
||||
@socket = @server.accept_nonblock
|
||||
@socket.should be_an_instance_of(TCPSocket)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
|
||||
describe "TCPServer#accept" do
|
||||
before :each do
|
||||
@server = TCPServer.new("127.0.0.1", 0)
|
||||
|
@ -64,3 +63,37 @@ describe "TCPServer#accept" do
|
|||
lambda { @server.accept }.should raise_error(IOError)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'TCPServer#accept' do
|
||||
SocketSpecs.each_ip_protocol do |family, ip_address|
|
||||
before do
|
||||
@server = TCPServer.new(ip_address, 0)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
describe 'without a connected client' do
|
||||
it 'blocks the caller' do
|
||||
lambda { @server.accept }.should block_caller
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a connected client' do
|
||||
before do
|
||||
@client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
|
||||
end
|
||||
|
||||
after do
|
||||
@socket.close if @socket
|
||||
@client.close
|
||||
end
|
||||
|
||||
it 'returns a TCPSocket' do
|
||||
@socket = @server.accept
|
||||
@socket.should be_an_instance_of(TCPSocket)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "TCPServer#gets" do
|
||||
|
|
99
spec/ruby/library/socket/tcpserver/initialize_spec.rb
Normal file
99
spec/ruby/library/socket/tcpserver/initialize_spec.rb
Normal file
|
@ -0,0 +1,99 @@
|
|||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe 'TCPServer#initialize' do
|
||||
describe 'with a single Fixnum argument' do
|
||||
before do
|
||||
@server = TCPServer.new(0)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'sets the port to the given argument' do
|
||||
@server.local_address.ip_port.should be_an_instance_of(Fixnum)
|
||||
@server.local_address.ip_port.should > 0
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it 'sets the hostname to 0.0.0.0' do
|
||||
@server.local_address.ip_address.should == '0.0.0.0'
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the socket to binmode" do
|
||||
@server.binmode?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a single String argument containing a numeric value' do
|
||||
before do
|
||||
@server = TCPServer.new('0')
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'sets the port to the given argument' do
|
||||
@server.local_address.ip_port.should be_an_instance_of(Fixnum)
|
||||
@server.local_address.ip_port.should > 0
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it 'sets the hostname to 0.0.0.0' do
|
||||
@server.local_address.ip_address.should == '0.0.0.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a single String argument containing a non numeric value' do
|
||||
it 'raises SocketError' do
|
||||
lambda { TCPServer.new('cats') }.should raise_error(SocketError)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a String and a Fixnum' do
|
||||
SocketSpecs.each_ip_protocol do |family, ip_address|
|
||||
before do
|
||||
@server = TCPServer.new(ip_address, 0)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'sets the port to the given port argument' do
|
||||
@server.local_address.ip_port.should be_an_instance_of(Fixnum)
|
||||
@server.local_address.ip_port.should > 0
|
||||
end
|
||||
|
||||
it 'sets the hostname to the given host argument' do
|
||||
@server.local_address.ip_address.should == ip_address
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a String and a custom object' do
|
||||
before do
|
||||
dummy = mock(:dummy)
|
||||
dummy.stub!(:to_str).and_return('0')
|
||||
|
||||
@server = TCPServer.new('127.0.0.1', dummy)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'sets the port to the given port argument' do
|
||||
@server.local_address.ip_port.should be_an_instance_of(Fixnum)
|
||||
@server.local_address.ip_port.should > 0
|
||||
end
|
||||
|
||||
it 'sets the hostname to the given host argument' do
|
||||
@server.local_address.ip_address.should == '127.0.0.1'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +1,22 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
require 'socket'
|
||||
|
||||
describe 'TCPServer#listen' do
|
||||
before :each do
|
||||
@server = TCPServer.new(SocketSpecs.hostname, 0)
|
||||
end
|
||||
SocketSpecs.each_ip_protocol do |family, ip_address|
|
||||
before do
|
||||
@server = TCPServer.new(ip_address, 0)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@server.close unless @server.closed?
|
||||
end
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
it 'returns 0' do
|
||||
@server.listen(10).should == 0
|
||||
it 'returns 0' do
|
||||
@server.listen(1).should == 0
|
||||
end
|
||||
|
||||
it "raises when the given argument can't be coerced to a Fixnum" do
|
||||
lambda { @server.listen('cats') }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
describe "TCPServer.new" do
|
||||
|
@ -25,7 +25,7 @@ describe "TCPServer.new" do
|
|||
addr[2].should =~ /^#{SocketSpecs.hostname}\b/
|
||||
addr[3].should == '127.0.0.1'
|
||||
else
|
||||
addr[2].should =~ /^#{SocketSpecs.hostnamev6}\b/
|
||||
addr[2].should =~ /^#{SocketSpecs.hostname('::1')}\b/
|
||||
addr[3].should == '::1'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
require 'socket'
|
||||
|
||||
describe "TCPServer#sysaccept" do
|
||||
before :each do
|
||||
@server = TCPServer.new(SocketSpecs.hostname, 0)
|
||||
|
@ -30,3 +28,39 @@ describe "TCPServer#sysaccept" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'TCPServer#sysaccept' do
|
||||
SocketSpecs.each_ip_protocol do |family, ip_address|
|
||||
before do
|
||||
@server = TCPServer.new(ip_address, 0)
|
||||
end
|
||||
|
||||
after do
|
||||
@server.close
|
||||
end
|
||||
|
||||
describe 'without a connected client' do
|
||||
it 'blocks the caller' do
|
||||
lambda { @server.sysaccept }.should block_caller
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a connected client' do
|
||||
before do
|
||||
@client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
|
||||
end
|
||||
|
||||
after do
|
||||
Socket.for_fd(@fd).close if @fd
|
||||
@client.close
|
||||
end
|
||||
|
||||
it 'returns a new file descriptor as a Fixnum' do
|
||||
@fd = @server.sysaccept
|
||||
|
||||
@fd.should be_an_instance_of(Fixnum)
|
||||
@fd.should_not == @client.fileno
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue