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.
This commit is contained in:
parent
29c0ca58c2
commit
35920f7a44
@ -49,16 +49,14 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
|
|||||||
server_addr = '127.0.0.1'
|
server_addr = '127.0.0.1'
|
||||||
server_port = 80
|
server_port = 80
|
||||||
|
|
||||||
begin
|
e = assert_raise_kind_of(SystemCallError) do
|
||||||
# Since client_addr is not an IP address of this host,
|
# Since client_addr is not an IP address of this host,
|
||||||
# bind() in TCPSocket.new should fail as EADDRNOTAVAIL.
|
# bind() in TCPSocket.new should fail as EADDRNOTAVAIL.
|
||||||
t = TCPSocket.new(server_addr, server_port, client_addr, client_port)
|
t = TCPSocket.new(server_addr, server_port, client_addr, client_port)
|
||||||
flunk "expected SystemCallError"
|
ensure
|
||||||
rescue SystemCallError => e
|
t&.close
|
||||||
assert_match "for \"#{client_addr}\" port #{client_port}", e.message
|
|
||||||
end
|
end
|
||||||
ensure
|
assert_include e.message, "for \"#{client_addr}\" port #{client_port}"
|
||||||
t.close if t && !t.closed?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_initialize_resolv_timeout
|
def test_initialize_resolv_timeout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user