aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/test_utilities.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/test_utilities.rb')
-rw-r--r--lib/rubygems/test_utilities.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb
index 069ecccabe..5d02b04897 100644
--- a/lib/rubygems/test_utilities.rb
+++ b/lib/rubygems/test_utilities.rb
@@ -13,6 +13,13 @@ require 'rubygems/remote_fetcher'
# @fetcher.data['http://gems.example.com/yaml'] = source_index.to_yaml
# Gem::RemoteFetcher.fetcher = @fetcher
#
+# use nested array if multiple response is needed
+#
+# @fetcher.data['http://gems.example.com/sequence'] = [['Success', 200, 'OK'], ['Failed', 401, 'Unauthorized']]
+#
+# @fetcher.fetch_path('http://gems.example.com/sequence') # => ['Success', 200, 'OK']
+# @fetcher.fetch_path('http://gems.example.com/sequence') # => ['Failed', 401, 'Unauthorized']
+#
# # invoke RubyGems code
#
# paths = @fetcher.paths
@@ -32,7 +39,7 @@ class Gem::FakeFetcher
@paths = []
end
- def find_data(path)
+ def find_data(path, nargs = 3)
return File.read path.path if URI === path and 'file' == path.scheme
if URI === path and "URI::#{path.scheme.upcase}" != path.class.name
@@ -48,7 +55,10 @@ class Gem::FakeFetcher
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
end
- @data[path]
+ data = @data[path]
+
+ data.flatten! and return data.shift(nargs) if data.respond_to?(:flatten!)
+ data
end
def fetch_path(path, mtime = nil, head = false)
@@ -60,7 +70,6 @@ class Gem::FakeFetcher
if path.to_s =~ /gz$/ and not data.nil? and not data.empty?
data = Gem::Util.gunzip data
end
-
data
end
end