Skip to content

Commit

Permalink
Add tests for warnings when passing block to creation of new IO object
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Sep 29, 2023
1 parent d353e7e commit 7b9bb21
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/file/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions core/io/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions library/socket/tcpserver/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions library/socket/udpsocket/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion library/socket/unixserver/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion library/socket/unixsocket/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7b9bb21

Please sign in to comment.