rubygems-update 2.1.11 → 2.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +37 -12
  5. data/History.txt +99 -2
  6. data/MIT.txt +1 -0
  7. data/Manifest.txt +59 -19
  8. data/Rakefile +4 -6
  9. data/lib/gauntlet_rubygems.rb +1 -1
  10. data/lib/rubygems.rb +102 -80
  11. data/lib/rubygems/available_set.rb +2 -2
  12. data/lib/rubygems/basic_specification.rb +97 -8
  13. data/lib/rubygems/commands/install_command.rb +58 -15
  14. data/lib/rubygems/commands/list_command.rb +1 -7
  15. data/lib/rubygems/commands/outdated_command.rb +1 -1
  16. data/lib/rubygems/commands/pristine_command.rb +14 -1
  17. data/lib/rubygems/commands/push_command.rb +9 -4
  18. data/lib/rubygems/commands/query_command.rb +33 -17
  19. data/lib/rubygems/commands/search_command.rb +0 -6
  20. data/lib/rubygems/commands/specification_command.rb +1 -1
  21. data/lib/rubygems/commands/unpack_command.rb +1 -1
  22. data/lib/rubygems/commands/update_command.rb +4 -1
  23. data/lib/rubygems/commands/which_command.rb +5 -8
  24. data/lib/rubygems/compatibility.rb +3 -0
  25. data/lib/rubygems/core_ext/kernel_gem.rb +6 -0
  26. data/lib/rubygems/defaults.rb +19 -0
  27. data/lib/rubygems/dependency_installer.rb +28 -9
  28. data/lib/rubygems/doctor.rb +17 -11
  29. data/lib/rubygems/errors.rb +16 -3
  30. data/lib/rubygems/exceptions.rb +52 -5
  31. data/lib/rubygems/ext.rb +1 -2
  32. data/lib/rubygems/ext/build_error.rb +6 -0
  33. data/lib/rubygems/ext/builder.rb +50 -17
  34. data/lib/rubygems/ext/cmake_builder.rb +1 -1
  35. data/lib/rubygems/ext/configure_builder.rb +1 -3
  36. data/lib/rubygems/ext/ext_conf_builder.rb +9 -3
  37. data/lib/rubygems/ext/rake_builder.rb +2 -5
  38. data/lib/rubygems/gemcutter_utilities.rb +8 -1
  39. data/lib/rubygems/installer.rb +14 -4
  40. data/lib/rubygems/installer_test_case.rb +0 -5
  41. data/lib/rubygems/package.rb +11 -2
  42. data/lib/rubygems/psych_additions.rb +1 -1
  43. data/lib/rubygems/rdoc.rb +1 -1
  44. data/lib/rubygems/remote_fetcher.rb +3 -3
  45. data/lib/rubygems/request.rb +16 -8
  46. data/lib/rubygems/request_set.rb +133 -42
  47. data/lib/rubygems/request_set/gem_dependency_api.rb +493 -11
  48. data/lib/rubygems/request_set/lockfile.rb +579 -0
  49. data/lib/rubygems/requirement.rb +58 -30
  50. data/lib/rubygems/resolver.rb +471 -0
  51. data/lib/rubygems/resolver/activation_request.rb +165 -0
  52. data/lib/rubygems/resolver/api_set.rb +110 -0
  53. data/lib/rubygems/resolver/api_specification.rb +79 -0
  54. data/lib/rubygems/resolver/best_set.rb +31 -0
  55. data/lib/rubygems/resolver/composed_set.rb +39 -0
  56. data/lib/rubygems/resolver/conflict.rb +122 -0
  57. data/lib/rubygems/{dependency_resolver → resolver}/current_set.rb +1 -4
  58. data/lib/rubygems/{dependency_resolver → resolver}/dependency_request.rb +37 -7
  59. data/lib/rubygems/resolver/git_set.rb +119 -0
  60. data/lib/rubygems/resolver/git_specification.rb +35 -0
  61. data/lib/rubygems/resolver/index_set.rb +74 -0
  62. data/lib/rubygems/resolver/index_specification.rb +69 -0
  63. data/lib/rubygems/resolver/installed_specification.rb +40 -0
  64. data/lib/rubygems/{dependency_resolver → resolver}/installer_set.rb +18 -17
  65. data/lib/rubygems/resolver/local_specification.rb +16 -0
  66. data/lib/rubygems/resolver/lock_set.rb +78 -0
  67. data/lib/rubygems/resolver/lock_specification.rb +58 -0
  68. data/lib/rubygems/resolver/requirement_list.rb +81 -0
  69. data/lib/rubygems/resolver/set.rb +27 -0
  70. data/lib/rubygems/resolver/spec_specification.rb +58 -0
  71. data/lib/rubygems/resolver/specification.rb +89 -0
  72. data/lib/rubygems/resolver/stats.rb +44 -0
  73. data/lib/rubygems/resolver/vendor_set.rb +83 -0
  74. data/lib/rubygems/resolver/vendor_specification.rb +24 -0
  75. data/lib/rubygems/security/trust_dir.rb +16 -2
  76. data/lib/rubygems/source.rb +71 -18
  77. data/lib/rubygems/source/git.rb +218 -0
  78. data/lib/rubygems/source/installed.rb +8 -1
  79. data/lib/rubygems/source/local.rb +14 -8
  80. data/lib/rubygems/source/lock.rb +48 -0
  81. data/lib/rubygems/source/specific_file.rb +14 -3
  82. data/lib/rubygems/source/vendor.rb +27 -0
  83. data/lib/rubygems/source_list.rb +74 -12
  84. data/lib/rubygems/spec_fetcher.rb +36 -4
  85. data/lib/rubygems/specification.rb +214 -65
  86. data/lib/rubygems/stub_specification.rb +57 -1
  87. data/lib/rubygems/syck_hack.rb +3 -3
  88. data/lib/rubygems/test_case.rb +226 -59
  89. data/lib/rubygems/test_utilities.rb +198 -0
  90. data/lib/rubygems/uninstaller.rb +22 -10
  91. data/lib/rubygems/uri_formatter.rb +20 -0
  92. data/lib/rubygems/user_interaction.rb +193 -71
  93. data/lib/rubygems/util.rb +121 -0
  94. data/lib/rubygems/util/list.rb +4 -0
  95. data/lib/rubygems/util/stringio.rb +34 -0
  96. data/lib/rubygems/validator.rb +6 -2
  97. data/lib/rubygems/version.rb +4 -8
  98. data/test/rubygems/test_bundled_ca.rb +1 -1
  99. data/test/rubygems/test_gem.rb +137 -29
  100. data/test/rubygems/test_gem_available_set.rb +19 -0
  101. data/test/rubygems/test_gem_commands_build_command.rb +1 -1
  102. data/test/rubygems/test_gem_commands_cert_command.rb +2 -2
  103. data/test/rubygems/test_gem_commands_cleanup_command.rb +13 -13
  104. data/test/rubygems/test_gem_commands_dependency_command.rb +24 -34
  105. data/test/rubygems/test_gem_commands_fetch_command.rb +43 -48
  106. data/test/rubygems/test_gem_commands_install_command.rb +244 -279
  107. data/test/rubygems/test_gem_commands_list_command.rb +3 -3
  108. data/test/rubygems/test_gem_commands_outdated_command.rb +7 -12
  109. data/test/rubygems/test_gem_commands_pristine_command.rb +73 -27
  110. data/test/rubygems/test_gem_commands_push_command.rb +76 -8
  111. data/test/rubygems/test_gem_commands_query_command.rb +239 -49
  112. data/test/rubygems/test_gem_commands_sources_command.rb +10 -43
  113. data/test/rubygems/test_gem_commands_specification_command.rb +24 -47
  114. data/test/rubygems/test_gem_commands_stale_command.rb +2 -2
  115. data/test/rubygems/test_gem_commands_uninstall_command.rb +3 -3
  116. data/test/rubygems/test_gem_commands_unpack_command.rb +16 -30
  117. data/test/rubygems/test_gem_commands_update_command.rb +149 -134
  118. data/test/rubygems/test_gem_commands_which_command.rb +4 -2
  119. data/test/rubygems/test_gem_dependency_installer.rb +68 -0
  120. data/test/rubygems/test_gem_dependency_list.rb +17 -17
  121. data/test/rubygems/test_gem_dependency_resolution_error.rb +28 -0
  122. data/test/rubygems/test_gem_doctor.rb +1 -1
  123. data/test/rubygems/test_gem_ext_builder.rb +178 -8
  124. data/test/rubygems/test_gem_ext_cmake_builder.rb +1 -7
  125. data/test/rubygems/test_gem_ext_configure_builder.rb +8 -10
  126. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +18 -21
  127. data/test/rubygems/test_gem_ext_rake_builder.rb +1 -3
  128. data/test/rubygems/test_gem_impossible_dependencies_error.rb +10 -6
  129. data/test/rubygems/test_gem_indexer.rb +6 -6
  130. data/test/rubygems/test_gem_installer.rb +29 -10
  131. data/test/rubygems/test_gem_local_remote_options.rb +1 -1
  132. data/test/rubygems/test_gem_package.rb +18 -0
  133. data/test/rubygems/test_gem_rdoc.rb +1 -1
  134. data/test/rubygems/test_gem_remote_fetcher.rb +1 -1
  135. data/test/rubygems/test_gem_request.rb +37 -10
  136. data/test/rubygems/test_gem_request_set.rb +271 -9
  137. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +684 -0
  138. data/test/rubygems/test_gem_request_set_lockfile.rb +849 -0
  139. data/test/rubygems/test_gem_requirement.rb +21 -0
  140. data/test/rubygems/{test_gem_dependency_resolver.rb → test_gem_resolver.rb} +231 -70
  141. data/test/rubygems/test_gem_resolver_activation_request.rb +63 -0
  142. data/test/rubygems/test_gem_resolver_api_set.rb +167 -0
  143. data/test/rubygems/test_gem_resolver_api_specification.rb +104 -0
  144. data/test/rubygems/test_gem_resolver_best_set.rb +30 -0
  145. data/test/rubygems/test_gem_resolver_conflict.rb +75 -0
  146. data/test/rubygems/test_gem_resolver_dependency_request.rb +20 -0
  147. data/test/rubygems/test_gem_resolver_git_set.rb +148 -0
  148. data/test/rubygems/test_gem_resolver_git_specification.rb +100 -0
  149. data/test/rubygems/test_gem_resolver_index_set.rb +28 -0
  150. data/test/rubygems/test_gem_resolver_index_specification.rb +89 -0
  151. data/test/rubygems/test_gem_resolver_installed_specification.rb +49 -0
  152. data/test/rubygems/test_gem_resolver_installer_set.rb +22 -0
  153. data/test/rubygems/test_gem_resolver_local_specification.rb +45 -0
  154. data/test/rubygems/test_gem_resolver_lock_set.rb +57 -0
  155. data/test/rubygems/test_gem_resolver_lock_specification.rb +87 -0
  156. data/test/rubygems/test_gem_resolver_requirement_list.rb +20 -0
  157. data/test/rubygems/test_gem_resolver_specification.rb +32 -0
  158. data/test/rubygems/test_gem_resolver_vendor_set.rb +67 -0
  159. data/test/rubygems/test_gem_resolver_vendor_specification.rb +83 -0
  160. data/test/rubygems/test_gem_server.rb +4 -4
  161. data/test/rubygems/test_gem_source.rb +54 -64
  162. data/test/rubygems/test_gem_source_git.rb +231 -0
  163. data/test/rubygems/test_gem_source_list.rb +24 -0
  164. data/test/rubygems/test_gem_source_local.rb +1 -1
  165. data/test/rubygems/test_gem_source_lock.rb +114 -0
  166. data/test/rubygems/test_gem_source_vendor.rb +27 -0
  167. data/test/rubygems/test_gem_spec_fetcher.rb +116 -61
  168. data/test/rubygems/test_gem_specification.rb +526 -94
  169. data/test/rubygems/test_gem_stub_specification.rb +123 -10
  170. data/test/rubygems/test_gem_uninstaller.rb +28 -2
  171. data/test/rubygems/test_gem_util.rb +31 -0
  172. data/test/rubygems/test_gem_validator.rb +9 -0
  173. data/util/update_bundled_ca_certificates.rb +8 -1
  174. metadata +89 -29
  175. metadata.gz.sig +2 -4
  176. data/lib/rubygems/dependency_resolver.rb +0 -254
  177. data/lib/rubygems/dependency_resolver/activation_request.rb +0 -109
  178. data/lib/rubygems/dependency_resolver/api_set.rb +0 -65
  179. data/lib/rubygems/dependency_resolver/api_specification.rb +0 -39
  180. data/lib/rubygems/dependency_resolver/composed_set.rb +0 -18
  181. data/lib/rubygems/dependency_resolver/dependency_conflict.rb +0 -85
  182. data/lib/rubygems/dependency_resolver/index_set.rb +0 -64
  183. data/lib/rubygems/dependency_resolver/index_specification.rb +0 -60
  184. data/lib/rubygems/dependency_resolver/installed_specification.rb +0 -52
  185. data/test/rubygems/test_gem_dependency_resolver_api_specification.rb +0 -33
  186. data/test/rubygems/test_gem_dependency_resolver_dependency_conflict.rb +0 -36
  187. data/test/rubygems/test_gem_dependency_resolver_index_set.rb +0 -53
  188. data/test/rubygems/test_gem_dependency_resolver_index_specification.rb +0 -73
  189. data/test/rubygems/test_gem_dependency_resolver_installed_specification.rb +0 -19
  190. data/test/rubygems/test_gem_dependency_resolver_installer_set.rb +0 -28
@@ -41,6 +41,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
41
41
  def initialize(filename)
42
42
  self.loaded_from = filename
43
43
  @data = nil
44
+ @extensions = nil
44
45
  @spec = nil
45
46
  end
46
47
 
@@ -52,17 +53,31 @@ class Gem::StubSpecification < Gem::BasicSpecification
52
53
  loaded && loaded.version == version
53
54
  end
54
55
 
56
+ def build_extensions # :nodoc:
57
+ return if default_gem?
58
+ return if extensions.empty?
59
+
60
+ to_spec.build_extensions
61
+ end
62
+
55
63
  ##
56
64
  # If the gemspec contains a stubline, returns a StubLine instance. Otherwise
57
65
  # returns the full Gem::Specification.
58
66
 
59
67
  def data
60
68
  unless @data
69
+ @extensions = []
70
+
61
71
  open loaded_from, OPEN_MODE do |file|
62
72
  begin
63
73
  file.readline # discard encoding line
64
74
  stubline = file.readline.chomp
65
- @data = StubLine.new(stubline) if stubline.start_with?(PREFIX)
75
+ if stubline.start_with?(PREFIX) then
76
+ @data = StubLine.new stubline
77
+
78
+ @extensions = $'.split "\0" if
79
+ /\A#{PREFIX}/ =~ file.readline.chomp
80
+ end
66
81
  rescue EOFError
67
82
  end
68
83
  end
@@ -73,6 +88,38 @@ class Gem::StubSpecification < Gem::BasicSpecification
73
88
 
74
89
  private :data
75
90
 
91
+ ##
92
+ # Extensions for this gem
93
+
94
+ def extensions
95
+ return @extensions if @extensions
96
+
97
+ data # load
98
+
99
+ @extensions
100
+ end
101
+
102
+ ##
103
+ # If a gem has a stub specification it doesn't need to bother with
104
+ # compatibility with original_name gems. It was installed with the
105
+ # normalized name.
106
+
107
+ def find_full_gem_path # :nodoc:
108
+ path = File.expand_path File.join gems_dir, full_name
109
+ path.untaint
110
+ path
111
+ end
112
+
113
+ ##
114
+ # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
115
+ # activated.
116
+
117
+ def full_require_paths
118
+ @require_paths ||= data.require_paths
119
+
120
+ super
121
+ end
122
+
76
123
  ##
77
124
  # Name of the gem
78
125
 
@@ -92,6 +139,8 @@ class Gem::StubSpecification < Gem::BasicSpecification
92
139
 
93
140
  def require_paths
94
141
  @require_paths ||= data.require_paths
142
+
143
+ super
95
144
  end
96
145
 
97
146
  ##
@@ -116,5 +165,12 @@ class Gem::StubSpecification < Gem::BasicSpecification
116
165
  @version ||= data.version
117
166
  end
118
167
 
168
+ ##
169
+ # Is there a stub line present for this StubSpecification?
170
+
171
+ def stubbed?
172
+ data.is_a? StubLine
173
+ end
174
+
119
175
  end
120
176
 
@@ -10,9 +10,9 @@
10
10
  # class no matter if the full yaml library has loaded or not.
11
11
  #
12
12
 
13
- module YAML
13
+ module YAML # :nodoc:
14
14
  # In newer 1.9.2, there is a Syck toplevel constant instead of it
15
- # being underneith YAML. If so, reference it back under YAML as
15
+ # being underneath YAML. If so, reference it back under YAML as
16
16
  # well.
17
17
  if defined? ::Syck
18
18
  # for tests that change YAML::ENGINE
@@ -29,7 +29,7 @@ module YAML
29
29
  # loaded, so lets define a stub for DefaultKey.
30
30
  elsif !defined? YAML::Syck
31
31
  module Syck
32
- class DefaultKey
32
+ class DefaultKey # :nodoc:
33
33
  end
34
34
  end
35
35
  end
@@ -24,17 +24,19 @@ unless Gem::Dependency.new('rdoc', '>= 3.10').matching_specs.empty?
24
24
  gem 'json'
25
25
  end
26
26
 
27
- require 'rubygems/deprecate'
28
27
  require 'minitest/autorun'
28
+
29
+ require 'rubygems/deprecate'
30
+
29
31
  require 'fileutils'
32
+ require 'pathname'
33
+ require 'pp'
34
+ require 'rubygems/package'
35
+ require 'shellwords'
30
36
  require 'tmpdir'
31
37
  require 'uri'
32
- require 'rubygems/package'
33
- require 'rubygems/test_utilities'
34
- require 'pp'
35
38
  require 'zlib'
36
- require 'pathname'
37
- require 'shellwords'
39
+
38
40
  Gem.load_yaml
39
41
 
40
42
  require 'rubygems/mock_gem_ui'
@@ -84,6 +86,12 @@ end
84
86
 
85
87
  class Gem::TestCase < MiniTest::Unit::TestCase
86
88
 
89
+ attr_accessor :fetcher # :nodoc:
90
+
91
+ attr_accessor :gem_repo # :nodoc:
92
+
93
+ attr_accessor :uri # :nodoc:
94
+
87
95
  def assert_activate expected, *specs
88
96
  specs.each do |spec|
89
97
  case spec
@@ -197,7 +205,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
197
205
  @orig_gem_path = ENV['GEM_PATH']
198
206
 
199
207
  @current_dir = Dir.pwd
200
- @ui = Gem::MockGemUi.new
208
+ @fetcher = nil
209
+ @ui = Gem::MockGemUi.new
201
210
 
202
211
  tmpdir = File.expand_path Dir.tmpdir
203
212
  tmpdir.untaint
@@ -231,6 +240,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
231
240
  ruby
232
241
  end
233
242
 
243
+ @git = ENV['GIT'] || 'git'
244
+
234
245
  Gem.ensure_gem_subdirectories @gemhome
235
246
 
236
247
  @orig_LOAD_PATH = $LOAD_PATH.dup
@@ -241,6 +252,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
241
252
  @orig_ENV_HOME = ENV['HOME']
242
253
  ENV['HOME'] = @userhome
243
254
  Gem.instance_variable_set :@user_home, nil
255
+ Gem.send :remove_instance_variable, :@ruby_version if
256
+ Gem.instance_variables.include? :@ruby_version
244
257
 
245
258
  FileUtils.mkdir_p @gemhome
246
259
  FileUtils.mkdir_p @userhome
@@ -368,6 +381,64 @@ class Gem::TestCase < MiniTest::Unit::TestCase
368
381
  Gem.pre_uninstall_hooks.clear
369
382
  end
370
383
 
384
+ ##
385
+ # A git_gem is used with a gem dependencies file. The gem created here
386
+ # has no files, just a gem specification for the given +name+ and +version+.
387
+ #
388
+ # Yields the +specification+ to the block, if given
389
+
390
+ def git_gem name = 'a', version = 1
391
+ have_git?
392
+
393
+ directory = File.join 'git', name
394
+ directory = File.expand_path directory
395
+
396
+ git_spec = Gem::Specification.new name, version do |specification|
397
+ yield specification if block_given?
398
+ end
399
+
400
+ FileUtils.mkdir_p directory
401
+
402
+ gemspec = "#{name}.gemspec"
403
+
404
+ open File.join(directory, gemspec), 'w' do |io|
405
+ io.write git_spec.to_ruby
406
+ end
407
+
408
+ head = nil
409
+
410
+ Dir.chdir directory do
411
+ unless File.exist? '.git' then
412
+ system @git, 'init', '--quiet'
413
+ system @git, 'config', 'user.name', 'RubyGems Tests'
414
+ system @git, 'config', 'user.email', 'rubygems@example'
415
+ end
416
+
417
+ system @git, 'add', gemspec
418
+ system @git, 'commit', '-a', '-m', 'a non-empty commit message', '--quiet'
419
+ head = Gem::Util.popen('git', 'rev-parse', 'master').strip
420
+ end
421
+
422
+ return name, git_spec.version, directory, head
423
+ end
424
+
425
+ ##
426
+ # Skips this test unless you have a git executable
427
+
428
+ def have_git?
429
+ return if in_path? @git
430
+
431
+ skip 'cannot find git executable, use GIT environment variable to set'
432
+ end
433
+
434
+ def in_path? executable # :nodoc:
435
+ return true if %r%\A([A-Z]:|/)% =~ executable and File.exist? executable
436
+
437
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
438
+ File.exist? File.join directory, executable
439
+ end
440
+ end
441
+
371
442
  ##
372
443
  # Builds and installs the Gem::Specification +spec+
373
444
 
@@ -376,7 +447,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
376
447
 
377
448
  gem = File.join @tempdir, "gems", "#{spec.full_name}.gem"
378
449
 
379
- unless File.exists? gem
450
+ unless File.exist? gem then
380
451
  use_ui Gem::MockGemUi.new do
381
452
  Dir.chdir @tempdir do
382
453
  Gem::Package.build spec
@@ -501,28 +572,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase
501
572
  return spec
502
573
  end
503
574
 
504
- def quick_spec name, version = '2'
505
- # TODO: deprecate
506
- require 'rubygems/specification'
507
-
508
- spec = Gem::Specification.new do |s|
509
- s.platform = Gem::Platform::RUBY
510
- s.name = name
511
- s.version = version
512
- s.author = 'A User'
513
- s.email = 'example@example.com'
514
- s.homepage = 'http://example.com'
515
- s.summary = "this is a summary"
516
- s.description = "This is a test description"
517
-
518
- yield(s) if block_given?
519
- end
520
-
521
- spec.loaded_from = spec.spec_file
522
-
523
- Gem::Specification.add_spec spec
575
+ ##
576
+ # TODO: remove in RubyGems 3.0
524
577
 
525
- return spec
578
+ def quick_spec name, version = '2' # :nodoc:
579
+ util_spec name, version
526
580
  end
527
581
 
528
582
  ##
@@ -559,7 +613,9 @@ class Gem::TestCase < MiniTest::Unit::TestCase
559
613
 
560
614
  def util_clear_gems
561
615
  FileUtils.rm_rf File.join(@gemhome, "gems") # TODO: use Gem::Dirs
616
+ FileUtils.mkdir File.join(@gemhome, "gems")
562
617
  FileUtils.rm_rf File.join(@gemhome, "specifications")
618
+ FileUtils.mkdir File.join(@gemhome, "specifications")
563
619
  Gem::Specification.reset
564
620
  end
565
621
 
@@ -610,10 +666,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase
610
666
  end
611
667
 
612
668
  ##
613
- # Create a new spec (or gem if passed an array of files) and set it
614
- # up properly. Use this instead of util_spec and util_gem.
669
+ # new_spec is deprecated as it is never used.
670
+ #
671
+ # TODO: remove in RubyGems 3.0
615
672
 
616
- def new_spec name, version, deps = nil, *files
673
+ def new_spec name, version, deps = nil, *files # :nodoc:
617
674
  require 'rubygems/specification'
618
675
 
619
676
  spec = Gem::Specification.new do |s|
@@ -654,7 +711,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
654
711
  end
655
712
 
656
713
  def new_default_spec(name, version, deps = nil, *files)
657
- spec = new_spec(name, version, deps)
714
+ spec = util_spec name, version, deps
715
+
658
716
  spec.loaded_from = File.join(@default_spec_dir, spec.spec_name)
659
717
  spec.files = files
660
718
 
@@ -672,24 +730,38 @@ class Gem::TestCase < MiniTest::Unit::TestCase
672
730
  end
673
731
 
674
732
  ##
675
- # Creates a spec with +name+, +version+ and +deps+.
733
+ # Creates a spec with +name+, +version+. +deps+ can specify the dependency
734
+ # or a +block+ can be given for full customization of the specification.
676
735
 
677
- def util_spec(name, version, deps = nil, &block)
678
- # TODO: deprecate
679
- raise "deps or block, not both" if deps and block
736
+ def util_spec name, version = 2, deps = nil # :yields: specification
737
+ raise "deps or block, not both" if deps and block_given?
738
+
739
+ spec = Gem::Specification.new do |s|
740
+ s.platform = Gem::Platform::RUBY
741
+ s.name = name
742
+ s.version = version
743
+ s.author = 'A User'
744
+ s.email = 'example@example.com'
745
+ s.homepage = 'http://example.com'
746
+ s.summary = "this is a summary"
747
+ s.description = "This is a test description"
748
+
749
+ yield s if block_given?
750
+ end
680
751
 
681
752
  if deps then
682
- block = proc do |s|
683
- # Since Hash#each is unordered in 1.8, sort
684
- # the keys and iterate that way so the tests are
685
- # deteriminstic on all implementations.
686
- deps.keys.sort.each do |n|
687
- s.add_dependency n, (deps[n] || '>= 0')
688
- end
753
+ # Since Hash#each is unordered in 1.8, sort the keys and iterate that
754
+ # way so the tests are deterministic on all implementations.
755
+ deps.keys.sort.each do |n|
756
+ spec.add_dependency n, (deps[n] || '>= 0')
689
757
  end
690
758
  end
691
759
 
692
- quick_spec(name, version, &block)
760
+ spec.loaded_from = spec.spec_file
761
+
762
+ Gem::Specification.add_spec spec
763
+
764
+ return spec
693
765
  end
694
766
 
695
767
  ##
@@ -898,14 +970,35 @@ Also, a list:
898
970
  spec_fetcher.prerelease_specs[@uri] << spec.name_tuple
899
971
  end
900
972
 
901
- v = Gem.marshal_version
973
+ # HACK for test_download_to_cache
974
+ unless Gem::RemoteFetcher === @fetcher then
975
+ v = Gem.marshal_version
976
+
977
+ specs = all.map { |spec| spec.name_tuple }
978
+ s_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic specs
979
+
980
+ latest_specs = Gem::Specification.latest_specs.map do |spec|
981
+ spec.name_tuple
982
+ end
983
+
984
+ l_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic latest_specs
985
+
986
+ prerelease_specs = prerelease.map { |spec| spec.name_tuple }
987
+ p_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic prerelease_specs
988
+
989
+ @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
990
+ @fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
991
+ @fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
902
992
 
903
- Gem::Specification.each do |spec|
904
- path = "#{@gem_repo}quick/Marshal.#{v}/#{spec.original_name}.gemspec.rz"
905
- data = Marshal.dump spec
906
- data_deflate = Zlib::Deflate.deflate data
907
- @fetcher.data[path] = data_deflate
908
- end unless Gem::RemoteFetcher === @fetcher # HACK for test_download_to_cache
993
+ v = Gem.marshal_version
994
+
995
+ Gem::Specification.each do |spec|
996
+ path = "#{@gem_repo}quick/Marshal.#{v}/#{spec.original_name}.gemspec.rz"
997
+ data = Marshal.dump spec
998
+ data_deflate = Zlib::Deflate.deflate data
999
+ @fetcher.data[path] = data_deflate
1000
+ end
1001
+ end
909
1002
 
910
1003
  nil # force errors
911
1004
  end
@@ -1056,21 +1149,23 @@ Also, a list:
1056
1149
  end
1057
1150
 
1058
1151
  ##
1059
- # Constructs a Gem::DependencyResolver::DependencyRequest from a
1152
+ # Constructs a Gem::Resolver::DependencyRequest from a
1060
1153
  # Gem::Dependency +dep+, a +from_name+ and +from_version+ requesting the
1061
1154
  # dependency and a +parent+ DependencyRequest
1062
1155
 
1063
1156
  def dependency_request dep, from_name, from_version, parent = nil
1064
1157
  remote = Gem::Source.new @uri
1065
1158
 
1066
- parent ||= Gem::DependencyResolver::DependencyRequest.new \
1067
- dep, nil
1159
+ unless parent then
1160
+ parent_dep = dep from_name, from_version
1161
+ parent = Gem::Resolver::DependencyRequest.new parent_dep, nil
1162
+ end
1068
1163
 
1069
- spec = Gem::DependencyResolver::IndexSpecification.new \
1164
+ spec = Gem::Resolver::IndexSpecification.new \
1070
1165
  nil, from_name, from_version, remote, Gem::Platform::RUBY
1071
- activation = Gem::DependencyResolver::ActivationRequest.new spec, parent
1166
+ activation = Gem::Resolver::ActivationRequest.new spec, parent
1072
1167
 
1073
- Gem::DependencyResolver::DependencyRequest.new dep, activation
1168
+ Gem::Resolver::DependencyRequest.new dep, activation
1074
1169
  end
1075
1170
 
1076
1171
  ##
@@ -1088,6 +1183,32 @@ Also, a list:
1088
1183
  Gem::Specification.new name, v(version), &block
1089
1184
  end
1090
1185
 
1186
+ ##
1187
+ # Creates a SpecFetcher pre-filled with the gems or specs defined in the
1188
+ # block.
1189
+ #
1190
+ # Yields a +fetcher+ object that responds to +spec+ and +gem+. +spec+ adds
1191
+ # a specification to the SpecFetcher while +gem+ adds both a specification
1192
+ # and the gem data to the RemoteFetcher so the built gem can be downloaded.
1193
+ #
1194
+ # If only the a-3 gem is supposed to be downloaded you can save setup
1195
+ # time by creating only specs for the other versions:
1196
+ #
1197
+ # spec_fetcher do |fetcher|
1198
+ # fetcher.spec 'a', 1
1199
+ # fetcher.spec 'a', 2, 'b' => 3 # dependency on b = 3
1200
+ # fetcher.gem 'a', 3 do |spec|
1201
+ # # spec is a Gem::Specification
1202
+ # # ...
1203
+ # end
1204
+ # end
1205
+
1206
+ def spec_fetcher repository = @gem_repo
1207
+ Gem::TestCase::SpecFetcherSetup.declare self, repository do |spec_fetcher_setup|
1208
+ yield spec_fetcher_setup if block_given?
1209
+ end
1210
+ end
1211
+
1091
1212
  ##
1092
1213
  # Construct a new Gem::Version.
1093
1214
 
@@ -1095,25 +1216,68 @@ Also, a list:
1095
1216
  Gem::Version.create string
1096
1217
  end
1097
1218
 
1219
+ ##
1220
+ # A vendor_gem is used with a gem dependencies file. The gem created here
1221
+ # has no files, just a gem specification for the given +name+ and +version+.
1222
+ #
1223
+ # Yields the +specification+ to the block, if given
1224
+
1225
+ def vendor_gem name = 'a', version = 1
1226
+ directory = File.join 'vendor', name
1227
+
1228
+ vendor_spec = Gem::Specification.new name, version do |specification|
1229
+ yield specification if block_given?
1230
+ end
1231
+
1232
+ FileUtils.mkdir_p directory
1233
+
1234
+ open File.join(directory, "#{name}.gemspec"), 'w' do |io|
1235
+ io.write vendor_spec.to_ruby
1236
+ end
1237
+
1238
+ return name, vendor_spec.version, directory
1239
+ end
1240
+
1241
+ ##
1242
+ # The StaticSet is a static set of gem specifications used for testing only.
1243
+ # It is available by requiring Gem::TestCase.
1244
+
1098
1245
  class StaticSet
1246
+
1247
+ ##
1248
+ # Creates a new StaticSet for the given +specs+
1249
+
1099
1250
  def initialize(specs)
1100
1251
  @specs = specs
1101
1252
  end
1102
1253
 
1254
+ ##
1255
+ # Adds +spec+ to this set.
1256
+
1103
1257
  def add spec
1104
1258
  @specs << spec
1105
1259
  end
1106
1260
 
1261
+ ##
1262
+ # Finds +dep+ in this set.
1263
+
1107
1264
  def find_spec(dep)
1108
1265
  @specs.reverse_each do |s|
1109
1266
  return s if dep.matches_spec? s
1110
1267
  end
1111
1268
  end
1112
1269
 
1270
+ ##
1271
+ # Finds all gems matching +dep+ in this set.
1272
+
1113
1273
  def find_all(dep)
1114
1274
  @specs.find_all { |s| dep.matches_spec? s }
1115
1275
  end
1116
1276
 
1277
+ ##
1278
+ # Loads a Gem::Specification from this set which has the given +name+,
1279
+ # version +ver+, +platform+. The +source+ is ignored.
1280
+
1117
1281
  def load_spec name, ver, platform, source
1118
1282
  dep = Gem::Dependency.new name, ver
1119
1283
  spec = find_spec dep
@@ -1123,7 +1287,7 @@ Also, a list:
1123
1287
  end
1124
1288
  end
1125
1289
 
1126
- def prefetch(reqs)
1290
+ def prefetch reqs # :nodoc:
1127
1291
  end
1128
1292
  end
1129
1293
 
@@ -1196,3 +1360,6 @@ Also, a list:
1196
1360
  end if defined?(OpenSSL::SSL)
1197
1361
 
1198
1362
  end
1363
+
1364
+ require 'rubygems/test_utilities'
1365
+