Skip to content

Commit 35920f7

Browse files
committed
Refine TestSocket_TCPSocket#test_initialize_failure
* Use `assert_raise_kind_of` instead of `rescue` and `flunk`. * Use `assert_include` for the pattern that may contain regexp meta characters.
1 parent 29c0ca5 commit 35920f7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

test/socket/test_tcp.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ def test_initialize_failure
4949
server_addr = '127.0.0.1'
5050
server_port = 80
5151

52-
begin
52+
e = assert_raise_kind_of(SystemCallError) do
5353
# Since client_addr is not an IP address of this host,
5454
# bind() in TCPSocket.new should fail as EADDRNOTAVAIL.
5555
t = TCPSocket.new(server_addr, server_port, client_addr, client_port)
56-
flunk "expected SystemCallError"
57-
rescue SystemCallError => e
58-
assert_match "for \"#{client_addr}\" port #{client_port}", e.message
56+
ensure
57+
t&.close
5958
end
60-
ensure
61-
t.close if t && !t.closed?
59+
assert_include e.message, "for \"#{client_addr}\" port #{client_port}"
6260
end
6361

6462
def test_initialize_resolv_timeout

0 commit comments

Comments
 (0)