diff --git a/core/file/new_spec.rb b/core/file/new_spec.rb index 715ac1aaf3..3e2641aed3 100644 --- a/core/file/new_spec.rb +++ b/core/file/new_spec.rb @@ -188,6 +188,12 @@ }.should raise_error(Errno::EEXIST, /File exists/) end + it "does not use the given block and warns to use File::open" do + -> { + @fh = File.new(@file) { raise } + }.should complain(/warning: File::new\(\) does not take block; use File::open\(\) instead/) + end + it "raises a TypeError if the first parameter can't be coerced to a string" do -> { File.new(true) }.should raise_error(TypeError) -> { File.new(false) }.should raise_error(TypeError) diff --git a/core/io/new_spec.rb b/core/io/new_spec.rb index 9d14ec18ad..979ac0efcb 100644 --- a/core/io/new_spec.rb +++ b/core/io/new_spec.rb @@ -5,6 +5,12 @@ describe "IO.new" do it_behaves_like :io_new, :new + + it "does not use the given block and warns to use IO::open" do + -> { + @io = IO.send(@method, @fd) { raise } + }.should complain(/warning: IO::new\(\) does not take block; use IO::open\(\) instead/) + end end describe "IO.new" do diff --git a/library/socket/tcpserver/new_spec.rb b/library/socket/tcpserver/new_spec.rb index 8d9696c9d8..dd1ba676bd 100644 --- a/library/socket/tcpserver/new_spec.rb +++ b/library/socket/tcpserver/new_spec.rb @@ -97,6 +97,12 @@ addr[1].should be_kind_of(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) end diff --git a/library/socket/udpsocket/new_spec.rb b/library/socket/udpsocket/new_spec.rb index 6cc0cadbcb..79bfcb624d 100644 --- a/library/socket/udpsocket/new_spec.rb +++ b/library/socket/udpsocket/new_spec.rb @@ -26,6 +26,12 @@ @socket.should be_an_instance_of(UDPSocket) end + it "does not use the given block and warns to use UDPSocket::open" do + -> { + @socket = UDPSocket.new { raise } + }.should complain(/warning: UDPSocket::new\(\) does not take block; use UDPSocket::open\(\) instead/) + end + it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT if unsupported family passed' do -> { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e| [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) diff --git a/library/socket/unixserver/new_spec.rb b/library/socket/unixserver/new_spec.rb index f831f40bc6..0ff6787559 100644 --- a/library/socket/unixserver/new_spec.rb +++ b/library/socket/unixserver/new_spec.rb @@ -2,5 +2,13 @@ require_relative 'shared/new' describe "UNIXServer.new" do - it_behaves_like :unixserver_new, :new + platform_is_not :windows do + it_behaves_like :unixserver_new, :new + + it "does not use the given block and warns to use UNIXServer::open" do + -> { + @server = UNIXServer.new(@path) { raise } + }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/) + end + end end diff --git a/library/socket/unixsocket/new_spec.rb b/library/socket/unixsocket/new_spec.rb index 05a6b3eda2..341c922808 100644 --- a/library/socket/unixsocket/new_spec.rb +++ b/library/socket/unixsocket/new_spec.rb @@ -2,5 +2,13 @@ require_relative 'shared/new' describe "UNIXSocket.new" do - it_behaves_like :unixsocket_new, :new + platform_is_not :windows do + it_behaves_like :unixsocket_new, :new + + it "does not use the given block and warns to use UNIXSocket::open" do + -> { + @client = UNIXSocket.new(@path) { raise } + }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/) + end + end end