From 27322e51a757f0ac6d1fd66802e02978def9904f Mon Sep 17 00:00:00 2001 From: Jenny Shen Date: Wed, 15 Feb 2023 10:50:45 -0500 Subject: [rubygems/rubygems] Add MockBrowser helper class https://github.com/rubygems/rubygems/commit/2d763cfd47 Co-authored-by: Jacques Chester --- test/rubygems/utilities.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/rubygems/utilities.rb b/test/rubygems/utilities.rb index 17a55107b1..6f5958c07c 100644 --- a/test/rubygems/utilities.rb +++ b/test/rubygems/utilities.rb @@ -187,6 +187,41 @@ class Gem::HTTPResponseFactory end end +## +# A Gem::MockBrowser is used in tests to mock a browser in that it can +# send HTTP requests to the defined URI. +# +# Example: +# +# # Sends a get request to http://localhost:5678 +# Gem::MockBrowser.get URI("http://localhost:5678") +# +# See RubyGems' tests for more examples of MockBrowser. +# + +class Gem::MockBrowser + def self.options(uri) + options = Net::HTTP::Options.new(uri) + Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(options) + end + end + + def self.get(uri) + get = Net::HTTP::Get.new(uri) + Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(get) + end + end + + def self.post(uri) + post = Net::HTTP::Post.new(uri) + Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(post) + end + end +end + # :stopdoc: class Gem::RemoteFetcher def self.fetcher=(fetcher) -- cgit v1.2.3