rubygems-update 1.8.30 → 2.0.0.preview2

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 (241) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/.autotest +6 -3
  5. data/History.txt +137 -63
  6. data/LICENSE.txt +1 -5
  7. data/Manifest.txt +69 -32
  8. data/README.rdoc +11 -9
  9. data/Rakefile +24 -38
  10. data/bin/gem +0 -9
  11. data/bin/update_rubygems +1 -0
  12. data/lib/rubygems.rb +193 -405
  13. data/lib/rubygems/available_set.rb +95 -0
  14. data/lib/rubygems/command.rb +88 -45
  15. data/lib/rubygems/command_manager.rb +67 -40
  16. data/lib/rubygems/commands/build_command.rb +5 -23
  17. data/lib/rubygems/commands/cert_command.rb +199 -57
  18. data/lib/rubygems/commands/check_command.rb +14 -39
  19. data/lib/rubygems/commands/cleanup_command.rb +9 -1
  20. data/lib/rubygems/commands/contents_command.rb +30 -12
  21. data/lib/rubygems/commands/dependency_command.rb +3 -8
  22. data/lib/rubygems/commands/environment_command.rb +13 -8
  23. data/lib/rubygems/commands/fetch_command.rb +3 -16
  24. data/lib/rubygems/commands/generate_index_command.rb +7 -47
  25. data/lib/rubygems/commands/help_command.rb +1 -1
  26. data/lib/rubygems/commands/install_command.rb +69 -36
  27. data/lib/rubygems/commands/list_command.rb +6 -4
  28. data/lib/rubygems/commands/lock_command.rb +1 -1
  29. data/lib/rubygems/commands/mirror_command.rb +17 -0
  30. data/lib/rubygems/commands/outdated_command.rb +6 -3
  31. data/lib/rubygems/commands/owner_command.rb +13 -5
  32. data/lib/rubygems/commands/pristine_command.rb +19 -4
  33. data/lib/rubygems/commands/push_command.rb +12 -1
  34. data/lib/rubygems/commands/query_command.rb +43 -27
  35. data/lib/rubygems/commands/rdoc_command.rb +23 -28
  36. data/lib/rubygems/commands/search_command.rb +4 -18
  37. data/lib/rubygems/commands/server_command.rb +1 -1
  38. data/lib/rubygems/commands/setup_command.rb +124 -38
  39. data/lib/rubygems/commands/sources_command.rb +16 -16
  40. data/lib/rubygems/commands/specification_command.rb +11 -13
  41. data/lib/rubygems/commands/uninstall_command.rb +24 -7
  42. data/lib/rubygems/commands/unpack_command.rb +7 -3
  43. data/lib/rubygems/commands/update_command.rb +22 -36
  44. data/lib/rubygems/commands/yank_command.rb +98 -0
  45. data/lib/rubygems/compatibility.rb +51 -0
  46. data/lib/rubygems/config_file.rb +82 -54
  47. data/lib/rubygems/core_ext/kernel_gem.rb +53 -0
  48. data/lib/rubygems/core_ext/kernel_require.rb +119 -0
  49. data/lib/rubygems/defaults.rb +10 -21
  50. data/lib/rubygems/dependency.rb +61 -10
  51. data/lib/rubygems/dependency_installer.rb +157 -69
  52. data/lib/rubygems/dependency_list.rb +11 -19
  53. data/lib/rubygems/dependency_resolver.rb +562 -0
  54. data/lib/rubygems/deprecate.rb +40 -40
  55. data/lib/rubygems/errors.rb +77 -24
  56. data/lib/rubygems/exceptions.rb +25 -7
  57. data/lib/rubygems/ext/builder.rb +20 -23
  58. data/lib/rubygems/ext/configure_builder.rb +2 -2
  59. data/lib/rubygems/ext/ext_conf_builder.rb +5 -45
  60. data/lib/rubygems/ext/rake_builder.rb +2 -2
  61. data/lib/rubygems/gem_runner.rb +3 -16
  62. data/lib/rubygems/gemcutter_utilities.rb +22 -7
  63. data/lib/rubygems/indexer.rb +6 -159
  64. data/lib/rubygems/install_message.rb +12 -0
  65. data/lib/rubygems/install_update_options.rb +56 -18
  66. data/lib/rubygems/installer.rb +244 -134
  67. data/lib/rubygems/installer_test_case.rb +71 -19
  68. data/lib/rubygems/mock_gem_ui.rb +17 -0
  69. data/lib/rubygems/name_tuple.rb +110 -0
  70. data/lib/rubygems/package.rb +514 -43
  71. data/lib/rubygems/package/digest_io.rb +64 -0
  72. data/lib/rubygems/package/old.rb +147 -0
  73. data/lib/rubygems/package/tar_header.rb +18 -55
  74. data/lib/rubygems/package/tar_reader.rb +20 -3
  75. data/lib/rubygems/package/tar_writer.rb +63 -7
  76. data/lib/rubygems/package_task.rb +3 -4
  77. data/lib/rubygems/path_support.rb +14 -7
  78. data/lib/rubygems/platform.rb +19 -26
  79. data/lib/rubygems/rdoc.rb +316 -0
  80. data/lib/rubygems/remote_fetcher.rb +117 -54
  81. data/lib/rubygems/request_set.rb +182 -0
  82. data/lib/rubygems/requirement.rb +63 -26
  83. data/lib/rubygems/security.rb +295 -555
  84. data/lib/rubygems/security/policies.rb +115 -0
  85. data/lib/rubygems/security/policy.rb +227 -0
  86. data/lib/rubygems/security/signer.rb +136 -0
  87. data/lib/rubygems/security/trust_dir.rb +104 -0
  88. data/lib/rubygems/server.rb +45 -55
  89. data/lib/rubygems/source.rb +144 -0
  90. data/lib/rubygems/source_list.rb +87 -0
  91. data/lib/rubygems/source_local.rb +92 -0
  92. data/lib/rubygems/source_specific_file.rb +28 -0
  93. data/lib/rubygems/spec_fetcher.rb +116 -184
  94. data/lib/rubygems/specification.rb +731 -335
  95. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  96. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  97. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  98. data/lib/rubygems/syck_hack.rb +2 -0
  99. data/lib/rubygems/test_case.rb +199 -109
  100. data/lib/rubygems/test_utilities.rb +25 -5
  101. data/lib/rubygems/uninstaller.rb +62 -20
  102. data/lib/rubygems/user_interaction.rb +10 -0
  103. data/lib/rubygems/validator.rb +33 -40
  104. data/lib/rubygems/version.rb +19 -8
  105. data/setup.rb +8 -1
  106. data/test/rubygems/alternate_cert.pem +9 -0
  107. data/test/rubygems/alternate_cert_32.pem +9 -0
  108. data/test/rubygems/alternate_key.pem +9 -0
  109. data/test/rubygems/bad_rake.rb +1 -0
  110. data/test/rubygems/child_cert.pem +9 -0
  111. data/test/rubygems/child_cert_32.pem +9 -0
  112. data/test/rubygems/child_key.pem +9 -0
  113. data/test/rubygems/data/null-type.gemspec.rz +0 -0
  114. data/test/rubygems/expired_cert.pem +9 -0
  115. data/test/rubygems/future_cert.pem +9 -0
  116. data/test/rubygems/future_cert_32.pem +9 -0
  117. data/test/rubygems/good_rake.rb +1 -0
  118. data/test/rubygems/grandchild_cert.pem +9 -0
  119. data/test/rubygems/grandchild_cert_32.pem +9 -0
  120. data/test/rubygems/grandchild_key.pem +9 -0
  121. data/test/rubygems/invalid_issuer_cert.pem +9 -0
  122. data/test/rubygems/invalid_issuer_cert_32.pem +9 -0
  123. data/test/rubygems/invalid_key.pem +9 -0
  124. data/test/rubygems/invalid_signer_cert.pem +9 -0
  125. data/test/rubygems/invalid_signer_cert_32.pem +9 -0
  126. data/test/rubygems/invalidchild_cert.pem +9 -0
  127. data/test/rubygems/invalidchild_cert_32.pem +9 -0
  128. data/test/rubygems/invalidchild_key.pem +9 -0
  129. data/test/rubygems/plugin/exception/rubygems_plugin.rb +1 -1
  130. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +1 -1
  131. data/test/rubygems/private_key.pem +7 -25
  132. data/test/rubygems/public_cert.pem +8 -18
  133. data/test/rubygems/public_cert_32.pem +10 -0
  134. data/test/rubygems/public_key.pem +4 -0
  135. data/test/rubygems/rubygems/commands/crash_command.rb +1 -1
  136. data/test/rubygems/test_config.rb +4 -6
  137. data/test/rubygems/test_deprecate.rb +76 -0
  138. data/test/rubygems/test_gem.rb +318 -83
  139. data/test/rubygems/test_gem_available_set.rb +106 -0
  140. data/test/rubygems/test_gem_command.rb +10 -0
  141. data/test/rubygems/test_gem_command_manager.rb +55 -9
  142. data/test/rubygems/test_gem_commands_build_command.rb +11 -19
  143. data/test/rubygems/test_gem_commands_cert_command.rb +441 -42
  144. data/test/rubygems/test_gem_commands_cleanup_command.rb +29 -1
  145. data/test/rubygems/test_gem_commands_contents_command.rb +23 -0
  146. data/test/rubygems/test_gem_commands_dependency_command.rb +5 -0
  147. data/test/rubygems/test_gem_commands_fetch_command.rb +19 -20
  148. data/test/rubygems/test_gem_commands_generate_index_command.rb +2 -83
  149. data/test/rubygems/test_gem_commands_help_command.rb +2 -1
  150. data/test/rubygems/test_gem_commands_install_command.rb +647 -48
  151. data/test/rubygems/test_gem_commands_mirror.rb +32 -0
  152. data/test/rubygems/test_gem_commands_owner_command.rb +4 -8
  153. data/test/rubygems/test_gem_commands_pristine_command.rb +99 -4
  154. data/test/rubygems/test_gem_commands_push_command.rb +62 -8
  155. data/test/rubygems/test_gem_commands_query_command.rb +51 -0
  156. data/test/rubygems/test_gem_commands_search_command.rb +25 -0
  157. data/test/rubygems/test_gem_commands_setup_command.rb +45 -0
  158. data/test/rubygems/test_gem_commands_sources_command.rb +21 -6
  159. data/test/rubygems/test_gem_commands_specification_command.rb +33 -1
  160. data/test/rubygems/test_gem_commands_uninstall_command.rb +91 -31
  161. data/test/rubygems/test_gem_commands_unpack_command.rb +3 -3
  162. data/test/rubygems/test_gem_commands_update_command.rb +56 -38
  163. data/test/rubygems/test_gem_commands_which_command.rb +4 -4
  164. data/test/rubygems/test_gem_commands_yank_command.rb +97 -0
  165. data/test/rubygems/test_gem_config_file.rb +66 -21
  166. data/test/rubygems/test_gem_dependency.rb +46 -0
  167. data/test/rubygems/test_gem_dependency_installer.rb +228 -18
  168. data/test/rubygems/test_gem_dependency_list.rb +0 -9
  169. data/test/rubygems/test_gem_dependency_resolver.rb +327 -0
  170. data/test/rubygems/test_gem_ext_configure_builder.rb +4 -4
  171. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +21 -49
  172. data/test/rubygems/test_gem_ext_rake_builder.rb +13 -13
  173. data/test/rubygems/test_gem_gem_runner.rb +27 -5
  174. data/test/rubygems/test_gem_gemcutter_utilities.rb +19 -0
  175. data/test/rubygems/test_gem_indexer.rb +14 -227
  176. data/test/rubygems/test_gem_install_update_options.rb +83 -3
  177. data/test/rubygems/test_gem_installer.rb +211 -236
  178. data/test/rubygems/test_gem_local_remote_options.rb +8 -2
  179. data/test/rubygems/test_gem_name_tuple.rb +15 -0
  180. data/test/rubygems/test_gem_package.rb +547 -0
  181. data/test/rubygems/test_gem_package_old.rb +37 -0
  182. data/test/rubygems/test_gem_package_tar_reader.rb +32 -0
  183. data/test/rubygems/test_gem_package_tar_writer.rb +84 -1
  184. data/test/rubygems/test_gem_path_support.rb +4 -30
  185. data/test/rubygems/test_gem_platform.rb +3 -6
  186. data/test/rubygems/test_gem_rdoc.rb +245 -0
  187. data/test/rubygems/test_gem_remote_fetcher.rb +51 -5
  188. data/test/rubygems/test_gem_request_set.rb +70 -0
  189. data/test/rubygems/test_gem_requirement.rb +53 -24
  190. data/test/rubygems/test_gem_security.rb +189 -43
  191. data/test/rubygems/test_gem_security_policy.rb +376 -0
  192. data/test/rubygems/test_gem_security_signer.rb +184 -0
  193. data/test/rubygems/test_gem_security_trust_dir.rb +94 -0
  194. data/test/rubygems/test_gem_server.rb +31 -36
  195. data/test/rubygems/test_gem_silent_ui.rb +2 -2
  196. data/test/rubygems/test_gem_source.rb +188 -0
  197. data/test/rubygems/test_gem_source_list.rb +87 -0
  198. data/test/rubygems/test_gem_source_local.rb +83 -0
  199. data/test/rubygems/test_gem_source_specific_file.rb +33 -0
  200. data/test/rubygems/test_gem_spec_fetcher.rb +91 -255
  201. data/test/rubygems/test_gem_specification.rb +293 -39
  202. data/test/rubygems/test_gem_uninstaller.rb +136 -13
  203. data/test/rubygems/test_gem_validator.rb +14 -41
  204. data/test/rubygems/test_gem_version.rb +15 -21
  205. data/test/rubygems/test_require.rb +193 -0
  206. data/test/rubygems/wrong_key_cert.pem +9 -0
  207. data/test/rubygems/wrong_key_cert_32.pem +9 -0
  208. metadata +171 -83
  209. metadata.gz.sig +1 -0
  210. data/CVE-2013-4287.txt +0 -36
  211. data/CVE-2013-4363.txt +0 -45
  212. data/ci_build.sh +0 -27
  213. data/cruise_config.rb +0 -32
  214. data/lib/rbconfig/datadir.rb +0 -13
  215. data/lib/rubygems/builder.rb +0 -99
  216. data/lib/rubygems/custom_require.rb +0 -69
  217. data/lib/rubygems/doc_manager.rb +0 -243
  218. data/lib/rubygems/format.rb +0 -82
  219. data/lib/rubygems/gem_openssl.rb +0 -90
  220. data/lib/rubygems/gem_path_searcher.rb +0 -172
  221. data/lib/rubygems/old_format.rb +0 -153
  222. data/lib/rubygems/package/f_sync_dir.rb +0 -23
  223. data/lib/rubygems/package/tar_input.rb +0 -234
  224. data/lib/rubygems/package/tar_output.rb +0 -146
  225. data/lib/rubygems/require_paths_builder.rb +0 -18
  226. data/lib/rubygems/source_index.rb +0 -406
  227. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  228. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  229. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  230. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  231. data/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem +0 -20
  232. data/test/rubygems/test_bundled_ca.rb +0 -59
  233. data/test/rubygems/test_gem_builder.rb +0 -44
  234. data/test/rubygems/test_gem_doc_manager.rb +0 -32
  235. data/test/rubygems/test_gem_ext_builder.rb +0 -58
  236. data/test/rubygems/test_gem_format.rb +0 -88
  237. data/test/rubygems/test_gem_gem_path_searcher.rb +0 -94
  238. data/test/rubygems/test_gem_package_tar_input.rb +0 -129
  239. data/test/rubygems/test_gem_package_tar_output.rb +0 -101
  240. data/test/rubygems/test_gem_source_index.rb +0 -250
  241. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -6,19 +6,17 @@ class TestGemUninstaller < Gem::InstallerTestCase
6
6
  def setup
7
7
  super
8
8
 
9
- @user_spec.executables = ["executable"]
10
-
11
9
  build_rake_in do
12
10
  use_ui ui do
13
11
  @installer.install
14
- @user_installer.install
15
-
16
- Gem.use_paths @gemhome, Gem.user_dir
12
+ @spec = @installer.spec
17
13
 
18
- @spec = Gem::Specification.find_by_name 'a'
19
- @user_spec = Gem::Specification.find_by_name 'b'
14
+ @user_installer.install
15
+ @user_spec = @user_installer.spec
20
16
  end
21
17
  end
18
+
19
+ Gem::Specification.reset
22
20
  end
23
21
 
24
22
  def test_initialize_expand_path
@@ -42,7 +40,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
42
40
  def test_remove_executables_force_keep
43
41
  uninstaller = Gem::Uninstaller.new nil, :executables => false
44
42
 
45
- executable = File.join Gem.user_dir, 'bin', 'executable'
43
+ executable = File.join Gem.bindir(@user_spec.base_dir), 'executable'
46
44
  assert File.exist?(executable), 'executable not written'
47
45
 
48
46
  use_ui @ui do
@@ -57,7 +55,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
57
55
  def test_remove_executables_force_remove
58
56
  uninstaller = Gem::Uninstaller.new nil, :executables => true
59
57
 
60
- executable = File.join Gem.user_dir, 'bin', 'executable'
58
+ executable = File.join Gem.bindir(@user_spec.base_dir), 'executable'
61
59
  assert File.exist?(executable), 'executable not written'
62
60
 
63
61
  use_ui @ui do
@@ -77,7 +75,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
77
75
  end
78
76
 
79
77
  exec_path = File.join Gem.user_dir, 'bin', 'executable'
80
- assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
78
+ refute File.exist?(exec_path), 'exec still exists in user bin dir'
81
79
 
82
80
  assert_equal "Removing executable\n", @ui.output
83
81
  end
@@ -200,7 +198,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
200
198
  :executables => true,
201
199
  :user_install => true)
202
200
 
203
- gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
201
+ gem_dir = File.join @user_spec.gem_dir
204
202
 
205
203
  Gem.pre_uninstall do
206
204
  assert_path_exists gem_dir
@@ -218,18 +216,143 @@ class TestGemUninstaller < Gem::InstallerTestCase
218
216
  assert_same uninstaller, @post_uninstall_hook_arg
219
217
  end
220
218
 
219
+ def test_uninstall_wrong_repo
220
+ Gem.use_paths "#{@gemhome}2", [@gemhome]
221
+
222
+ uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
223
+
224
+ e = assert_raises Gem::InstallError do
225
+ uninstaller.uninstall
226
+ end
227
+
228
+ expected = <<-MESSAGE.strip
229
+ #{@spec.name} is not installed in GEM_HOME, try:
230
+ \tgem uninstall -i #{@gemhome} a
231
+ MESSAGE
232
+
233
+ assert_equal expected, e.message
234
+ end
235
+
221
236
  def test_uninstall_selection_greater_than_one
222
237
  util_make_gems
223
-
238
+
224
239
  list = Gem::Specification.find_all_by_name('a')
225
240
 
226
241
  uninstaller = Gem::Uninstaller.new('a')
227
242
 
228
- use_ui Gem::MockGemUi.new("2\n") do
243
+ use_ui Gem::MockGemUi.new("2\ny\n") do
229
244
  uninstaller.uninstall
230
245
  end
231
246
 
232
247
  updated_list = Gem::Specification.find_all_by_name('a')
233
248
  assert_equal list.length - 1, updated_list.length
234
249
  end
250
+
251
+ def test_uninstall_prompts_about_broken_deps
252
+ util_gem 'r', '1', 'q' => '= 1'
253
+ util_gem 'q', '1'
254
+
255
+ un = Gem::Uninstaller.new('q')
256
+ ui = Gem::MockGemUi.new("y\n")
257
+
258
+ use_ui ui do
259
+ un.uninstall
260
+ end
261
+
262
+ lines = ui.output.split("\n")
263
+ lines.shift
264
+
265
+ assert_match %r!You have requested to uninstall the gem:!, lines.shift
266
+ lines.shift
267
+ lines.shift
268
+
269
+ assert_match %r!r-1 depends on q \(= 1\)!, lines.shift
270
+ assert_match %r!Successfully uninstalled q-1!, lines.last
271
+ end
272
+
273
+ def test_uninstall_only_lists_unsatified_deps
274
+ util_gem 'r', '1', 'q' => '~> 1.0'
275
+ util_gem 'x', '1', 'q' => '= 1.0'
276
+ util_gem 'q', '1.0'
277
+ util_gem 'q', '1.1'
278
+
279
+ un = Gem::Uninstaller.new('q', :version => "1.0")
280
+ ui = Gem::MockGemUi.new("y\n")
281
+
282
+ use_ui ui do
283
+ un.uninstall
284
+ end
285
+
286
+ lines = ui.output.split("\n")
287
+ lines.shift
288
+
289
+ assert_match %r!You have requested to uninstall the gem:!, lines.shift
290
+ lines.shift
291
+ lines.shift
292
+
293
+ assert_match %r!x-1 depends on q \(= 1.0\)!, lines.shift
294
+ assert_match %r!Successfully uninstalled q-1.0!, lines.last
295
+ end
296
+
297
+ def test_uninstall_doesnt_prompt_when_other_gem_satifies_requirement
298
+ util_gem 'r', '1', 'q' => '~> 1.0'
299
+ util_gem 'q', '1.0'
300
+ util_gem 'q', '1.1'
301
+
302
+ un = Gem::Uninstaller.new('q', :version => "1.0")
303
+ ui = Gem::MockGemUi.new("y\n")
304
+
305
+ use_ui ui do
306
+ un.uninstall
307
+ end
308
+
309
+ lines = ui.output.split("\n")
310
+
311
+ assert_equal "Successfully uninstalled q-1.0", lines.shift
312
+ end
313
+
314
+ def test_uninstall_doesnt_prompt_when_removing_a_dev_dep
315
+ util_gem('r', '1') do |s|
316
+ s.add_development_dependency "q", "= 1.0"
317
+ end
318
+
319
+ util_gem 'q', '1.0'
320
+
321
+ un = Gem::Uninstaller.new('q', :version => "1.0")
322
+ ui = Gem::MockGemUi.new("y\n")
323
+
324
+ use_ui ui do
325
+ un.uninstall
326
+ end
327
+
328
+ lines = ui.output.split("\n")
329
+
330
+ assert_equal "Successfully uninstalled q-1.0", lines.shift
331
+ end
332
+
333
+
334
+ def test_uninstall_prompt_includes_dep_type
335
+ util_gem 'r', '1' do |s|
336
+ s.add_development_dependency 'q', '= 1'
337
+ end
338
+
339
+ util_gem 'q', '1'
340
+
341
+ un = Gem::Uninstaller.new('q', :check_dev => true)
342
+ ui = Gem::MockGemUi.new("y\n")
343
+
344
+ use_ui ui do
345
+ un.uninstall
346
+ end
347
+
348
+ lines = ui.output.split("\n")
349
+ lines.shift
350
+
351
+ assert_match %r!You have requested to uninstall the gem:!, lines.shift
352
+ lines.shift
353
+ lines.shift
354
+
355
+ assert_match %r!r-1 depends on q \(= 1, development\)!, lines.shift
356
+ assert_match %r!Successfully uninstalled q-1!, lines.last
357
+ end
235
358
  end
@@ -11,53 +11,26 @@ class TestGemValidator < Gem::TestCase
11
11
  @validator = Gem::Validator.new
12
12
  end
13
13
 
14
- def test_verify_gem_file
15
- gem_file = File.join @tempdir, 'simple_gem.gem'
16
- File.open gem_file, 'wb' do |fp| fp.write @simple_gem end
17
-
18
- assert_equal nil, @validator.verify_gem_file(gem_file)
19
- end
20
-
21
- def test_verify_gem_file_empty
22
- e = assert_raises Gem::VerificationError do
23
- @validator.verify_gem_file ''
24
- end
25
-
26
- assert_equal 'missing gem file ', e.message
27
- end
28
-
29
- def test_verify_gem_file_nonexistent
30
- file = '/nonexistent/nonexistent.gem'
31
- e = assert_raises Gem::VerificationError do
32
- @validator.verify_gem_file file
14
+ def test_alien
15
+ @spec = quick_gem 'a' do |s|
16
+ s.files = %w[lib/a.rb lib/b.rb]
33
17
  end
34
18
 
35
- assert_equal "missing gem file #{file}", e.message
36
- end
37
-
38
- def test_verify_gem
39
- assert_equal nil, @validator.verify_gem(@simple_gem)
40
- end
41
-
42
- def test_verify_gem_empty
43
- e = assert_raises Gem::VerificationError do
44
- @validator.verify_gem ''
45
- end
19
+ util_build_gem @spec
46
20
 
47
- assert_equal 'empty gem file', e.message
48
- end
21
+ FileUtils.rm File.join(@spec.gem_dir, 'lib/b.rb')
22
+ FileUtils.touch File.join(@spec.gem_dir, 'lib/c.rb')
49
23
 
50
- def test_verify_gem_invalid_checksum
51
- e = assert_raises Gem::VerificationError do
52
- @validator.verify_gem @simple_gem.upcase
53
- end
24
+ alien = @validator.alien 'a'
54
25
 
55
- assert_equal 'invalid checksum for gem file', e.message
56
- end
26
+ expected = {
27
+ @spec.file_name => [
28
+ Gem::Validator::ErrorData.new('lib/b.rb', 'Missing file'),
29
+ Gem::Validator::ErrorData.new('lib/c.rb', 'Extra file'),
30
+ ]
31
+ }
57
32
 
58
- def test_verify_gem_no_sum
59
- assert_equal nil, @validator.verify_gem('words')
33
+ assert_equal expected, alien
60
34
  end
61
-
62
35
  end
63
36
 
@@ -33,7 +33,7 @@ class TestGemVersion < Gem::TestCase
33
33
  assert_same fake, Gem::Version.create(fake)
34
34
  assert_nil Gem::Version.create(nil)
35
35
  assert_equal v("5.1"), Gem::Version.create("5.1")
36
-
36
+
37
37
  ver = '1.1'.freeze
38
38
  assert_equal v('1.1'), Gem::Version.create(ver)
39
39
  end
@@ -59,7 +59,7 @@ class TestGemVersion < Gem::TestCase
59
59
  end
60
60
 
61
61
  def test_initialize
62
- ["1.0", "1.0 ", " 1.0 ", "1.0\n", "\n1.0\n"].each do |good|
62
+ ["1.0", "1.0 ", " 1.0 ", "1.0\n", "\n1.0\n", "1.0".freeze].each do |good|
63
63
  assert_version_equal "1.0", good
64
64
  end
65
65
 
@@ -67,18 +67,12 @@ class TestGemVersion < Gem::TestCase
67
67
  end
68
68
 
69
69
  def test_initialize_bad
70
- %W[
71
- junk
72
- 1.0\n2.0
73
- 1..2
74
- 1.2\ 3.4
75
- 1-2-3
76
- ].each do |bad|
77
- e = assert_raises ArgumentError, bad do
70
+ ["junk", "1.0\n2.0"].each do |bad|
71
+ e = assert_raises ArgumentError do
78
72
  Gem::Version.new bad
79
73
  end
80
74
 
81
- assert_equal "Malformed version number string #{bad}", e.message, bad
75
+ assert_equal "Malformed version number string #{bad}", e.message
82
76
  end
83
77
  end
84
78
 
@@ -115,13 +109,13 @@ class TestGemVersion < Gem::TestCase
115
109
  assert_nil v("1.0") <=> "whatever"
116
110
  end
117
111
 
118
- def test_spermy_recommendation
119
- assert_spermy_equal "~> 1.0", "1"
120
- assert_spermy_equal "~> 1.0", "1.0"
121
- assert_spermy_equal "~> 1.2", "1.2"
122
- assert_spermy_equal "~> 1.2", "1.2.0"
123
- assert_spermy_equal "~> 1.2", "1.2.3"
124
- assert_spermy_equal "~> 1.2", "1.2.3.a.4"
112
+ def test_approximate_recommendation
113
+ assert_approximate_equal "~> 1.0", "1"
114
+ assert_approximate_equal "~> 1.0", "1.0"
115
+ assert_approximate_equal "~> 1.2", "1.2"
116
+ assert_approximate_equal "~> 1.2", "1.2.0"
117
+ assert_approximate_equal "~> 1.2", "1.2.3"
118
+ assert_approximate_equal "~> 1.2", "1.2.3.a.4"
125
119
  end
126
120
 
127
121
  def test_to_s
@@ -134,10 +128,10 @@ class TestGemVersion < Gem::TestCase
134
128
  assert v(version).prerelease?, "#{version} is a prerelease"
135
129
  end
136
130
 
137
- # Assert that +expected+ is the "spermy" recommendation for +version".
131
+ # Assert that +expected+ is the "approximate" recommendation for +version".
138
132
 
139
- def assert_spermy_equal expected, version
140
- assert_equal expected, v(version).spermy_recommendation
133
+ def assert_approximate_equal expected, version
134
+ assert_equal expected, v(version).approximate_recommendation
141
135
  end
142
136
 
143
137
  # Assert that bumping the +unbumped+ version yields the +expected+.
@@ -0,0 +1,193 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems'
3
+
4
+ class TestGemRequire < Gem::TestCase
5
+ def assert_require(path)
6
+ assert require(path), "'#{path}' was already required"
7
+ end
8
+
9
+ def test_require_is_not_lazy_with_exact_req
10
+ a1 = new_spec "a", "1", {"b" => "= 1"}, "lib/a.rb"
11
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
12
+ b2 = new_spec "b", "2", nil, "lib/b/c.rb"
13
+
14
+ install_specs a1, b1, b2
15
+
16
+ save_loaded_features do
17
+ assert_require 'a'
18
+ assert_equal %w(a-1 b-1), loaded_spec_names
19
+ assert_equal unresolved_names, []
20
+
21
+ assert_require "b/c"
22
+ assert_equal %w(a-1 b-1), loaded_spec_names
23
+ end
24
+ end
25
+
26
+ def test_require_is_lazy_with_inexact_req
27
+ a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/a.rb"
28
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
29
+ b2 = new_spec "b", "2", nil, "lib/b/c.rb"
30
+
31
+ install_specs a1, b1, b2
32
+
33
+ save_loaded_features do
34
+ assert_require 'a'
35
+ assert_equal %w(a-1), loaded_spec_names
36
+ assert_equal unresolved_names, ["b (>= 1)"]
37
+
38
+ assert_require "b/c"
39
+ assert_equal %w(a-1 b-2), loaded_spec_names
40
+ end
41
+ end
42
+
43
+ def test_require_is_not_lazy_with_one_possible
44
+ a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/a.rb"
45
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
46
+
47
+ install_specs a1, b1
48
+
49
+ save_loaded_features do
50
+ assert_require 'a'
51
+ assert_equal %w(a-1 b-1), loaded_spec_names
52
+ assert_equal unresolved_names, []
53
+
54
+ assert_require "b/c"
55
+ assert_equal %w(a-1 b-1), loaded_spec_names
56
+ end
57
+ end
58
+
59
+ def test_activate_via_require_respects_loaded_files
60
+ save_loaded_features do
61
+ require 'benchmark' # stdlib
62
+
63
+ a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/a.rb"
64
+ b1 = new_spec "b", "1", nil, "lib/benchmark.rb"
65
+ b2 = new_spec "b", "2", nil, "lib/benchmark.rb"
66
+
67
+ install_specs a1, b1, b2
68
+
69
+ require 'a'
70
+ assert_equal unresolved_names, ["b (>= 1)"]
71
+
72
+ refute require('benchmark'), "benchmark should have already been loaded"
73
+
74
+ # We detected that we should activate b-2, so we did so, but
75
+ # then original_require decided "I've already got benchmark.rb" loaded.
76
+ # This case is fine because our lazy loading is provided exactly
77
+ # the same behavior as eager loading would have.
78
+
79
+ assert_equal %w(a-1 b-2), loaded_spec_names
80
+ end
81
+ end
82
+
83
+ def test_already_activated_direct_conflict
84
+ save_loaded_features do
85
+ a1 = new_spec "a", "1", { "b" => "> 0" }
86
+ b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
87
+ b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
88
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
89
+ c2 = new_spec("c", "2", nil, "lib/d.rb")
90
+
91
+ install_specs a1, b1, b2, c1, c2
92
+
93
+ a1.activate
94
+ c1.activate
95
+ assert_equal %w(a-1 c-1), loaded_spec_names
96
+ assert_equal ["b (> 0)"], unresolved_names
97
+
98
+ assert require("ib")
99
+
100
+ assert_equal %w(a-1 b-1 c-1), loaded_spec_names
101
+ assert_equal [], unresolved_names
102
+ end
103
+ end
104
+
105
+ def test_multiple_gems_with_the_same_path
106
+ save_loaded_features do
107
+ a1 = new_spec "a", "1", { "b" => "> 0", "x" => "> 0" }
108
+ b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
109
+ b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
110
+ x1 = new_spec "x", "1", nil, "lib/ib.rb"
111
+ x2 = new_spec "x", "2", nil, "lib/ib.rb"
112
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
113
+ c2 = new_spec("c", "2", nil, "lib/d.rb")
114
+
115
+ install_specs a1, b1, b2, c1, c2, x1, x2
116
+
117
+ a1.activate
118
+ c1.activate
119
+ assert_equal %w(a-1 c-1), loaded_spec_names
120
+ assert_equal ["b (> 0)", "x (> 0)"], unresolved_names
121
+
122
+ e = assert_raises(Gem::LoadError) do
123
+ require("ib")
124
+ end
125
+
126
+ assert_equal "ib found in multiple gems: b, x", e.message
127
+ end
128
+ end
129
+
130
+ def test_unable_to_find_good_unresolved_version
131
+ save_loaded_features do
132
+ a1 = new_spec "a", "1", { "b" => "> 0" }
133
+ b1 = new_spec "b", "1", { "c" => ">= 2" }, "lib/ib.rb"
134
+ b2 = new_spec "b", "2", { "c" => ">= 3" }, "lib/ib.rb"
135
+
136
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
137
+ c2 = new_spec "c", "2", nil, "lib/d.rb"
138
+ c3 = new_spec "c", "3", nil, "lib/d.rb"
139
+
140
+ install_specs a1, b1, b2, c1, c2, c3
141
+
142
+ a1.activate
143
+ c1.activate
144
+ assert_equal %w(a-1 c-1), loaded_spec_names
145
+ assert_equal ["b (> 0)"], unresolved_names
146
+
147
+ e = assert_raises(Gem::LoadError) do
148
+ require("ib")
149
+ end
150
+
151
+ assert_equal "unable to find a version of 'b' to activate", e.message
152
+ end
153
+ end
154
+
155
+ def test_default_gem_only
156
+ save_loaded_features do
157
+ default_gem_spec = new_default_spec("default", "2.0.0.0",
158
+ nil, "default/gem.rb")
159
+ install_default_specs(default_gem_spec)
160
+ assert_require "default/gem"
161
+ assert_equal %w(default-2.0.0.0), loaded_spec_names
162
+ end
163
+ end
164
+
165
+ def test_default_gem_and_normal_gem
166
+ save_loaded_features do
167
+ default_gem_spec = new_default_spec("default", "2.0.0.0",
168
+ nil, "default/gem.rb")
169
+ install_default_specs(default_gem_spec)
170
+ normal_gem_spec = new_spec("default", "3.0", nil,
171
+ "lib/default/gem.rb")
172
+ install_specs(normal_gem_spec)
173
+ assert_require "default/gem"
174
+ assert_equal %w(default-3.0), loaded_spec_names
175
+ end
176
+ end
177
+
178
+ def loaded_spec_names
179
+ Gem.loaded_specs.values.map(&:full_name).sort
180
+ end
181
+
182
+ def unresolved_names
183
+ Gem::Specification.unresolved_deps.values.map(&:to_s).sort
184
+ end
185
+
186
+ def save_loaded_features
187
+ old_loaded_features = $LOADED_FEATURES.dup
188
+ yield
189
+ ensure
190
+ $LOADED_FEATURES.replace old_loaded_features
191
+ end
192
+
193
+ end