summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/utilities.rb35
1 files changed, 35 insertions, 0 deletions
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)