max_redirects = 3 # Follow redirects response = max_redirects.times.lazy.filter_map { puts "Requesting #{url}…" response = Net::HTTP.get_response(URI(url)) case response when Net::HTTPRedirection url = response["location"] nil else response end }.first assert_equal 200, response.code.to_i