diff --git a/test/test_helper.rb b/test/test_helper.rb index 6bb3f7ef6..a00682f8f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -73,6 +73,38 @@ config.allow_http_connections_when_no_cassette = false config.default_cassette_options = {match_requests_on: %i[method uri body], decode_compressed_response: true} end + +module WebMock + # class RequestPattern + # alias_method :_matches?, :matches? + + # def matches?(request_signature) + # return if request_signature.uri.host == '127.0.0.1' && request_signature.uri.path == '/__identify__' + # _matches?(request_signature) + # end + # end + + def self.net_connect_explicit_allowed?(allowed, uri=nil) + case allowed + when Array + allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) } + when Regexp + (uri.to_s =~ allowed) != nil || + (uri.omit(:port).to_s =~ allowed) != nil && uri.port == uri.default_port + when String + allowed == uri.to_s || + allowed == uri.host || + allowed == "#{uri.host}:#{uri.port}" || + allowed == "#{uri.scheme}://#{uri.host}:#{uri.port}" || + (allowed == uri.omit(:port).to_s && uri.port == uri.default_port) + else + if allowed.respond_to?(:call) + allowed.call(uri) + end + end + end +end + module ActiveSupport class TestCase include ServiceClassHelpers