summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/tcpserver/new_spec.rb
diff options
context:
space:
mode:
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