1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
|
require 'rubygems/test_case'
require 'stringio'
require 'rubygems/specification'
class TestGemSpecification < Gem::TestCase
LEGACY_YAML_SPEC = <<-EOF
--- !ruby/object:Gem::Specification
rubygems_version: "1.0"
name: keyedlist
version: !ruby/object:Gem::Version
version: 0.4.0
date: 2004-03-28 15:37:49.828000 +02:00
platform:
summary: A Hash which automatically computes keys.
require_paths:
- lib
files:
- lib/keyedlist.rb
autorequire: keyedlist
author: Florian Gross
email: flgr@ccan.de
has_rdoc: true
EOF
LEGACY_RUBY_SPEC = <<-EOF
Gem::Specification.new do |s|
s.name = %q{keyedlist}
s.version = %q{0.4.0}
s.has_rdoc = true
s.summary = %q{A Hash which automatically computes keys.}
s.files = [%q{lib/keyedlist.rb}]
s.require_paths = [%q{lib}]
s.autorequire = %q{keyedlist}
s.author = %q{Florian Gross}
s.email = %q{flgr@ccan.de}
end
EOF
def setup
super
@a1 = quick_spec 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
s.license = 'MIT'
s.add_dependency 'rake', '> 0.4'
s.add_dependency 'jabber4r', '> 0.0.0'
s.add_dependency 'pqa', ['> 0.4', '<= 0.6']
s.mark_version
s.files = %w[lib/code.rb]
end
@a2 = quick_spec 'a', '2' do |s|
s.files = %w[lib/code.rb]
end
@current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
load 'rubygems/syck_hack.rb'
end
def test_self_attribute_names
expected_value = %w[
authors
autorequire
bindir
cert_chain
date
dependencies
description
email
executables
extensions
extra_rdoc_files
files
homepage
licenses
name
platform
post_install_message
rdoc_options
require_paths
required_ruby_version
required_rubygems_version
requirements
rubyforge_project
rubygems_version
signing_key
specification_version
summary
test_files
version
]
actual_value = Gem::Specification.attribute_names.map { |a| a.to_s }.sort
assert_equal expected_value, actual_value
end
def test_self__load_future
spec = Gem::Specification.new
spec.name = 'a'
spec.version = '1'
spec.specification_version = @current_version + 1
new_spec = Marshal.load Marshal.dump(spec)
assert_equal 'a', new_spec.name
assert_equal Gem::Version.new(1), new_spec.version
assert_equal @current_version, new_spec.specification_version
end
def test_self_from_yaml_syck_date_bug
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = @a1.to_yaml
yaml.sub!(/^date:.*/, "date: 2011-04-26 00:00:00.000000000Z")
new_spec = with_syck do
Gem::Specification.from_yaml yaml
end
assert_kind_of Time, @a1.date
assert_kind_of Time, new_spec.date
end
def test_self_from_yaml_syck_default_key_bug
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - =
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
new_spec = with_syck do
Gem::Specification.from_yaml yaml
end
op = new_spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r%DefaultKey%, new_spec.to_ruby
end
def test_self_from_yaml_cleans_up_defaultkey
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - !ruby/object:YAML::Syck::DefaultKey {}
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
new_spec = Gem::Specification.from_yaml yaml
op = new_spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r%DefaultKey%, new_spec.to_ruby
end
def test_self_from_yaml_cleans_up_defaultkey_from_newer_192
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - !ruby/object:Syck::DefaultKey {}
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
new_spec = Gem::Specification.from_yaml yaml
op = new_spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r%DefaultKey%, new_spec.to_ruby
end
def test_self_from_yaml_cleans_up_Date_objects
yaml = <<-YAML
--- !ruby/object:Gem::Specification
rubygems_version: 0.8.1
specification_version: 1
name: diff-lcs
version: !ruby/object:Gem::Version
version: 1.1.2
date: 2004-10-20
summary: Provides a list of changes that represent the difference between two sequenced collections.
require_paths:
- lib
author: Austin Ziegler
email: diff-lcs@halostatue.ca
homepage: http://rubyforge.org/projects/ruwiki/
rubyforge_project: ruwiki
description: "Test"
bindir: bin
has_rdoc: true
required_ruby_version: !ruby/object:Gem::Version::Requirement
requirements:
-
- ">="
- !ruby/object:Gem::Version
version: 1.8.1
version:
platform: ruby
files:
- tests/00test.rb
rdoc_options:
- "--title"
- "Diff::LCS -- A Diff Algorithm"
- "--main"
- README
- "--line-numbers"
extra_rdoc_files:
- README
- ChangeLog
- Install
executables:
- ldiff
- htmldiff
extensions: []
requirements: []
dependencies: []
YAML
new_spec = Gem::Specification.from_yaml yaml
assert_kind_of Time, new_spec.date
end
def test_self_load
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_escape_curly
@a2.name = 'a};raise "improper escaping";%q{'
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_escape_interpolation
@a2.name = 'a#{raise %<improper escaping>}'
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_escape_quote
@a2.name = 'a";raise "improper escaping";"'
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
if defined?(Encoding)
def test_self_load_utf8_with_ascii_encoding
int_enc = Encoding.default_internal
silence_warnings { Encoding.default_internal = 'US-ASCII' }
spec2 = @a2.dup
bin = "\u5678"
spec2.authors = [bin]
full_path = spec2.spec_file
write_file full_path do |io|
io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY'))
end
spec = Gem::Specification.load full_path
spec2.files.clear
assert_equal spec2, spec
ensure
silence_warnings { Encoding.default_internal = int_enc }
end
end
def test_self_load_legacy_ruby
spec = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
end
assert_equal 'keyedlist', spec.name
assert_equal '0.4.0', spec.version.to_s
assert_equal Gem::Specification::TODAY, spec.date
assert spec.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, spec.has_unit_tests?
end
def test_self_normalize_yaml_input_with_183_yaml
input = "!ruby/object:Gem::Specification "
assert_equal "--- #{input}", Gem::Specification.normalize_yaml_input(input)
end
def test_self_normalize_yaml_input_with_non_183_yaml
input = "--- !ruby/object:Gem::Specification "
assert_equal input, Gem::Specification.normalize_yaml_input(input)
end
def test_self_normalize_yaml_input_with_183_io
input = "!ruby/object:Gem::Specification "
assert_equal "--- #{input}",
Gem::Specification.normalize_yaml_input(StringIO.new(input))
end
def test_self_normalize_yaml_input_with_non_183_io
input = "--- !ruby/object:Gem::Specification "
assert_equal input,
Gem::Specification.normalize_yaml_input(StringIO.new(input))
end
def test_self_normalize_yaml_input_with_192_yaml
input = "--- !ruby/object:Gem::Specification \nblah: !!null \n"
expected = "--- !ruby/object:Gem::Specification \nblah: \n"
assert_equal expected, Gem::Specification.normalize_yaml_input(input)
end
DATA_PATH = File.expand_path "../data", __FILE__
def test_handles_private_null_type
path = File.join DATA_PATH, "null-type.gemspec.rz"
data = Marshal.load Gem.inflate(Gem.read_binary(path))
assert_equal nil, data.rubyforge_project
end
def test_emits_zulu_timestamps_properly
t = Time.utc(2012, 3, 12)
@a2.date = t
yaml = with_psych { @a2.to_yaml }
assert_match %r!date: 2012-03-12 00:00:00\.000000000 Z!, yaml
end if RUBY_VERSION =~ /1\.9\.2/
def test_initialize
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
end
assert_equal "blah", spec.name
assert_equal "1.3.5", spec.version.to_s
assert_equal Gem::Platform::RUBY, spec.platform
assert_equal nil, spec.summary
assert_equal [], spec.files
assert_equal [], spec.test_files
assert_equal [], spec.rdoc_options
assert_equal [], spec.extra_rdoc_files
assert_equal [], spec.executables
assert_equal [], spec.extensions
assert_equal [], spec.requirements
assert_equal [], spec.dependencies
assert_equal 'bin', spec.bindir
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_equal '>= 0', spec.required_rubygems_version.to_s
end
def test_initialize_future
version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + 1
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
s.specification_version = version
s.new_unknown_attribute = "a value"
end
assert_equal "blah", spec.name
assert_equal "1.3.5", spec.version.to_s
end
def test_initialize_copy
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
s.summary = 'summary'
s.description = 'description'
s.authors = 'author a', 'author b'
s.licenses = 'BSD'
s.files = 'lib/file.rb'
s.test_files = 'test/file.rb'
s.rdoc_options = '--foo'
s.extra_rdoc_files = 'README.txt'
s.executables = 'exec'
s.extensions = 'ext/extconf.rb'
s.requirements = 'requirement'
s.add_dependency 'some_gem'
end
new_spec = spec.dup
assert_equal "blah", spec.name
assert_same spec.name, new_spec.name
assert_equal "1.3.5", spec.version.to_s
assert_same spec.version, new_spec.version
assert_equal Gem::Platform::RUBY, spec.platform
assert_same spec.platform, new_spec.platform
assert_equal 'summary', spec.summary
assert_same spec.summary, new_spec.summary
assert_equal %w[lib/file.rb test/file.rb bin/exec README.txt
ext/extconf.rb],
spec.files
refute_same spec.files, new_spec.files, 'files'
assert_equal %w[test/file.rb], spec.test_files
refute_same spec.test_files, new_spec.test_files, 'test_files'
assert_equal %w[--foo], spec.rdoc_options
refute_same spec.rdoc_options, new_spec.rdoc_options, 'rdoc_options'
assert_equal %w[README.txt], spec.extra_rdoc_files
refute_same spec.extra_rdoc_files, new_spec.extra_rdoc_files,
'extra_rdoc_files'
assert_equal %w[exec], spec.executables
refute_same spec.executables, new_spec.executables, 'executables'
assert_equal %w[ext/extconf.rb], spec.extensions
refute_same spec.extensions, new_spec.extensions, 'extensions'
assert_equal %w[requirement], spec.requirements
refute_same spec.requirements, new_spec.requirements, 'requirements'
assert_equal [Gem::Dependency.new('some_gem', Gem::Requirement.default)],
spec.dependencies
refute_same spec.dependencies, new_spec.dependencies, 'dependencies'
assert_equal 'bin', spec.bindir
assert_same spec.bindir, new_spec.bindir
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_same spec.required_ruby_version, new_spec.required_ruby_version
assert_equal '>= 0', spec.required_rubygems_version.to_s
assert_same spec.required_rubygems_version,
new_spec.required_rubygems_version
end
def test_initialize_copy_broken
spec = Gem::Specification.new do |s|
s.name = 'a'
s.version = '1'
end
spec.instance_variable_set :@licenses, :blah
spec.loaded_from = '/path/to/file'
e = assert_raises Gem::FormatException do
spec.dup
end
assert_equal 'a-1 has an invalid value for @licenses', e.message
assert_equal '/path/to/file', e.file_path
end
def test__dump
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
data = Marshal.dump @a2
same_spec = Marshal.load data
assert_equal 'old_platform', same_spec.original_platform
end
def test_activate
@a2.activate
assert @a2.activated?
Gem::Deprecate.skip_during do
assert @a2.loaded?
end
end
def test_add_dependency_with_explicit_type
gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_development_dependency "monkey"
end
monkey = gem.dependencies.detect { |d| d.name == "monkey" }
assert_equal(:development, monkey.type)
end
def test_author
assert_equal 'A User', @a1.author
end
def test_authors
assert_equal ['A User'], @a1.authors
end
def test_bindir_equals
@a1.bindir = 'apps'
assert_equal 'apps', @a1.bindir
end
def test_bindir_equals_nil
@a2.bindir = nil
@a2.executable = 'app'
assert_equal nil, @a2.bindir
assert_equal %w[lib/code.rb app], @a2.files
end
def test_date
assert_equal Gem::Specification::TODAY, @a1.date
end
def test_date_equals_date
@a1.date = Date.new(2003, 9, 17)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string
@a1.date = '2003-09-17'
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string_bad
assert_raises Gem::InvalidSpecificationException do
@a1.date = '9/11/2003'
end
end
def test_date_equals_time
@a1.date = Time.local(2003, 9, 17, 0,0,0)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_local
@a1.date = Time.local(2003, 9, 17, 19,50,0) # may not pass in utc >= +4
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_utc
@a1.date = Time.utc(2003, 9, 17, 19,50,0)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_dependencies
util_setup_deps
assert_equal [@bonobo, @monkey], @gem.dependencies
end
def test_runtime_dependencies
util_setup_deps
assert_equal [@bonobo], @gem.runtime_dependencies
end
def test_development_dependencies
util_setup_deps
assert_equal [@monkey], @gem.development_dependencies
end
def test_description
assert_equal 'This is a test description', @a1.description
end
def test_eql_eh
g1 = new_spec 'gem', 1
g2 = new_spec 'gem', 1
assert_equal g1, g2
assert_equal g1.hash, g2.hash
assert_equal true, g1.eql?(g2)
end
def test_eql_eh_extensions
spec = @a1.dup
spec.extensions = 'xx'
refute_operator @a1, :eql?, spec
refute_operator spec, :eql?, @a1
end
def test_executables
@a1.executable = 'app'
assert_equal %w[app], @a1.executables
end
def test_executable_equals
@a2.executable = 'app'
assert_equal 'app', @a2.executable
assert_equal %w[lib/code.rb bin/app], @a2.files
end
def test_extensions
assert_equal ['ext/a/extconf.rb'], @a1.extensions
end
def test_files
@a1.files = %w(files bin/common)
@a1.test_files = %w(test_files bin/common)
@a1.executables = %w(executables common)
@a1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
@a1.extensions = %w(extensions bin/common)
expected = %w[
bin/common
bin/executables
extensions
extra_rdoc_files
files
test_files
]
assert_equal expected, @a1.files.sort
end
def test_files_append
@a1.files = %w(files bin/common)
@a1.test_files = %w(test_files bin/common)
@a1.executables = %w(executables common)
@a1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
@a1.extensions = %w(extensions bin/common)
expected = %w[
bin/common
bin/executables
extensions
extra_rdoc_files
files
test_files
]
assert_equal expected, @a1.files.sort
@a1.files << "generated_file.c"
expected << "generated_file.c"
expected.sort!
assert_equal expected, @a1.files.sort
end
def test_files_duplicate
@a2.files = %w[a b c d b]
@a2.extra_rdoc_files = %w[x y z x]
@a2.normalize
assert_equal %w[a b c d x y z], @a2.files
assert_equal %w[x y z], @a2.extra_rdoc_files
end
def test_files_extra_rdoc_files
@a2.files = %w[a b c d]
@a2.extra_rdoc_files = %w[x y z]
@a2.normalize
assert_equal %w[a b c d x y z], @a2.files
end
def test_files_non_array
@a1.files = "F"
@a1.test_files = "TF"
@a1.executables = "X"
@a1.extra_rdoc_files = "ERF"
@a1.extensions = "E"
assert_equal %w[E ERF F TF bin/X], @a1.files.sort
end
def test_files_non_array_pathological
@a1.instance_variable_set :@files, "F"
@a1.instance_variable_set :@test_files, "TF"
@a1.instance_variable_set :@extra_rdoc_files, "ERF"
@a1.instance_variable_set :@extensions, "E"
@a1.instance_variable_set :@executables, "X"
assert_equal %w[E ERF F TF bin/X], @a1.files.sort
assert_kind_of Integer, @a1.hash
end
def test_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
@a2.test_files = %w[test/test_b.rb]
refute_empty @a2.files
refute_empty @a2.test_files
spec = @a2.for_cache
assert_empty spec.files
assert_empty spec.test_files
refute_empty @a2.files
refute_empty @a2.test_files
end
def test_full_gem_path
assert_equal File.join(@gemhome, 'gems', @a1.full_name), @a1.full_gem_path
@a1.original_platform = 'mswin32'
assert_equal File.join(@gemhome, 'gems', @a1.original_name),
@a1.full_gem_path
end
def test_full_gem_path_double_slash
gemhome = @gemhome.to_s.sub(/\w\//, '\&/')
@a1.loaded_from = File.join gemhome, "specifications", @a1.spec_name
expected = File.join @gemhome, "gems", @a1.full_name
assert_equal expected, @a1.full_gem_path
end
def test_full_name
assert_equal 'a-1', @a1.full_name
@a1.platform = Gem::Platform.new ['universal', 'darwin', nil]
assert_equal 'a-1-universal-darwin', @a1.full_name
@a1.instance_variable_set :@new_platform, 'mswin32'
assert_equal 'a-1-mswin32', @a1.full_name, 'legacy'
return if win_platform?
@a1.platform = 'current'
assert_equal 'a-1-x86-darwin-8', @a1.full_name
end
def test_full_name_windows
test_cases = {
'i386-mswin32' => 'a-1-x86-mswin32-60',
'i386-mswin32_80' => 'a-1-x86-mswin32-80',
'i386-mingw32' => 'a-1-x86-mingw32'
}
test_cases.each do |arch, expected|
util_set_arch arch
@a1.platform = 'current'
assert_equal expected, @a1.full_name
end
end
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
refute_equal @a1.hash, @a2.hash
end
def test_installation_path
Gem::Deprecate.skip_during do
assert_equal @gemhome, @a1.installation_path
@a1.instance_variable_set :@loaded_from, nil
@a1.instance_variable_set :@loaded, false
assert_nil @a1.installation_path
end
end
def test_lib_files
@a1.files = %w[lib/foo.rb Rakefile]
assert_equal %w[lib/foo.rb], @a1.lib_files
end
def test_license
assert_equal 'MIT', @a1.license
end
def test_licenses
assert_equal ['MIT'], @a1.licenses
end
def test_name
assert_equal 'a', @a1.name
end
def test_original_name
assert_equal 'a-1', @a1.full_name
@a1.platform = 'i386-linux'
@a1.instance_variable_set :@original_platform, 'i386-linux'
assert_equal 'a-1-i386-linux', @a1.original_name
end
def test_platform
assert_equal Gem::Platform::RUBY, @a1.platform
end
def test_platform_equals
@a1.platform = nil
assert_equal Gem::Platform::RUBY, @a1.platform
@a1.platform = Gem::Platform::RUBY
assert_equal Gem::Platform::RUBY, @a1.platform
test_cases = {
'i386-mswin32' => ['x86', 'mswin32', '60'],
'i386-mswin32_80' => ['x86', 'mswin32', '80'],
'i386-mingw32' => ['x86', 'mingw32', nil ],
'x86-darwin8' => ['x86', 'darwin', '8' ],
}
test_cases.each do |arch, expected|
util_set_arch arch
@a1.platform = Gem::Platform::CURRENT
assert_equal Gem::Platform.new(expected), @a1.platform
end
end
def test_platform_equals_current
@a1.platform = Gem::Platform::CURRENT
assert_equal Gem::Platform.local, @a1.platform
assert_equal Gem::Platform.local.to_s, @a1.original_platform
end
def test_platform_equals_legacy
@a1.platform = 'mswin32'
assert_equal Gem::Platform.new('x86-mswin32'), @a1.platform
@a1.platform = 'i586-linux'
assert_equal Gem::Platform.new('x86-linux'), @a1.platform
@a1.platform = 'powerpc-darwin'
assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform
end
def test_prerelease_spec_adds_required_rubygems_version
@prerelease = quick_spec('tardis', '2.2.0.a')
refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1'))
assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0'))
end
def test_require_paths
@a1.require_path = 'lib'
assert_equal %w[lib], @a1.require_paths
end
def test_requirements
assert_equal ['A working computer'], @a1.requirements
end
def test_runtime_dependencies_legacy
# legacy gems don't have a type
@a1.runtime_dependencies.each do |dep|
dep.instance_variable_set :@type, nil
end
expected = %w[rake jabber4r pqa]
assert_equal expected, @a1.runtime_dependencies.map { |d| d.name }
end
def test_spaceship_name
s1 = new_spec 'a', '1'
s2 = new_spec 'b', '1'
assert_equal(-1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
assert_equal( 1, (s2 <=> s1))
end
def test_spaceship_platform
s1 = new_spec 'a', '1'
s2 = new_spec 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
assert_equal( -1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
assert_equal( 1, (s2 <=> s1))
end
def test_spaceship_version
s1 = new_spec 'a', '1'
s2 = new_spec 'a', '2'
assert_equal( -1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
assert_equal( 1, (s2 <=> s1))
end
def test_spec_name
assert_equal 'a-1.gemspec', @a1.spec_name
end
def test_summary
assert_equal 'this is a summary', @a1.summary
end
def test_test_files
@a1.test_file = 'test/suite.rb'
assert_equal ['test/suite.rb'], @a1.test_files
end
def test_to_ruby
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
ruby_code = @a2.to_ruby
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
s.email = "example@example.com"
s.files = ["lib/code.rb"]
s.homepage = "http://example.com"
s.require_paths = ["lib"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<b>, [\"= 1\"])
else
s.add_dependency(%q<b>, [\"= 1\"])
end
else
s.add_dependency(%q<b>, [\"= 1\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
assert_equal @a2, same_spec
end
def test_to_ruby_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
# cached specs do not have spec.files populated:
ruby_code = @a2.to_ruby_for_cache
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
s.email = "example@example.com"
s.homepage = "http://example.com"
s.require_paths = ["lib"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<b>, [\"= 1\"])
else
s.add_dependency(%q<b>, [\"= 1\"])
end
else
s.add_dependency(%q<b>, [\"= 1\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
# cached specs do not have spec.files populated:
@a2.files = []
assert_equal @a2, same_spec
end
def test_to_ruby_fancy
@a1.platform = Gem::Platform.local
ruby_code = @a1.to_ruby
local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
s.version = "1"
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
s.email = "example@example.com"
s.executables = ["exec"]
s.extensions = ["ext/a/extconf.rb"]
s.files = ["lib/code.rb", "test/suite.rb", "bin/exec", "ext/a/extconf.rb"]
s.homepage = "http://example.com"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.requirements = ["A working computer"]
s.rubyforge_project = "example"
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
s.test_files = ["test/suite.rb"]
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"])
else
s.add_dependency(%q<rake>, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"])
end
else
s.add_dependency(%q<rake>, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
assert_equal @a1, same_spec
end
def test_to_ruby_legacy
gemspec1 = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
end
ruby_code = gemspec1.to_ruby
gemspec2 = eval ruby_code
assert_equal gemspec1, gemspec2
end
def test_to_ruby_platform
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
ruby_code = @a2.to_ruby
same_spec = eval ruby_code
assert_equal 'old_platform', same_spec.original_platform
end
def test_to_yaml
yaml_str = @a1.to_yaml
refute_match '!!null', yaml_str
same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal @a1, same_spec
end
def test_to_yaml_fancy
@a1.platform = Gem::Platform.local
yaml_str = @a1.to_yaml
same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal Gem::Platform.local, same_spec.platform
assert_equal @a1, same_spec
end
def test_to_yaml_platform_empty_string
@a1.instance_variable_set :@original_platform, ''
assert_match %r|^platform: ruby$|, @a1.to_yaml
end
def test_to_yaml_platform_legacy
@a1.platform = 'powerpc-darwin7.9.0'
@a1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0'
yaml_str = @a1.to_yaml
same_spec = YAML.load yaml_str
assert_equal Gem::Platform.new('powerpc-darwin7'), same_spec.platform
assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform
end
def test_to_yaml_platform_nil
@a1.instance_variable_set :@original_platform, nil
assert_match %r|^platform: ruby$|, @a1.to_yaml
end
def test_to_yaml_emits_syck_compat_yaml
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
end
begin
@a1.add_dependency "gx", "1.0.0"
y = @a1.to_yaml
refute_match %r!^\s*- - =!, y
ensure
YAML::ENGINE.yamler = yamler if yamler
end
end
def test_validate
util_setup_validate
Dir.chdir @tempdir do
assert @a1.validate
end
end
def x s; s.gsub(/xxx/, ''); end
def w; x "WARxxxNING"; end
def t; x "TOxxxDO"; end
def f; x "FxxxIXME"; end
def test_validate_authors
util_setup_validate
Dir.chdir @tempdir do
@a1.authors = [""]
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no author specified\n", @ui.error, 'error'
@a1.authors = [Object.new]
assert_equal [], @a1.authors
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "authors may not be empty", e.message
@a1.authors = ["#{f} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not an author}, e.message
@a1.authors = ["#{t} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not an author}, e.message
end
end
def test_validate_autorequire
util_setup_validate
Dir.chdir @tempdir do
@a1.autorequire = 'code'
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: deprecated autorequire specified\n",
@ui.error, 'error'
end
end
def test_validate_description
util_setup_validate
Dir.chdir @tempdir do
@a1.description = ''
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no description specified\n", @ui.error, "error"
@ui = Gem::MockGemUi.new
@a1.summary = "this is my summary"
@a1.description = @a1.summary
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: description and summary are identical\n",
@ui.error, "error"
@a1.description = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not a description}, e.message
@a1.description = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not a description}, e.message
end
end
def test_validate_email
util_setup_validate
Dir.chdir @tempdir do
@a1.email = ""
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no email specified\n", @ui.error, "error"
@a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "")
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not an email}, e.message
@a1.email = "#{t} (your e-mail)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not an email}, e.message
end
end
def test_validate_empty
e = assert_raises Gem::InvalidSpecificationException do
Gem::Specification.new.validate
end
assert_equal 'missing value for attribute name', e.message
end
def test_validate_executables
util_setup_validate
FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.open File.join(@tempdir, 'bin', 'exec'), 'w' do end
FileUtils.mkdir_p File.join(@tempdir, 'exec')
use_ui @ui do
Dir.chdir @tempdir do
assert @a1.validate
end
end
assert_equal %w[exec], @a1.executables
assert_equal '', @ui.output, 'output'
assert_equal "#{w}: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
if win_platform? then
skip 'test_validate_empty_require_paths skipped on MS Windows (symlink)'
else
util_setup_validate
@a1.require_paths = []
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal 'specification must have at least one require_path',
e.message
end
end
def test_validate_files
skip 'test_validate_files skipped on MS Windows (symlink)' if win_platform?
util_setup_validate
@a1.files += ['lib', 'lib2']
Dir.chdir @tempdir do
FileUtils.ln_s '/root/path', 'lib2' unless vc_windows?
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal '["lib2"] are not files', e.message
end
assert_equal %w[lib/code.rb test/suite.rb bin/exec ext/a/extconf.rb lib2],
@a1.files
end
def test_validate_homepage
util_setup_validate
Dir.chdir @tempdir do
@a1.homepage = nil
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
@a1.homepage = ''
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
@a1.homepage = 'over at my cool site'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal '"over at my cool site" is not a URI', e.message
end
end
def test_validate_name
util_setup_validate
e = assert_raises Gem::InvalidSpecificationException do
@a1.name = :json
@a1.validate
end
assert_equal 'invalid value for attribute name: ":json"', e.message
end
def test_validate_non_nil
util_setup_validate
Dir.chdir @tempdir do
assert @a1.validate
Gem::Specification.non_nil_attributes.each do |name|
next if name == :files # set by #normalize
spec = @a1.dup
spec.instance_variable_set "@#{name}", nil
e = assert_raises Gem::InvalidSpecificationException do
spec.validate
end
assert_match %r%^#{name}%, e.message
end
end
end
def test_validate_platform_legacy
util_setup_validate
Dir.chdir @tempdir do
@a1.platform = 'mswin32'
assert @a1.validate
@a1.platform = 'i586-linux'
assert @a1.validate
@a1.platform = 'powerpc-darwin'
assert @a1.validate
end
end
def test_validate_rubygems_version
util_setup_validate
@a1.rubygems_version = "3"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "expected RubyGems version #{Gem::VERSION}, was 3",
e.message
end
def test_validate_specification_version
util_setup_validate
Dir.chdir @tempdir do
@a1.specification_version = '1.0'
e = assert_raises Gem::InvalidSpecificationException do
use_ui @ui do
@a1.validate
end
end
err = 'specification_version must be a Fixnum (did you mean version?)'
assert_equal err, e.message
end
end
def test_validate_summary
util_setup_validate
Dir.chdir @tempdir do
@a1.summary = ''
use_ui @ui do
@a1.validate
end
assert_equal "#{w}: no summary specified\n", @ui.error, 'error'
@a1.summary = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not a summary}, e.message
@a1.summary = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %{"#{f}" or "#{t}" is not a summary}, e.message
end
end
def test_version
assert_equal Gem::Version.new('1'), @a1.version
end
def test__load_fixes_Date_objects
spec = new_spec "a", 1
spec.instance_variable_set :@date, Date.today
spec = Marshal.load Marshal.dump(spec)
assert_kind_of Time, spec.date
end
def test_load_errors_contain_filename
specfile = Tempfile.new(self.class.name.downcase)
specfile.write "raise 'boom'"
specfile.close
begin
capture_io do
Gem::Specification.load(specfile.path)
end
rescue => e
name_rexp = Regexp.new(Regexp.escape(specfile.path))
assert e.backtrace.grep(name_rexp).any?
end
ensure
specfile.delete
end
##
# KEEP p-1-x86-darwin-8
# KEEP p-1
# KEEP c-1.2
# KEEP a_evil-9
# a-1
# a-1-x86-my_platform-1
# KEEP a-2
# a-2-x86-other_platform-1
# KEEP a-2-x86-my_platform-1
# a-3.a
# KEEP a-3-x86-other_platform-1
def test_latest_specs
util_clear_gems
util_setup_fake_fetcher
quick_spec 'p', '1'
p1_curr = quick_spec 'p', '1' do |spec|
spec.platform = Gem::Platform::CURRENT
end
quick_spec @a1.name, @a1.version do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
quick_spec @a1.name, @a1.version do |s|
s.platform = Gem::Platform.new 'x86-third_platform1'
end
quick_spec @a2.name, @a2.version do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
quick_spec @a2.name, @a2.version do |s|
s.platform = Gem::Platform.new 'x86-other_platform1'
end
quick_spec @a2.name, @a2.version.bump do |s|
s.platform = Gem::Platform.new 'x86-other_platform1'
end
Gem::Specification.remove_spec @b2
Gem::Specification.remove_spec @pl1
expected = %W[
a-2
a-2-x86-my_platform-1
a-3-x86-other_platform-1
a_evil-9
c-1.2
p-1
#{p1_curr.full_name}
]
latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
assert_equal expected, latest_specs
end
def util_setup_deps
@gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
awesome.add_development_dependency "monkey", []
end
@bonobo = Gem::Dependency.new("bonobo", [])
@monkey = Gem::Dependency.new("monkey", [], :development)
end
def util_setup_validate
Dir.chdir @tempdir do
FileUtils.mkdir_p File.join("ext", "a")
FileUtils.mkdir_p "lib"
FileUtils.mkdir_p "test"
FileUtils.mkdir_p "bin"
FileUtils.touch File.join("ext", "a", "extconf.rb")
FileUtils.touch File.join("lib", "code.rb")
FileUtils.touch File.join("test", "suite.rb")
File.open "bin/exec", "w" do |fp|
fp.puts "#!#{Gem.ruby}"
end
end
end
def with_syck
begin
require "yaml"
old_engine = YAML::ENGINE.yamler
YAML::ENGINE.yamler = 'syck'
load 'rubygems/syck_hack.rb'
rescue NameError
# probably on 1.8, ignore
end
yield
ensure
begin
YAML::ENGINE.yamler = old_engine
load 'rubygems/syck_hack.rb'
rescue NameError
# ignore
end
end
def with_psych
begin
require "yaml"
old_engine = YAML::ENGINE.yamler
YAML::ENGINE.yamler = 'psych'
load 'rubygems/syck_hack.rb'
rescue NameError
# probably on 1.8, ignore
end
yield
ensure
begin
YAML::ENGINE.yamler = old_engine
load 'rubygems/syck_hack.rb'
rescue NameError
# ignore
end
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield
ensure
$VERBOSE = old_verbose
end
end
|