From 749a4c5937ab57c430bf96ae5cca0f02081f4a45 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 8 Mar 2023 09:28:09 +0800 Subject: [PATCH] DEV: Introduce `stub_ip_lookup` spec helper (#20571) --- spec/lib/final_destination/http_spec.rb | 9 --------- spec/support/helpers.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/lib/final_destination/http_spec.rb b/spec/lib/final_destination/http_spec.rb index 9ef4977826b..fe1132acc82 100644 --- a/spec/lib/final_destination/http_spec.rb +++ b/spec/lib/final_destination/http_spec.rb @@ -25,15 +25,6 @@ describe FinalDestination::HTTP do end end - def stub_ip_lookup(stub_addr, ips) - Addrinfo - .stubs(:getaddrinfo) - .with { |addr, _| addr == stub_addr } - .returns( - ips.map { |ip| Addrinfo.new([IPAddr.new(ip).ipv6? ? "AF_INET6" : "AF_INET", 80, nil, ip]) }, - ) - end - def stub_tcp_to_raise(stub_addr, exception) TCPSocket.stubs(:open).with { |addr| addr == stub_addr }.once.raises(exception) end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index fef1ad63562..ff611df35e3 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -192,4 +192,13 @@ module Helpers queries end + + def stub_ip_lookup(stub_addr, ips) + Addrinfo + .stubs(:getaddrinfo) + .with { |addr, _| addr == stub_addr } + .returns( + ips.map { |ip| Addrinfo.new([IPAddr.new(ip).ipv6? ? "AF_INET6" : "AF_INET", 80, nil, ip]) }, + ) + end end