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
@@ -8,9 +8,9 @@ class TestGemCommandsListCommand < Gem::TestCase
8
8
 
9
9
  @cmd = Gem::Commands::ListCommand.new
10
10
 
11
- util_setup_fake_fetcher
12
-
13
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
11
+ spec_fetcher do |fetcher|
12
+ fetcher.spec 'c', 1
13
+ end
14
14
 
15
15
  @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
16
16
  raise Gem::RemoteFetcher::FetchError
@@ -14,18 +14,13 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
14
14
  end
15
15
 
16
16
  def test_execute
17
- remote_10 = quick_spec 'foo', '1.0'
18
- remote_20 = quick_spec 'foo', '2.0'
19
-
20
- Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
21
-
22
- util_clear_gems
23
- util_setup_spec_fetcher remote_10, remote_20
24
-
25
- quick_gem 'foo', '0.1'
26
- quick_gem 'foo', '0.2'
27
-
28
- Gem::Specification.reset
17
+ spec_fetcher do |fetcher|
18
+ fetcher.spec 'foo', '1.0'
19
+ fetcher.spec 'foo', '2.0'
20
+ fetcher.clear
21
+ fetcher.gem 'foo', '0.1'
22
+ fetcher.gem 'foo', '0.2'
23
+ end
29
24
 
30
25
  use_ui @ui do
31
26
  @cmd.execute
@@ -9,7 +9,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
9
9
  end
10
10
 
11
11
  def test_execute
12
- a = quick_spec 'a' do |s|
12
+ a = util_spec 'a' do |s|
13
13
  s.executables = %w[foo]
14
14
  s.files = %w[bin/foo lib/a.rb]
15
15
  end
@@ -51,7 +51,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
51
51
  end
52
52
 
53
53
  def test_execute_all
54
- a = quick_spec 'a' do |s| s.executables = %w[foo] end
54
+ a = util_spec 'a' do |s| s.executables = %w[foo] end
55
55
  write_file File.join(@tempdir, 'bin', 'foo') do |fp|
56
56
  fp.puts "#!/usr/bin/ruby"
57
57
  end
@@ -81,7 +81,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
81
81
  end
82
82
 
83
83
  def test_execute_env_shebang
84
- a = quick_spec 'a' do |s|
84
+ a = util_spec 'a' do |s|
85
85
  s.executables = %w[foo]
86
86
  s.files = %w[bin/foo]
87
87
  end
@@ -110,8 +110,44 @@ class TestGemCommandsPristineCommand < Gem::TestCase
110
110
  end
111
111
  end
112
112
 
113
+ def test_execute_extensions_explicit
114
+ a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
115
+
116
+ ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
117
+ write_file ext_path do |io|
118
+ io.write <<-'RUBY'
119
+ File.open "Makefile", "w" do |f|
120
+ f.puts "clean:\n\techo cleaned\n"
121
+ f.puts "all:\n\techo built\n"
122
+ f.puts "install:\n\techo installed\n"
123
+ end
124
+ RUBY
125
+ end
126
+
127
+ b = util_spec 'b'
128
+
129
+ install_gem a
130
+ install_gem b
131
+
132
+ @cmd.options[:extensions] = true
133
+ @cmd.options[:extensions_set] = true
134
+ @cmd.options[:args] = []
135
+
136
+ use_ui @ui do
137
+ @cmd.execute
138
+ end
139
+
140
+ out = @ui.output.split "\n"
141
+
142
+ assert_equal 'Restoring gems to pristine condition...', out.shift
143
+ assert_equal 'Building native extensions. This could take a while...',
144
+ out.shift
145
+ assert_equal "Restored #{a.full_name}", out.shift
146
+ assert_empty out, out.inspect
147
+ end
148
+
113
149
  def test_execute_no_extension
114
- a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
150
+ a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
115
151
 
116
152
  ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
117
153
  write_file ext_path do |io|
@@ -136,14 +172,15 @@ class TestGemCommandsPristineCommand < Gem::TestCase
136
172
  end
137
173
 
138
174
  def test_execute_with_extension_with_build_args
139
- a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
175
+ a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
140
176
 
141
177
  ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
142
178
  write_file ext_path do |io|
143
179
  io.write <<-'RUBY'
144
180
  File.open "Makefile", "w" do |f|
181
+ f.puts "clean:\n\techo cleaned\n"
145
182
  f.puts "all:\n\techo built\n"
146
- f.puts "install:\n\techo built\n"
183
+ f.puts "install:\n\techo installed\n"
147
184
  end
148
185
  RUBY
149
186
  end
@@ -168,8 +205,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
168
205
  end
169
206
 
170
207
  def test_execute_many
171
- a = quick_spec 'a'
172
- b = quick_spec 'b'
208
+ a = util_spec 'a'
209
+ b = util_spec 'b'
173
210
 
174
211
  install_gem a
175
212
  install_gem b
@@ -189,14 +226,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
189
226
  end
190
227
 
191
228
  def test_execute_many_multi_repo
192
- a = quick_spec 'a'
229
+ a = util_spec 'a'
193
230
  install_gem a
194
231
 
195
232
  Gem.clear_paths
196
233
  gemhome2 = File.join @tempdir, 'gemhome2'
197
234
  Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
198
235
 
199
- b = quick_spec 'b'
236
+ b = util_spec 'b'
200
237
  install_gem b
201
238
 
202
239
  @cmd.options[:args] = %w[a b]
@@ -219,24 +256,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
219
256
  end
220
257
 
221
258
  def test_execute_missing_cache_gem
222
- a_2 = quick_spec 'a', 2
223
- a_3 = quick_spec 'a', 3
224
-
225
- install_gem a_2
226
- install_gem a_3
227
-
228
- a_2_data = nil
229
- open File.join(@gemhome, 'cache', a_2.file_name), 'rb' do |fp|
230
- a_2_data = fp.read
259
+ specs = spec_fetcher do |fetcher|
260
+ fetcher.gem 'a', 1
261
+ fetcher.gem 'a', 2
262
+ fetcher.gem 'a', 3
263
+ fetcher.gem 'a', '3.a'
231
264
  end
232
265
 
233
- util_setup_fake_fetcher
234
- util_setup_spec_fetcher a_2
235
-
236
- url = "http://gems.example.com/gems/#{a_2.file_name}"
237
- Gem::RemoteFetcher.fetcher.data[url] = a_2_data
238
-
239
- FileUtils.rm a_2.cache_file
266
+ FileUtils.rm specs['a-2'].cache_file
240
267
 
241
268
  @cmd.options[:args] = %w[a]
242
269
 
@@ -273,7 +300,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
273
300
  end
274
301
 
275
302
  def test_execute_only_executables
276
- a = quick_spec 'a' do |s|
303
+ a = util_spec 'a' do |s|
277
304
  s.executables = %w[foo]
278
305
  s.files = %w[bin/foo lib/a.rb]
279
306
  end
@@ -320,5 +347,24 @@ class TestGemCommandsPristineCommand < Gem::TestCase
320
347
  @ui.output.split("\n"))
321
348
  assert_empty(@ui.error)
322
349
  end
350
+
351
+ def test_handle_options
352
+ @cmd.handle_options %w[]
353
+
354
+ refute @cmd.options[:all]
355
+
356
+ assert @cmd.options[:extensions]
357
+ refute @cmd.options[:extensions_set]
358
+
359
+ assert_equal Gem::Requirement.default, @cmd.options[:version]
360
+ end
361
+
362
+ def test_handle_options_extensions
363
+ @cmd.handle_options %w[--extensions]
364
+
365
+ assert @cmd.options[:extensions]
366
+ assert @cmd.options[:extensions_set]
367
+ end
368
+
323
369
  end
324
370
 
@@ -62,17 +62,15 @@ class TestGemCommandsPushCommand < Gem::TestCase
62
62
  end
63
63
 
64
64
  def test_execute
65
- open 'example', 'w' do |io| io.write 'hello' end
66
-
67
65
  @response = "Successfully registered gem: freewill (1.0.0)"
68
66
  @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
69
67
 
70
- @cmd.options[:args] = %w[example]
68
+ @cmd.options[:args] = [@path]
71
69
 
72
70
  @cmd.execute
73
71
 
74
72
  assert_equal Net::HTTP::Post, @fetcher.last_request.class
75
- assert_equal 'hello', @fetcher.last_request.body
73
+ assert_equal Gem.read_binary(@path), @fetcher.last_request.body
76
74
  assert_equal "application/octet-stream",
77
75
  @fetcher.last_request["Content-Type"]
78
76
  end
@@ -80,20 +78,18 @@ class TestGemCommandsPushCommand < Gem::TestCase
80
78
  def test_execute_host
81
79
  host = 'https://other.example'
82
80
 
83
- open 'example', 'w' do |io| io.write 'hello' end
84
-
85
81
  @response = "Successfully registered gem: freewill (1.0.0)"
86
82
  @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
87
83
  @fetcher.data["#{Gem.host}/api/v1/gems"] =
88
84
  ['fail', 500, 'Internal Server Error']
89
85
 
90
86
  @cmd.options[:host] = host
91
- @cmd.options[:args] = %w[example]
87
+ @cmd.options[:args] = [@path]
92
88
 
93
89
  @cmd.execute
94
90
 
95
91
  assert_equal Net::HTTP::Post, @fetcher.last_request.class
96
- assert_equal 'hello', @fetcher.last_request.body
92
+ assert_equal Gem.read_binary(@path), @fetcher.last_request.body
97
93
  assert_equal "application/octet-stream",
98
94
  @fetcher.last_request["Content-Type"]
99
95
  end
@@ -154,6 +150,78 @@ class TestGemCommandsPushCommand < Gem::TestCase
154
150
  send_battery
155
151
  end
156
152
 
153
+ def test_sending_gem_to_allowed_push_host
154
+ @host = "http://privategemserver.com"
155
+
156
+ @spec, @path = util_gem "freebird", "1.0.1" do |spec|
157
+ spec.metadata['allowed_push_host'] = @host
158
+ end
159
+
160
+ @api_key = "PRIVKEY"
161
+
162
+ keys = {
163
+ :rubygems_api_key => 'KEY',
164
+ @host => @api_key
165
+ }
166
+
167
+ FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
168
+ open Gem.configuration.credentials_path, 'w' do |f|
169
+ f.write keys.to_yaml
170
+ end
171
+ Gem.configuration.load_api_keys
172
+
173
+ FileUtils.rm Gem.configuration.credentials_path
174
+
175
+ @response = "Successfully registered gem: freebird (1.0.1)"
176
+ @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
177
+ send_battery
178
+ end
179
+
180
+ def test_sending_gem_to_disallowed_default_host
181
+ @spec, @path = util_gem "freebird", "1.0.1" do |spec|
182
+ spec.metadata['allowed_push_host'] = "https://privategemserver.com"
183
+ end
184
+
185
+ response = %{ERROR: "#{@host}" is not allowed by the gemspec, which only allows "https://privategemserver.com"}
186
+
187
+ assert_raises Gem::MockGemUi::TermError do
188
+ send_battery
189
+ end
190
+
191
+ assert_match response, @ui.error
192
+ end
193
+
194
+ def test_sending_gem_to_disallowed_push_host
195
+ @host = "https://somebodyelse.com"
196
+
197
+ @spec, @path = util_gem "freebird", "1.0.1" do |spec|
198
+ spec.metadata['allowed_push_host'] = "https://privategemserver.com"
199
+ end
200
+
201
+ @api_key = "PRIVKEY"
202
+
203
+ keys = {
204
+ :rubygems_api_key => 'KEY',
205
+ @host => @api_key
206
+ }
207
+
208
+ FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
209
+ open Gem.configuration.credentials_path, 'w' do |f|
210
+ f.write keys.to_yaml
211
+ end
212
+ Gem.configuration.load_api_keys
213
+
214
+ FileUtils.rm Gem.configuration.credentials_path
215
+
216
+ response = 'ERROR: "https://somebodyelse.com" is not allowed by the gemspec, which only allows "https://privategemserver.com"'
217
+
218
+ assert_raises Gem::MockGemUi::TermError do
219
+ send_battery
220
+ end
221
+
222
+ assert_match response, @ui.error
223
+ end
224
+
157
225
  def test_raises_error_with_no_arguments
158
226
  def @cmd.sign_in(*); end
159
227
  assert_raises Gem::CommandLineError do
@@ -8,9 +8,11 @@ class TestGemCommandsQueryCommand < Gem::TestCase
8
8
 
9
9
  @cmd = Gem::Commands::QueryCommand.new
10
10
 
11
- util_setup_fake_fetcher
12
- util_clear_gems
13
- util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
11
+ @specs = spec_fetcher do |fetcher|
12
+ fetcher.spec 'a', 1
13
+ fetcher.spec 'a', 2
14
+ fetcher.spec 'a', '3.a'
15
+ end
14
16
 
15
17
  @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
16
18
  raise Gem::RemoteFetcher::FetchError
@@ -18,6 +20,10 @@ class TestGemCommandsQueryCommand < Gem::TestCase
18
20
  end
19
21
 
20
22
  def test_execute
23
+ spec_fetcher do |fetcher|
24
+ fetcher.legacy_platform
25
+ end
26
+
21
27
  @cmd.handle_options %w[-r]
22
28
 
23
29
  use_ui @ui do
@@ -37,13 +43,18 @@ pl (1 i386-linux)
37
43
  end
38
44
 
39
45
  def test_execute_platform
40
- @a1r = @a1.dup
46
+ spec_fetcher do |fetcher|
47
+ fetcher.clear
41
48
 
42
- @a1.platform = 'x86-linux'
43
- @a2.platform = 'universal-darwin'
49
+ fetcher.spec 'a', 1
50
+ fetcher.spec 'a', 1 do |s|
51
+ s.platform = 'x86-linux'
52
+ end
44
53
 
45
- util_clear_gems
46
- util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
54
+ fetcher.spec 'a', 2 do |s|
55
+ s.platform = 'universal-darwin'
56
+ end
57
+ end
47
58
 
48
59
  @cmd.handle_options %w[-r -a]
49
60
 
@@ -56,8 +67,6 @@ pl (1 i386-linux)
56
67
  *** REMOTE GEMS ***
57
68
 
58
69
  a (2 universal-darwin, 1 ruby x86-linux)
59
- b (2)
60
- pl (1 i386-linux)
61
70
  EOF
62
71
 
63
72
  assert_equal expected, @ui.output
@@ -65,6 +74,10 @@ pl (1 i386-linux)
65
74
  end
66
75
 
67
76
  def test_execute_all
77
+ spec_fetcher do |fetcher|
78
+ fetcher.legacy_platform
79
+ end
80
+
68
81
  @cmd.handle_options %w[-r --all]
69
82
 
70
83
  use_ui @ui do
@@ -84,6 +97,10 @@ pl (1 i386-linux)
84
97
  end
85
98
 
86
99
  def test_execute_all_prerelease
100
+ spec_fetcher do |fetcher|
101
+ fetcher.legacy_platform
102
+ end
103
+
87
104
  @cmd.handle_options %w[-r --all --prerelease]
88
105
 
89
106
  use_ui @ui do
@@ -103,12 +120,15 @@ pl (1 i386-linux)
103
120
  end
104
121
 
105
122
  def test_execute_details
106
- @a2.summary = 'This is a lot of text. ' * 4
107
- @a2.authors = ['Abraham Lincoln', 'Hirohito']
108
- @a2.homepage = 'http://a.example.com/'
123
+ spec_fetcher do |fetcher|
124
+ fetcher.spec 'a', 2 do |s|
125
+ s.summary = 'This is a lot of text. ' * 4
126
+ s.authors = ['Abraham Lincoln', 'Hirohito']
127
+ s.homepage = 'http://a.example.com/'
128
+ end
109
129
 
110
- util_clear_gems
111
- util_setup_spec_fetcher @a1, @a2, @pl1
130
+ fetcher.legacy_platform
131
+ end
112
132
 
113
133
  @cmd.handle_options %w[-r -d]
114
134
 
@@ -140,15 +160,22 @@ pl (1)
140
160
  end
141
161
 
142
162
  def test_execute_details_platform
143
- @a1.platform = 'x86-linux'
163
+ spec_fetcher do |fetcher|
164
+ fetcher.clear
144
165
 
145
- @a2.summary = 'This is a lot of text. ' * 4
146
- @a2.authors = ['Abraham Lincoln', 'Hirohito']
147
- @a2.homepage = 'http://a.example.com/'
148
- @a2.platform = 'universal-darwin'
166
+ fetcher.spec 'a', 1 do |s|
167
+ s.platform = 'x86-linux'
168
+ end
149
169
 
150
- util_clear_gems
151
- util_setup_spec_fetcher @a1, @a2, @pl1
170
+ fetcher.spec 'a', 2 do |s|
171
+ s.summary = 'This is a lot of text. ' * 4
172
+ s.authors = ['Abraham Lincoln', 'Hirohito']
173
+ s.homepage = 'http://a.example.com/'
174
+ s.platform = 'universal-darwin'
175
+ end
176
+
177
+ fetcher.legacy_platform
178
+ end
152
179
 
153
180
  @cmd.handle_options %w[-r -d]
154
181
 
@@ -281,7 +308,34 @@ pl (1)
281
308
  assert_equal 1, e.exit_code
282
309
  end
283
310
 
311
+ def test_execute_local
312
+ spec_fetcher do |fetcher|
313
+ fetcher.legacy_platform
314
+ end
315
+
316
+ @cmd.options[:domain] = :local
317
+
318
+ use_ui @ui do
319
+ @cmd.execute
320
+ end
321
+
322
+ expected = <<-EOF
323
+
324
+ *** LOCAL GEMS ***
325
+
326
+ a (3.a, 2, 1)
327
+ pl (1 i386-linux)
328
+ EOF
329
+
330
+ assert_equal expected, @ui.output
331
+ assert_equal '', @ui.error
332
+ end
333
+
284
334
  def test_execute_local_notty
335
+ spec_fetcher do |fetcher|
336
+ fetcher.legacy_platform
337
+ end
338
+
285
339
  @cmd.handle_options %w[]
286
340
 
287
341
  @ui.outs.tty = false
@@ -299,7 +353,32 @@ pl (1 i386-linux)
299
353
  assert_equal '', @ui.error
300
354
  end
301
355
 
356
+ def test_execute_local_quiet
357
+ spec_fetcher do |fetcher|
358
+ fetcher.legacy_platform
359
+ end
360
+
361
+ @cmd.options[:domain] = :local
362
+ Gem.configuration.verbose = false
363
+
364
+ use_ui @ui do
365
+ @cmd.execute
366
+ end
367
+
368
+ expected = <<-EOF
369
+ a (3.a, 2, 1)
370
+ pl (1 i386-linux)
371
+ EOF
372
+
373
+ assert_equal expected, @ui.output
374
+ assert_equal '', @ui.error
375
+ end
376
+
302
377
  def test_execute_no_versions
378
+ spec_fetcher do |fetcher|
379
+ fetcher.legacy_platform
380
+ end
381
+
303
382
  @cmd.handle_options %w[-r --no-versions]
304
383
 
305
384
  use_ui @ui do
@@ -319,6 +398,10 @@ pl
319
398
  end
320
399
 
321
400
  def test_execute_notty
401
+ spec_fetcher do |fetcher|
402
+ fetcher.legacy_platform
403
+ end
404
+
322
405
  @cmd.handle_options %w[-r]
323
406
 
324
407
  @ui.outs.tty = false
@@ -355,6 +438,10 @@ a (3.a)
355
438
  end
356
439
 
357
440
  def test_execute_prerelease_local
441
+ spec_fetcher do |fetcher|
442
+ fetcher.legacy_platform
443
+ end
444
+
358
445
  @cmd.handle_options %w[-l --prerelease]
359
446
 
360
447
  use_ui @ui do
@@ -373,16 +460,89 @@ pl (1 i386-linux)
373
460
  assert_equal "WARNING: prereleases are always shown locally\n", @ui.error
374
461
  end
375
462
 
463
+ def test_execute_remote
464
+ spec_fetcher do |fetcher|
465
+ fetcher.legacy_platform
466
+ end
467
+
468
+ @cmd.options[:domain] = :remote
469
+
470
+ use_ui @ui do
471
+ @cmd.execute
472
+ end
473
+
474
+ expected = <<-EOF
475
+
476
+ *** REMOTE GEMS ***
477
+
478
+ a (2)
479
+ pl (1 i386-linux)
480
+ EOF
481
+
482
+ assert_equal expected, @ui.output
483
+ assert_equal '', @ui.error
484
+ end
485
+
486
+ def test_execute_remote_notty
487
+ spec_fetcher do |fetcher|
488
+ fetcher.legacy_platform
489
+ end
490
+
491
+ @cmd.handle_options %w[]
492
+
493
+ @ui.outs.tty = false
494
+
495
+ use_ui @ui do
496
+ @cmd.execute
497
+ end
498
+
499
+ expected = <<-EOF
500
+ a (3.a, 2, 1)
501
+ pl (1 i386-linux)
502
+ EOF
503
+
504
+ assert_equal expected, @ui.output
505
+ assert_equal '', @ui.error
506
+ end
507
+
508
+ def test_execute_remote_quiet
509
+ spec_fetcher do |fetcher|
510
+ fetcher.legacy_platform
511
+ end
512
+
513
+ @cmd.options[:domain] = :remote
514
+ Gem.configuration.verbose = false
515
+
516
+ use_ui @ui do
517
+ @cmd.execute
518
+ end
519
+
520
+ expected = <<-EOF
521
+ a (2)
522
+ pl (1 i386-linux)
523
+ EOF
524
+
525
+ assert_equal expected, @ui.output
526
+ assert_equal '', @ui.error
527
+ end
528
+
376
529
  def test_execute_local_details
377
- @a1.platform = 'x86-linux'
530
+ spec_fetcher do |fetcher|
531
+ fetcher.clear
378
532
 
379
- @a2.summary = 'This is a lot of text. ' * 4
380
- @a2.authors = ['Abraham Lincoln', 'Hirohito']
381
- @a2.homepage = 'http://a.example.com/'
382
- @a2.platform = 'universal-darwin'
533
+ fetcher.spec 'a', 1 do |s|
534
+ s.platform = 'x86-linux'
535
+ end
536
+
537
+ fetcher.spec 'a', 2 do |s|
538
+ s.summary = 'This is a lot of text. ' * 4
539
+ s.authors = ['Abraham Lincoln', 'Hirohito']
540
+ s.homepage = 'http://a.example.com/'
541
+ s.platform = 'universal-darwin'
542
+ end
383
543
 
384
- util_clear_gems
385
- util_setup_spec_fetcher @a1, @a2, @pl1
544
+ fetcher.legacy_platform
545
+ end
386
546
 
387
547
  @cmd.handle_options %w[-l -d]
388
548
 
@@ -396,6 +556,7 @@ pl (1 i386-linux)
396
556
  str.gsub!(/at: [^\n]*/, "at: -")
397
557
 
398
558
  expected = <<-EOF
559
+
399
560
  *** LOCAL GEMS ***
400
561
 
401
562
  a (2, 1)
@@ -410,7 +571,7 @@ a (2, 1)
410
571
  This is a lot of text. This is a lot of text. This is a lot of text.
411
572
  This is a lot of text.
412
573
 
413
- pl \(1\)
574
+ pl (1)
414
575
  Platform: i386-linux
415
576
  Author: A User
416
577
  Homepage: http://example.com
@@ -419,13 +580,18 @@ pl \(1\)
419
580
  this is a summary
420
581
  EOF
421
582
 
422
- assert_match expected, @ui.output
583
+ assert_equal expected, @ui.output
423
584
  end
424
585
 
425
586
  def test_execute_default_details
426
- default_gem_dir = Gem::Specification.default_specifications_dir
427
- @a1.loaded_from =
428
- File.join default_gem_dir, @a1.spec_name
587
+ spec_fetcher do |fetcher|
588
+ fetcher.clear
589
+
590
+ fetcher.spec 'a', 2
591
+ end
592
+
593
+ a1 = new_default_spec 'a', 1
594
+ install_default_specs a1
429
595
 
430
596
  @cmd.handle_options %w[-l -d]
431
597
 
@@ -437,20 +603,11 @@ pl \(1\)
437
603
 
438
604
  *** LOCAL GEMS ***
439
605
 
440
- a (3.a, 2, 1)
441
- Author: A User
442
- Homepage: http://example.com
443
- Installed at (3.a): #{@gemhome}
444
- (2): #{@gemhome}
445
- (1, default): #{@a1.base_dir}
446
-
447
- this is a summary
448
-
449
- pl \(1\)
450
- Platform: i386-linux
606
+ a (2, 1)
451
607
  Author: A User
452
608
  Homepage: http://example.com
453
- Installed at: #{@gemhome}
609
+ Installed at (2): #{@gemhome}
610
+ (1, default): #{a1.base_dir}
454
611
 
455
612
  this is a summary
456
613
  EOF
@@ -459,20 +616,53 @@ pl \(1\)
459
616
  end
460
617
 
461
618
  def test_make_entry
619
+ a_2_name = @specs['a-2'].original_name
620
+
462
621
  @fetcher.data.delete \
463
- "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{@a2.original_name}.gemspec.rz"
622
+ "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a_2_name}.gemspec.rz"
464
623
 
624
+ a2 = @specs['a-2']
465
625
  entry_tuples = [
466
- [Gem::NameTuple.new(@a2.name, @a2.version, @a2.platform),
626
+ [Gem::NameTuple.new(a2.name, a2.version, a2.platform),
467
627
  Gem.sources.first],
468
628
  ]
469
629
 
470
- platforms = { @a2.version => [@a2.platform] }
630
+ platforms = { a2.version => [a2.platform] }
471
631
 
472
632
  entry = @cmd.send :make_entry, entry_tuples, platforms
473
633
 
474
634
  assert_equal 'a (2)', entry
475
635
  end
476
636
 
637
+ # Test for multiple args handling!
638
+ def test_execute_multiple_args
639
+ spec_fetcher do |fetcher|
640
+ fetcher.legacy_platform
641
+ end
642
+
643
+ @cmd.handle_options %w[a pl]
644
+
645
+ use_ui @ui do
646
+ @cmd.execute
647
+ end
648
+
649
+ assert_match %r%^a %, @ui.output
650
+ assert_match %r%^pl %, @ui.output
651
+ assert_equal '', @ui.error
652
+ end
653
+
654
+ def test_show_gems
655
+ @cmd.options[:name] = //
656
+ @cmd.options[:domain] = :remote
657
+
658
+ use_ui @ui do
659
+ @cmd.send :show_gems, /a/i, false
660
+ end
661
+
662
+ assert_match %r%^a %, @ui.output
663
+ refute_match %r%^pl %, @ui.output
664
+ assert_empty @ui.error
665
+ end
666
+
477
667
  end
478
668