libgems 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) 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 +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/list_command'
3
+
4
+ class TestGemCommandsListCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::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.#{LibGems.marshal_version}"] = proc do
16
+ raise LibGems::RemoteFetcher::FetchError
17
+ end
18
+ end
19
+
20
+ def test_execute_installed
21
+ @cmd.handle_options %w[c --installed]
22
+
23
+ e = assert_raises LibGems::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 'libgems/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 = LibGems::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 'libgems'
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 'libgems'
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 LibGems::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 'libgems/indexer'
3
+ require 'libgems/commands/mirror_command'
4
+
5
+ class TestGemCommandsMirrorCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = LibGems::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
+ LibGems::Indexer.new(@tempdir).generate_index
28
+ end
29
+
30
+ orig_HOME = ENV['HOME']
31
+ ENV['HOME'] = @tempdir
32
+ LibGems.instance_variable_set :@user_home, nil
33
+
34
+ File.open File.join(LibGems.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
+ LibGems.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 'libgems/commands/outdated_command'
3
+
4
+ class TestGemCommandsOutdatedCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::Commands::OutdatedCommand.new
10
+ end
11
+
12
+ def test_initialize
13
+ assert @cmd.handles?(%W[--platform #{LibGems::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 = LibGems::FakeFetcher.new
29
+ LibGems::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 'libgems/commands/owner_command'
3
+
4
+ class TestGemCommandsOwnerCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @fetcher = LibGems::FakeFetcher.new
10
+ LibGems::RemoteFetcher.fetcher = @fetcher
11
+ LibGems.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
12
+
13
+ @cmd = LibGems::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["#{LibGems.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 LibGems.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["#{LibGems.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["#{LibGems.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 LibGems.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["#{LibGems.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["#{LibGems.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 LibGems.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["#{LibGems.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 'libgems/commands/pristine_command'
3
+
4
+ class TestGemCommandsPristineCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+ @cmd = LibGems::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 LibGems::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 'libgems/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
+ LibGems.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
13
+ @spec, @path = util_gem("freewill", "1.0.0")
14
+
15
+ @fetcher = LibGems::FakeFetcher.new
16
+ LibGems::RemoteFetcher.fetcher = @fetcher
17
+
18
+ @cmd = LibGems::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 #{LibGems.host}...}, @ui.output
27
+
28
+ assert_equal Net::HTTP::Post, @fetcher.last_request.class
29
+ assert_equal LibGems.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 LibGems.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["#{LibGems.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["#{LibGems.host}/api/v1/gems"] = [@response, 200, 'OK']
47
+ @cmd.options[:host] = "#{LibGems.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["#{LibGems.host}/api/v1/gems"] = [@response, 200, 'OK']
55
+ ENV["RUBYGEMS_HOST"] = "#{LibGems.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 LibGems::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["#{LibGems.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
+