libgems 0.0.1

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