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,144 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/commands/environment_command'
3
+
4
+ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::Commands::EnvironmentCommand.new
10
+ end
11
+
12
+ def test_execute
13
+ orig_sources = LibGems.sources.dup
14
+ LibGems.sources.replace %w[http://gems.example.com]
15
+ LibGems.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:.*#{LibGems::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|- #{LibGems::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
+ LibGems.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
+ LibGems.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 "#{LibGems.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 "#{LibGems::RubyGemsPackageVersion}\n", @ui.output
90
+ assert_equal '', @ui.error
91
+ end
92
+
93
+ def test_execute_remotesources
94
+ orig_sources = LibGems.sources.dup
95
+ LibGems.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
+ LibGems.sources.replace orig_sources
108
+ end
109
+
110
+ def test_execute_unknown
111
+ @cmd.send :handle_options, %w[unknown]
112
+
113
+ assert_raises LibGems::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 "#{LibGems::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 "#{LibGems.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 'libgems/package'
3
+ require 'libgems/security'
4
+ require 'libgems/commands/fetch_command'
5
+
6
+ class TestGemCommandsFetchCommand < RubyGemTestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ @cmd = LibGems::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] = LibGems::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 'libgems/indexer'
3
+ require 'libgems/commands/generate_index_command'
4
+
5
+ class TestGemCommandsGenerateIndexCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = LibGems::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 = LibGems::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 'libgems/commands/install_command'
3
+
4
+ class TestGemCommandsInstallCommand < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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 LibGems::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
+