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,144 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/environment_command'
3
+
4
+ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = Gem::Commands::EnvironmentCommand.new
10
+ end
11
+
12
+ def test_execute
13
+ orig_sources = Gem.sources.dup
14
+ Gem.sources.replace %w[http://gems.example.com]
15
+ Gem.configuration['gemcutter_key'] = 'blah'
16
+
17
+ @cmd.send :handle_options, %w[]
18
+
19
+ use_ui @ui do
20
+ @cmd.execute
21
+ end
22
+
23
+ assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
24
+ assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
25
+ assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
26
+ @ui.output
27
+ assert_match %r|RUBYGEMS PREFIX: |, @ui.output
28
+ assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:ruby_install_name]}|,
29
+ @ui.output
30
+ assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
31
+ assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
32
+ assert_match %r|- #{Gem::Platform.local}|, @ui.output
33
+ assert_match %r|GEM PATHS:|, @ui.output
34
+ assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output
35
+ assert_match %r|GEM CONFIGURATION:|, @ui.output
36
+ assert_match %r|"gemcutter_key" => "\*\*\*\*"|, @ui.output
37
+ assert_match %r|:verbose => |, @ui.output
38
+ assert_match %r|REMOTE SOURCES:|, @ui.output
39
+ assert_equal '', @ui.error
40
+
41
+ ensure
42
+ Gem.sources.replace orig_sources
43
+ end
44
+
45
+ def test_execute_gemdir
46
+ @cmd.send :handle_options, %w[gemdir]
47
+
48
+ use_ui @ui do
49
+ @cmd.execute
50
+ end
51
+
52
+ assert_equal "#{@gemhome}\n", @ui.output
53
+ assert_equal '', @ui.error
54
+ end
55
+
56
+ def test_execute_gempath
57
+ @cmd.send :handle_options, %w[gempath]
58
+
59
+ use_ui @ui do
60
+ @cmd.execute
61
+ end
62
+
63
+ assert_equal "#{@gemhome}\n", @ui.output
64
+ assert_equal '', @ui.error
65
+ end
66
+
67
+ def test_execute_gempath_multiple
68
+ Gem.clear_paths
69
+ path = [@gemhome, "#{@gemhome}2"].join File::PATH_SEPARATOR
70
+ ENV['GEM_PATH'] = path
71
+
72
+ @cmd.send :handle_options, %w[gempath]
73
+
74
+ use_ui @ui do
75
+ @cmd.execute
76
+ end
77
+
78
+ assert_equal "#{Gem.path.join File::PATH_SEPARATOR}\n", @ui.output
79
+ assert_equal '', @ui.error
80
+ end
81
+
82
+ def test_execute_packageversion
83
+ @cmd.send :handle_options, %w[packageversion]
84
+
85
+ use_ui @ui do
86
+ @cmd.execute
87
+ end
88
+
89
+ assert_equal "#{Gem::RubyGemsPackageVersion}\n", @ui.output
90
+ assert_equal '', @ui.error
91
+ end
92
+
93
+ def test_execute_remotesources
94
+ orig_sources = Gem.sources.dup
95
+ Gem.sources.replace %w[http://gems.example.com]
96
+
97
+ @cmd.send :handle_options, %w[remotesources]
98
+
99
+ use_ui @ui do
100
+ @cmd.execute
101
+ end
102
+
103
+ assert_equal "http://gems.example.com\n", @ui.output
104
+ assert_equal '', @ui.error
105
+
106
+ ensure
107
+ Gem.sources.replace orig_sources
108
+ end
109
+
110
+ def test_execute_unknown
111
+ @cmd.send :handle_options, %w[unknown]
112
+
113
+ assert_raises Gem::CommandLineError do
114
+ use_ui @ui do
115
+ @cmd.execute
116
+ end
117
+ end
118
+
119
+ assert_equal '', @ui.output
120
+ assert_equal '', @ui.error
121
+ end
122
+
123
+ def test_execute_version
124
+ @cmd.send :handle_options, %w[version]
125
+
126
+ use_ui @ui do
127
+ @cmd.execute
128
+ end
129
+
130
+ assert_equal "#{Gem::VERSION}\n", @ui.output
131
+ assert_equal '', @ui.error
132
+ end
133
+
134
+ def test_execute_platform
135
+ @cmd.send :handle_options, %w[platform]
136
+
137
+ use_ui @ui do
138
+ @cmd.execute
139
+ end
140
+
141
+ assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output
142
+ assert_equal '', @ui.error
143
+ end
144
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/package'
3
+ require 'rubygems/security'
4
+ require 'rubygems/commands/fetch_command'
5
+
6
+ class TestGemCommandsFetchCommand < RubyGemTestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ @cmd = Gem::Commands::FetchCommand.new
12
+ end
13
+
14
+ def test_execute
15
+ util_setup_fake_fetcher
16
+ util_setup_spec_fetcher @a2
17
+
18
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
19
+ File.read(File.join(@gemhome, 'cache', @a2.file_name))
20
+
21
+ @cmd.options[:args] = [@a2.name]
22
+
23
+ use_ui @ui do
24
+ Dir.chdir @tempdir do
25
+ @cmd.execute
26
+ end
27
+ end
28
+
29
+ assert File.exist?(File.join(@tempdir, @a2.file_name)),
30
+ "#{@a2.full_name} not fetched"
31
+ end
32
+
33
+ def test_execute_prerelease
34
+ util_setup_fake_fetcher true
35
+ util_setup_spec_fetcher @a2, @a2_pre
36
+
37
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
38
+ File.read(File.join(@gemhome, 'cache', @a2.file_name))
39
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
40
+ File.read(File.join(@gemhome, 'cache', @a2_pre.file_name))
41
+
42
+ @cmd.options[:args] = [@a2.name]
43
+ @cmd.options[:prerelease] = true
44
+
45
+ use_ui @ui do
46
+ Dir.chdir @tempdir do
47
+ @cmd.execute
48
+ end
49
+ end
50
+
51
+ assert File.exist?(File.join(@tempdir, @a2_pre.file_name)),
52
+ "#{@a2_pre.full_name} not fetched"
53
+ end
54
+
55
+ def test_execute_version
56
+ util_setup_fake_fetcher
57
+ util_setup_spec_fetcher @a1, @a2
58
+
59
+ @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
60
+ File.read(File.join(@gemhome, 'cache', @a1.file_name))
61
+
62
+ @cmd.options[:args] = [@a2.name]
63
+ @cmd.options[:version] = Gem::Requirement.new '1'
64
+
65
+ use_ui @ui do
66
+ Dir.chdir @tempdir do
67
+ @cmd.execute
68
+ end
69
+ end
70
+
71
+ assert File.exist?(File.join(@tempdir, @a1.file_name)),
72
+ "#{@a1.full_name} not fetched"
73
+ end
74
+
75
+ end
76
+
@@ -0,0 +1,135 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/indexer'
3
+ require 'rubygems/commands/generate_index_command'
4
+
5
+ class TestGemCommandsGenerateIndexCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Commands::GenerateIndexCommand.new
11
+ @cmd.options[:directory] = @gemhome
12
+ end
13
+
14
+ def test_execute
15
+ use_ui @ui do
16
+ @cmd.execute
17
+ end
18
+
19
+ yaml = File.join @gemhome, 'yaml'
20
+ yaml_z = File.join @gemhome, 'yaml.Z'
21
+ quick_index = File.join @gemhome, 'quick', 'index'
22
+ quick_index_rz = File.join @gemhome, 'quick', 'index.rz'
23
+
24
+ assert File.exist?(yaml), yaml
25
+ assert File.exist?(yaml_z), yaml_z
26
+ assert File.exist?(quick_index), quick_index
27
+ assert File.exist?(quick_index_rz), quick_index_rz
28
+ end
29
+
30
+ def test_execute_rss_update
31
+ @cmd.options[:update] = true
32
+ @cmd.options[:rss_host] = 'example.com'
33
+ @cmd.options[:rss_gems_host] = 'gems.example.com'
34
+
35
+ use_ui @ui do
36
+ assert_raises MockGemUi::TermError do
37
+ @cmd.execute
38
+ end
39
+ end
40
+
41
+ assert_equal "ERROR: --update not compatible with RSS generation\n",
42
+ @ui.error
43
+ assert_empty @ui.output
44
+ end
45
+
46
+ def test_handle_options_directory
47
+ return if win_platform?
48
+ refute_equal '/nonexistent', @cmd.options[:directory]
49
+
50
+ @cmd.handle_options %w[--directory /nonexistent]
51
+
52
+ assert_equal '/nonexistent', @cmd.options[:directory]
53
+ end
54
+
55
+ def test_handle_options_directory_windows
56
+ return unless win_platform?
57
+
58
+ refute_equal '/nonexistent', @cmd.options[:directory]
59
+
60
+ @cmd.handle_options %w[--directory C:/nonexistent]
61
+
62
+ assert_equal 'C:/nonexistent', @cmd.options[:directory]
63
+ end
64
+
65
+ def test_handle_options_invalid
66
+ e = assert_raises OptionParser::InvalidOption do
67
+ @cmd.handle_options %w[--no-modern --no-legacy]
68
+ end
69
+
70
+ assert_equal 'invalid option: --no-legacy no indicies will be built',
71
+ e.message
72
+
73
+ @cmd = Gem::Commands::GenerateIndexCommand.new
74
+ e = assert_raises OptionParser::InvalidOption do
75
+ @cmd.handle_options %w[--no-legacy --no-modern]
76
+ end
77
+
78
+ assert_equal 'invalid option: --no-modern no indicies will be built',
79
+ e.message
80
+ end
81
+
82
+ def test_handle_options_legacy
83
+ @cmd.handle_options %w[--legacy]
84
+
85
+ assert @cmd.options[:build_legacy]
86
+ assert @cmd.options[:build_modern], ':build_modern not set'
87
+ end
88
+
89
+ def test_handle_options_modern
90
+ @cmd.handle_options %w[--modern]
91
+
92
+ assert @cmd.options[:build_legacy]
93
+ assert @cmd.options[:build_modern], ':build_modern not set'
94
+ end
95
+
96
+ def test_handle_options_no_legacy
97
+ @cmd.handle_options %w[--no-legacy]
98
+
99
+ refute @cmd.options[:build_legacy]
100
+ assert @cmd.options[:build_modern]
101
+ end
102
+
103
+ def test_handle_options_no_modern
104
+ @cmd.handle_options %w[--no-modern]
105
+
106
+ assert @cmd.options[:build_legacy]
107
+ refute @cmd.options[:build_modern]
108
+ end
109
+
110
+ def test_handle_options_rss_gems_host
111
+ @cmd.handle_options %w[--rss-gems-host gems.example.com]
112
+
113
+ assert_equal 'gems.example.com', @cmd.options[:rss_gems_host]
114
+ end
115
+
116
+ def test_handle_options_rss_host
117
+ @cmd.handle_options %w[--rss-host example.com]
118
+
119
+ assert_equal 'example.com', @cmd.options[:rss_host]
120
+ end
121
+
122
+ def test_handle_options_rss_title
123
+ @cmd.handle_options %w[--rss-title Example\ Gems]
124
+
125
+ assert_equal 'Example Gems', @cmd.options[:rss_title]
126
+ end
127
+
128
+ def test_handle_options_update
129
+ @cmd.handle_options %w[--update]
130
+
131
+ assert @cmd.options[:update]
132
+ end
133
+
134
+ end if ''.respond_to? :to_xs
135
+
@@ -0,0 +1,315 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/commands/install_command'
3
+
4
+ class TestGemCommandsInstallCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = Gem::Commands::InstallCommand.new
10
+ @cmd.options[:generate_rdoc] = false
11
+ @cmd.options[:generate_ri] = false
12
+ end
13
+
14
+ def test_execute_exclude_prerelease
15
+ util_setup_fake_fetcher(:prerelease)
16
+ util_setup_spec_fetcher @a2, @a2_pre
17
+
18
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
19
+ read_binary(File.join(@gemhome, 'cache', @a2.file_name))
20
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
21
+ read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
22
+
23
+ @cmd.options[:args] = [@a2.name]
24
+
25
+ use_ui @ui do
26
+ e = assert_raises Gem::SystemExitException do
27
+ @cmd.execute
28
+ end
29
+ assert_equal 0, e.exit_code, @ui.error
30
+ end
31
+
32
+ assert_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
33
+ refute_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
34
+ end
35
+
36
+ def test_execute_explicit_version_includes_prerelease
37
+ util_setup_fake_fetcher(:prerelease)
38
+ util_setup_spec_fetcher @a2, @a2_pre
39
+
40
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
41
+ read_binary(File.join(@gemhome, 'cache', @a2.file_name))
42
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
43
+ read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
44
+
45
+ @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s]
46
+ assert @cmd.options[:prerelease]
47
+ assert @cmd.options[:version].satisfied_by?(@a2_pre.version)
48
+
49
+ use_ui @ui do
50
+ e = assert_raises Gem::SystemExitException do
51
+ @cmd.execute
52
+ end
53
+ assert_equal 0, e.exit_code, @ui.error
54
+ end
55
+
56
+ refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
57
+ assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
58
+ end
59
+
60
+ def test_execute_include_dependencies
61
+ @cmd.options[:include_dependencies] = true
62
+ @cmd.options[:args] = []
63
+
64
+ assert_raises Gem::CommandLineError do
65
+ use_ui @ui do
66
+ @cmd.execute
67
+ end
68
+ end
69
+
70
+ output = @ui.output.split "\n"
71
+ assert_equal "INFO: `gem install -y` is now default and will be removed",
72
+ output.shift
73
+ assert_equal "INFO: use --ignore-dependencies to install only the gems you list",
74
+ output.shift
75
+ assert output.empty?, output.inspect
76
+ end
77
+
78
+ def test_execute_local
79
+ util_setup_fake_fetcher
80
+ @cmd.options[:domain] = :local
81
+
82
+ FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
83
+ File.join(@tempdir)
84
+
85
+ @cmd.options[:args] = [@a2.name]
86
+
87
+ use_ui @ui do
88
+ orig_dir = Dir.pwd
89
+ begin
90
+ Dir.chdir @tempdir
91
+ e = assert_raises Gem::SystemExitException do
92
+ @cmd.execute
93
+ end
94
+ assert_equal 0, e.exit_code
95
+ ensure
96
+ Dir.chdir orig_dir
97
+ end
98
+ end
99
+
100
+ out = @ui.output.split "\n"
101
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
102
+ assert_equal "1 gem installed", out.shift
103
+ assert out.empty?, out.inspect
104
+ end
105
+
106
+ def test_no_user_install
107
+ skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
108
+
109
+ util_setup_fake_fetcher
110
+ @cmd.options[:user_install] = false
111
+
112
+ FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
113
+ File.join(@tempdir)
114
+
115
+ @cmd.options[:args] = [@a2.name]
116
+
117
+ use_ui @ui do
118
+ orig_dir = Dir.pwd
119
+ begin
120
+ File.chmod 0755, @userhome
121
+ File.chmod 0555, @gemhome
122
+
123
+ Dir.chdir @tempdir
124
+ assert_raises Gem::FilePermissionError do
125
+ @cmd.execute
126
+ end
127
+ ensure
128
+ Dir.chdir orig_dir
129
+ File.chmod 0755, @gemhome
130
+ end
131
+ end
132
+ end
133
+
134
+ def test_execute_local_missing
135
+ util_setup_fake_fetcher
136
+ @cmd.options[:domain] = :local
137
+
138
+ @cmd.options[:args] = %w[no_such_gem]
139
+
140
+ use_ui @ui do
141
+ e = assert_raises Gem::SystemExitException do
142
+ @cmd.execute
143
+ end
144
+ assert_equal 2, e.exit_code
145
+ end
146
+
147
+ # HACK no repository was checked
148
+ assert_match(/ould not find a valid gem 'no_such_gem'/, @ui.error)
149
+ end
150
+
151
+ def test_execute_no_gem
152
+ @cmd.options[:args] = %w[]
153
+
154
+ assert_raises Gem::CommandLineError do
155
+ @cmd.execute
156
+ end
157
+ end
158
+
159
+ def test_execute_nonexistent
160
+ util_setup_fake_fetcher
161
+ util_setup_spec_fetcher
162
+
163
+ @cmd.options[:args] = %w[nonexistent]
164
+
165
+ use_ui @ui do
166
+ e = assert_raises Gem::SystemExitException do
167
+ @cmd.execute
168
+ end
169
+ assert_equal 2, e.exit_code
170
+ end
171
+
172
+ assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
173
+ end
174
+
175
+ def test_execute_nonexistent_with_hint
176
+ misspelled="nonexistent_with_hint"
177
+ correctly_spelled="non_existent_with_hint"
178
+
179
+ util_setup_fake_fetcher
180
+ util_setup_spec_fetcher quick_gem(correctly_spelled, '2')
181
+
182
+ @cmd.options[:args] = [misspelled]
183
+
184
+ use_ui @ui do
185
+ e = assert_raises Gem::SystemExitException do
186
+ @cmd.execute
187
+ end
188
+ assert_equal 2, e.exit_code
189
+ end
190
+
191
+ expected = "ERROR: Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any repository
192
+ ERROR: Possible alternatives: non_existent_with_hint
193
+ "
194
+
195
+ assert_equal expected, @ui.error
196
+ end
197
+
198
+ def test_execute_prerelease
199
+ util_setup_fake_fetcher(:prerelease)
200
+ util_setup_spec_fetcher @a2, @a2_pre
201
+
202
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
203
+ read_binary(File.join(@gemhome, 'cache', @a2.file_name))
204
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
205
+ read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name))
206
+
207
+ @cmd.options[:prerelease] = true
208
+ @cmd.options[:args] = [@a2_pre.name]
209
+
210
+ use_ui @ui do
211
+ e = assert_raises Gem::SystemExitException do
212
+ @cmd.execute
213
+ end
214
+ assert_equal 0, e.exit_code, @ui.error
215
+ end
216
+
217
+ refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
218
+ assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
219
+ end
220
+
221
+ def test_execute_remote
222
+ @cmd.options[:generate_rdoc] = true
223
+ @cmd.options[:generate_ri] = true
224
+
225
+ util_setup_fake_fetcher
226
+ util_setup_spec_fetcher @a2
227
+
228
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
229
+ read_binary(File.join(@gemhome, 'cache', @a2.file_name))
230
+
231
+ @cmd.options[:args] = [@a2.name]
232
+
233
+ use_ui @ui do
234
+ e = assert_raises Gem::SystemExitException do
235
+ capture_io do
236
+ @cmd.execute
237
+ end
238
+ end
239
+ assert_equal 0, e.exit_code
240
+ end
241
+
242
+ assert_match "Successfully installed #{@a2.full_name}", @ui.output
243
+ assert_match "1 gem installed", @ui.output
244
+ assert_match "Installing ri documentation for #{@a2.full_name}...",
245
+ @ui.output
246
+ assert_match "Installing RDoc documentation for #{@a2.full_name}...",
247
+ @ui.output
248
+ assert !@ui.output.empty?, @ui.output.inspect
249
+ end
250
+
251
+ def test_execute_two
252
+ util_setup_fake_fetcher
253
+ @cmd.options[:domain] = :local
254
+
255
+ FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name),
256
+ File.join(@tempdir)
257
+
258
+ FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name),
259
+ File.join(@tempdir)
260
+
261
+ @cmd.options[:args] = [@a2.name, @b2.name]
262
+
263
+ use_ui @ui do
264
+ orig_dir = Dir.pwd
265
+ begin
266
+ Dir.chdir @tempdir
267
+ e = assert_raises Gem::SystemExitException do
268
+ @cmd.execute
269
+ end
270
+ assert_equal 0, e.exit_code
271
+ ensure
272
+ Dir.chdir orig_dir
273
+ end
274
+ end
275
+
276
+ out = @ui.output.split "\n"
277
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
278
+ assert_equal "Successfully installed #{@b2.full_name}", out.shift
279
+ assert_equal "2 gems installed", out.shift
280
+ assert out.empty?, out.inspect
281
+ end
282
+
283
+ def test_execute_conservative
284
+ util_setup_fake_fetcher
285
+ util_setup_spec_fetcher @b2
286
+
287
+ @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
288
+ read_binary(File.join(@gemhome, 'cache', @b2.file_name))
289
+
290
+ uninstall_gem(@b2)
291
+
292
+ @cmd.options[:conservative] = true
293
+
294
+ @cmd.options[:args] = [@a2.name, @b2.name]
295
+
296
+ use_ui @ui do
297
+ orig_dir = Dir.pwd
298
+ begin
299
+ Dir.chdir @tempdir
300
+ e = assert_raises Gem::SystemExitException do
301
+ @cmd.execute
302
+ end
303
+ assert_equal 0, e.exit_code
304
+ ensure
305
+ Dir.chdir orig_dir
306
+ end
307
+ end
308
+
309
+ out = @ui.output.split "\n"
310
+ assert_equal "Successfully installed #{@b2.full_name}", out.shift
311
+ assert_equal "1 gem installed", out.shift
312
+ assert out.empty?, out.inspect
313
+ end
314
+ end
315
+