diff options
Diffstat (limited to 'spec/ruby/library/socket/tcpserver')
7 files changed, 54 insertions, 35 deletions
diff --git a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb index 91f6a327f0..ac08fe37c6 100644 --- a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb @@ -15,7 +15,7 @@ describe "Socket::TCPServer.accept_nonblock" do @server.listen(5) -> { @server.accept_nonblock - }.should raise_error(IO::WaitReadable) + }.should.raise(IO::WaitReadable) c = TCPSocket.new("127.0.0.1", @port) IO.select([@server]) @@ -25,7 +25,7 @@ describe "Socket::TCPServer.accept_nonblock" do port.should == @port address.should == "127.0.0.1" - s.should be_kind_of(TCPSocket) + s.should.is_a?(TCPSocket) c.close s.close @@ -33,12 +33,12 @@ describe "Socket::TCPServer.accept_nonblock" do it "raises an IOError if the socket is closed" do @server.close - -> { @server.accept }.should raise_error(IOError) + -> { @server.accept }.should.raise(IOError) end describe 'without a connected client' do it 'raises error' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end it 'returns :wait_readable in exceptionless mode' do @@ -59,7 +59,7 @@ describe 'TCPServer#accept_nonblock' do describe 'without a connected client' do it 'raises IO::WaitReadable' do - -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable) + -> { @server.accept_nonblock }.should.raise(IO::WaitReadable) end end @@ -77,7 +77,7 @@ describe 'TCPServer#accept_nonblock' do it 'returns a TCPSocket' do IO.select([@server]) @socket = @server.accept_nonblock - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) end end end diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb index d38d95e0e1..f2aa0bf8e1 100644 --- a/spec/ruby/library/socket/tcpserver/accept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb @@ -15,7 +15,7 @@ describe "TCPServer#accept" do data = nil t = Thread.new do client = @server.accept - client.should be_kind_of(TCPSocket) + client.should.is_a?(TCPSocket) data = client.read(5) client << "goodbye" client.close @@ -50,7 +50,7 @@ describe "TCPServer#accept" do t = Thread.new { -> { @server.accept - }.should raise_error(Exception, "interrupted") + }.should.raise(Exception, "interrupted") } Thread.pass while t.status and t.status != "sleep" @@ -69,7 +69,7 @@ describe "TCPServer#accept" do Thread.pass while t.status and t.status != "sleep" # Thread#backtrace uses SIGVTALRM on TruffleRuby and potentially other implementations. # Sending a signal to a thread is not possible with Ruby APIs. - t.backtrace.join("\n").should.include?("in `accept'") + t.backtrace.join("\n").should =~ /in [`'](?:TCPServer#)?accept'/ socket = TCPSocket.new('127.0.0.1', @port) socket.write("OK") @@ -80,7 +80,7 @@ describe "TCPServer#accept" do it "raises an IOError if the socket is closed" do @server.close - -> { @server.accept }.should raise_error(IOError) + -> { @server.accept }.should.raise(IOError) end end @@ -112,7 +112,20 @@ describe 'TCPServer#accept' do it 'returns a TCPSocket' do @socket = @server.accept - @socket.should be_an_instance_of(TCPSocket) + @socket.should.instance_of?(TCPSocket) + end + + platform_is_not :windows do + it "returns a TCPSocket which is set to nonblocking" do + require 'io/nonblock' + @socket = @server.accept + @socket.should.nonblock? + end + end + + it "returns a TCPSocket which is set to close on exec" do + @socket = @server.accept + @socket.should.close_on_exec? end end end diff --git a/spec/ruby/library/socket/tcpserver/gets_spec.rb b/spec/ruby/library/socket/tcpserver/gets_spec.rb index 417976d737..72a72fa2dc 100644 --- a/spec/ruby/library/socket/tcpserver/gets_spec.rb +++ b/spec/ruby/library/socket/tcpserver/gets_spec.rb @@ -11,6 +11,6 @@ describe "TCPServer#gets" do end it "raises Errno::ENOTCONN on gets" do - -> { @server.gets }.should raise_error(Errno::ENOTCONN) + -> { @server.gets }.should.raise(Errno::ENOTCONN) end end diff --git a/spec/ruby/library/socket/tcpserver/initialize_spec.rb b/spec/ruby/library/socket/tcpserver/initialize_spec.rb index 4ddd1f465f..517b014edc 100644 --- a/spec/ruby/library/socket/tcpserver/initialize_spec.rb +++ b/spec/ruby/library/socket/tcpserver/initialize_spec.rb @@ -12,7 +12,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -24,7 +24,7 @@ describe 'TCPServer#initialize' do end it "sets the socket to binmode" do - @server.binmode?.should be_true + @server.binmode?.should == true end end @@ -38,7 +38,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -52,7 +52,7 @@ describe 'TCPServer#initialize' do describe 'with a single String argument containing a non numeric value' do it 'raises SocketError' do - -> { TCPServer.new('cats') }.should raise_error(SocketError) + -> { TCPServer.new('cats') }.should.raise(SocketError) end end @@ -67,7 +67,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given port argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end @@ -90,7 +90,7 @@ describe 'TCPServer#initialize' do end it 'sets the port to the given port argument' do - @server.local_address.ip_port.should be_kind_of(Integer) + @server.local_address.ip_port.should.is_a?(Integer) @server.local_address.ip_port.should > 0 end diff --git a/spec/ruby/library/socket/tcpserver/listen_spec.rb b/spec/ruby/library/socket/tcpserver/listen_spec.rb index c877fdced6..5b046ef6f7 100644 --- a/spec/ruby/library/socket/tcpserver/listen_spec.rb +++ b/spec/ruby/library/socket/tcpserver/listen_spec.rb @@ -16,7 +16,7 @@ describe 'TCPServer#listen' do end it "raises when the given argument can't be coerced to an Integer" do - -> { @server.listen('cats') }.should raise_error(TypeError) + -> { @server.listen('cats') }.should.raise(TypeError) end end end diff --git a/spec/ruby/library/socket/tcpserver/new_spec.rb b/spec/ruby/library/socket/tcpserver/new_spec.rb index 8d9696c9d8..70b8d4352e 100644 --- a/spec/ruby/library/socket/tcpserver/new_spec.rb +++ b/spec/ruby/library/socket/tcpserver/new_spec.rb @@ -10,7 +10,7 @@ describe "TCPServer.new" do @server = TCPServer.new('127.0.0.1', 0) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) # on some platforms (Mac), MRI # returns comma at the end. addr[2].should =~ /^#{SocketSpecs.hostname}\b/ @@ -20,7 +20,7 @@ describe "TCPServer.new" do it "binds to localhost and a port with either IPv4 or IPv6" do @server = TCPServer.new(SocketSpecs.hostname, 0) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) if addr[0] == 'AF_INET' addr[2].should =~ /^#{SocketSpecs.hostname}\b/ addr[3].should == '127.0.0.1' @@ -34,7 +34,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', 0) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -43,7 +43,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', '0') addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -52,7 +52,7 @@ describe "TCPServer.new" do @server = TCPServer.new('', nil) addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) addr[2].should == '0.0.0.0' addr[3].should == '0.0.0.0' end @@ -61,20 +61,20 @@ describe "TCPServer.new" do @server = TCPServer.new('', '') addr = @server.addr addr[0].should == 'AF_INET' - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(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) + -> { TCPServer.new(SocketSpecs.hostname, Object.new) }.should.raise(TypeError) port = Object.new port.should_receive(:to_str).and_return("0") @server = TCPServer.new(SocketSpecs.hostname, port) addr = @server.addr - addr[1].should be_kind_of(Integer) + addr[1].should.is_a?(Integer) # TODO: This should also accept strings like 'https', but I don't know how to # pick such a service port that will be able to reliably bind... @@ -83,22 +83,28 @@ describe "TCPServer.new" do 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) + addr[1].should.is_a?(Integer) end it "coerces port to a string when it is the only argument" do - -> { TCPServer.new(Object.new) }.should raise_error(TypeError) + -> { TCPServer.new(Object.new) }.should.raise(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) + addr[1].should.is_a?(Integer) + end + + it "does not use the given block and warns to use TCPServer::open" do + -> { + @server = TCPServer.new(0) { raise } + }.should complain(/warning: TCPServer::new\(\) does not take block; use TCPServer::open\(\) instead/) end it "raises Errno::EADDRNOTAVAIL when the address is unknown" do - -> { TCPServer.new("1.2.3.4", 0) }.should raise_error(Errno::EADDRNOTAVAIL) + -> { TCPServer.new("1.2.3.4", 0) }.should.raise(Errno::EADDRNOTAVAIL) end # There is no way to make this fail-proof on all machines, because @@ -108,7 +114,7 @@ describe "TCPServer.new" do it "raises a SocketError when the host is unknown" do -> { TCPServer.new("--notavalidname", 0) - }.should raise_error(SocketError) + }.should.raise(SocketError) end end @@ -116,7 +122,7 @@ describe "TCPServer.new" do @server = TCPServer.new('127.0.0.1', 0) -> { @server = TCPServer.new('127.0.0.1', @server.addr[1]) - }.should raise_error(Errno::EADDRINUSE) + }.should.raise(Errno::EADDRINUSE) end platform_is_not :windows, :aix do diff --git a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb index bd7d33faf4..ed23bced23 100644 --- a/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb @@ -21,7 +21,7 @@ describe "TCPServer#sysaccept" do fd = @server.sysaccept - fd.should be_kind_of(Integer) + fd.should.is_a?(Integer) ensure sock.close if sock && !sock.closed? IO.for_fd(fd).close if fd @@ -58,7 +58,7 @@ describe 'TCPServer#sysaccept' do it 'returns a new file descriptor as an Integer' do @fd = @server.sysaccept - @fd.should be_kind_of(Integer) + @fd.should.is_a?(Integer) @fd.should_not == @client.fileno end end |
