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,410 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/spec_fetcher'
3
+
4
+ class TestGemSpecFetcher < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @uri = URI.parse @gem_repo
10
+
11
+ util_setup_fake_fetcher
12
+
13
+ @a_pre = quick_gem 'a', '1.a'
14
+ @source_index.add_spec @pl1
15
+ @source_index.add_spec @a_pre
16
+
17
+ @specs = @source_index.gems.sort.map do |name, spec|
18
+ [spec.name, spec.version, spec.original_platform]
19
+ end.sort
20
+
21
+ @latest_specs = @source_index.latest_specs.sort.map do |spec|
22
+ [spec.name, spec.version, spec.original_platform]
23
+ end
24
+
25
+ @prerelease_specs = @source_index.prerelease_gems.sort.map do |name, spec|
26
+ [spec.name, spec.version, spec.original_platform]
27
+ end.sort
28
+
29
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
30
+ util_gzip(Marshal.dump(@specs))
31
+
32
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
33
+ util_gzip(Marshal.dump(@latest_specs))
34
+
35
+ @fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] =
36
+ util_gzip(Marshal.dump(@prerelease_specs))
37
+
38
+ @sf = Gem::SpecFetcher.new
39
+ end
40
+
41
+ def test_fetch_all
42
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
43
+ util_zip(Marshal.dump(@a1))
44
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
45
+ util_zip(Marshal.dump(@a2))
46
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
47
+ util_zip(Marshal.dump(@a_pre))
48
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a3a.spec_name}.rz"] =
49
+ util_zip(Marshal.dump(@a3a))
50
+
51
+ dep = Gem::Dependency.new 'a', 1
52
+
53
+ specs_and_sources = @sf.fetch dep, true
54
+
55
+ spec_names = specs_and_sources.map do |spec, source_uri|
56
+ [spec.full_name, source_uri]
57
+ end
58
+
59
+ expected = [[@a1.full_name, @gem_repo], [@a2.full_name, @gem_repo]]
60
+
61
+ assert_equal expected, spec_names
62
+
63
+ assert_same specs_and_sources.first.last, specs_and_sources.last.last
64
+ end
65
+
66
+ def test_fetch_latest
67
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
68
+ util_zip(Marshal.dump(@a1))
69
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
70
+ util_zip(Marshal.dump(@a2))
71
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
72
+ util_zip(Marshal.dump(@a_pre))
73
+
74
+ dep = Gem::Dependency.new 'a', 1
75
+ specs_and_sources = @sf.fetch dep
76
+
77
+ spec_names = specs_and_sources.map do |spec, source_uri|
78
+ [spec.full_name, source_uri]
79
+ end
80
+
81
+ assert_equal [[@a2.full_name, @gem_repo]], spec_names
82
+ end
83
+
84
+ def test_fetch_prerelease
85
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
86
+ util_zip(Marshal.dump(@a1))
87
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
88
+ util_zip(Marshal.dump(@a2))
89
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
90
+ util_zip(Marshal.dump(@a_pre))
91
+
92
+ dep = Gem::Dependency.new 'a', '1.a'
93
+ specs_and_sources = @sf.fetch dep, false, true, true
94
+
95
+ spec_names = specs_and_sources.map do |spec, source_uri|
96
+ [spec.full_name, source_uri]
97
+ end
98
+
99
+ assert_equal [[@a_pre.full_name, @gem_repo]], spec_names
100
+ end
101
+
102
+ def test_fetch_platform
103
+ util_set_arch 'i386-linux'
104
+
105
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
106
+ util_zip(Marshal.dump(@pl1))
107
+
108
+ dep = Gem::Dependency.new 'pl', 1
109
+ specs_and_sources = @sf.fetch dep
110
+
111
+ spec_names = specs_and_sources.map do |spec, source_uri|
112
+ [spec.full_name, source_uri]
113
+ end
114
+
115
+ assert_equal [[@pl1.full_name, @gem_repo]], spec_names
116
+ end
117
+
118
+ def test_fetch_with_errors_mismatched_platform
119
+ util_set_arch 'hrpa-989'
120
+
121
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
122
+ util_zip(Marshal.dump(@pl1))
123
+
124
+ dep = Gem::Dependency.new 'pl', 1
125
+ specs_and_sources, errors = @sf.fetch_with_errors dep
126
+
127
+ assert_equal 0, specs_and_sources.size
128
+ assert_equal 1, errors.size
129
+
130
+ assert_equal "i386-linux", errors[0].platforms.first
131
+ end
132
+
133
+ def test_fetch_spec
134
+ spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
135
+ @fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1))
136
+
137
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
138
+ assert_equal @a1.full_name, spec.full_name
139
+
140
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
141
+
142
+ cache_file = File.join cache_dir, @a1.spec_name
143
+
144
+ assert File.exist?(cache_file)
145
+ end
146
+
147
+ def test_fetch_spec_cached
148
+ spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
149
+ @fetcher.data["#{spec_uri}.rz"] = nil
150
+
151
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
152
+ FileUtils.mkdir_p cache_dir
153
+
154
+ cache_file = File.join cache_dir, @a1.spec_name
155
+
156
+ open cache_file, 'wb' do |io|
157
+ Marshal.dump @a1, io
158
+ end
159
+
160
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
161
+ assert_equal @a1.full_name, spec.full_name
162
+ end
163
+
164
+ def test_fetch_spec_platform
165
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
166
+ util_zip(Marshal.dump(@pl1))
167
+
168
+ spec = @sf.fetch_spec ['pl', Gem::Version.new(1), 'i386-linux'], @uri
169
+
170
+ assert_equal @pl1.full_name, spec.full_name
171
+ end
172
+
173
+ def test_fetch_spec_platform_ruby
174
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
175
+ util_zip(Marshal.dump(@a1))
176
+
177
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), nil], @uri
178
+ assert_equal @a1.full_name, spec.full_name
179
+
180
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), ''], @uri
181
+ assert_equal @a1.full_name, spec.full_name
182
+ end
183
+
184
+ def test_find_matching_all
185
+ dep = Gem::Dependency.new 'a', 1
186
+ specs = @sf.find_matching dep, true
187
+
188
+ expected = [
189
+ [['a', Gem::Version.new(1), Gem::Platform::RUBY], @gem_repo],
190
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
191
+ ]
192
+
193
+ assert_equal expected, specs
194
+ end
195
+
196
+ def test_find_matching_latest
197
+ dep = Gem::Dependency.new 'a', 1
198
+ specs = @sf.find_matching dep
199
+
200
+ expected = [
201
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
202
+ ]
203
+
204
+ assert_equal expected, specs
205
+ end
206
+
207
+ def test_find_matching_prerelease
208
+ dep = Gem::Dependency.new 'a', '1.a'
209
+ specs = @sf.find_matching dep, false, true, true
210
+
211
+ expected = [
212
+ [['a', Gem::Version.new('1.a'), Gem::Platform::RUBY], @gem_repo],
213
+ ]
214
+
215
+ assert_equal expected, specs
216
+ end
217
+
218
+ def test_find_matching_platform
219
+ util_set_arch 'i386-linux'
220
+
221
+ dep = Gem::Dependency.new 'pl', 1
222
+ specs = @sf.find_matching dep
223
+
224
+ expected = [
225
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
226
+ ]
227
+
228
+ assert_equal expected, specs
229
+
230
+ util_set_arch 'i386-freebsd6'
231
+
232
+ dep = Gem::Dependency.new 'pl', 1
233
+ specs = @sf.find_matching dep
234
+
235
+ assert_equal [], specs
236
+ end
237
+
238
+ def test_find_matching_with_errors_matched_platform
239
+ util_set_arch 'i386-linux'
240
+
241
+ dep = Gem::Dependency.new 'pl', 1
242
+ specs, errors = @sf.find_matching_with_errors dep
243
+
244
+ expected = [
245
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
246
+ ]
247
+
248
+ assert_equal expected, specs
249
+ assert_equal 0, errors.size
250
+ end
251
+
252
+ def test_find_matching_with_errors_invalid_platform
253
+ util_set_arch 'hrpa-899'
254
+
255
+ dep = Gem::Dependency.new 'pl', 1
256
+ specs, errors = @sf.find_matching_with_errors dep
257
+
258
+ assert_equal 0, specs.size
259
+
260
+ assert_equal 1, errors.size
261
+
262
+ assert_equal "i386-linux", errors[0].platforms.first
263
+ end
264
+
265
+ def test_find_all_platforms
266
+ util_set_arch 'i386-freebsd6'
267
+
268
+ dep = Gem::Dependency.new 'pl', 1
269
+ specs = @sf.find_matching dep, false, false
270
+
271
+ expected = [
272
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
273
+ ]
274
+
275
+ assert_equal expected, specs
276
+ end
277
+
278
+ def test_list
279
+ specs = @sf.list
280
+
281
+ assert_equal [@uri], specs.keys
282
+ assert_equal @latest_specs, specs[@uri].sort
283
+ end
284
+
285
+ def test_list_all
286
+ specs = @sf.list true
287
+
288
+ assert_equal [@uri], specs.keys
289
+
290
+ assert_equal([["a", Gem::Version.new("1"), "ruby"],
291
+ ["a", Gem::Version.new("2"), "ruby"],
292
+ ["a_evil", Gem::Version.new("9"), "ruby"],
293
+ ["c", Gem::Version.new("1.2"), "ruby"],
294
+ ["pl", Gem::Version.new("1"), "i386-linux"]],
295
+ specs[@uri].sort)
296
+ end
297
+
298
+ def test_list_cache
299
+ specs = @sf.list
300
+
301
+ refute specs[@uri].empty?
302
+
303
+ @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
304
+
305
+ cached_specs = @sf.list
306
+
307
+ assert_equal specs, cached_specs
308
+ end
309
+
310
+ def test_list_cache_all
311
+ specs = @sf.list true
312
+
313
+ refute specs[@uri].empty?
314
+
315
+ @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
316
+
317
+ cached_specs = @sf.list true
318
+
319
+ assert_equal specs, cached_specs
320
+ end
321
+
322
+ def test_list_latest_all
323
+ specs = @sf.list false
324
+
325
+ assert_equal [@latest_specs], specs.values
326
+
327
+ specs = @sf.list true
328
+
329
+ assert_equal([[["a", Gem::Version.new("1"), "ruby"],
330
+ ["a", Gem::Version.new("2"), "ruby"],
331
+ ["a_evil", Gem::Version.new("9"), "ruby"],
332
+ ["c", Gem::Version.new("1.2"), "ruby"],
333
+ ["pl", Gem::Version.new("1"), "i386-linux"]]],
334
+ specs.values, 'specs file not loaded')
335
+ end
336
+
337
+ def test_list_prerelease
338
+ specs = @sf.list false, true
339
+
340
+ assert_equal @prerelease_specs, specs[@uri].sort
341
+ end
342
+
343
+ def test_load_specs
344
+ specs = @sf.load_specs @uri, 'specs'
345
+
346
+ expected = [
347
+ ['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
348
+ ['a', Gem::Version.new(1), Gem::Platform::RUBY],
349
+ ['a', Gem::Version.new(2), Gem::Platform::RUBY],
350
+ ['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
351
+ ['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
352
+ ['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
353
+ ['pl', Gem::Version.new(1), 'i386-linux'],
354
+ ]
355
+
356
+ assert_equal expected, specs
357
+
358
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
359
+ assert File.exist?(cache_dir), "#{cache_dir} does not exist"
360
+
361
+ cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
362
+ assert File.exist?(cache_file)
363
+ end
364
+
365
+ def test_load_specs_cached
366
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
367
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
368
+ ' ' * Marshal.dump(@latest_specs).length
369
+
370
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
371
+
372
+ FileUtils.mkdir_p cache_dir
373
+
374
+ cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
375
+
376
+ open cache_file, 'wb' do |io|
377
+ Marshal.dump @latest_specs, io
378
+ end
379
+
380
+ latest_specs = @sf.load_specs @uri, 'latest_specs'
381
+
382
+ assert_equal @latest_specs, latest_specs
383
+ end
384
+
385
+ def test_load_specs_cached_empty
386
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
387
+ proc do
388
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
389
+ util_gzip(Marshal.dump(@latest_specs))
390
+
391
+ nil
392
+ end
393
+
394
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
395
+
396
+ FileUtils.mkdir_p cache_dir
397
+
398
+ cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
399
+
400
+ open cache_file, 'wb' do |io|
401
+ io.write Marshal.dump(@latest_specs)[0, 10]
402
+ end
403
+
404
+ latest_specs = @sf.load_specs @uri, 'latest_specs'
405
+
406
+ assert_equal @latest_specs, latest_specs
407
+ end
408
+
409
+ end
410
+
@@ -0,0 +1,1291 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'stringio'
3
+ require 'rubygems/specification'
4
+
5
+ class TestGemSpecification < RubyGemTestCase
6
+
7
+ LEGACY_YAML_SPEC = <<-EOF
8
+ --- !ruby/object:Gem::Specification
9
+ rubygems_version: "1.0"
10
+ name: keyedlist
11
+ version: !ruby/object:Gem::Version
12
+ version: 0.4.0
13
+ date: 2004-03-28 15:37:49.828000 +02:00
14
+ platform:
15
+ summary: A Hash which automatically computes keys.
16
+ require_paths:
17
+ - lib
18
+ files:
19
+ - lib/keyedlist.rb
20
+ autorequire: keyedlist
21
+ author: Florian Gross
22
+ email: flgr@ccan.de
23
+ has_rdoc: true
24
+ EOF
25
+
26
+ LEGACY_RUBY_SPEC = <<-EOF
27
+ Gem::Specification.new do |s|
28
+ s.name = %q{keyedlist}
29
+ s.version = %q{0.4.0}
30
+ s.has_rdoc = true
31
+ s.summary = %q{A Hash which automatically computes keys.}
32
+ s.files = ["lib/keyedlist.rb"]
33
+ s.require_paths = ["lib"]
34
+ s.autorequire = %q{keyedlist}
35
+ s.author = %q{Florian Gross}
36
+ s.email = %q{flgr@ccan.de}
37
+ end
38
+ EOF
39
+
40
+ def setup
41
+ super
42
+
43
+ @a1 = quick_gem 'a', '1' do |s|
44
+ s.executable = 'exec'
45
+ s.extensions << 'ext/a/extconf.rb'
46
+ s.has_rdoc = 'true'
47
+ s.test_file = 'test/suite.rb'
48
+ s.requirements << 'A working computer'
49
+ s.rubyforge_project = 'example'
50
+ s.license = 'MIT'
51
+
52
+ s.add_dependency 'rake', '> 0.4'
53
+ s.add_dependency 'jabber4r', '> 0.0.0'
54
+ s.add_dependency 'pqa', ['> 0.4', '<= 0.6']
55
+
56
+ s.mark_version
57
+ s.files = %w[lib/code.rb]
58
+ end
59
+
60
+ @a2 = quick_gem 'a', '2' do |s|
61
+ s.files = %w[lib/code.rb]
62
+ end
63
+
64
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
65
+ File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
66
+ fp.puts "#!#{Gem.ruby}"
67
+ end
68
+
69
+ @current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ end
71
+
72
+ def test_self_attribute_names
73
+ expected_value = %w[
74
+ authors
75
+ autorequire
76
+ bindir
77
+ cert_chain
78
+ date
79
+ default_executable
80
+ dependencies
81
+ description
82
+ email
83
+ executables
84
+ extensions
85
+ extra_rdoc_files
86
+ files
87
+ has_rdoc
88
+ homepage
89
+ licenses
90
+ name
91
+ platform
92
+ post_install_message
93
+ rdoc_options
94
+ require_paths
95
+ required_ruby_version
96
+ required_rubygems_version
97
+ requirements
98
+ rubyforge_project
99
+ rubygems_version
100
+ signing_key
101
+ specification_version
102
+ summary
103
+ test_files
104
+ version
105
+ ]
106
+
107
+ actual_value = Gem::Specification.attribute_names.map { |a| a.to_s }.sort
108
+
109
+ assert_equal expected_value, actual_value
110
+ end
111
+
112
+ def test_self__load_future
113
+ spec = Gem::Specification.new
114
+ spec.name = 'a'
115
+ spec.version = '1'
116
+ spec.specification_version = @current_version + 1
117
+
118
+ new_spec = Marshal.load Marshal.dump(spec)
119
+
120
+ assert_equal 'a', new_spec.name
121
+ assert_equal Gem::Version.new(1), new_spec.version
122
+ assert_equal @current_version, new_spec.specification_version
123
+ end
124
+
125
+ def test_self_load
126
+ spec = File.join @gemhome, 'specifications', @a2.spec_name
127
+ gs = Gem::Specification.load spec
128
+
129
+ assert_equal @a2, gs
130
+ end
131
+
132
+ def test_self_load_legacy_ruby
133
+ spec = eval LEGACY_RUBY_SPEC
134
+ assert_equal 'keyedlist', spec.name
135
+ assert_equal '0.4.0', spec.version.to_s
136
+ assert_equal true, spec.has_rdoc?
137
+ assert_equal Gem::Specification::TODAY, spec.date
138
+ assert spec.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
139
+ assert_equal false, spec.has_unit_tests?
140
+ end
141
+
142
+ def test_self_normalize_yaml_input_with_183_yaml
143
+ input = "!ruby/object:Gem::Specification "
144
+ assert_equal "--- #{input}", Gem::Specification.normalize_yaml_input(input)
145
+ end
146
+
147
+ def test_self_normalize_yaml_input_with_non_183_yaml
148
+ input = "--- !ruby/object:Gem::Specification "
149
+ assert_equal input, Gem::Specification.normalize_yaml_input(input)
150
+ end
151
+
152
+ def test_self_normalize_yaml_input_with_183_io
153
+ input = "!ruby/object:Gem::Specification "
154
+ assert_equal "--- #{input}",
155
+ Gem::Specification.normalize_yaml_input(StringIO.new(input))
156
+ end
157
+
158
+ def test_self_normalize_yaml_input_with_non_183_io
159
+ input = "--- !ruby/object:Gem::Specification "
160
+ assert_equal input,
161
+ Gem::Specification.normalize_yaml_input(StringIO.new(input))
162
+ end
163
+
164
+ def test_self_normalize_yaml_input_with_192_yaml
165
+ input = "--- !ruby/object:Gem::Specification \nblah: !!null \n"
166
+ expected = "--- !ruby/object:Gem::Specification \nblah: \n"
167
+
168
+ assert_equal expected, Gem::Specification.normalize_yaml_input(input)
169
+ end
170
+
171
+ def test_initialize
172
+ spec = Gem::Specification.new do |s|
173
+ s.name = "blah"
174
+ s.version = "1.3.5"
175
+ end
176
+
177
+ assert_equal "blah", spec.name
178
+ assert_equal "1.3.5", spec.version.to_s
179
+ assert_equal Gem::Platform::RUBY, spec.platform
180
+ assert_equal nil, spec.summary
181
+ assert_equal [], spec.files
182
+
183
+ assert_equal [], spec.test_files
184
+ assert_equal [], spec.rdoc_options
185
+ assert_equal [], spec.extra_rdoc_files
186
+ assert_equal [], spec.executables
187
+ assert_equal [], spec.extensions
188
+ assert_equal [], spec.requirements
189
+ assert_equal [], spec.dependencies
190
+ assert_equal 'bin', spec.bindir
191
+ assert_equal true, spec.has_rdoc
192
+ assert_equal true, spec.has_rdoc?
193
+ assert_equal '>= 0', spec.required_ruby_version.to_s
194
+ assert_equal '>= 0', spec.required_rubygems_version.to_s
195
+ end
196
+
197
+ def test_initialize_future
198
+ version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + 1
199
+ spec = Gem::Specification.new do |s|
200
+ s.name = "blah"
201
+ s.version = "1.3.5"
202
+
203
+ s.specification_version = version
204
+
205
+ s.new_unknown_attribute = "a value"
206
+ end
207
+
208
+ assert_equal "blah", spec.name
209
+ assert_equal "1.3.5", spec.version.to_s
210
+ end
211
+
212
+ def test_initialize_copy
213
+ spec = Gem::Specification.new do |s|
214
+ s.name = "blah"
215
+ s.version = "1.3.5"
216
+ s.summary = 'summary'
217
+ s.description = 'description'
218
+ s.authors = 'author a', 'author b'
219
+ s.licenses = 'BSD'
220
+ s.files = 'lib/file.rb'
221
+ s.test_files = 'test/file.rb'
222
+ s.rdoc_options = '--foo'
223
+ s.extra_rdoc_files = 'README.txt'
224
+ s.executables = 'exec'
225
+ s.extensions = 'ext/extconf.rb'
226
+ s.requirements = 'requirement'
227
+ s.add_dependency 'some_gem'
228
+ end
229
+
230
+ new_spec = spec.dup
231
+
232
+ assert_equal "blah", spec.name
233
+ assert_same spec.name, new_spec.name
234
+
235
+ assert_equal "1.3.5", spec.version.to_s
236
+ assert_same spec.version, new_spec.version
237
+
238
+ assert_equal Gem::Platform::RUBY, spec.platform
239
+ assert_same spec.platform, new_spec.platform
240
+
241
+ assert_equal 'summary', spec.summary
242
+ assert_same spec.summary, new_spec.summary
243
+
244
+ assert_equal %w[lib/file.rb test/file.rb bin/exec README.txt
245
+ ext/extconf.rb],
246
+ spec.files
247
+ refute_same spec.files, new_spec.files, 'files'
248
+
249
+ assert_equal %w[test/file.rb], spec.test_files
250
+ refute_same spec.test_files, new_spec.test_files, 'test_files'
251
+
252
+ assert_equal %w[--foo], spec.rdoc_options
253
+ refute_same spec.rdoc_options, new_spec.rdoc_options, 'rdoc_options'
254
+
255
+ assert_equal %w[README.txt], spec.extra_rdoc_files
256
+ refute_same spec.extra_rdoc_files, new_spec.extra_rdoc_files,
257
+ 'extra_rdoc_files'
258
+
259
+ assert_equal %w[exec], spec.executables
260
+ refute_same spec.executables, new_spec.executables, 'executables'
261
+
262
+ assert_equal %w[ext/extconf.rb], spec.extensions
263
+ refute_same spec.extensions, new_spec.extensions, 'extensions'
264
+
265
+ assert_equal %w[requirement], spec.requirements
266
+ refute_same spec.requirements, new_spec.requirements, 'requirements'
267
+
268
+ assert_equal [Gem::Dependency.new('some_gem', Gem::Requirement.default)],
269
+ spec.dependencies
270
+ refute_same spec.dependencies, new_spec.dependencies, 'dependencies'
271
+
272
+ assert_equal 'bin', spec.bindir
273
+ assert_same spec.bindir, new_spec.bindir
274
+
275
+ assert_equal true, spec.has_rdoc
276
+ assert_same spec.has_rdoc, new_spec.has_rdoc
277
+
278
+ assert_equal '>= 0', spec.required_ruby_version.to_s
279
+ assert_same spec.required_ruby_version, new_spec.required_ruby_version
280
+
281
+ assert_equal '>= 0', spec.required_rubygems_version.to_s
282
+ assert_same spec.required_rubygems_version,
283
+ new_spec.required_rubygems_version
284
+ end
285
+
286
+ def test__dump
287
+ @a2.platform = Gem::Platform.local
288
+ @a2.instance_variable_set :@original_platform, 'old_platform'
289
+
290
+ data = Marshal.dump @a2
291
+
292
+ same_spec = Marshal.load data
293
+
294
+ assert_equal 'old_platform', same_spec.original_platform
295
+ end
296
+
297
+ def test_add_dependency_with_explicit_type
298
+ gem = quick_gem "awesome", "1.0" do |awesome|
299
+ awesome.add_development_dependency "monkey"
300
+ end
301
+
302
+ monkey = gem.dependencies.detect { |d| d.name == "monkey" }
303
+ assert_equal(:development, monkey.type)
304
+ end
305
+
306
+ def test_author
307
+ assert_equal 'A User', @a1.author
308
+ end
309
+
310
+ def test_authors
311
+ assert_equal ['A User'], @a1.authors
312
+ end
313
+
314
+ def test_bindir_equals
315
+ @a1.bindir = 'apps'
316
+
317
+ assert_equal 'apps', @a1.bindir
318
+ end
319
+
320
+ def test_bindir_equals_nil
321
+ @a2.bindir = nil
322
+ @a2.executable = 'app'
323
+
324
+ assert_equal nil, @a2.bindir
325
+ assert_equal %w[lib/code.rb app], @a2.files
326
+ end
327
+
328
+ def test_date
329
+ assert_equal Gem::Specification::TODAY, @a1.date
330
+ end
331
+
332
+ def test_date_equals_date
333
+ @a1.date = Date.new(2003, 9, 17)
334
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
335
+ end
336
+
337
+ def test_date_equals_string
338
+ @a1.date = '2003-09-17'
339
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
340
+ end
341
+
342
+ def test_date_equals_time
343
+ @a1.date = Time.local(2003, 9, 17, 0,0,0)
344
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
345
+ end
346
+
347
+ def test_date_equals_time_local
348
+ # HACK PDT
349
+ @a1.date = Time.local(2003, 9, 17, 19,50,0)
350
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
351
+ end
352
+
353
+ def test_date_equals_time_utc
354
+ # HACK PDT
355
+ @a1.date = Time.local(2003, 9, 17, 19,50,0)
356
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
357
+ end
358
+
359
+ def test_default_executable
360
+ assert_equal 'exec', @a1.default_executable
361
+
362
+ @a1.default_executable = nil
363
+ @a1.instance_variable_set :@executables, nil
364
+ assert_equal nil, @a1.default_executable
365
+ end
366
+
367
+ def test_dependencies
368
+ rake = Gem::Dependency.new 'rake', '> 0.4'
369
+ jabber = Gem::Dependency.new 'jabber4r', '> 0.0.0'
370
+ pqa = Gem::Dependency.new 'pqa', ['> 0.4', '<= 0.6']
371
+
372
+ assert_equal [rake, jabber, pqa], @a1.dependencies
373
+ end
374
+
375
+ def test_dependencies_scoped_by_type
376
+ gem = quick_gem "awesome", "1.0" do |awesome|
377
+ awesome.add_runtime_dependency "bonobo", []
378
+ awesome.add_development_dependency "monkey", []
379
+ end
380
+
381
+ bonobo = Gem::Dependency.new("bonobo", [])
382
+ monkey = Gem::Dependency.new("monkey", [], :development)
383
+
384
+ assert_equal([bonobo, monkey], gem.dependencies)
385
+ assert_equal([bonobo], gem.runtime_dependencies)
386
+ assert_equal([monkey], gem.development_dependencies)
387
+ end
388
+
389
+ def test_description
390
+ assert_equal 'This is a test description', @a1.description
391
+ end
392
+
393
+ def test_eql_eh
394
+ g1 = quick_gem 'gem'
395
+ g2 = quick_gem 'gem'
396
+
397
+ assert_equal g1, g2
398
+ assert_equal g1.hash, g2.hash
399
+ assert_equal true, g1.eql?(g2)
400
+ end
401
+
402
+ def test_equals2
403
+ assert_equal @a1, @a1
404
+ assert_equal @a1, @a1.dup
405
+ refute_equal @a1, @a2
406
+ refute_equal @a1, Object.new
407
+ end
408
+
409
+ # The cgikit specification was reported to be causing trouble in at least
410
+ # one version of SlimGems, so we test explicitly for it.
411
+ def test_equals2_cgikit
412
+ cgikit = Gem::Specification.new do |s|
413
+ s.name = %q{cgikit}
414
+ s.version = "1.1.0"
415
+ s.date = %q{2004-03-13}
416
+ s.summary = %q{CGIKit is a componented-oriented web application } +
417
+ %q{framework like Apple Computers WebObjects. } +
418
+ %{This framework services Model-View-Controller architecture } +
419
+ %q{programming by components based on a HTML file, a definition } +
420
+ %q{file and a Ruby source. }
421
+ s.email = %q{info@spice-of-life.net}
422
+ s.homepage = %q{http://www.spice-of-life.net/download/cgikit/}
423
+ s.autorequire = %q{cgikit}
424
+ s.bindir = nil
425
+ s.has_rdoc = true
426
+ s.required_ruby_version = nil
427
+ s.platform = nil
428
+ s.files = ["lib/cgikit", "lib/cgikit.rb", "lib/cgikit/components", "..."]
429
+ end
430
+
431
+ assert_equal cgikit, cgikit
432
+ end
433
+
434
+ def test_equals2_default_executable
435
+ spec = @a1.dup
436
+ spec.default_executable = 'xx'
437
+
438
+ refute_equal @a1, spec
439
+ refute_equal spec, @a1
440
+ end
441
+
442
+ def test_equals2_extensions
443
+ spec = @a1.dup
444
+ spec.extensions = 'xx'
445
+
446
+ refute_equal @a1, spec
447
+ refute_equal spec, @a1
448
+ end
449
+
450
+ def test_executables
451
+ @a1.executable = 'app'
452
+ assert_equal %w[app], @a1.executables
453
+ end
454
+
455
+ def test_executable_equals
456
+ @a2.executable = 'app'
457
+ assert_equal 'app', @a2.executable
458
+ assert_equal %w[lib/code.rb bin/app], @a2.files
459
+ end
460
+
461
+ def test_extensions
462
+ assert_equal ['ext/a/extconf.rb'], @a1.extensions
463
+ end
464
+
465
+ def test_files
466
+ @a1.files = %w(files bin/common)
467
+ @a1.test_files = %w(test_files bin/common)
468
+ @a1.executables = %w(executables common)
469
+ @a1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
470
+ @a1.extensions = %w(extensions bin/common)
471
+
472
+ expected = %w[
473
+ bin/common
474
+ bin/executables
475
+ extensions
476
+ extra_rdoc_files
477
+ files
478
+ test_files
479
+ ]
480
+ assert_equal expected, @a1.files.sort
481
+ end
482
+
483
+ def test_files_append
484
+ @a1.files = %w(files bin/common)
485
+ @a1.test_files = %w(test_files bin/common)
486
+ @a1.executables = %w(executables common)
487
+ @a1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
488
+ @a1.extensions = %w(extensions bin/common)
489
+
490
+ expected = %w[
491
+ bin/common
492
+ bin/executables
493
+ extensions
494
+ extra_rdoc_files
495
+ files
496
+ test_files
497
+ ]
498
+ assert_equal expected, @a1.files.sort
499
+
500
+ @a1.files << "generated_file.c"
501
+
502
+ expected << "generated_file.c"
503
+ expected.sort!
504
+
505
+ assert_equal expected, @a1.files.sort
506
+ end
507
+
508
+ def test_files_duplicate
509
+ @a2.files = %w[a b c d b]
510
+ @a2.extra_rdoc_files = %w[x y z x]
511
+ @a2.normalize
512
+
513
+ assert_equal %w[a b c d x y z], @a2.files
514
+ assert_equal %w[x y z], @a2.extra_rdoc_files
515
+ end
516
+
517
+ def test_files_extra_rdoc_files
518
+ @a2.files = %w[a b c d]
519
+ @a2.extra_rdoc_files = %w[x y z]
520
+ @a2.normalize
521
+ assert_equal %w[a b c d x y z], @a2.files
522
+ end
523
+
524
+ def test_files_non_array
525
+ @a1.files = "F"
526
+ @a1.test_files = "TF"
527
+ @a1.executables = "X"
528
+ @a1.extra_rdoc_files = "ERF"
529
+ @a1.extensions = "E"
530
+
531
+ assert_equal %w[E ERF F TF bin/X], @a1.files.sort
532
+ end
533
+
534
+ def test_files_non_array_pathological
535
+ @a1.instance_variable_set :@files, "F"
536
+ @a1.instance_variable_set :@test_files, "TF"
537
+ @a1.instance_variable_set :@extra_rdoc_files, "ERF"
538
+ @a1.instance_variable_set :@extensions, "E"
539
+ @a1.instance_variable_set :@executables, "X"
540
+
541
+ assert_equal %w[E ERF F TF bin/X], @a1.files.sort
542
+ assert_kind_of Integer, @a1.hash
543
+ end
544
+
545
+ def test_full_gem_path
546
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name),
547
+ @a1.full_gem_path
548
+
549
+ @a1.original_platform = 'mswin32'
550
+
551
+ assert_equal File.join(@gemhome, 'gems', @a1.original_name),
552
+ @a1.full_gem_path
553
+ end
554
+
555
+ def test_full_gem_path_double_slash
556
+ gemhome = @gemhome.sub(/\w\//, '\&/')
557
+ @a1.loaded_from = File.join gemhome, 'specifications', @a1.spec_name
558
+
559
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name),
560
+ @a1.full_gem_path
561
+ end
562
+
563
+ def test_full_name
564
+ assert_equal 'a-1', @a1.full_name
565
+
566
+ @a1.platform = Gem::Platform.new ['universal', 'darwin', nil]
567
+ assert_equal 'a-1-universal-darwin', @a1.full_name
568
+
569
+ @a1.instance_variable_set :@new_platform, 'mswin32'
570
+ assert_equal 'a-1-mswin32', @a1.full_name, 'legacy'
571
+
572
+ return if win_platform?
573
+
574
+ @a1.platform = 'current'
575
+ assert_equal 'a-1-x86-darwin-8', @a1.full_name
576
+ end
577
+
578
+ def test_full_name_windows
579
+ test_cases = {
580
+ 'i386-mswin32' => 'a-1-x86-mswin32-60',
581
+ 'i386-mswin32_80' => 'a-1-x86-mswin32-80',
582
+ 'i386-mingw32' => 'a-1-x86-mingw32'
583
+ }
584
+
585
+ test_cases.each do |arch, expected|
586
+ util_set_arch arch
587
+ @a1.platform = 'current'
588
+ assert_equal expected, @a1.full_name
589
+ end
590
+ end
591
+
592
+ def test_has_rdoc_eh
593
+ assert @a1.has_rdoc?
594
+ end
595
+
596
+ def test_has_rdoc_equals
597
+
598
+ use_ui @ui do
599
+ @a1.has_rdoc = false
600
+ end
601
+
602
+ assert_equal '', @ui.output
603
+
604
+ assert_equal false, @a1.has_rdoc
605
+ end
606
+
607
+ def test_hash
608
+ assert_equal @a1.hash, @a1.hash
609
+ assert_equal @a1.hash, @a1.dup.hash
610
+ refute_equal @a1.hash, @a2.hash
611
+ end
612
+
613
+ def test_installation_path
614
+ assert_equal @gemhome, @a1.installation_path
615
+
616
+ @a1.instance_variable_set :@loaded_from, nil
617
+
618
+ e = assert_raises Gem::Exception do
619
+ @a1.installation_path
620
+ end
621
+
622
+ assert_equal 'spec a-1 is not from an installed gem', e.message
623
+ end
624
+
625
+ def test_lib_files
626
+ @a1.files = %w[lib/foo.rb Rakefile]
627
+
628
+ assert_equal %w[lib/foo.rb], @a1.lib_files
629
+ end
630
+
631
+ def test_license
632
+ assert_equal 'MIT', @a1.license
633
+ end
634
+
635
+ def test_licenses
636
+ assert_equal ['MIT'], @a1.licenses
637
+ end
638
+
639
+ def test_name
640
+ assert_equal 'a', @a1.name
641
+ end
642
+
643
+ def test_original_name
644
+ assert_equal 'a-1', @a1.full_name
645
+
646
+ @a1.platform = 'i386-linux'
647
+ @a1.instance_variable_set :@original_platform, 'i386-linux'
648
+ assert_equal 'a-1-i386-linux', @a1.original_name
649
+ end
650
+
651
+ def test_platform
652
+ assert_equal Gem::Platform::RUBY, @a1.platform
653
+ end
654
+
655
+ def test_platform_equals
656
+ @a1.platform = nil
657
+ assert_equal Gem::Platform::RUBY, @a1.platform
658
+
659
+ @a1.platform = Gem::Platform::RUBY
660
+ assert_equal Gem::Platform::RUBY, @a1.platform
661
+
662
+ test_cases = {
663
+ 'i386-mswin32' => ['x86', 'mswin32', '60'],
664
+ 'i386-mswin32_80' => ['x86', 'mswin32', '80'],
665
+ 'i386-mingw32' => ['x86', 'mingw32', nil ],
666
+ 'x86-darwin8' => ['x86', 'darwin', '8' ],
667
+ }
668
+
669
+ test_cases.each do |arch, expected|
670
+ util_set_arch arch
671
+ @a1.platform = Gem::Platform::CURRENT
672
+ assert_equal Gem::Platform.new(expected), @a1.platform
673
+ end
674
+ end
675
+
676
+ def test_platform_equals_current
677
+ @a1.platform = Gem::Platform::CURRENT
678
+ assert_equal Gem::Platform.local, @a1.platform
679
+ assert_equal Gem::Platform.local.to_s, @a1.original_platform
680
+ end
681
+
682
+ def test_platform_equals_legacy
683
+ @a1.platform = 'mswin32'
684
+ assert_equal Gem::Platform.new('x86-mswin32'), @a1.platform
685
+
686
+ @a1.platform = 'i586-linux'
687
+ assert_equal Gem::Platform.new('x86-linux'), @a1.platform
688
+
689
+ @a1.platform = 'powerpc-darwin'
690
+ assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform
691
+ end
692
+
693
+ def test_prerelease_spec_adds_required_rubygems_version
694
+ @prerelease = quick_gem('tardis', '2.2.0.a')
695
+ refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1'))
696
+ assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0'))
697
+ end
698
+
699
+ def test_require_paths
700
+ @a1.require_path = 'lib'
701
+ assert_equal %w[lib], @a1.require_paths
702
+ end
703
+
704
+ def test_requirements
705
+ assert_equal ['A working computer'], @a1.requirements
706
+ end
707
+
708
+ def test_runtime_dependencies_legacy
709
+ # legacy gems don't have a type
710
+ @a1.runtime_dependencies.each do |dep|
711
+ dep.instance_variable_set :@type, nil
712
+ end
713
+
714
+ expected = %w[rake jabber4r pqa]
715
+
716
+ assert_equal expected, @a1.runtime_dependencies.map { |d| d.name }
717
+ end
718
+
719
+ def test_spaceship_name
720
+ s1 = quick_gem 'a', '1'
721
+ s2 = quick_gem 'b', '1'
722
+
723
+ assert_equal(-1, (s1 <=> s2))
724
+ assert_equal( 0, (s1 <=> s1))
725
+ assert_equal( 1, (s2 <=> s1))
726
+ end
727
+
728
+ def test_spaceship_platform
729
+ s1 = quick_gem 'a', '1'
730
+ s2 = quick_gem 'a', '1' do |s|
731
+ s.platform = Gem::Platform.new 'x86-my_platform1'
732
+ end
733
+
734
+ assert_equal( -1, (s1 <=> s2))
735
+ assert_equal( 0, (s1 <=> s1))
736
+ assert_equal( 1, (s2 <=> s1))
737
+ end
738
+
739
+ def test_spaceship_version
740
+ s1 = quick_gem 'a', '1'
741
+ s2 = quick_gem 'a', '2'
742
+
743
+ assert_equal( -1, (s1 <=> s2))
744
+ assert_equal( 0, (s1 <=> s1))
745
+ assert_equal( 1, (s2 <=> s1))
746
+ end
747
+
748
+ def test_spec_name
749
+ assert_equal 'a-1.gemspec', @a1.spec_name
750
+ end
751
+
752
+ def test_summary
753
+ assert_equal 'this is a summary', @a1.summary
754
+ end
755
+
756
+ def test_test_files
757
+ @a1.test_file = 'test/suite.rb'
758
+ assert_equal ['test/suite.rb'], @a1.test_files
759
+ end
760
+
761
+ def test_to_ruby
762
+ @a2.add_runtime_dependency 'b', '1'
763
+ @a2.dependencies.first.instance_variable_set :@type, nil
764
+ @a2.required_rubygems_version = Gem::Requirement.new '> 0'
765
+
766
+ ruby_code = @a2.to_ruby
767
+
768
+ expected = <<-SPEC
769
+ # -*- encoding: utf-8 -*-
770
+
771
+ Gem::Specification.new do |s|
772
+ s.name = %q{a}
773
+ s.version = \"2\"
774
+
775
+ s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
776
+ s.authors = [\"A User\"]
777
+ s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
778
+ s.description = %q{This is a test description}
779
+ s.email = %q{example@example.com}
780
+ s.files = [\"lib/code.rb\"]
781
+ s.homepage = %q{http://example.com}
782
+ s.require_paths = [\"lib\"]
783
+ s.rubygems_version = %q{#{Gem::VERSION}}
784
+ s.summary = %q{this is a summary}
785
+
786
+ if s.respond_to? :specification_version then
787
+ s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
788
+
789
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
790
+ s.add_runtime_dependency(%q<b>, [\"= 1\"])
791
+ else
792
+ s.add_dependency(%q<b>, [\"= 1\"])
793
+ end
794
+ else
795
+ s.add_dependency(%q<b>, [\"= 1\"])
796
+ end
797
+ end
798
+ SPEC
799
+
800
+ assert_equal expected, ruby_code
801
+
802
+ same_spec = eval ruby_code
803
+
804
+ assert_equal @a2, same_spec
805
+ end
806
+
807
+ def test_to_ruby_fancy
808
+ @a1.platform = Gem::Platform.local
809
+ ruby_code = @a1.to_ruby
810
+
811
+ local = Gem::Platform.local
812
+ expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
813
+
814
+ expected = <<-SPEC
815
+ # -*- encoding: utf-8 -*-
816
+
817
+ Gem::Specification.new do |s|
818
+ s.name = %q{a}
819
+ s.version = \"1\"
820
+ s.platform = Gem::Platform.new(#{expected_platform})
821
+
822
+ s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
823
+ s.authors = [\"A User\"]
824
+ s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
825
+ s.default_executable = %q{exec}
826
+ s.description = %q{This is a test description}
827
+ s.email = %q{example@example.com}
828
+ s.executables = [\"exec\"]
829
+ s.extensions = [\"ext/a/extconf.rb\"]
830
+ s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
831
+ s.has_rdoc = %q{true}
832
+ s.homepage = %q{http://example.com}
833
+ s.licenses = [\"MIT\"]
834
+ s.require_paths = [\"lib\"]
835
+ s.requirements = [\"A working computer\"]
836
+ s.rubyforge_project = %q{example}
837
+ s.rubygems_version = %q{#{Gem::VERSION}}
838
+ s.summary = %q{this is a summary}
839
+ s.test_files = [\"test/suite.rb\"]
840
+
841
+ if s.respond_to? :specification_version then
842
+ s.specification_version = 3
843
+
844
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
845
+ s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
846
+ s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
847
+ s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
848
+ else
849
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
850
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
851
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
852
+ end
853
+ else
854
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
855
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
856
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
857
+ end
858
+ end
859
+ SPEC
860
+
861
+ assert_equal expected, ruby_code
862
+
863
+ same_spec = eval ruby_code
864
+
865
+ assert_equal @a1, same_spec
866
+ end
867
+
868
+ def test_to_ruby_legacy
869
+ gemspec1 = eval LEGACY_RUBY_SPEC
870
+ ruby_code = gemspec1.to_ruby
871
+ gemspec2 = eval ruby_code
872
+
873
+ assert_equal gemspec1, gemspec2
874
+ end
875
+
876
+ def test_to_ruby_platform
877
+ @a2.platform = Gem::Platform.local
878
+ @a2.instance_variable_set :@original_platform, 'old_platform'
879
+
880
+ ruby_code = @a2.to_ruby
881
+
882
+ same_spec = eval ruby_code
883
+
884
+ assert_equal 'old_platform', same_spec.original_platform
885
+ end
886
+
887
+ def test_to_yaml
888
+ yaml_str = @a1.to_yaml
889
+
890
+ refute_match '!!null', yaml_str
891
+
892
+ same_spec = YAML.load(yaml_str)
893
+
894
+ assert_equal @a1, same_spec
895
+ end
896
+
897
+ def test_to_yaml_fancy
898
+ @a1.platform = Gem::Platform.local
899
+ yaml_str = @a1.to_yaml
900
+
901
+ same_spec = YAML.load(yaml_str)
902
+
903
+ assert_equal Gem::Platform.local, same_spec.platform
904
+
905
+ assert_equal @a1, same_spec
906
+ end
907
+
908
+ def test_to_yaml_platform_empty_string
909
+ @a1.instance_variable_set :@original_platform, ''
910
+
911
+ assert_match %r|^platform: ruby$|, @a1.to_yaml
912
+ end
913
+
914
+ def test_to_yaml_platform_legacy
915
+ @a1.platform = 'powerpc-darwin7.9.0'
916
+ @a1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0'
917
+
918
+ yaml_str = @a1.to_yaml
919
+
920
+ same_spec = YAML.load yaml_str
921
+
922
+ assert_equal Gem::Platform.new('powerpc-darwin7'), same_spec.platform
923
+ assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform
924
+ end
925
+
926
+ def test_to_yaml_platform_nil
927
+ @a1.instance_variable_set :@original_platform, nil
928
+
929
+ assert_match %r|^platform: ruby$|, @a1.to_yaml
930
+ end
931
+
932
+ def test_validate
933
+ util_setup_validate
934
+
935
+ Dir.chdir @tempdir do
936
+ assert @a1.validate
937
+ end
938
+ end
939
+
940
+ def test_validate_authors
941
+ util_setup_validate
942
+
943
+ Dir.chdir @tempdir do
944
+ @a1.authors = []
945
+
946
+ use_ui @ui do
947
+ @a1.validate
948
+ end
949
+
950
+ assert_equal "WARNING: no author specified\n", @ui.error, 'error'
951
+
952
+ @a1.authors = [Object.new]
953
+
954
+ e = assert_raises Gem::InvalidSpecificationException do
955
+ @a1.validate
956
+ end
957
+
958
+ assert_equal 'authors must be Array of Strings', e.message
959
+
960
+ @a1.authors = ['FIXME (who is writing this software)']
961
+
962
+ e = assert_raises Gem::InvalidSpecificationException do
963
+ @a1.validate
964
+ end
965
+
966
+ assert_equal '"FIXME" or "TODO" is not an author', e.message
967
+
968
+ @a1.authors = ['TODO (who is writing this software)']
969
+
970
+ e = assert_raises Gem::InvalidSpecificationException do
971
+ @a1.validate
972
+ end
973
+
974
+ assert_equal '"FIXME" or "TODO" is not an author', e.message
975
+ end
976
+ end
977
+
978
+ def test_validate_autorequire
979
+ util_setup_validate
980
+
981
+ Dir.chdir @tempdir do
982
+ @a1.autorequire = 'code'
983
+
984
+ use_ui @ui do
985
+ @a1.validate
986
+ end
987
+
988
+ assert_equal "WARNING: deprecated autorequire specified\n",
989
+ @ui.error, 'error'
990
+ end
991
+ end
992
+
993
+ def test_validate_description
994
+ util_setup_validate
995
+
996
+ Dir.chdir @tempdir do
997
+ @a1.description = ''
998
+
999
+ use_ui @ui do
1000
+ @a1.validate
1001
+ end
1002
+
1003
+ assert_equal "WARNING: no description specified\n", @ui.error, 'error'
1004
+
1005
+ @ui = MockGemUi.new
1006
+ @a1.summary = 'this is my summary'
1007
+ @a1.description = @a1.summary
1008
+
1009
+ use_ui @ui do
1010
+ @a1.validate
1011
+ end
1012
+
1013
+ assert_equal "WARNING: description and summary are identical\n",
1014
+ @ui.error, 'error'
1015
+
1016
+ @a1.description = 'FIXME (describe your package)'
1017
+
1018
+ e = assert_raises Gem::InvalidSpecificationException do
1019
+ @a1.validate
1020
+ end
1021
+
1022
+ assert_equal '"FIXME" or "TODO" is not a description', e.message
1023
+
1024
+ @a1.description = 'TODO (describe your package)'
1025
+
1026
+ e = assert_raises Gem::InvalidSpecificationException do
1027
+ @a1.validate
1028
+ end
1029
+
1030
+ assert_equal '"FIXME" or "TODO" is not a description', e.message
1031
+ end
1032
+ end
1033
+
1034
+ def test_validate_email
1035
+ util_setup_validate
1036
+
1037
+ Dir.chdir @tempdir do
1038
+ @a1.email = ''
1039
+
1040
+ use_ui @ui do
1041
+ @a1.validate
1042
+ end
1043
+
1044
+ assert_equal "WARNING: no email specified\n", @ui.error, 'error'
1045
+
1046
+ @a1.email = 'FIXME (your e-mail)'
1047
+
1048
+ e = assert_raises Gem::InvalidSpecificationException do
1049
+ @a1.validate
1050
+ end
1051
+
1052
+ assert_equal '"FIXME" or "TODO" is not an email address', e.message
1053
+
1054
+ @a1.email = 'TODO (your e-mail)'
1055
+
1056
+ e = assert_raises Gem::InvalidSpecificationException do
1057
+ @a1.validate
1058
+ end
1059
+
1060
+ assert_equal '"FIXME" or "TODO" is not an email address', e.message
1061
+ end
1062
+ end
1063
+
1064
+ def test_validate_empty
1065
+ util_setup_validate
1066
+
1067
+ e = assert_raises Gem::InvalidSpecificationException do
1068
+ Gem::Specification.new.validate
1069
+ end
1070
+
1071
+ assert_equal 'missing value for attribute name', e.message
1072
+ end
1073
+
1074
+ def test_validate_executables
1075
+ util_setup_validate
1076
+
1077
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
1078
+ File.open File.join(@tempdir, 'bin', 'exec'), 'w' do end
1079
+ FileUtils.mkdir_p File.join(@tempdir, 'exec')
1080
+
1081
+ use_ui @ui do
1082
+ Dir.chdir @tempdir do
1083
+ assert @a1.validate
1084
+ end
1085
+ end
1086
+
1087
+ assert_equal %w[exec], @a1.executables
1088
+
1089
+ assert_equal '', @ui.output, 'output'
1090
+ assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error'
1091
+ end
1092
+
1093
+ def test_validate_empty_require_paths
1094
+ if win_platform? then
1095
+ skip 'test_validate_empty_require_paths skipped on MS Windows (symlink)'
1096
+ else
1097
+ util_setup_validate
1098
+
1099
+ @a1.require_paths = []
1100
+ e = assert_raises Gem::InvalidSpecificationException do
1101
+ @a1.validate
1102
+ end
1103
+
1104
+ assert_equal 'specification must have at least one require_path',
1105
+ e.message
1106
+ end
1107
+ end
1108
+
1109
+ def test_validate_files
1110
+ skip 'test_validate_files skipped on MS Windows (symlink)' if win_platform?
1111
+ util_setup_validate
1112
+
1113
+ @a1.files += ['lib', 'lib2']
1114
+
1115
+ Dir.chdir @tempdir do
1116
+ FileUtils.ln_s '/root/path', 'lib2' unless vc_windows?
1117
+
1118
+ e = assert_raises Gem::InvalidSpecificationException do
1119
+ @a1.validate
1120
+ end
1121
+
1122
+ assert_equal '["lib2"] are not files', e.message
1123
+ end
1124
+
1125
+ assert_equal %w[lib/code.rb test/suite.rb bin/exec ext/a/extconf.rb lib2],
1126
+ @a1.files
1127
+ end
1128
+
1129
+ def test_validate_homepage
1130
+ util_setup_validate
1131
+
1132
+ Dir.chdir @tempdir do
1133
+ @a1.homepage = nil
1134
+
1135
+ use_ui @ui do
1136
+ @a1.validate
1137
+ end
1138
+
1139
+ assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
1140
+
1141
+ @ui = MockGemUi.new
1142
+
1143
+ @a1.homepage = ''
1144
+
1145
+ use_ui @ui do
1146
+ @a1.validate
1147
+ end
1148
+
1149
+ assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
1150
+
1151
+ @a1.homepage = 'over at my cool site'
1152
+
1153
+ e = assert_raises Gem::InvalidSpecificationException do
1154
+ @a1.validate
1155
+ end
1156
+
1157
+ assert_equal '"over at my cool site" is not a URI', e.message
1158
+ end
1159
+ end
1160
+
1161
+ def test_validate_name
1162
+ util_setup_validate
1163
+
1164
+ e = assert_raises Gem::InvalidSpecificationException do
1165
+ @a1.name = :json
1166
+ @a1.validate
1167
+ end
1168
+
1169
+ assert_equal 'invalid value for attribute name: ":json"', e.message
1170
+ end
1171
+
1172
+ def test_validate_platform_legacy
1173
+ util_setup_validate
1174
+
1175
+ Dir.chdir @tempdir do
1176
+ @a1.platform = 'mswin32'
1177
+ assert @a1.validate
1178
+
1179
+ @a1.platform = 'i586-linux'
1180
+ assert @a1.validate
1181
+
1182
+ @a1.platform = 'powerpc-darwin'
1183
+ assert @a1.validate
1184
+ end
1185
+ end
1186
+
1187
+ def test_validate_rubyforge_project
1188
+ util_setup_validate
1189
+
1190
+ Dir.chdir @tempdir do
1191
+ @a1.rubyforge_project = ''
1192
+
1193
+ use_ui @ui do
1194
+ @a1.validate
1195
+ end
1196
+
1197
+ assert_equal "", @ui.error, 'error'
1198
+ end
1199
+ end
1200
+
1201
+ def test_validate_rubygems_version
1202
+ util_setup_validate
1203
+
1204
+ @a1.rubygems_version = "3"
1205
+ e = assert_raises Gem::InvalidSpecificationException do
1206
+ @a1.validate
1207
+ end
1208
+
1209
+ assert_equal "expected #{Gem::NAME} version #{Gem::VERSION}, was 3",
1210
+ e.message
1211
+ end
1212
+
1213
+ def test_validate_specification_version
1214
+ util_setup_validate
1215
+
1216
+ Dir.chdir @tempdir do
1217
+ @a1.specification_version = '1.0'
1218
+
1219
+ e = assert_raises Gem::InvalidSpecificationException do
1220
+ use_ui @ui do
1221
+ @a1.validate
1222
+ end
1223
+ end
1224
+
1225
+ err = 'specification_version must be a Fixnum (did you mean version?)'
1226
+ assert_equal err, e.message
1227
+ end
1228
+ end
1229
+
1230
+ def test_validate_summary
1231
+ util_setup_validate
1232
+
1233
+ Dir.chdir @tempdir do
1234
+ @a1.summary = ''
1235
+
1236
+ use_ui @ui do
1237
+ @a1.validate
1238
+ end
1239
+
1240
+ assert_equal "WARNING: no summary specified\n", @ui.error, 'error'
1241
+
1242
+ @a1.summary = 'FIXME (describe your package)'
1243
+
1244
+ e = assert_raises Gem::InvalidSpecificationException do
1245
+ @a1.validate
1246
+ end
1247
+
1248
+ assert_equal '"FIXME" or "TODO" is not a summary', e.message
1249
+
1250
+ @a1.summary = 'TODO (describe your package)'
1251
+
1252
+ e = assert_raises Gem::InvalidSpecificationException do
1253
+ @a1.validate
1254
+ end
1255
+
1256
+ assert_equal '"FIXME" or "TODO" is not a summary', e.message
1257
+ end
1258
+ end
1259
+
1260
+ def test_version
1261
+ assert_equal Gem::Version.new('1'), @a1.version
1262
+ end
1263
+
1264
+ def test_load_errors_contain_filename
1265
+ specfile = Tempfile.new(self.class.name.downcase)
1266
+ specfile.write "raise 'boom'"
1267
+ specfile.close
1268
+ begin
1269
+ Gem::Specification.load(specfile.path)
1270
+ rescue => e
1271
+ name_rexp = Regexp.new(Regexp.escape(specfile.path))
1272
+ assert e.backtrace.grep(name_rexp).any?
1273
+ end
1274
+ ensure
1275
+ specfile.delete
1276
+ end
1277
+
1278
+ def util_setup_validate
1279
+ Dir.chdir @tempdir do
1280
+ FileUtils.mkdir_p File.join('ext', 'a')
1281
+ FileUtils.mkdir_p 'lib'
1282
+ FileUtils.mkdir_p 'test'
1283
+
1284
+ FileUtils.touch File.join('ext', 'a', 'extconf.rb')
1285
+ FileUtils.touch File.join('lib', 'code.rb')
1286
+ FileUtils.touch File.join('test', 'suite.rb')
1287
+ end
1288
+ end
1289
+
1290
+ end
1291
+