summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/tcpserver/new_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-11-30 21:26:52 +0100
committerBenoit Daloze <eregontp@gmail.com>2019-11-30 21:26:52 +0100
commit1243255c3a36433041012b6107a5ac48658a0895 (patch)
tree04440f84b48999ff08d4a2a16d066d0ad731400e /spec/ruby/library/socket/tcpserver/new_spec.rb
parentab8345271eb87ff155d8bd5f22f53a4cf2902c26 (diff)
Update to ruby/spec@4eec3dc
Diffstat (limited to 'spec/ruby/library/socket/tcpserver/new_spec.rb')
-rw-r--r--spec/ruby/library/socket/tcpserver/new_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/ruby/library/socket/tcpserver/new_spec.rb b/spec/ruby/library/socket/tcpserver/new_spec.rb
index d099f0175f..8d9696c9d8 100644
--- a/spec/ruby/library/socket/tcpserver/new_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/new_spec.rb
@@ -48,6 +48,24 @@ describe "TCPServer.new" do
addr[3].should == '0.0.0.0'
end
+ it "binds to a port if the port is explicitly nil" do
+ @server = TCPServer.new('', nil)
+ addr = @server.addr
+ addr[0].should == 'AF_INET'
+ addr[1].should be_kind_of(Integer)
+ addr[2].should == '0.0.0.0'
+ addr[3].should == '0.0.0.0'
+ end
+
+ it "binds to a port if the port is an empty string" do
+ @server = TCPServer.new('', '')
+ addr = @server.addr
+ addr[0].should == 'AF_INET'
+ addr[1].should be_kind_of(Integer)
+ addr[2].should == '0.0.0.0'
+ addr[3].should == '0.0.0.0'
+ end
+
it "coerces port to string, then determines port from that number or service name" do
-> { TCPServer.new(SocketSpecs.hostname, Object.new) }.should raise_error(TypeError)
@@ -62,6 +80,23 @@ describe "TCPServer.new" do
# pick such a service port that will be able to reliably bind...
end
+ it "has a single argument form and treats it as a port number" do
+ @server = TCPServer.new(0)
+ addr = @server.addr
+ addr[1].should be_kind_of(Integer)
+ end
+
+ it "coerces port to a string when it is the only argument" do
+ -> { TCPServer.new(Object.new) }.should raise_error(TypeError)
+
+ port = Object.new
+ port.should_receive(:to_str).and_return("0")
+
+ @server = TCPServer.new(port)
+ addr = @server.addr
+ addr[1].should be_kind_of(Integer)
+ end
+
it "raises Errno::EADDRNOTAVAIL when the address is unknown" do
-> { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL)
end