mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -04:00
21 lines
554 B
Ruby
21 lines
554 B
Ruby
module Requests
|
|
module Errors
|
|
def test_connection_refused
|
|
unavailable_host = URI(origin("localhost"))
|
|
unavailable_host.port = next_available_port
|
|
response = HTTPX.get(unavailable_host.to_s)
|
|
assert response.is_a?(HTTPX::ErrorResponse), "response should contain errors"
|
|
assert response.status =~ /Connection refused/, "connection should have been refused"
|
|
end
|
|
|
|
private
|
|
|
|
def next_available_port
|
|
server = TCPServer.new("localhost", 0)
|
|
server.addr[1]
|
|
ensure
|
|
server.close
|
|
end
|
|
end
|
|
end
|