slimgems 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +120 -0
  6. data/bin/gem +25 -0
  7. data/bin/update_slimgems +35 -0
  8. data/bootstrap/Rakefile +4 -0
  9. data/hide_lib_for_update/note.txt +5 -0
  10. data/lib/gauntlet_rubygems.rb +50 -0
  11. data/lib/rbconfig/datadir.rb +20 -0
  12. data/lib/rubygems.rb +1220 -0
  13. data/lib/rubygems/builder.rb +102 -0
  14. data/lib/rubygems/command.rb +534 -0
  15. data/lib/rubygems/command_manager.rb +182 -0
  16. data/lib/rubygems/commands/build_command.rb +53 -0
  17. data/lib/rubygems/commands/cert_command.rb +86 -0
  18. data/lib/rubygems/commands/check_command.rb +80 -0
  19. data/lib/rubygems/commands/cleanup_command.rb +106 -0
  20. data/lib/rubygems/commands/contents_command.rb +98 -0
  21. data/lib/rubygems/commands/dependency_command.rb +195 -0
  22. data/lib/rubygems/commands/environment_command.rb +132 -0
  23. data/lib/rubygems/commands/fetch_command.rb +67 -0
  24. data/lib/rubygems/commands/generate_index_command.rb +133 -0
  25. data/lib/rubygems/commands/help_command.rb +172 -0
  26. data/lib/rubygems/commands/install_command.rb +178 -0
  27. data/lib/rubygems/commands/list_command.rb +35 -0
  28. data/lib/rubygems/commands/lock_command.rb +110 -0
  29. data/lib/rubygems/commands/mirror_command.rb +111 -0
  30. data/lib/rubygems/commands/outdated_command.rb +33 -0
  31. data/lib/rubygems/commands/owner_command.rb +75 -0
  32. data/lib/rubygems/commands/pristine_command.rb +93 -0
  33. data/lib/rubygems/commands/push_command.rb +56 -0
  34. data/lib/rubygems/commands/query_command.rb +280 -0
  35. data/lib/rubygems/commands/rdoc_command.rb +91 -0
  36. data/lib/rubygems/commands/search_command.rb +31 -0
  37. data/lib/rubygems/commands/server_command.rb +86 -0
  38. data/lib/rubygems/commands/setup_command.rb +387 -0
  39. data/lib/rubygems/commands/sources_command.rb +157 -0
  40. data/lib/rubygems/commands/specification_command.rb +125 -0
  41. data/lib/rubygems/commands/stale_command.rb +27 -0
  42. data/lib/rubygems/commands/uninstall_command.rb +83 -0
  43. data/lib/rubygems/commands/unpack_command.rb +121 -0
  44. data/lib/rubygems/commands/update_command.rb +212 -0
  45. data/lib/rubygems/commands/which_command.rb +86 -0
  46. data/lib/rubygems/config_file.rb +345 -0
  47. data/lib/rubygems/custom_require.rb +44 -0
  48. data/lib/rubygems/defaults.rb +101 -0
  49. data/lib/rubygems/dependency.rb +227 -0
  50. data/lib/rubygems/dependency_installer.rb +286 -0
  51. data/lib/rubygems/dependency_list.rb +208 -0
  52. data/lib/rubygems/doc_manager.rb +242 -0
  53. data/lib/rubygems/errors.rb +35 -0
  54. data/lib/rubygems/exceptions.rb +91 -0
  55. data/lib/rubygems/ext.rb +18 -0
  56. data/lib/rubygems/ext/builder.rb +56 -0
  57. data/lib/rubygems/ext/configure_builder.rb +25 -0
  58. data/lib/rubygems/ext/ext_conf_builder.rb +24 -0
  59. data/lib/rubygems/ext/rake_builder.rb +39 -0
  60. data/lib/rubygems/format.rb +81 -0
  61. data/lib/rubygems/gem_openssl.rb +92 -0
  62. data/lib/rubygems/gem_path_searcher.rb +100 -0
  63. data/lib/rubygems/gem_runner.rb +79 -0
  64. data/lib/rubygems/gemcutter_utilities.rb +49 -0
  65. data/lib/rubygems/indexer.rb +720 -0
  66. data/lib/rubygems/install_update_options.rb +125 -0
  67. data/lib/rubygems/installer.rb +604 -0
  68. data/lib/rubygems/local_remote_options.rb +135 -0
  69. data/lib/rubygems/old_format.rb +153 -0
  70. data/lib/rubygems/package.rb +97 -0
  71. data/lib/rubygems/package/f_sync_dir.rb +23 -0
  72. data/lib/rubygems/package/tar_header.rb +266 -0
  73. data/lib/rubygems/package/tar_input.rb +222 -0
  74. data/lib/rubygems/package/tar_output.rb +144 -0
  75. data/lib/rubygems/package/tar_reader.rb +106 -0
  76. data/lib/rubygems/package/tar_reader/entry.rb +141 -0
  77. data/lib/rubygems/package/tar_writer.rb +241 -0
  78. data/lib/rubygems/package_task.rb +126 -0
  79. data/lib/rubygems/platform.rb +183 -0
  80. data/lib/rubygems/remote_fetcher.rb +414 -0
  81. data/lib/rubygems/require_paths_builder.rb +18 -0
  82. data/lib/rubygems/requirement.rb +153 -0
  83. data/lib/rubygems/security.rb +814 -0
  84. data/lib/rubygems/server.rb +872 -0
  85. data/lib/rubygems/source_index.rb +597 -0
  86. data/lib/rubygems/source_info_cache.rb +395 -0
  87. data/lib/rubygems/source_info_cache_entry.rb +56 -0
  88. data/lib/rubygems/spec_fetcher.rb +337 -0
  89. data/lib/rubygems/specification.rb +1486 -0
  90. data/lib/rubygems/test_utilities.rb +147 -0
  91. data/lib/rubygems/text.rb +65 -0
  92. data/lib/rubygems/uninstaller.rb +278 -0
  93. data/lib/rubygems/user_interaction.rb +527 -0
  94. data/lib/rubygems/validator.rb +240 -0
  95. data/lib/rubygems/version.rb +316 -0
  96. data/lib/rubygems/version_option.rb +65 -0
  97. data/lib/ubygems.rb +10 -0
  98. data/setup.rb +42 -0
  99. data/test/bogussources.rb +8 -0
  100. data/test/data/gem-private_key.pem +27 -0
  101. data/test/data/gem-public_cert.pem +20 -0
  102. data/test/fake_certlib/openssl.rb +7 -0
  103. data/test/foo/discover.rb +0 -0
  104. data/test/functional.rb +92 -0
  105. data/test/gem_installer_test_case.rb +97 -0
  106. data/test/gem_package_tar_test_case.rb +132 -0
  107. data/test/gemutilities.rb +605 -0
  108. data/test/insure_session.rb +43 -0
  109. data/test/mockgemui.rb +56 -0
  110. data/test/plugin/exception/rubygems_plugin.rb +2 -0
  111. data/test/plugin/load/rubygems_plugin.rb +1 -0
  112. data/test/plugin/standarderror/rubygems_plugin.rb +2 -0
  113. data/test/private_key.pem +27 -0
  114. data/test/public_cert.pem +20 -0
  115. data/test/rubygems_plugin.rb +21 -0
  116. data/test/simple_gem.rb +66 -0
  117. data/test/test_config.rb +12 -0
  118. data/test/test_gem.rb +766 -0
  119. data/test/test_gem_builder.rb +27 -0
  120. data/test/test_gem_command.rb +178 -0
  121. data/test/test_gem_command_manager.rb +207 -0
  122. data/test/test_gem_commands_build_command.rb +74 -0
  123. data/test/test_gem_commands_cert_command.rb +124 -0
  124. data/test/test_gem_commands_check_command.rb +18 -0
  125. data/test/test_gem_commands_contents_command.rb +156 -0
  126. data/test/test_gem_commands_dependency_command.rb +216 -0
  127. data/test/test_gem_commands_environment_command.rb +144 -0
  128. data/test/test_gem_commands_fetch_command.rb +76 -0
  129. data/test/test_gem_commands_generate_index_command.rb +135 -0
  130. data/test/test_gem_commands_install_command.rb +315 -0
  131. data/test/test_gem_commands_list_command.rb +36 -0
  132. data/test/test_gem_commands_lock_command.rb +68 -0
  133. data/test/test_gem_commands_mirror_command.rb +60 -0
  134. data/test/test_gem_commands_outdated_command.rb +40 -0
  135. data/test/test_gem_commands_owner_command.rb +105 -0
  136. data/test/test_gem_commands_pristine_command.rb +108 -0
  137. data/test/test_gem_commands_push_command.rb +81 -0
  138. data/test/test_gem_commands_query_command.rb +426 -0
  139. data/test/test_gem_commands_server_command.rb +59 -0
  140. data/test/test_gem_commands_sources_command.rb +209 -0
  141. data/test/test_gem_commands_specification_command.rb +139 -0
  142. data/test/test_gem_commands_stale_command.rb +38 -0
  143. data/test/test_gem_commands_uninstall_command.rb +83 -0
  144. data/test/test_gem_commands_unpack_command.rb +199 -0
  145. data/test/test_gem_commands_update_command.rb +353 -0
  146. data/test/test_gem_commands_which_command.rb +66 -0
  147. data/test/test_gem_config_file.rb +287 -0
  148. data/test/test_gem_dependency.rb +149 -0
  149. data/test/test_gem_dependency_installer.rb +661 -0
  150. data/test/test_gem_dependency_list.rb +230 -0
  151. data/test/test_gem_doc_manager.rb +31 -0
  152. data/test/test_gem_ext_configure_builder.rb +84 -0
  153. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  154. data/test/test_gem_ext_rake_builder.rb +81 -0
  155. data/test/test_gem_format.rb +70 -0
  156. data/test/test_gem_gem_path_searcher.rb +78 -0
  157. data/test/test_gem_gem_runner.rb +45 -0
  158. data/test/test_gem_gemcutter_utilities.rb +103 -0
  159. data/test/test_gem_indexer.rb +673 -0
  160. data/test/test_gem_install_update_options.rb +68 -0
  161. data/test/test_gem_installer.rb +857 -0
  162. data/test/test_gem_local_remote_options.rb +97 -0
  163. data/test/test_gem_package_tar_header.rb +130 -0
  164. data/test/test_gem_package_tar_input.rb +112 -0
  165. data/test/test_gem_package_tar_output.rb +97 -0
  166. data/test/test_gem_package_tar_reader.rb +46 -0
  167. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  168. data/test/test_gem_package_tar_writer.rb +144 -0
  169. data/test/test_gem_package_task.rb +59 -0
  170. data/test/test_gem_platform.rb +264 -0
  171. data/test/test_gem_remote_fetcher.rb +740 -0
  172. data/test/test_gem_requirement.rb +292 -0
  173. data/test/test_gem_server.rb +356 -0
  174. data/test/test_gem_silent_ui.rb +113 -0
  175. data/test/test_gem_source_index.rb +461 -0
  176. data/test/test_gem_spec_fetcher.rb +410 -0
  177. data/test/test_gem_specification.rb +1291 -0
  178. data/test/test_gem_stream_ui.rb +218 -0
  179. data/test/test_gem_text.rb +43 -0
  180. data/test/test_gem_uninstaller.rb +146 -0
  181. data/test/test_gem_validator.rb +63 -0
  182. data/test/test_gem_version.rb +181 -0
  183. data/test/test_gem_version_option.rb +89 -0
  184. data/test/test_kernel.rb +59 -0
  185. metadata +413 -0
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/list_command'
3
+
4
+ class TestGemCommandsListCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = Gem::Commands::ListCommand.new
10
+
11
+ util_setup_fake_fetcher
12
+
13
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1
14
+
15
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
16
+ raise Gem::RemoteFetcher::FetchError
17
+ end
18
+ end
19
+
20
+ def test_execute_installed
21
+ @cmd.handle_options %w[c --installed]
22
+
23
+ e = assert_raises Gem::SystemExitException do
24
+ use_ui @ui do
25
+ @cmd.execute
26
+ end
27
+ end
28
+
29
+ assert_equal 0, e.exit_code
30
+
31
+ assert_equal "true\n", @ui.output
32
+
33
+ assert_equal '', @ui.error
34
+ end
35
+
36
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/lock_command'
3
+
4
+ class TestGemCommandsLockCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @a1 = quick_gem 'a', '1'
10
+ @b1 = quick_gem 'b', '1' do |s|
11
+ s.add_runtime_dependency 'a'
12
+ end
13
+
14
+ @d1 = quick_gem 'd', '1' do |s|
15
+ s.add_runtime_dependency 'z'
16
+ end
17
+
18
+ @cmd = Gem::Commands::LockCommand.new
19
+ end
20
+
21
+ def test_execute
22
+ @cmd.handle_options %w[b-1]
23
+
24
+ use_ui @ui do
25
+ @cmd.execute
26
+ end
27
+
28
+ expected = <<-EXPECTED
29
+ require 'rubygems'
30
+ gem 'b', '= 1'
31
+ gem 'a', '= 1'
32
+ EXPECTED
33
+
34
+ assert_equal expected, @ui.output
35
+ assert_equal '', @ui.error
36
+ end
37
+
38
+ def test_execute_missing_dependency
39
+ @cmd.handle_options %w[d-1]
40
+
41
+ use_ui @ui do
42
+ @cmd.execute
43
+ end
44
+
45
+ expected = <<-EXPECTED
46
+ require 'rubygems'
47
+ gem 'd', '= 1'
48
+ # Unable to satisfy 'z (>= 0, runtime)' from currently installed gems
49
+ EXPECTED
50
+
51
+ assert_equal expected, @ui.output
52
+ assert_equal '', @ui.error
53
+ end
54
+
55
+ def test_execute_strict
56
+ @cmd.handle_options %w[c-1 --strict]
57
+
58
+ e = assert_raises Gem::Exception do
59
+ use_ui @ui do
60
+ @cmd.execute
61
+ end
62
+ end
63
+
64
+ assert_equal 'Could not find gem c-1, try using the full name', e.message
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,60 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/indexer'
3
+ require 'rubygems/commands/mirror_command'
4
+
5
+ class TestGemCommandsMirrorCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Commands::MirrorCommand.new
11
+ end
12
+
13
+ def test_execute
14
+ util_make_gems
15
+
16
+ gems_dir = File.join @tempdir, 'gems'
17
+ mirror = File.join @tempdir, 'mirror'
18
+
19
+ FileUtils.mkdir_p gems_dir
20
+ FileUtils.mkdir_p mirror
21
+
22
+ Dir[File.join(@gemhome, 'cache', '*.gem')].each do |gem|
23
+ FileUtils.mv gem, gems_dir
24
+ end
25
+
26
+ use_ui @ui do
27
+ Gem::Indexer.new(@tempdir).generate_index
28
+ end
29
+
30
+ orig_HOME = ENV['HOME']
31
+ ENV['HOME'] = @tempdir
32
+ Gem.instance_variable_set :@user_home, nil
33
+
34
+ File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp|
35
+ fp.puts "---"
36
+ # tempdir could be a drive+path (under windows)
37
+ if @tempdir.match(/[a-z]:/i)
38
+ fp.puts "- from: file:///#{@tempdir}"
39
+ else
40
+ fp.puts "- from: file://#{@tempdir}"
41
+ end
42
+ fp.puts " to: #{mirror}"
43
+ end
44
+
45
+ use_ui @ui do
46
+ @cmd.execute
47
+ end
48
+
49
+ assert File.exist?(File.join(mirror, 'gems', @a1.file_name))
50
+ assert File.exist?(File.join(mirror, 'gems', @a2.file_name))
51
+ assert File.exist?(File.join(mirror, 'gems', @b2.file_name))
52
+ assert File.exist?(File.join(mirror, 'gems', @c1_2.file_name))
53
+ assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}"))
54
+ ensure
55
+ orig_HOME.nil? ? ENV.delete('HOME') : ENV['HOME'] = orig_HOME
56
+ Gem.instance_variable_set :@user_home, nil
57
+ end
58
+
59
+ end if ''.respond_to? :to_xs
60
+
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/outdated_command'
3
+
4
+ class TestGemCommandsOutdatedCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = Gem::Commands::OutdatedCommand.new
10
+ end
11
+
12
+ def test_initialize
13
+ assert @cmd.handles?(%W[--platform #{Gem::Platform.local}])
14
+ end
15
+
16
+ def test_execute
17
+ local_01 = quick_gem 'foo', '0.1'
18
+ local_02 = quick_gem 'foo', '0.2'
19
+ remote_10 = quick_gem 'foo', '1.0'
20
+ remote_20 = quick_gem 'foo', '2.0'
21
+
22
+ remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name
23
+ FileUtils.rm remote_spec_file
24
+
25
+ remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name
26
+ FileUtils.rm remote_spec_file
27
+
28
+ @fetcher = Gem::FakeFetcher.new
29
+ Gem::RemoteFetcher.fetcher = @fetcher
30
+
31
+ util_setup_spec_fetcher remote_10, remote_20
32
+
33
+ use_ui @ui do @cmd.execute end
34
+
35
+ assert_equal "foo (0.2 < 2.0)\n", @ui.output
36
+ assert_equal "", @ui.error
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,105 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/owner_command'
3
+
4
+ class TestGemCommandsOwnerCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @fetcher = Gem::FakeFetcher.new
10
+ Gem::RemoteFetcher.fetcher = @fetcher
11
+ Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
12
+
13
+ @cmd = Gem::Commands::OwnerCommand.new
14
+ end
15
+
16
+ def test_show_owners
17
+ response = <<EOF
18
+ ---
19
+ - email: user1@example.com
20
+ - email: user2@example.com
21
+ EOF
22
+
23
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
24
+
25
+ use_ui @ui do
26
+ @cmd.show_owners("freewill")
27
+ end
28
+
29
+ assert_equal Net::HTTP::Get, @fetcher.last_request.class
30
+ assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
31
+
32
+ assert_match %r{Owners for gem: freewill}, @ui.output
33
+ assert_match %r{- user1@example.com}, @ui.output
34
+ assert_match %r{- user2@example.com}, @ui.output
35
+ end
36
+
37
+ def test_show_owners_denied
38
+ response = "You don't have permission to push to this gem"
39
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden']
40
+
41
+ assert_raises MockGemUi::TermError do
42
+ use_ui @ui do
43
+ @cmd.show_owners("freewill")
44
+ end
45
+ end
46
+
47
+ assert_match response, @ui.output
48
+ end
49
+
50
+ def test_add_owners
51
+ response = "Owner added successfully."
52
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
53
+
54
+ use_ui @ui do
55
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
56
+ end
57
+
58
+ assert_equal Net::HTTP::Post, @fetcher.last_request.class
59
+ assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
60
+ assert_equal "email=user-new1%40example.com", @fetcher.last_request.body
61
+
62
+ assert_match response, @ui.output
63
+ end
64
+
65
+ def test_add_owners_denied
66
+ response = "You don't have permission to push to this gem"
67
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
68
+
69
+ assert_raises MockGemUi::TermError do
70
+ use_ui @ui do
71
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
72
+ end
73
+ end
74
+
75
+ assert_match response, @ui.output
76
+ end
77
+
78
+ def test_remove_owners
79
+ response = "Owner removed successfully."
80
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
81
+
82
+ use_ui @ui do
83
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
84
+ end
85
+
86
+ assert_equal Net::HTTP::Delete, @fetcher.last_request.class
87
+ assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
88
+ assert_equal "email=user-remove1%40example.com", @fetcher.last_request.body
89
+
90
+ assert_match response, @ui.output
91
+ end
92
+
93
+ def test_remove_owners_denied
94
+ response = "You don't have permission to push to this gem"
95
+ @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
96
+
97
+ assert_raises MockGemUi::TermError do
98
+ use_ui @ui do
99
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
100
+ end
101
+ end
102
+
103
+ assert_match response, @ui.output
104
+ end
105
+ end
@@ -0,0 +1,108 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/pristine_command'
3
+
4
+ class TestGemCommandsPristineCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+ @cmd = Gem::Commands::PristineCommand.new
9
+ end
10
+
11
+ def test_execute
12
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
13
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
14
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
15
+ fp.puts "#!/usr/bin/ruby"
16
+ end
17
+
18
+ install_gem a
19
+
20
+ foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
21
+
22
+ File.open foo_path, 'w' do |io|
23
+ io.puts 'I changed it!'
24
+ end
25
+
26
+ @cmd.options[:args] = %w[a]
27
+
28
+ use_ui @ui do
29
+ @cmd.execute
30
+ end
31
+
32
+ assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
33
+
34
+ out = @ui.output.split "\n"
35
+
36
+ assert_equal "Restoring gem(s) to pristine condition...", out.shift
37
+ assert_equal "Restored #{a.full_name}", out.shift
38
+ assert_empty out, out.inspect
39
+ end
40
+
41
+ def test_execute_all
42
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
43
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
44
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
45
+ fp.puts "#!/usr/bin/ruby"
46
+ end
47
+
48
+ install_gem a
49
+
50
+ gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
51
+
52
+ FileUtils.rm gem_bin
53
+
54
+ @cmd.handle_options %w[--all]
55
+
56
+ use_ui @ui do
57
+ @cmd.execute
58
+ end
59
+
60
+ assert File.exist?(gem_bin)
61
+
62
+ out = @ui.output.split "\n"
63
+
64
+ assert_equal "Restoring gem(s) to pristine condition...", out.shift
65
+ assert_equal "Restored #{a.full_name}", out.shift
66
+ assert_empty out, out.inspect
67
+ end
68
+
69
+ def test_execute_missing_cache_gem
70
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
71
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
72
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
73
+ fp.puts "#!/usr/bin/ruby"
74
+ end
75
+
76
+ install_gem a
77
+
78
+ FileUtils.rm File.join(@gemhome, 'cache', a.file_name)
79
+
80
+ @cmd.options[:args] = %w[a]
81
+
82
+ use_ui @ui do
83
+ @cmd.execute
84
+ end
85
+
86
+ out = @ui.output.split "\n"
87
+
88
+ assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
89
+ assert_empty out, out.inspect
90
+
91
+ assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
92
+ @ui.error
93
+ end
94
+
95
+ def test_execute_no_gem
96
+ @cmd.options[:args] = %w[]
97
+
98
+ e = assert_raises Gem::CommandLineError do
99
+ use_ui @ui do
100
+ @cmd.execute
101
+ end
102
+ end
103
+
104
+ assert_match %r|specify a gem name|, e.message
105
+ end
106
+
107
+ end
108
+
@@ -0,0 +1,81 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/push_command'
3
+
4
+ class TestGemCommandsPushCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @gems_dir = File.join @tempdir, 'gems'
10
+ @cache_dir = File.join @gemhome, 'cache'
11
+ FileUtils.mkdir @gems_dir
12
+ Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
13
+ @spec, @path = util_gem("freewill", "1.0.0")
14
+
15
+ @fetcher = Gem::FakeFetcher.new
16
+ Gem::RemoteFetcher.fetcher = @fetcher
17
+
18
+ @cmd = Gem::Commands::PushCommand.new
19
+ end
20
+
21
+ def send_battery
22
+ use_ui @ui do
23
+ @cmd.send_gem(@path)
24
+ end
25
+
26
+ assert_match %r{Pushing gem to #{Gem.host}...}, @ui.output
27
+
28
+ assert_equal Net::HTTP::Post, @fetcher.last_request.class
29
+ assert_equal Gem.read_binary(@path), @fetcher.last_request.body
30
+ assert_equal File.size(@path), @fetcher.last_request["Content-Length"].to_i
31
+ assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"]
32
+ assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
33
+
34
+ assert_match @response, @ui.output
35
+ end
36
+
37
+ def test_sending_gem_default
38
+ @response = "Successfully registered gem: freewill (1.0.0)"
39
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
40
+
41
+ send_battery
42
+ end
43
+
44
+ def test_sending_gem_host
45
+ @response = "Successfully registered gem: freewill (1.0.0)"
46
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
47
+ @cmd.options[:host] = "#{Gem.host}"
48
+
49
+ send_battery
50
+ end
51
+
52
+ def test_sending_gem_ENV
53
+ @response = "Successfully registered gem: freewill (1.0.0)"
54
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
55
+ ENV["RUBYGEMS_HOST"] = "#{Gem.host}"
56
+
57
+ send_battery
58
+ end
59
+
60
+ def test_raises_error_with_no_arguments
61
+ def @cmd.sign_in; end
62
+ assert_raises Gem::CommandLineError do
63
+ @cmd.execute
64
+ end
65
+ end
66
+
67
+ def test_sending_gem_denied
68
+ response = "You don't have permission to push to this gem"
69
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 403, 'Forbidden']
70
+
71
+ assert_raises MockGemUi::TermError do
72
+ use_ui @ui do
73
+ @cmd.send_gem(@path)
74
+ end
75
+ end
76
+
77
+ assert_match response, @ui.output
78
+ end
79
+
80
+ end
81
+