rubygems-update 1.1.1 → 1.2.0

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 (152) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +267 -1
  3. data/Rakefile +13 -7
  4. data/doc/release_notes/rel_1_2_0.rdoc +105 -0
  5. data/lib/rubygems.rb +82 -14
  6. data/lib/rubygems/command.rb +1 -1
  7. data/lib/rubygems/command_manager.rb +3 -2
  8. data/lib/rubygems/commands/cert_command.rb +1 -1
  9. data/lib/rubygems/commands/dependency_command.rb +57 -19
  10. data/lib/rubygems/commands/environment_command.rb +2 -0
  11. data/lib/rubygems/commands/fetch_command.rb +3 -1
  12. data/lib/rubygems/commands/install_command.rb +3 -3
  13. data/lib/rubygems/commands/list_command.rb +30 -28
  14. data/lib/rubygems/commands/lock_command.rb +1 -1
  15. data/lib/rubygems/commands/outdated_command.rb +5 -2
  16. data/lib/rubygems/commands/pristine_command.rb +3 -44
  17. data/lib/rubygems/commands/query_command.rb +80 -21
  18. data/lib/rubygems/commands/sources_command.rb +56 -28
  19. data/lib/rubygems/commands/specification_command.rb +4 -3
  20. data/lib/rubygems/commands/stale_command.rb +27 -0
  21. data/lib/rubygems/commands/update_command.rb +35 -22
  22. data/lib/rubygems/config_file.rb +29 -12
  23. data/lib/rubygems/custom_require.rb +1 -1
  24. data/lib/rubygems/defaults.rb +1 -1
  25. data/lib/rubygems/dependency.rb +63 -9
  26. data/lib/rubygems/dependency_installer.rb +60 -23
  27. data/lib/rubygems/dependency_list.rb +1 -1
  28. data/lib/rubygems/doc_manager.rb +5 -5
  29. data/lib/rubygems/gem_openssl.rb +1 -1
  30. data/lib/rubygems/indexer.rb +269 -84
  31. data/lib/rubygems/install_update_options.rb +6 -0
  32. data/lib/rubygems/installer.rb +35 -12
  33. data/lib/rubygems/local_remote_options.rb +26 -5
  34. data/lib/rubygems/platform.rb +15 -1
  35. data/lib/rubygems/remote_fetcher.rb +158 -90
  36. data/lib/rubygems/requirement.rb +16 -12
  37. data/lib/rubygems/rubygems_version.rb +1 -1
  38. data/lib/rubygems/security.rb +2 -2
  39. data/lib/rubygems/server.rb +239 -110
  40. data/lib/rubygems/source_index.rb +44 -18
  41. data/lib/rubygems/source_info_cache.rb +1 -1
  42. data/lib/rubygems/spec_fetcher.rb +251 -0
  43. data/lib/rubygems/specification.rb +120 -38
  44. data/lib/rubygems/test_utilities.rb +120 -0
  45. data/lib/rubygems/uninstaller.rb +11 -10
  46. data/lib/rubygems/user_interaction.rb +149 -74
  47. data/lib/rubygems/validator.rb +3 -3
  48. data/lib/rubygems/version.rb +23 -21
  49. data/setup.rb +105 -100
  50. data/test/gemutilities.rb +63 -86
  51. data/test/test_config.rb +0 -5
  52. data/test/test_gem.rb +22 -2
  53. data/test/test_gem_command_manager.rb +1 -1
  54. data/test/test_gem_commands_dependency_command.rb +125 -6
  55. data/test/test_gem_commands_environment_command.rb +1 -0
  56. data/test/test_gem_commands_fetch_command.rb +24 -4
  57. data/test/test_gem_commands_install_command.rb +6 -8
  58. data/test/{test_gem_outdated_command.rb → test_gem_commands_outdated_command.rb} +5 -2
  59. data/test/test_gem_commands_pristine_command.rb +13 -4
  60. data/test/test_gem_commands_query_command.rb +113 -37
  61. data/test/test_gem_commands_sources_command.rb +101 -31
  62. data/test/test_gem_commands_specification_command.rb +4 -1
  63. data/test/test_gem_commands_stale_command.rb +39 -0
  64. data/test/test_gem_commands_update_command.rb +17 -27
  65. data/test/test_gem_config_file.rb +38 -1
  66. data/test/test_gem_dependency.rb +51 -0
  67. data/test/test_gem_dependency_installer.rb +133 -25
  68. data/test/test_gem_gem_path_searcher.rb +4 -1
  69. data/test/test_gem_indexer.rb +124 -19
  70. data/test/test_gem_installer.rb +32 -2
  71. data/test/test_gem_local_remote_options.rb +6 -5
  72. data/test/test_gem_remote_fetcher.rb +14 -9
  73. data/test/test_gem_server.rb +207 -21
  74. data/test/test_gem_source_index.rb +203 -63
  75. data/test/test_gem_source_info_cache.rb +8 -6
  76. data/test/test_gem_source_info_cache_entry.rb +11 -9
  77. data/test/test_gem_spec_fetcher.rb +303 -0
  78. data/test/test_gem_specification.rb +91 -7
  79. data/test/test_gem_uninstaller.rb +21 -0
  80. data/test/test_gem_version.rb +14 -5
  81. data/test/test_kernel.rb +1 -1
  82. metadata +10 -73
  83. metadata.gz.sig +0 -0
  84. data/lib/rubygems/indexer/abstract_index_builder.rb +0 -88
  85. data/lib/rubygems/indexer/latest_index_builder.rb +0 -35
  86. data/lib/rubygems/indexer/marshal_index_builder.rb +0 -17
  87. data/lib/rubygems/indexer/master_index_builder.rb +0 -54
  88. data/lib/rubygems/indexer/quick_index_builder.rb +0 -50
  89. data/test/gem_installer_test_case.rbc +0 -0
  90. data/test/gem_package_tar_test_case.rbc +0 -0
  91. data/test/gemutilities.rbc +0 -0
  92. data/test/mockgemui.rbc +0 -0
  93. data/test/simple_gem.rbc +0 -0
  94. data/test/test_config.rbc +0 -0
  95. data/test/test_gem.rbc +0 -0
  96. data/test/test_gem_builder.rbc +0 -0
  97. data/test/test_gem_command.rbc +0 -0
  98. data/test/test_gem_command_manager.rbc +0 -0
  99. data/test/test_gem_commands_build_command.rbc +0 -0
  100. data/test/test_gem_commands_cert_command.rbc +0 -0
  101. data/test/test_gem_commands_check_command.rbc +0 -0
  102. data/test/test_gem_commands_contents_command.rbc +0 -0
  103. data/test/test_gem_commands_dependency_command.rbc +0 -0
  104. data/test/test_gem_commands_environment_command.rbc +0 -0
  105. data/test/test_gem_commands_fetch_command.rbc +0 -0
  106. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  107. data/test/test_gem_commands_install_command.rbc +0 -0
  108. data/test/test_gem_commands_mirror_command.rbc +0 -0
  109. data/test/test_gem_commands_pristine_command.rbc +0 -0
  110. data/test/test_gem_commands_query_command.rbc +0 -0
  111. data/test/test_gem_commands_server_command.rbc +0 -0
  112. data/test/test_gem_commands_sources_command.rbc +0 -0
  113. data/test/test_gem_commands_specification_command.rbc +0 -0
  114. data/test/test_gem_commands_unpack_command.rbc +0 -0
  115. data/test/test_gem_commands_update_command.rbc +0 -0
  116. data/test/test_gem_config_file.rbc +0 -0
  117. data/test/test_gem_dependency.rbc +0 -0
  118. data/test/test_gem_dependency_installer.rbc +0 -0
  119. data/test/test_gem_dependency_list.rbc +0 -0
  120. data/test/test_gem_digest.rbc +0 -0
  121. data/test/test_gem_doc_manager.rbc +0 -0
  122. data/test/test_gem_ext_configure_builder.rbc +0 -0
  123. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  124. data/test/test_gem_ext_rake_builder.rbc +0 -0
  125. data/test/test_gem_format.rbc +0 -0
  126. data/test/test_gem_gem_path_searcher.rbc +0 -0
  127. data/test/test_gem_gem_runner.rbc +0 -0
  128. data/test/test_gem_indexer.rbc +0 -0
  129. data/test/test_gem_install_update_options.rbc +0 -0
  130. data/test/test_gem_installer.rbc +0 -0
  131. data/test/test_gem_local_remote_options.rbc +0 -0
  132. data/test/test_gem_outdated_command.rbc +0 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rbc +0 -0
  135. data/test/test_gem_package_tar_output.rbc +0 -0
  136. data/test/test_gem_package_tar_reader.rbc +0 -0
  137. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  138. data/test/test_gem_package_tar_writer.rbc +0 -0
  139. data/test/test_gem_platform.rbc +0 -0
  140. data/test/test_gem_remote_fetcher.rbc +0 -0
  141. data/test/test_gem_requirement.rbc +0 -0
  142. data/test/test_gem_server.rbc +0 -0
  143. data/test/test_gem_source_index.rbc +0 -0
  144. data/test/test_gem_source_info_cache.rbc +0 -0
  145. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  146. data/test/test_gem_specification.rbc +0 -0
  147. data/test/test_gem_stream_ui.rbc +0 -0
  148. data/test/test_gem_uninstaller.rbc +0 -0
  149. data/test/test_gem_validator.rbc +0 -0
  150. data/test/test_gem_version.rbc +0 -0
  151. data/test/test_gem_version_option.rbc +0 -0
  152. data/test/test_kernel.rbc +0 -0
@@ -60,6 +60,21 @@ class TestGemDependency < RubyGemTestCase
60
60
  assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
61
61
  end
62
62
 
63
+ def test_initialize_with_type
64
+ dep = Gem::Dependency.new("pkg", [], :development)
65
+ assert_equal(:development, dep.type)
66
+ end
67
+
68
+ def test_type_is_runtime_by_default
69
+ assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
70
+ end
71
+
72
+ def test_type_is_restricted
73
+ assert_raise(ArgumentError) do
74
+ Gem::Dependency.new("pkg", [:sometimes])
75
+ end
76
+ end
77
+
63
78
  def test_equals2
64
79
  assert_equal @pkg1_0, @pkg1_0.dup
65
80
  assert_equal @pkg1_0.dup, @pkg1_0
@@ -74,6 +89,36 @@ class TestGemDependency < RubyGemTestCase
74
89
  assert_not_equal Object.new, @pkg1_0
75
90
  end
76
91
 
92
+ def test_equals2_type
93
+ runtime = Gem::Dependency.new("pkg", [])
94
+ development = Gem::Dependency.new("pkg", [], :development)
95
+
96
+ assert_not_equal(runtime, development)
97
+ end
98
+
99
+ def test_equals_tilde
100
+ def dep(name, version)
101
+ Gem::Dependency.new name, version
102
+ end
103
+
104
+ a0 = dep 'a', '0'
105
+ a1 = dep 'a', '1'
106
+ b0 = dep 'b', '0'
107
+
108
+ pa0 = dep 'a', '>= 0'
109
+ pa0r = dep(/a/, '>= 0')
110
+ pab0r = dep(/a|b/, '>= 0')
111
+
112
+ assert((a0 =~ a0), 'match self')
113
+ assert((pa0 =~ a0), 'match version exact')
114
+ assert((pa0 =~ a1), 'match version')
115
+ assert((pa0r =~ a0), 'match regex simple')
116
+ assert((pab0r =~ a0), 'match regex complex')
117
+
118
+ assert(!(pa0r =~ b0), 'fail match regex')
119
+ assert(!(pa0r =~ Object.new), 'fail match Object')
120
+ end
121
+
77
122
  def test_hash
78
123
  assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
79
124
  assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
@@ -85,5 +130,11 @@ class TestGemDependency < RubyGemTestCase
85
130
  assert_not_equal @oth1_0.hash, @pkg1_0.hash, "names different"
86
131
  end
87
132
 
133
+ def test_hash_type
134
+ runtime = Gem::Dependency.new("pkg", [])
135
+ development = Gem::Dependency.new("pkg", [], :development)
136
+
137
+ assert_not_equal(runtime.hash, development.hash)
138
+ end
88
139
  end
89
140
 
@@ -15,8 +15,12 @@ class TestGemDependencyInstaller < RubyGemTestCase
15
15
  fp.puts "#!/usr/bin/ruby"
16
16
  end
17
17
  @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
18
+ @aa1, @aa1_gem = util_gem 'aa', '1'
18
19
 
19
- @b1, @b1_gem = util_gem 'b', '1' do |s| s.add_dependency 'a' end
20
+ @b1, @b1_gem = util_gem 'b', '1' do |s|
21
+ s.add_dependency 'a'
22
+ s.add_development_dependency 'aa'
23
+ end
20
24
 
21
25
  @d1, @d1_gem = util_gem 'd', '1'
22
26
  @d2, @d2_gem = util_gem 'd', '2'
@@ -38,15 +42,13 @@ class TestGemDependencyInstaller < RubyGemTestCase
38
42
 
39
43
  @z1, @z1_gem = util_gem 'z', '1' do |s| s.add_dependency 'y' end
40
44
 
41
- si = util_setup_source_info_cache @a1, @b1, @d1, @d2, @x1_m, @x1_o, @w1,
42
- @y1, @y1_1_p, @z1
45
+ @fetcher = Gem::FakeFetcher.new
46
+ Gem::RemoteFetcher.fetcher = @fetcher
43
47
 
44
- @fetcher = FakeFetcher.new
45
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
46
- @fetcher.uri = URI.parse 'http://gems.example.com'
47
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
48
+ si = util_setup_spec_fetcher @a1, @b1, @d1, @d2, @x1_m, @x1_o, @w1, @y1,
49
+ @y1_1_p, @z1
48
50
 
49
- FileUtils.rm_rf File.join(@gemhome, 'gems')
51
+ util_clear_gems
50
52
  end
51
53
 
52
54
  def test_install
@@ -64,6 +66,77 @@ class TestGemDependencyInstaller < RubyGemTestCase
64
66
  assert_equal [@a1], inst.installed_gems
65
67
  end
66
68
 
69
+ def test_install_all_dependencies
70
+ e1, e1_gem = util_gem 'e', '1' do |s|
71
+ s.add_dependency 'b'
72
+ end
73
+
74
+ util_clear_gems
75
+
76
+ FileUtils.mv @a1_gem, @tempdir
77
+ FileUtils.mv @b1_gem, @tempdir
78
+ FileUtils.mv e1_gem, @tempdir
79
+ inst = nil
80
+
81
+ Dir.chdir @tempdir do
82
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
83
+ inst.install 'b'
84
+ end
85
+
86
+ Dir.chdir @tempdir do
87
+ inst = Gem::DependencyInstaller.new
88
+ inst.install 'e'
89
+ end
90
+
91
+ assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
92
+ end
93
+
94
+ def test_install_cache_dir
95
+ FileUtils.mv @a1_gem, @tempdir
96
+ FileUtils.mv @b1_gem, @tempdir
97
+ inst = nil
98
+
99
+ Dir.chdir @tempdir do
100
+ inst = Gem::DependencyInstaller.new :cache_dir => @tempdir
101
+ inst.install 'b'
102
+ end
103
+
104
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
105
+
106
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@a1.full_name}.gem"))
107
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@b1.full_name}.gem"))
108
+ end
109
+
110
+ def test_install_dependencies_satisfied
111
+ a2, a2_gem = util_gem 'a', '2'
112
+
113
+ FileUtils.rm_rf File.join(@gemhome, 'gems')
114
+ Gem.source_index.refresh!
115
+
116
+ FileUtils.mv @a1_gem, @tempdir
117
+ FileUtils.mv a2_gem, @tempdir # not in index
118
+ FileUtils.mv @b1_gem, @tempdir
119
+ inst = nil
120
+
121
+ Dir.chdir @tempdir do
122
+ inst = Gem::DependencyInstaller.new
123
+ inst.install 'a-2'
124
+ end
125
+
126
+ FileUtils.rm File.join(@tempdir, "#{a2.full_name}.gem")
127
+
128
+ Dir.chdir @tempdir do
129
+ inst = Gem::DependencyInstaller.new
130
+ inst.install 'b'
131
+ end
132
+
133
+ installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
134
+
135
+ assert_equal %w[a-2 b-1], installed.sort
136
+
137
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
138
+ end
139
+
67
140
  def test_install_dependency
68
141
  FileUtils.mv @a1_gem, @tempdir
69
142
  FileUtils.mv @b1_gem, @tempdir
@@ -77,6 +150,20 @@ class TestGemDependencyInstaller < RubyGemTestCase
77
150
  assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
78
151
  end
79
152
 
153
+ def test_install_dependency_development
154
+ FileUtils.mv @a1_gem, @tempdir
155
+ FileUtils.mv @aa1_gem, @tempdir
156
+ FileUtils.mv @b1_gem, @tempdir
157
+ inst = nil
158
+
159
+ Dir.chdir @tempdir do
160
+ inst = Gem::DependencyInstaller.new(:development => true)
161
+ inst.install 'b'
162
+ end
163
+
164
+ assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
165
+ end
166
+
80
167
  def test_install_dependency_existing
81
168
  Gem::Installer.new(@a1_gem).install
82
169
  FileUtils.mv @a1_gem, @tempdir
@@ -177,7 +264,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
177
264
 
178
265
  def test_install_force
179
266
  FileUtils.mv @b1_gem, @tempdir
180
- si = util_setup_source_info_cache @b1
267
+ si = util_setup_spec_fetcher @b1
181
268
  @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
182
269
  inst = nil
183
270
 
@@ -249,8 +336,6 @@ class TestGemDependencyInstaller < RubyGemTestCase
249
336
  end
250
337
 
251
338
  def test_install_domain_both_no_network
252
- Gem::SourceInfoCache.instance_variable_set :@cache, nil
253
-
254
339
  @fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
255
340
  proc do
256
341
  raise Gem::RemoteFetcher::FetchError
@@ -272,12 +357,14 @@ class TestGemDependencyInstaller < RubyGemTestCase
272
357
  FileUtils.mv @b1_gem, @tempdir
273
358
  inst = nil
274
359
 
360
+ Gem.source_index.gems.delete @a1.full_name
361
+
275
362
  Dir.chdir @tempdir do
276
363
  e = assert_raise Gem::InstallError do
277
364
  inst = Gem::DependencyInstaller.new :domain => :local
278
365
  inst.install 'b'
279
366
  end
280
- assert_equal 'b requires a (>= 0)', e.message
367
+ assert_equal 'b requires a (>= 0, runtime)', e.message
281
368
  end
282
369
 
283
370
  assert_equal [], inst.installed_gems.map { |s| s.full_name }
@@ -297,6 +384,30 @@ class TestGemDependencyInstaller < RubyGemTestCase
297
384
  assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
298
385
  end
299
386
 
387
+ def test_install_dual_repository
388
+ FileUtils.mv @a1_gem, @tempdir
389
+ FileUtils.mv @b1_gem, @tempdir
390
+ inst = nil
391
+
392
+ gemhome2 = "#{@gemhome}2"
393
+
394
+ Dir.chdir @tempdir do
395
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
396
+ inst.install 'a'
397
+ end
398
+
399
+ ENV['GEM_HOME'] = @gemhome
400
+ ENV['GEM_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
401
+ Gem.clear_paths
402
+
403
+ Dir.chdir @tempdir do
404
+ inst = Gem::DependencyInstaller.new
405
+ inst.install 'b'
406
+ end
407
+
408
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
409
+ end
410
+
300
411
  def test_install_remote
301
412
  a1_data = nil
302
413
  File.open @a1_gem, 'rb' do |fp|
@@ -337,7 +448,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
337
448
  s.platform = Gem::Platform.new %w[cpu other_platform 1]
338
449
  end
339
450
 
340
- si = util_setup_source_info_cache @a1, a2_o
451
+ util_clear_gems
452
+
453
+ si = util_setup_spec_fetcher @a1, a2_o
341
454
 
342
455
  @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
343
456
 
@@ -439,7 +552,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
439
552
  inst = Gem::DependencyInstaller.new
440
553
  dep = Gem::Dependency.new 'b', '>= 0'
441
554
 
442
- assert_equal [[@b1, 'http://gems.example.com']],
555
+ assert_equal [[@b1, @gem_repo]],
443
556
  inst.find_gems_with_sources(dep)
444
557
  end
445
558
 
@@ -456,7 +569,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
456
569
  assert_equal 2, gems.length
457
570
  remote = gems.first
458
571
  assert_equal 'a-1', remote.first.full_name, 'remote spec'
459
- assert_equal 'http://gems.example.com', remote.last, 'remote path'
572
+ assert_equal @gem_repo, remote.last, 'remote path'
460
573
 
461
574
  local = gems.last
462
575
  assert_equal 'a-1', local.first.full_name, 'local spec'
@@ -476,12 +589,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
476
589
  b2, = util_gem 'b', '2'
477
590
  c1, = util_gem 'c', '1' do |s| s.add_dependency 'b' end
478
591
 
479
- si = util_setup_source_info_cache @a1, @b1, b2, c1
592
+ util_clear_gems
480
593
 
481
- @fetcher = FakeFetcher.new
482
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
483
- @fetcher.uri = URI.parse 'http://gems.example.com'
484
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
594
+ si = util_setup_spec_fetcher @a1, @b1, b2, c1
485
595
 
486
596
  inst = Gem::DependencyInstaller.new
487
597
  inst.find_spec_by_name_and_version 'c'
@@ -512,12 +622,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
512
622
  def test_gather_dependencies_old_required
513
623
  e1, = util_gem 'e', '1' do |s| s.add_dependency 'd', '= 1' end
514
624
 
515
- si = util_setup_source_info_cache @d1, @d2, e1
625
+ util_clear_gems
516
626
 
517
- @fetcher = FakeFetcher.new
518
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
519
- @fetcher.uri = URI.parse 'http://gems.example.com'
520
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
627
+ si = util_setup_spec_fetcher @d1, @d2, e1
521
628
 
522
629
  inst = Gem::DependencyInstaller.new
523
630
  inst.find_spec_by_name_and_version 'e'
@@ -525,5 +632,6 @@ class TestGemDependencyInstaller < RubyGemTestCase
525
632
 
526
633
  assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
527
634
  end
635
+
528
636
  end
529
637
 
@@ -28,7 +28,10 @@ class TestGemGemPathSearcher < RubyGemTestCase
28
28
  @bar1 = quick_gem 'bar', '0.1'
29
29
  @bar2 = quick_gem 'bar', '0.2'
30
30
 
31
- Gem.source_index = util_setup_source_info_cache @foo1, @foo2, @bar1, @bar2
31
+ @fetcher = Gem::FakeFetcher.new
32
+ Gem::RemoteFetcher.fetcher = @fetcher
33
+
34
+ Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
32
35
 
33
36
  @gps = Gem::GemPathSearcher.new
34
37
  end
@@ -20,6 +20,10 @@ class TestGemIndexer < RubyGemTestCase
20
20
 
21
21
  util_make_gems
22
22
 
23
+ @d2_0 = quick_gem 'd', '2.0'
24
+ write_file File.join(*%W[gems #{@d2_0.original_name} lib code.rb]) do end
25
+ util_build_gem @d2_0
26
+
23
27
  gems = File.join(@tempdir, 'gems')
24
28
  FileUtils.mkdir_p gems
25
29
  cache_gems = File.join @gemhome, 'cache', '*.gem'
@@ -39,10 +43,10 @@ class TestGemIndexer < RubyGemTestCase
39
43
  @indexer.generate_index
40
44
  end
41
45
 
42
- assert File.exist?(File.join(@tempdir, 'yaml'))
43
- assert File.exist?(File.join(@tempdir, 'yaml.Z'))
44
- assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}"))
45
- assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}.Z"))
46
+ assert_indexed @tempdir, 'yaml'
47
+ assert_indexed @tempdir, 'yaml.Z'
48
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
49
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
46
50
 
47
51
  quickdir = File.join @tempdir, 'quick'
48
52
  marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
@@ -53,10 +57,33 @@ class TestGemIndexer < RubyGemTestCase
53
57
  assert_indexed quickdir, "index"
54
58
  assert_indexed quickdir, "index.rz"
55
59
 
60
+ quick_index = File.read File.join(quickdir, 'index')
61
+ expected = <<-EOF
62
+ a-1
63
+ a-2
64
+ a_evil-9
65
+ b-2
66
+ c-1.2
67
+ d-2.0
68
+ pl-1-i386-linux
69
+ EOF
70
+
71
+ assert_equal expected, quick_index
72
+
56
73
  assert_indexed quickdir, "latest_index"
57
74
  assert_indexed quickdir, "latest_index.rz"
58
75
 
59
- assert_no_match %r|a-1|, File.read(File.join(quickdir, 'latest_index'))
76
+ latest_quick_index = File.read File.join(quickdir, 'latest_index')
77
+ expected = <<-EOF
78
+ a-2
79
+ a_evil-9
80
+ b-2
81
+ c-1.2
82
+ d-2.0
83
+ pl-1-i386-linux
84
+ EOF
85
+
86
+ assert_equal expected, latest_quick_index
60
87
 
61
88
  assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz"
62
89
  assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz"
@@ -64,13 +91,19 @@ class TestGemIndexer < RubyGemTestCase
64
91
  assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz"
65
92
 
66
93
  assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
67
- deny_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
94
+ refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
68
95
 
69
96
  assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
70
97
  assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
71
98
 
72
- deny_indexed quickdir, "#{@c1_2.full_name}.gemspec"
73
- deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
99
+ refute_indexed quickdir, "#{@c1_2.full_name}.gemspec"
100
+ refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
101
+
102
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
103
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
104
+
105
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
106
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
74
107
  end
75
108
 
76
109
  def test_generate_index_ui
@@ -79,28 +112,37 @@ class TestGemIndexer < RubyGemTestCase
79
112
  end
80
113
 
81
114
  expected = <<-EOF
82
- Generating index for 6 gems in #{@tempdir}
83
- ......
115
+ Loading 7 gems from #{@tempdir}
116
+ .......
84
117
  Loaded all gems
85
- Generating master indexes (this may take a while)
118
+ Generating quick index gemspecs for 7 gems
119
+ .......
120
+ Complete
121
+ Generating specs index
122
+ Generating latest specs index
123
+ Generating quick index
124
+ Generating latest index
125
+ Generating Marshal master index
126
+ Generating YAML master index for 7 gems (this may take a while)
127
+ .......
128
+ Complete
129
+ Compressing indicies
86
130
  EOF
87
131
 
88
132
  assert_equal expected, @ui.output
89
133
  assert_equal '', @ui.error
90
134
  end
91
135
 
92
- def test_generate_index_contents
136
+ def test_generate_index_master
93
137
  use_ui @ui do
94
138
  @indexer.generate_index
95
139
  end
96
140
 
97
- yaml_path = File.join(@tempdir, 'yaml')
98
- dump_path = File.join(@tempdir, "Marshal.#{@marshal_version}")
141
+ yaml_path = File.join @tempdir, 'yaml'
142
+ dump_path = File.join @tempdir, "Marshal.#{@marshal_version}"
99
143
 
100
- yaml_index = YAML.load_file(yaml_path)
101
- dump_str = nil
102
- File.open dump_path, 'rb' do |fp| dump_str = fp.read end
103
- dump_index = Marshal.load dump_str
144
+ yaml_index = YAML.load_file yaml_path
145
+ dump_index = Marshal.load Gem.read_binary(dump_path)
104
146
 
105
147
  dump_index.each do |_,gem|
106
148
  gem.send :remove_instance_variable, :@loaded
@@ -110,12 +152,75 @@ Generating master indexes (this may take a while)
110
152
  "expected YAML and Marshal to produce identical results"
111
153
  end
112
154
 
155
+ def test_generate_index_specs
156
+ use_ui @ui do
157
+ @indexer.generate_index
158
+ end
159
+
160
+ specs_path = File.join @tempdir, "specs.#{@marshal_version}"
161
+
162
+ specs_dump = Gem.read_binary specs_path
163
+ specs = Marshal.load specs_dump
164
+
165
+ expected = [
166
+ ['a', Gem::Version.new(1), 'ruby'],
167
+ ['a', Gem::Version.new(2), 'ruby'],
168
+ ['a_evil', Gem::Version.new(9), 'ruby'],
169
+ ['b', Gem::Version.new(2), 'ruby'],
170
+ ['c', Gem::Version.new('1.2'), 'ruby'],
171
+ ['d', Gem::Version.new('2.0'), 'ruby'],
172
+ ['pl', Gem::Version.new(1), 'i386-linux'],
173
+ ]
174
+
175
+ assert_equal expected, specs
176
+
177
+ assert_same specs[0].first, specs[1].first,
178
+ 'identical names not identical'
179
+
180
+ assert_same specs[0][1], specs[-1][1],
181
+ 'identical versions not identical'
182
+
183
+ assert_same specs[0].last, specs[1].last,
184
+ 'identical platforms not identical'
185
+
186
+ assert_not_same specs[1][1], specs[5][1],
187
+ 'different versions not different'
188
+ end
189
+
190
+ def test_generate_index_latest_specs
191
+ use_ui @ui do
192
+ @indexer.generate_index
193
+ end
194
+
195
+ latest_specs_path = File.join @tempdir, "latest_specs.#{@marshal_version}"
196
+
197
+ latest_specs_dump = Gem.read_binary latest_specs_path
198
+ latest_specs = Marshal.load latest_specs_dump
199
+
200
+ expected = [
201
+ ['a', Gem::Version.new(2), 'ruby'],
202
+ ['a_evil', Gem::Version.new(9), 'ruby'],
203
+ ['b', Gem::Version.new(2), 'ruby'],
204
+ ['c', Gem::Version.new('1.2'), 'ruby'],
205
+ ['d', Gem::Version.new('2.0'), 'ruby'],
206
+ ['pl', Gem::Version.new(1), 'i386-linux'],
207
+ ]
208
+
209
+ assert_equal expected, latest_specs
210
+
211
+ assert_same latest_specs[0][1], latest_specs[2][1],
212
+ 'identical versions not identical'
213
+
214
+ assert_same latest_specs[0].last, latest_specs[1].last,
215
+ 'identical platforms not identical'
216
+ end
217
+
113
218
  def assert_indexed(dir, name)
114
219
  file = File.join dir, name
115
220
  assert File.exist?(file), "#{file} does not exist"
116
221
  end
117
222
 
118
- def deny_indexed(dir, name)
223
+ def refute_indexed(dir, name)
119
224
  file = File.join dir, name
120
225
  assert !File.exist?(file), "#{file} exists"
121
226
  end