rubygems-update 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -0,0 +1,147 @@
1
+ require 'test/unit'
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require 'rubygems/commands/sources_command'
4
+
5
+ class TestGemCommandsSourcesCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Commands::SourcesCommand.new
11
+ end
12
+
13
+ def test_execute
14
+ util_setup_source_info_cache
15
+ @cmd.handle_options []
16
+
17
+ use_ui @ui do
18
+ @cmd.execute
19
+ end
20
+
21
+ expected = <<-EOF
22
+ *** CURRENT SOURCES ***
23
+
24
+ #{@gem_repo}
25
+ EOF
26
+
27
+ assert_equal expected, @ui.output
28
+ assert_equal '', @ui.error
29
+ end
30
+
31
+ def test_execute_add
32
+ util_setup_fake_fetcher
33
+
34
+ @si = Gem::SourceIndex.new @gem1.full_name => @gem1.name
35
+
36
+ @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
37
+ @si.dump
38
+
39
+ @cmd.handle_options %w[--add http://beta-gems.example.com]
40
+
41
+ util_setup_source_info_cache
42
+
43
+ use_ui @ui do
44
+ @cmd.execute
45
+ end
46
+
47
+ expected = <<-EOF
48
+ Bulk updating Gem source index for: http://beta-gems.example.com
49
+ http://beta-gems.example.com added to sources
50
+ EOF
51
+
52
+ assert_equal expected, @ui.output
53
+ assert_equal '', @ui.error
54
+
55
+ Gem::SourceInfoCache.cache.flush
56
+ assert_equal %W[http://beta-gems.example.com #{@gem_repo}],
57
+ Gem::SourceInfoCache.cache_data.keys.sort
58
+ end
59
+
60
+ def test_execute_add_nonexistent_source
61
+ util_setup_fake_fetcher
62
+
63
+ @si = Gem::SourceIndex.new @gem1.full_name => @gem1.name
64
+
65
+ @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
66
+ proc do
67
+ raise Gem::RemoteFetcher::FetchError, 'it died'
68
+ end
69
+
70
+
71
+ Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
72
+
73
+ @cmd.handle_options %w[--add http://beta-gems.example.com]
74
+
75
+ util_setup_source_info_cache
76
+
77
+ use_ui @ui do
78
+ @cmd.execute
79
+ end
80
+
81
+ expected = <<-EOF
82
+ Error fetching http://beta-gems.example.com:
83
+ \tit died
84
+ EOF
85
+
86
+ assert_equal expected, @ui.output
87
+ assert_equal '', @ui.error
88
+ end
89
+
90
+ def test_execute_add_bad_uri
91
+ @cmd.handle_options %w[--add beta-gems.example.com]
92
+
93
+ util_setup_source_info_cache
94
+
95
+ use_ui @ui do
96
+ @cmd.execute
97
+ end
98
+
99
+ expected = <<-EOF
100
+ beta-gems.example.com is not a URI
101
+ EOF
102
+
103
+ assert_equal expected, @ui.output
104
+ assert_equal '', @ui.error
105
+ end
106
+
107
+ def test_execute_remove
108
+ @cmd.handle_options %W[--remove #{@gem_repo}]
109
+
110
+ util_setup_source_info_cache
111
+
112
+ use_ui @ui do
113
+ @cmd.execute
114
+ end
115
+
116
+ expected = "#{@gem_repo} removed from sources\n"
117
+
118
+ assert_equal expected, @ui.output
119
+ assert_equal '', @ui.error
120
+
121
+ Gem::SourceInfoCache.cache.flush
122
+ assert_equal [], Gem::SourceInfoCache.cache_data.keys
123
+ end
124
+
125
+ def test_execute_update
126
+ @cmd.handle_options %w[--update]
127
+
128
+ util_setup_source_info_cache
129
+ util_setup_fake_fetcher
130
+ @si = Gem::SourceIndex.new @gem1.full_name => @gem1.name
131
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
132
+
133
+ use_ui @ui do
134
+ @cmd.execute
135
+ end
136
+
137
+ expected = <<-EOF
138
+ Bulk updating Gem source index for: #{@gem_repo}
139
+ source cache successfully updated
140
+ EOF
141
+
142
+ assert_equal expected, @ui.output
143
+ assert_equal '', @ui.error
144
+ end
145
+
146
+ end
147
+
@@ -0,0 +1,93 @@
1
+ require 'test/unit'
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require 'rubygems/commands/specification_command'
4
+
5
+ class TestGemCommandsSpecificationCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Commands::SpecificationCommand.new
11
+ end
12
+
13
+ def test_execute
14
+ foo = quick_gem 'foo'
15
+
16
+ @cmd.options[:args] = %w[foo]
17
+
18
+ use_ui @ui do
19
+ @cmd.execute
20
+ end
21
+
22
+ assert_match %r|Gem::Specification|, @ui.output
23
+ assert_match %r|name: foo|, @ui.output
24
+ assert_equal '', @ui.error
25
+ end
26
+
27
+ def test_execute_all
28
+ foo1 = quick_gem 'foo', '0.0.1'
29
+ foo2 = quick_gem 'foo', '0.0.2'
30
+
31
+ @cmd.options[:args] = %w[foo]
32
+ @cmd.options[:all] = true
33
+
34
+ use_ui @ui do
35
+ @cmd.execute
36
+ end
37
+
38
+ assert_match %r|Gem::Specification|, @ui.output
39
+ assert_match %r|name: foo|, @ui.output
40
+ assert_match %r|version: 0.0.1|, @ui.output
41
+ assert_match %r|version: 0.0.2|, @ui.output
42
+ assert_equal '', @ui.error
43
+ end
44
+
45
+ def test_execute_bad_name
46
+ @cmd.options[:args] = %w[foo]
47
+
48
+ assert_raise MockGemUi::TermError do
49
+ use_ui @ui do
50
+ @cmd.execute
51
+ end
52
+ end
53
+
54
+ assert_equal '', @ui.output
55
+ assert_equal "ERROR: Unknown gem 'foo'\n", @ui.error
56
+ end
57
+
58
+ def test_execute_exact_match
59
+ foo = quick_gem 'foo'
60
+ foo_bar = quick_gem 'foo_bar'
61
+
62
+ @cmd.options[:args] = %w[foo]
63
+
64
+ use_ui @ui do
65
+ @cmd.execute
66
+ end
67
+
68
+ assert_match %r|Gem::Specification|, @ui.output
69
+ assert_match %r|name: foo|, @ui.output
70
+ assert_equal '', @ui.error
71
+ end
72
+
73
+ def test_execute_remote
74
+ foo = quick_gem 'foo'
75
+
76
+ util_setup_source_info_cache foo
77
+
78
+ FileUtils.rm File.join(@gemhome, 'specifications',
79
+ "#{foo.full_name}.gemspec")
80
+
81
+ @cmd.options[:args] = %w[foo]
82
+ @cmd.options[:domain] = :remote
83
+
84
+ use_ui @ui do
85
+ @cmd.execute
86
+ end
87
+
88
+ assert_equal "#{foo.to_yaml}\n", @ui.output
89
+ assert_equal "WARNING: Remote information is not complete\n\n", @ui.error
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,55 @@
1
+ require 'test/unit'
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require 'rubygems/commands/unpack_command'
4
+
5
+ class TestGemCommandsUnpackCommand < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Commands::UnpackCommand.new
11
+ end
12
+
13
+ def test_execute
14
+ util_make_gems
15
+
16
+ @cmd.options[:args] = %w[a]
17
+
18
+ use_ui @ui do
19
+ Dir.chdir @tempdir do
20
+ @cmd.execute
21
+ end
22
+ end
23
+
24
+ assert File.exist?(File.join(@tempdir, 'a-0.0.2'))
25
+ end
26
+
27
+ def test_execute_exact_match
28
+ foo_spec = quick_gem 'foo'
29
+ foo_bar_spec = quick_gem 'foo_bar'
30
+
31
+ use_ui @ui do
32
+ Dir.chdir @tempdir do
33
+ Gem::Builder.new(foo_spec).build
34
+ Gem::Builder.new(foo_bar_spec).build
35
+ end
36
+ end
37
+
38
+ foo_path = File.join(@tempdir, "#{foo_spec.full_name}.gem")
39
+ foo_bar_path = File.join(@tempdir, "#{foo_bar_spec.full_name}.gem")
40
+ Gem::Installer.new(foo_path).install
41
+ Gem::Installer.new(foo_bar_path).install
42
+
43
+ @cmd.options[:args] = %w[foo]
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, foo_spec.full_name))
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4
+ # All rights reserved.
5
+ # See LICENSE.txt for permissions.
6
+ #++
7
+
8
+ require 'test/unit'
9
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
10
+ require 'rubygems/config_file'
11
+
12
+ class TestGemConfigFile < RubyGemTestCase
13
+
14
+ def setup
15
+ super
16
+
17
+ @temp_conf = File.join @tempdir, '.gemrc'
18
+
19
+ @cfg_args = %W[--config-file #{@temp_conf}]
20
+ util_config_file
21
+ end
22
+
23
+ def test_initialize
24
+ assert_equal @temp_conf, @cfg.config_file_name
25
+
26
+ assert_equal false, @cfg.backtrace
27
+ assert_equal true, @cfg.update_sources
28
+ assert_equal false, @cfg.benchmark
29
+ assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
30
+ assert_equal true, @cfg.verbose
31
+ assert_equal %w[http://gems.example.com], Gem.sources
32
+
33
+ File.open @temp_conf, 'w' do |fp|
34
+ fp.puts ":backtrace: true"
35
+ fp.puts ":update_sources: false"
36
+ fp.puts ":benchmark: true"
37
+ fp.puts ":bulk_threshold: 10"
38
+ fp.puts ":verbose: false"
39
+ fp.puts ":sources:"
40
+ fp.puts " - http://more-gems.example.com"
41
+ fp.puts "install: --wrappers"
42
+ end
43
+
44
+ util_config_file
45
+
46
+ assert_equal true, @cfg.backtrace
47
+ assert_equal true, @cfg.benchmark
48
+ assert_equal 10, @cfg.bulk_threshold
49
+ assert_equal false, @cfg.verbose
50
+ assert_equal false, @cfg.update_sources
51
+ assert_equal %w[http://more-gems.example.com], Gem.sources
52
+ assert_equal '--wrappers', @cfg[:install]
53
+ end
54
+
55
+ def test_initialize_handle_arguments_config_file
56
+ util_config_file %W[--config-file #{@temp_conf}]
57
+
58
+ assert_equal @temp_conf, @cfg.config_file_name
59
+ end
60
+
61
+ def test_initialize_handle_arguments_config_file_equals
62
+ util_config_file %W[--config-file=#{@temp_conf}]
63
+
64
+ assert_equal @temp_conf, @cfg.config_file_name
65
+ end
66
+
67
+ def test_handle_arguments
68
+ args = %w[--backtrace --bunch --of --args here]
69
+
70
+ @cfg.handle_arguments args
71
+
72
+ assert_equal %w[--bunch --of --args here], @cfg.args
73
+ end
74
+
75
+ def test_handle_arguments_backtrace
76
+ assert_equal false, @cfg.backtrace
77
+
78
+ args = %w[--backtrace]
79
+
80
+ @cfg.handle_arguments args
81
+
82
+ assert_equal true, @cfg.backtrace
83
+ end
84
+
85
+ def test_handle_arguments_benchmark
86
+ assert_equal false, @cfg.benchmark
87
+
88
+ args = %w[--benchmark]
89
+
90
+ @cfg.handle_arguments args
91
+
92
+ assert_equal true, @cfg.benchmark
93
+ end
94
+
95
+ def test_handle_arguments_debug
96
+ old_dollar_DEBUG = $DEBUG
97
+ assert_equal false, $DEBUG
98
+
99
+ args = %w[--debug]
100
+
101
+ @cfg.handle_arguments args
102
+
103
+ assert_equal true, $DEBUG
104
+ ensure
105
+ $DEBUG = old_dollar_DEBUG
106
+ end
107
+
108
+ def test_handle_arguments_override
109
+ File.open @temp_conf, 'w' do |fp|
110
+ fp.puts ":benchmark: false"
111
+ end
112
+
113
+ util_config_file %W[--benchmark --config-file=#{@temp_conf}]
114
+
115
+ assert_equal true, @cfg.benchmark
116
+ end
117
+
118
+ def test_handle_arguments_traceback
119
+ assert_equal false, @cfg.backtrace
120
+
121
+ args = %w[--traceback]
122
+
123
+ @cfg.handle_arguments args
124
+
125
+ assert_equal true, @cfg.backtrace
126
+ end
127
+
128
+ def test_really_verbose
129
+ assert_equal false, @cfg.really_verbose
130
+
131
+ @cfg.verbose = true
132
+
133
+ assert_equal false, @cfg.really_verbose
134
+
135
+ @cfg.verbose = 1
136
+
137
+ assert_equal true, @cfg.really_verbose
138
+ end
139
+
140
+ def test_write
141
+ @cfg.backtrace = true
142
+ @cfg.benchmark = true
143
+ @cfg.update_sources = false
144
+ @cfg.bulk_threshold = 10
145
+ @cfg.verbose = false
146
+ Gem.sources.replace %w[http://more-gems.example.com]
147
+ @cfg[:install] = '--wrappers'
148
+
149
+ @cfg.write
150
+
151
+ util_config_file
152
+
153
+ # These should not be written out to the config file.
154
+ assert_equal false, @cfg.backtrace, 'backtrace'
155
+ assert_equal false, @cfg.benchmark, 'benchmark'
156
+ assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold,
157
+ 'bulk_threshold'
158
+ assert_equal true, @cfg.update_sources, 'update_sources'
159
+ assert_equal true, @cfg.verbose, 'verbose'
160
+
161
+ assert_equal '--wrappers', @cfg[:install], 'install'
162
+
163
+ # this should be written out to the config file.
164
+ assert_equal %w[http://more-gems.example.com], Gem.sources
165
+ end
166
+
167
+ def test_write_from_hash
168
+ File.open @temp_conf, 'w' do |fp|
169
+ fp.puts ":backtrace: true"
170
+ fp.puts ":benchmark: true"
171
+ fp.puts ":bulk_threshold: 10"
172
+ fp.puts ":update_sources: false"
173
+ fp.puts ":verbose: false"
174
+ fp.puts ":sources:"
175
+ fp.puts " - http://more-gems.example.com"
176
+ fp.puts "install: --wrappers"
177
+ end
178
+
179
+ util_config_file
180
+
181
+ @cfg.backtrace = :junk
182
+ @cfg.benchmark = :junk
183
+ @cfg.update_sources = :junk
184
+ @cfg.bulk_threshold = 20
185
+ @cfg.verbose = :junk
186
+ Gem.sources.replace %w[http://even-more-gems.example.com]
187
+ @cfg[:install] = '--wrappers --no-rdoc'
188
+
189
+ @cfg.write
190
+
191
+ util_config_file
192
+
193
+ # These should not be written out to the config file
194
+ assert_equal true, @cfg.backtrace, 'backtrace'
195
+ assert_equal true, @cfg.benchmark, 'benchmark'
196
+ assert_equal 10, @cfg.bulk_threshold, 'bulk_threshold'
197
+ assert_equal false, @cfg.update_sources, 'update_sources'
198
+ assert_equal false, @cfg.verbose, 'verbose'
199
+
200
+ assert_equal '--wrappers --no-rdoc', @cfg[:install], 'install'
201
+
202
+ assert_equal %w[http://even-more-gems.example.com], Gem.sources
203
+ end
204
+
205
+ def util_config_file(args = @cfg_args)
206
+ @cfg = Gem::ConfigFile.new args
207
+ end
208
+
209
+ end
210
+