rubygems-update 1.4.2 → 1.5.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 (150) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +4 -5
  3. data/{test/foo/discover.rb → .gemtest} +0 -0
  4. data/ChangeLog +13 -0
  5. data/History.txt +35 -1
  6. data/Manifest.txt +89 -88
  7. data/README.rdoc +21 -10
  8. data/Rakefile +31 -17
  9. data/UPGRADING.rdoc +81 -0
  10. data/ci_build.sh +27 -0
  11. data/cruise_config.rb +20 -13
  12. data/lib/rbconfig/datadir.rb +1 -1
  13. data/lib/rubygems.rb +102 -45
  14. data/lib/rubygems/builder.rb +5 -11
  15. data/lib/rubygems/command_manager.rb +0 -1
  16. data/lib/rubygems/commands/check_command.rb +2 -17
  17. data/lib/rubygems/commands/cleanup_command.rb +1 -1
  18. data/lib/rubygems/commands/dependency_command.rb +5 -18
  19. data/lib/rubygems/commands/environment_command.rb +5 -4
  20. data/lib/rubygems/commands/fetch_command.rb +0 -1
  21. data/lib/rubygems/commands/generate_index_command.rb +1 -10
  22. data/lib/rubygems/commands/help_command.rb +0 -5
  23. data/lib/rubygems/commands/query_command.rb +4 -24
  24. data/lib/rubygems/commands/setup_command.rb +4 -19
  25. data/lib/rubygems/commands/sources_command.rb +15 -37
  26. data/lib/rubygems/commands/specification_command.rb +1 -2
  27. data/lib/rubygems/commands/unpack_command.rb +19 -7
  28. data/lib/rubygems/commands/update_command.rb +29 -44
  29. data/lib/rubygems/config_file.rb +25 -19
  30. data/lib/rubygems/custom_require.rb +4 -6
  31. data/lib/rubygems/dependency.rb +1 -43
  32. data/lib/rubygems/dependency_installer.rb +1 -1
  33. data/lib/rubygems/doc_manager.rb +3 -1
  34. data/lib/rubygems/ext/builder.rb +3 -1
  35. data/lib/rubygems/ext/rake_builder.rb +10 -2
  36. data/lib/rubygems/format.rb +7 -4
  37. data/lib/rubygems/gem_runner.rb +1 -1
  38. data/lib/rubygems/indexer.rb +11 -74
  39. data/lib/rubygems/install_update_options.rb +13 -8
  40. data/lib/rubygems/installer.rb +139 -95
  41. data/{test/gem_installer_test_case.rb → lib/rubygems/installer_test_case.rb} +41 -2
  42. data/{test/mockgemui.rb → lib/rubygems/mock_gem_ui.rb} +8 -1
  43. data/lib/rubygems/old_format.rb +2 -1
  44. data/lib/rubygems/package.rb +17 -2
  45. data/lib/rubygems/package/tar_input.rb +7 -3
  46. data/lib/rubygems/package/tar_output.rb +2 -0
  47. data/lib/rubygems/package/tar_reader/entry.rb +4 -0
  48. data/{test/gem_package_tar_test_case.rb → lib/rubygems/package/tar_test_case.rb} +5 -2
  49. data/lib/rubygems/package_task.rb +6 -4
  50. data/lib/rubygems/remote_fetcher.rb +10 -2
  51. data/lib/rubygems/require_paths_builder.rb +2 -1
  52. data/lib/rubygems/server.rb +3 -44
  53. data/lib/rubygems/source_index.rb +3 -216
  54. data/lib/rubygems/spec_fetcher.rb +15 -63
  55. data/lib/rubygems/specification.rb +1 -1
  56. data/{test/gemutilities.rb → lib/rubygems/test_case.rb} +219 -90
  57. data/lib/rubygems/test_utilities.rb +7 -20
  58. data/lib/rubygems/uninstaller.rb +27 -28
  59. data/lib/rubygems/user_interaction.rb +81 -42
  60. data/lib/rubygems/validator.rb +0 -73
  61. data/test/{bogussources.rb → rubygems/bogussources.rb} +0 -0
  62. data/test/{data → rubygems/data}/gem-private_key.pem +0 -0
  63. data/test/{data → rubygems/data}/gem-public_cert.pem +0 -0
  64. data/test/{fake_certlib → rubygems/fake_certlib}/openssl.rb +0 -0
  65. data/test/rubygems/foo/discover.rb +0 -0
  66. data/test/{functional.rb → rubygems/functional.rb} +0 -0
  67. data/test/{insure_session.rb → rubygems/insure_session.rb} +0 -0
  68. data/test/{plugin → rubygems/plugin}/exception/rubygems_plugin.rb +0 -0
  69. data/test/{plugin → rubygems/plugin}/load/rubygems_plugin.rb +0 -0
  70. data/test/{plugin → rubygems/plugin}/standarderror/rubygems_plugin.rb +0 -0
  71. data/test/{private_key.pem → rubygems/private_key.pem} +0 -0
  72. data/test/{public_cert.pem → rubygems/public_cert.pem} +0 -0
  73. data/test/rubygems/{commands → rubygems/commands}/crash_command.rb +0 -0
  74. data/test/{rubygems_plugin.rb → rubygems/rubygems_plugin.rb} +0 -0
  75. data/test/rubygems/sff/discover.rb +0 -0
  76. data/test/{simple_gem.rb → rubygems/simple_gem.rb} +2 -2
  77. data/test/{test_config.rb → rubygems/test_config.rb} +2 -2
  78. data/test/{test_gem.rb → rubygems/test_gem.rb} +12 -2
  79. data/test/{test_gem_builder.rb → rubygems/test_gem_builder.rb} +2 -2
  80. data/test/{test_gem_command.rb → rubygems/test_gem_command.rb} +3 -3
  81. data/test/{test_gem_command_manager.rb → rubygems/test_gem_command_manager.rb} +15 -6
  82. data/test/{test_gem_commands_build_command.rb → rubygems/test_gem_commands_build_command.rb} +2 -2
  83. data/test/{test_gem_commands_cert_command.rb → rubygems/test_gem_commands_cert_command.rb} +2 -2
  84. data/test/{test_gem_commands_check_command.rb → rubygems/test_gem_commands_check_command.rb} +2 -2
  85. data/test/{test_gem_commands_contents_command.rb → rubygems/test_gem_commands_contents_command.rb} +3 -3
  86. data/test/{test_gem_commands_dependency_command.rb → rubygems/test_gem_commands_dependency_command.rb} +4 -4
  87. data/test/{test_gem_commands_environment_command.rb → rubygems/test_gem_commands_environment_command.rb} +12 -3
  88. data/test/{test_gem_commands_fetch_command.rb → rubygems/test_gem_commands_fetch_command.rb} +2 -2
  89. data/test/{test_gem_commands_generate_index_command.rb → rubygems/test_gem_commands_generate_index_command.rb} +7 -11
  90. data/test/{test_gem_commands_install_command.rb → rubygems/test_gem_commands_install_command.rb} +2 -2
  91. data/test/{test_gem_commands_list_command.rb → rubygems/test_gem_commands_list_command.rb} +2 -2
  92. data/test/{test_gem_commands_lock_command.rb → rubygems/test_gem_commands_lock_command.rb} +2 -2
  93. data/test/{test_gem_commands_outdated_command.rb → rubygems/test_gem_commands_outdated_command.rb} +2 -2
  94. data/test/{test_gem_commands_owner_command.rb → rubygems/test_gem_commands_owner_command.rb} +5 -5
  95. data/test/{test_gem_commands_pristine_command.rb → rubygems/test_gem_commands_pristine_command.rb} +2 -2
  96. data/test/{test_gem_commands_push_command.rb → rubygems/test_gem_commands_push_command.rb} +3 -3
  97. data/test/{test_gem_commands_query_command.rb → rubygems/test_gem_commands_query_command.rb} +2 -2
  98. data/test/{test_gem_commands_server_command.rb → rubygems/test_gem_commands_server_command.rb} +2 -2
  99. data/test/{test_gem_commands_sources_command.rb → rubygems/test_gem_commands_sources_command.rb} +8 -8
  100. data/test/{test_gem_commands_specification_command.rb → rubygems/test_gem_commands_specification_command.rb} +3 -3
  101. data/test/{test_gem_commands_stale_command.rb → rubygems/test_gem_commands_stale_command.rb} +2 -2
  102. data/test/{test_gem_commands_uninstall_command.rb → rubygems/test_gem_commands_uninstall_command.rb} +16 -10
  103. data/test/{test_gem_commands_unpack_command.rb → rubygems/test_gem_commands_unpack_command.rb} +42 -2
  104. data/test/{test_gem_commands_update_command.rb → rubygems/test_gem_commands_update_command.rb} +2 -2
  105. data/test/{test_gem_commands_which_command.rb → rubygems/test_gem_commands_which_command.rb} +3 -3
  106. data/test/{test_gem_config_file.rb → rubygems/test_gem_config_file.rb} +2 -2
  107. data/test/{test_gem_dependency.rb → rubygems/test_gem_dependency.rb} +3 -27
  108. data/test/{test_gem_dependency_installer.rb → rubygems/test_gem_dependency_installer.rb} +2 -2
  109. data/test/{test_gem_dependency_list.rb → rubygems/test_gem_dependency_list.rb} +3 -3
  110. data/test/{test_gem_doc_manager.rb → rubygems/test_gem_doc_manager.rb} +2 -2
  111. data/test/{test_gem_ext_configure_builder.rb → rubygems/test_gem_ext_configure_builder.rb} +4 -4
  112. data/test/{test_gem_ext_ext_conf_builder.rb → rubygems/test_gem_ext_ext_conf_builder.rb} +46 -2
  113. data/test/{test_gem_ext_rake_builder.rb → rubygems/test_gem_ext_rake_builder.rb} +2 -2
  114. data/test/{test_gem_format.rb → rubygems/test_gem_format.rb} +24 -6
  115. data/test/{test_gem_gem_path_searcher.rb → rubygems/test_gem_gem_path_searcher.rb} +2 -2
  116. data/test/{test_gem_gem_runner.rb → rubygems/test_gem_gem_runner.rb} +2 -2
  117. data/test/{test_gem_gemcutter_utilities.rb → rubygems/test_gem_gemcutter_utilities.rb} +4 -4
  118. data/test/{test_gem_indexer.rb → rubygems/test_gem_indexer.rb} +4 -121
  119. data/test/{test_gem_install_update_options.rb → rubygems/test_gem_install_update_options.rb} +3 -3
  120. data/test/{test_gem_installer.rb → rubygems/test_gem_installer.rb} +106 -13
  121. data/test/{test_gem_local_remote_options.rb → rubygems/test_gem_local_remote_options.rb} +2 -2
  122. data/test/{test_gem_package_tar_header.rb → rubygems/test_gem_package_tar_header.rb} +2 -2
  123. data/test/{test_gem_package_tar_input.rb → rubygems/test_gem_package_tar_input.rb} +21 -4
  124. data/test/{test_gem_package_tar_output.rb → rubygems/test_gem_package_tar_output.rb} +2 -2
  125. data/test/{test_gem_package_tar_reader.rb → rubygems/test_gem_package_tar_reader.rb} +2 -2
  126. data/test/{test_gem_package_tar_reader_entry.rb → rubygems/test_gem_package_tar_reader_entry.rb} +12 -2
  127. data/test/{test_gem_package_tar_writer.rb → rubygems/test_gem_package_tar_writer.rb} +2 -2
  128. data/test/{test_gem_package_task.rb → rubygems/test_gem_package_task.rb} +15 -2
  129. data/test/{test_gem_platform.rb → rubygems/test_gem_platform.rb} +2 -2
  130. data/test/{test_gem_remote_fetcher.rb → rubygems/test_gem_remote_fetcher.rb} +7 -7
  131. data/test/{test_gem_requirement.rb → rubygems/test_gem_requirement.rb} +2 -2
  132. data/test/{test_gem_security.rb → rubygems/test_gem_security.rb} +3 -4
  133. data/test/{test_gem_server.rb → rubygems/test_gem_server.rb} +2 -132
  134. data/test/rubygems/test_gem_silent_ui.rb +113 -0
  135. data/test/{test_gem_source_index.rb → rubygems/test_gem_source_index.rb} +2 -61
  136. data/test/{test_gem_spec_fetcher.rb → rubygems/test_gem_spec_fetcher.rb} +2 -2
  137. data/test/{test_gem_specification.rb → rubygems/test_gem_specification.rb} +4 -4
  138. data/test/{test_gem_stream_ui.rb → rubygems/test_gem_stream_ui.rb} +24 -2
  139. data/test/{test_gem_text.rb → rubygems/test_gem_text.rb} +2 -2
  140. data/test/{test_gem_uninstaller.rb → rubygems/test_gem_uninstaller.rb} +15 -12
  141. data/test/{test_gem_validator.rb → rubygems/test_gem_validator.rb} +3 -3
  142. data/test/{test_gem_version.rb → rubygems/test_gem_version.rb} +2 -2
  143. data/test/{test_gem_version_option.rb → rubygems/test_gem_version_option.rb} +2 -2
  144. data/test/{test_kernel.rb → rubygems/test_kernel.rb} +7 -10
  145. metadata +281 -177
  146. metadata.gz.sig +0 -0
  147. data/lib/rubygems/commands/mirror_command.rb +0 -111
  148. data/lib/rubygems/source_info_cache.rb +0 -394
  149. data/lib/rubygems/source_info_cache_entry.rb +0 -56
  150. data/test/test_gem_commands_mirror_command.rb +0 -60
@@ -11,6 +11,12 @@ class Gem::SpecFetcher
11
11
  include Gem::UserInteraction
12
12
  include Gem::Text
13
13
 
14
+ FILES = {
15
+ :all => 'specs',
16
+ :latest => 'latest_specs',
17
+ :prerelease => 'prerelease_specs',
18
+ }
19
+
14
20
  ##
15
21
  # The SpecFetcher cache dir.
16
22
 
@@ -51,6 +57,12 @@ class Gem::SpecFetcher
51
57
  @latest_specs = {}
52
58
  @prerelease_specs = {}
53
59
 
60
+ @caches = {
61
+ :latest => @latest_specs,
62
+ :prerelease => @prerelease_specs,
63
+ :all => @specs
64
+ }
65
+
54
66
  @fetcher = Gem::RemoteFetcher.fetcher
55
67
  end
56
68
 
@@ -75,14 +87,6 @@ class Gem::SpecFetcher
75
87
  end
76
88
 
77
89
  return [ss, errors]
78
-
79
- rescue Gem::RemoteFetcher::FetchError => e
80
- raise unless warn_legacy e do
81
- require 'rubygems/source_info_cache'
82
-
83
- return [Gem::SourceInfoCache.search_with_source(dependency,
84
- matching_platform, all), nil]
85
- end
86
90
  end
87
91
 
88
92
  def fetch(*args)
@@ -160,29 +164,6 @@ class Gem::SpecFetcher
160
164
  find_matching_with_errors(*args).first
161
165
  end
162
166
 
163
- ##
164
- # Returns Array of gem repositories that were generated with RubyGems less
165
- # than 1.2.
166
-
167
- def legacy_repos
168
- Gem.sources.reject do |source_uri|
169
- source_uri = URI.parse source_uri
170
- spec_path = source_uri + "specs.#{Gem.marshal_version}.gz"
171
-
172
- begin
173
- @fetcher.fetch_size spec_path
174
- rescue Gem::RemoteFetcher::FetchError
175
- begin
176
- @fetcher.fetch_size(source_uri + 'yaml') # re-raise if non-repo
177
- rescue Gem::RemoteFetcher::FetchError
178
- alert_error "#{source_uri} does not appear to be a repository"
179
- raise
180
- end
181
- false
182
- end
183
- end
184
- end
185
-
186
167
  ##
187
168
  # Suggests a gem based on the supplied +gem_name+. Returns a string
188
169
  # of the gem name if an approximate match can be found or nil
@@ -226,15 +207,9 @@ class Gem::SpecFetcher
226
207
  :latest
227
208
  end
228
209
 
229
- list = {}
230
-
231
- file = { :latest => 'latest_specs',
232
- :prerelease => 'prerelease_specs',
233
- :all => 'specs' }[type]
234
-
235
- cache = { :latest => @latest_specs,
236
- :prerelease => @prerelease_specs,
237
- :all => @specs }[type]
210
+ list = {}
211
+ file = FILES[type]
212
+ cache = @caches[type]
238
213
 
239
214
  Gem.sources.each do |source_uri|
240
215
  source_uri = URI.parse source_uri
@@ -302,28 +277,5 @@ class Gem::SpecFetcher
302
277
  specs
303
278
  end
304
279
 
305
- ##
306
- # Warn about legacy repositories if +exception+ indicates only legacy
307
- # repositories are available, and yield to the block. Returns false if the
308
- # exception indicates some other FetchError.
309
-
310
- def warn_legacy(exception)
311
- uri = exception.uri.to_s
312
- if uri =~ /specs\.#{Regexp.escape Gem.marshal_version}\.gz$/ then
313
- alert_warning <<-EOF
314
- RubyGems 1.2+ index not found for:
315
- \t#{legacy_repos.join "\n\t"}
316
-
317
- RubyGems will revert to legacy indexes degrading performance.
318
- EOF
319
-
320
- yield
321
-
322
- return true
323
- end
324
-
325
- false
326
- end
327
-
328
280
  end
329
281
 
@@ -330,7 +330,7 @@ class Gem::Specification
330
330
  end
331
331
 
332
332
  ##
333
- # List of depedencies that will automatically be activated at runtime.
333
+ # List of dependencies that will automatically be activated at runtime.
334
334
 
335
335
  def runtime_dependencies
336
336
  dependencies.select { |d| d.type == :runtime || d.type == nil }
@@ -1,14 +1,18 @@
1
1
  at_exit { $SAFE = 1 }
2
2
 
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
-
5
3
  if defined? Gem::QuickLoader
6
4
  Gem::QuickLoader.load_full_rubygems_library
7
5
  else
8
6
  require 'rubygems'
9
7
  end
10
- require 'fileutils'
8
+
9
+ begin
10
+ gem 'minitest'
11
+ rescue Gem::LoadError
12
+ end
13
+
11
14
  require 'minitest/autorun'
15
+ require 'fileutils'
12
16
  require 'tmpdir'
13
17
  require 'uri'
14
18
  require 'rubygems/package'
@@ -29,45 +33,93 @@ end
29
33
 
30
34
  require 'rdoc/rdoc'
31
35
 
32
- require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
36
+ require 'rubygems/mock_gem_ui'
33
37
 
34
38
  module Gem
39
+
40
+ ##
41
+ # Allows setting the gem path searcher. This method is available when
42
+ # requiring 'rubygems/test_case'
43
+
35
44
  def self.searcher=(searcher)
36
45
  @searcher = searcher
37
46
  end
38
47
 
48
+ ##
49
+ # Allows setting the default SourceIndex. This method is available when
50
+ # requiring 'rubygems/test_case'
51
+
39
52
  def self.source_index=(si)
40
53
  @@source_index = si
41
54
  end
42
55
 
56
+ ##
57
+ # Allows toggling Windows behavior. This method is available when requiring
58
+ # 'rubygems/test_case'
59
+
43
60
  def self.win_platform=(val)
44
61
  @@win_platform = val
45
62
  end
46
63
 
64
+ ##
65
+ # Allows setting path to ruby. This method is available when requiring
66
+ # 'rubygems/test_case'
67
+
68
+ def self.ruby= ruby
69
+ @ruby = ruby
70
+ end
71
+
72
+ ##
73
+ # When rubygems/test_case is required the default user interaction is a
74
+ # MockGemUi.
75
+
47
76
  module DefaultUserInteraction
48
- @ui = MockGemUi.new
77
+ @ui = Gem::MockGemUi.new
49
78
  end
50
79
  end
51
80
 
52
- class RubyGemTestCase < MiniTest::Unit::TestCase
81
+ ##
82
+ # RubyGemTestCase provides a variety of methods for testing rubygems and
83
+ # gem-related behavior in a sandbox. Through RubyGemTestCase you can install
84
+ # and uninstall gems, fetch remote gems through a stub fetcher and be assured
85
+ # your normal set of gems is not affected.
86
+ #
87
+ # Tests are always run at a safe level of 1.
88
+
89
+ class Gem::TestCase < MiniTest::Unit::TestCase
53
90
 
54
91
  include Gem::DefaultUserInteraction
55
92
 
56
93
  undef_method :default_test if instance_methods.include? 'default_test' or
57
94
  instance_methods.include? :default_test
58
95
 
96
+ ##
97
+ # #setup prepares a sandboxed location to install gems. All installs are
98
+ # directed to a temporary directory. All install plugins are removed.
99
+ #
100
+ # If the +RUBY+ environment variable is set the given path is used for
101
+ # Gem::ruby. The local platform is set to <tt>i386-mswin32</tt> for Windows
102
+ # or <tt>i686-darwin8.10.1</tt> otherwise.
103
+ #
104
+ # If the +KEEP_FILES+ environment variable is set the files will not be
105
+ # removed from <tt>/tmp/test_rubygems_#{$$}.#{Time.now.to_i}</tt>.
106
+
59
107
  def setup
60
108
  super
61
109
 
62
- @ui = MockGemUi.new
110
+ @orig_gem_home = ENV['GEM_HOME']
111
+ @orig_gem_path = ENV['GEM_PATH']
112
+
113
+ @ui = Gem::MockGemUi.new
63
114
  tmpdir = nil
64
115
  Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
65
- @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
116
+ if ENV['KEEP_FILES'] then
117
+ @tempdir = File.join tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}"
118
+ else
119
+ @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
120
+ end
66
121
  @tempdir.untaint
67
- @gemhome = File.join @tempdir, "gemhome"
68
- @gemcache = File.join(@gemhome, "source_cache")
69
- @usrcache = File.join(@gemhome, ".gem", "user_cache")
70
- @latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
122
+ @gemhome = File.join @tempdir, 'gemhome'
71
123
  @userhome = File.join @tempdir, 'userhome'
72
124
 
73
125
  Gem.ensure_gem_subdirectories @gemhome
@@ -86,7 +138,6 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
86
138
  FileUtils.mkdir_p @gemhome
87
139
  FileUtils.mkdir_p @userhome
88
140
 
89
- ENV['GEMCACHE'] = @usrcache
90
141
  Gem.use_paths(@gemhome)
91
142
  Gem.loaded_specs.clear
92
143
 
@@ -112,16 +163,22 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
112
163
 
113
164
  @marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
114
165
 
115
- @private_key = File.expand_path File.join(File.dirname(__FILE__),
116
- 'private_key.pem')
117
- @public_cert = File.expand_path File.join(File.dirname(__FILE__),
118
- 'public_cert.pem')
166
+ @private_key = File.expand_path('../../../test/rubygems/private_key.pem',
167
+ __FILE__)
168
+ @public_cert = File.expand_path('../../../test/rubygems/public_cert.pem',
169
+ __FILE__)
119
170
 
171
+ Gem.post_build_hooks.clear
120
172
  Gem.post_install_hooks.clear
121
173
  Gem.post_uninstall_hooks.clear
122
174
  Gem.pre_install_hooks.clear
123
175
  Gem.pre_uninstall_hooks.clear
124
176
 
177
+ Gem.post_build do |installer|
178
+ @post_build_hook_arg = installer
179
+ true
180
+ end
181
+
125
182
  Gem.post_install do |installer|
126
183
  @post_install_hook_arg = installer
127
184
  end
@@ -132,6 +189,7 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
132
189
 
133
190
  Gem.pre_install do |installer|
134
191
  @pre_install_hook_arg = installer
192
+ true
135
193
  end
136
194
 
137
195
  Gem.pre_uninstall do |uninstaller|
@@ -141,6 +199,10 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
141
199
  @orig_LOAD_PATH = $LOAD_PATH.dup
142
200
  end
143
201
 
202
+ ##
203
+ # #teardown restores the process to its original state and removes the
204
+ # tempdir unless the +KEEP_FILES+ environment variable was set.
205
+
144
206
  def teardown
145
207
  $LOAD_PATH.replace @orig_LOAD_PATH
146
208
 
@@ -151,15 +213,15 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
151
213
  Gem::RemoteFetcher.fetcher = nil
152
214
  end
153
215
 
154
- FileUtils.rm_rf @tempdir
216
+ FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES']
155
217
 
156
- ENV.delete 'GEMCACHE'
157
- ENV.delete 'GEM_HOME'
158
- ENV.delete 'GEM_PATH'
218
+ ENV['GEM_HOME'] = @orig_gem_home
219
+ ENV['GEM_PATH'] = @orig_gem_path
159
220
 
160
221
  Gem.clear_paths
161
222
 
162
- Gem.class_eval { @ruby = _ } if _ = @orig_ruby
223
+ _ = @orig_ruby
224
+ Gem.class_eval { @ruby = _ } if _
163
225
 
164
226
  if @orig_ENV_HOME then
165
227
  ENV['HOME'] = @orig_ENV_HOME
@@ -168,27 +230,36 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
168
230
  end
169
231
  end
170
232
 
171
- def install_gem gem
233
+ ##
234
+ # Builds and installs the Gem::Specification +spec+
235
+
236
+ def install_gem spec
172
237
  require 'rubygems/installer'
173
238
 
174
- use_ui MockGemUi.new do
239
+ use_ui Gem::MockGemUi.new do
175
240
  Dir.chdir @tempdir do
176
- Gem::Builder.new(gem).build
241
+ Gem::Builder.new(spec).build
177
242
  end
178
243
  end
179
244
 
180
- gem = File.join(@tempdir, gem.file_name).untaint
245
+ gem = File.join(@tempdir, spec.file_name).untaint
246
+
181
247
  Gem::Installer.new(gem, :wrappers => true).install
182
248
  end
183
249
 
184
- def uninstall_gem gem
250
+ ##
251
+ # Uninstalls the Gem::Specification +spec+
252
+ def uninstall_gem spec
185
253
  require 'rubygems/uninstaller'
186
254
 
187
- uninstaller = Gem::Uninstaller.new gem.name, :executables => true,
255
+ uninstaller = Gem::Uninstaller.new spec.name, :executables => true,
188
256
  :user_install => true
189
257
  uninstaller.uninstall
190
258
  end
191
259
 
260
+ ##
261
+ # Enables pretty-print for all tests
262
+
192
263
  def mu_pp(obj)
193
264
  s = ''
194
265
  s = PP.pp obj, s
@@ -196,33 +267,8 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
196
267
  s.chomp
197
268
  end
198
269
 
199
- def prep_cache_files(lc)
200
- @usr_si ||= Gem::SourceIndex.new
201
- @usr_sice ||= Gem::SourceInfoCacheEntry.new @usr_si, 0
202
-
203
- @sys_si ||= Gem::SourceIndex.new
204
- @sys_sice ||= Gem::SourceInfoCacheEntry.new @sys_si, 0
205
-
206
- latest_si = Gem::SourceIndex.new
207
- latest_si.add_specs(*@sys_si.latest_specs)
208
- latest_sys_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
209
-
210
- latest_si = Gem::SourceIndex.new
211
- latest_si.add_specs(*@usr_si.latest_specs)
212
- latest_usr_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
213
-
214
- [ [lc.system_cache_file, @sys_sice],
215
- [lc.latest_system_cache_file, latest_sys_sice],
216
- [lc.user_cache_file, @usr_sice],
217
- [lc.latest_user_cache_file, latest_usr_sice],
218
- ].each do |filename, data|
219
- FileUtils.mkdir_p File.dirname(filename).untaint
220
-
221
- open filename.dup.untaint, 'wb' do |f|
222
- f.write Marshal.dump({ @gem_repo => data })
223
- end
224
- end
225
- end
270
+ ##
271
+ # Reads a Marshal file at +path+
226
272
 
227
273
  def read_cache(path)
228
274
  open path.dup.untaint, 'rb' do |io|
@@ -230,28 +276,45 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
230
276
  end
231
277
  end
232
278
 
279
+ ##
280
+ # Reads a binary file at +path+
281
+
233
282
  def read_binary(path)
234
283
  Gem.read_binary path
235
284
  end
236
285
 
286
+ ##
287
+ # Writes a binary file to +path+ which is relative to +@gemhome+
288
+
237
289
  def write_file(path)
238
- path = File.join(@gemhome, path)
290
+ path = File.join @gemhome, path
239
291
  dir = File.dirname path
240
292
  FileUtils.mkdir_p dir
241
293
 
242
294
  open path, 'wb' do |io|
243
- yield io
295
+ yield io if block_given?
244
296
  end
245
297
 
246
298
  path
247
299
  end
248
300
 
249
- def quick_gem(gemname, version='2')
301
+ ##
302
+ # Creates a Gem::Specification with a minimum of extra work. +name+ and
303
+ # +version+ are the gem's name and version, platform, author, email,
304
+ # homepage, summary and description are defaulted. The specification is
305
+ # yielded for customization.
306
+ #
307
+ # The gem is added to the installed gems in +@gemhome+ and to the current
308
+ # source_index.
309
+ #
310
+ # Use this with #write_file to build an installed gem.
311
+
312
+ def quick_gem(name, version='2')
250
313
  require 'rubygems/specification'
251
314
 
252
315
  spec = Gem::Specification.new do |s|
253
316
  s.platform = Gem::Platform::RUBY
254
- s.name = gemname
317
+ s.name = name
255
318
  s.version = version
256
319
  s.author = 'A User'
257
320
  s.email = 'example@example.com'
@@ -275,6 +338,10 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
275
338
  return spec
276
339
  end
277
340
 
341
+ ##
342
+ # Builds a gem from +spec+ and places it in <tt>File.join @gemhome,
343
+ # 'cache'</tt>. Automatically creates files based on +spec.files+
344
+
278
345
  def util_build_gem(spec)
279
346
  dir = File.join(@gemhome, 'gems', spec.full_name)
280
347
  FileUtils.mkdir_p dir
@@ -286,7 +353,7 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
286
353
  File.open file, 'w' do |fp| fp.puts "# #{file}" end
287
354
  end
288
355
 
289
- use_ui MockGemUi.new do
356
+ use_ui Gem::MockGemUi.new do
290
357
  Gem::Builder.new(spec).build
291
358
  end
292
359
 
@@ -295,14 +362,23 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
295
362
  end
296
363
  end
297
364
 
365
+ ##
366
+ # Removes all installed gems from +@gemhome+.
367
+
298
368
  def util_clear_gems
299
369
  FileUtils.rm_r File.join(@gemhome, 'gems')
300
370
  FileUtils.rm_r File.join(@gemhome, 'specifications')
301
371
  Gem.source_index.refresh!
302
372
  end
303
373
 
374
+ ##
375
+ # Creates a gem with +name+, +version+ and +deps+. The specification will
376
+ # be yielded before gem creation for customization. The gem will be placed
377
+ # in <tt>File.join @tempdir, 'gems'</tt>. The specification and .gem file
378
+ # location are returned.
379
+
304
380
  def util_gem(name, version, deps = nil, &block)
305
- if deps then # fuck you eric
381
+ if deps then
306
382
  block = proc do |s|
307
383
  deps.each do |n, req|
308
384
  s.add_dependency n, (req || '>= 0')
@@ -325,6 +401,9 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
325
401
  [spec, cache_file]
326
402
  end
327
403
 
404
+ ##
405
+ # Gzips +data+.
406
+
328
407
  def util_gzip(data)
329
408
  out = StringIO.new
330
409
 
@@ -335,6 +414,23 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
335
414
  out.string
336
415
  end
337
416
 
417
+ ##
418
+ # Creates several default gems which all have a lib/code.rb file. The gems
419
+ # are not installed but are available in the cache dir.
420
+ #
421
+ # +@a1+:: gem a version 1, this is the best-described gem.
422
+ # +@a2+:: gem a version 2
423
+ # +@a3a:: gem a version 3.a
424
+ # +@a_evil9+:: gem a_evil version 9, use this to ensure similarly-named gems
425
+ # don't collide with a.
426
+ # +@b2+:: gem b version 2
427
+ # +@c1_2+:: gem c version 1.2
428
+ # +@pl1+:: gem pl version 1, this gem has a legacy platform of i386-linux.
429
+ #
430
+ # Additional +prerelease+ gems may also be created:
431
+ #
432
+ # +@a2_pre+:: gem a version 2.a
433
+
338
434
  def util_make_gems(prerelease = false)
339
435
  @a1 = quick_gem 'a', '1' do |s|
340
436
  s.files = %w[lib/code.rb]
@@ -371,17 +467,16 @@ Also, a list:
371
467
 
372
468
  if prerelease
373
469
  @a2_pre = quick_gem('a', '2.a', &init)
374
- write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb]) do
375
- end
470
+ write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb])
376
471
  util_build_gem @a2_pre
377
472
  end
378
473
 
379
- write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end
380
- write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end
381
- write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb]) do end
382
- write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end
383
- write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end
384
- write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end
474
+ write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
475
+ write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
476
+ write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
477
+ write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
478
+ write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
479
+ write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
385
480
 
386
481
  [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].each do |spec|
387
482
  util_build_gem spec
@@ -405,6 +500,12 @@ Also, a list:
405
500
  platform
406
501
  end
407
502
 
503
+ ##
504
+ # Sets up a fake fetcher using the gems from #util_make_gems. Optionally
505
+ # additional +prerelease+ gems may be included.
506
+ #
507
+ # Gems created by this method may be fetched using Gem::RemoteFetcher.
508
+
408
509
  def util_setup_fake_fetcher(prerelease = false)
409
510
  require 'zlib'
410
511
  require 'socket'
@@ -431,6 +532,10 @@ Also, a list:
431
532
  Gem::RemoteFetcher.fetcher = @fetcher
432
533
  end
433
534
 
535
+ ##
536
+ # Sets up Gem::SpecFetcher to return information from the gems in +specs+.
537
+ # Best used with +@all_gems+ from #util_setup_fake_fetcher.
538
+
434
539
  def util_setup_spec_fetcher(*specs)
435
540
  specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
436
541
  si = Gem::SourceIndex.new specs
@@ -465,74 +570,95 @@ Also, a list:
465
570
  si
466
571
  end
467
572
 
573
+ ##
574
+ # Deflates +data+
575
+
468
576
  def util_zip(data)
469
577
  Zlib::Deflate.deflate data
470
578
  end
471
579
 
580
+ ##
581
+ # Is this test being run on a Windows platform?
582
+
472
583
  def self.win_platform?
473
584
  Gem.win_platform?
474
585
  end
475
586
 
587
+ ##
588
+ # Is this test being run on a Windows platform?
589
+
476
590
  def win_platform?
477
591
  Gem.win_platform?
478
592
  end
479
593
 
594
+ ##
480
595
  # Returns whether or not we're on a version of Ruby built with VC++ (or
481
596
  # Borland) versus Cygwin, Mingw, etc.
482
- #
597
+
483
598
  def self.vc_windows?
484
599
  RUBY_PLATFORM.match('mswin')
485
600
  end
486
601
 
602
+ ##
487
603
  # Returns whether or not we're on a version of Ruby built with VC++ (or
488
604
  # Borland) versus Cygwin, Mingw, etc.
489
- #
605
+
490
606
  def vc_windows?
491
607
  RUBY_PLATFORM.match('mswin')
492
608
  end
493
609
 
610
+ ##
494
611
  # Returns the make command for the current platform. For versions of Ruby
495
612
  # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
496
613
  # other platforms, including Cygwin, it will return 'make'.
497
- #
614
+
498
615
  def self.make_command
499
- vc_windows? ? 'nmake' : 'make'
616
+ ENV["make"] || (vc_windows? ? 'nmake' : 'make')
500
617
  end
501
618
 
619
+ ##
502
620
  # Returns the make command for the current platform. For versions of Ruby
503
621
  # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
504
622
  # other platforms, including Cygwin, it will return 'make'.
505
- #
623
+
506
624
  def make_command
507
- vc_windows? ? 'nmake' : 'make'
625
+ ENV["make"] || (vc_windows? ? 'nmake' : 'make')
508
626
  end
509
627
 
628
+ ##
510
629
  # Returns whether or not the nmake command could be found.
511
- #
630
+
512
631
  def nmake_found?
513
632
  system('nmake /? 1>NUL 2>&1')
514
633
  end
515
634
 
516
- # NOTE Allow tests to use a random (but controlled) port number instead of
635
+ ##
636
+ # Allows tests to use a random (but controlled) port number instead of
517
637
  # a hardcoded one. This helps CI tools when running parallels builds on
518
638
  # the same builder slave.
639
+
519
640
  def self.process_based_port
520
641
  @@process_based_port ||= 8000 + $$ % 1000
521
642
  end
522
643
 
644
+ ##
645
+ # See ::process_based_port
646
+
523
647
  def process_based_port
524
648
  self.class.process_based_port
525
649
  end
526
650
 
651
+ ##
652
+ # Allows the proper version of +rake+ to be used for the test.
653
+
527
654
  def build_rake_in
528
655
  gem_ruby = Gem.ruby
529
- ruby = @@ruby
530
- Gem.module_eval {@ruby = ruby}
656
+ Gem.ruby = @@ruby
531
657
  env_rake = ENV["rake"]
532
658
  ENV["rake"] = @@rake
533
659
  yield @@rake
534
660
  ensure
535
- Gem.module_eval {@ruby = gem_ruby}
661
+ Gem.ruby = gem_ruby
536
662
  if env_rake
537
663
  ENV["rake"] = env_rake
538
664
  else
@@ -540,12 +666,15 @@ Also, a list:
540
666
  end
541
667
  end
542
668
 
669
+ ##
670
+ # Finds the path to the ruby executable
671
+
543
672
  def self.rubybin
544
- if ruby = ENV["RUBY"]
545
- return ruby
546
- end
673
+ ruby = ENV["RUBY"]
674
+ return ruby if ruby
547
675
  ruby = "ruby"
548
- rubyexe = ruby+".exe"
676
+ rubyexe = "#{ruby}.exe"
677
+
549
678
  3.times do
550
679
  if File.exist? ruby and File.executable? ruby and !File.directory? ruby
551
680
  return File.expand_path(ruby)
@@ -555,12 +684,12 @@ Also, a list:
555
684
  end
556
685
  ruby = File.join("..", ruby)
557
686
  end
687
+
558
688
  begin
559
689
  require "rbconfig"
560
- File.join(
561
- RbConfig::CONFIG["bindir"],
562
- RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
563
- )
690
+ File.join(RbConfig::CONFIG["bindir"],
691
+ RbConfig::CONFIG["ruby_install_name"] +
692
+ RbConfig::CONFIG["EXEEXT"])
564
693
  rescue LoadError
565
694
  "ruby"
566
695
  end
@@ -585,7 +714,7 @@ Also, a list:
585
714
  end
586
715
 
587
716
  ##
588
- # Construct a new Gem::Requirement.
717
+ # Constructs a new Gem::Requirement.
589
718
 
590
719
  def req *requirements
591
720
  return requirements.first if Gem::Requirement === requirements.first
@@ -593,7 +722,7 @@ Also, a list:
593
722
  end
594
723
 
595
724
  ##
596
- # Construct a new Gem::Specification.
725
+ # Constructs a new Gem::Specification.
597
726
 
598
727
  def spec name, version, &block
599
728
  Gem::Specification.new name, v(version), &block