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
|
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe :kernel_integer, shared: true do
it "returns a Bignum for a Bignum" do
Integer(2e100).should == 2e100
end
it "returns a Fixnum for a Fixnum" do
Integer(100).should == 100
end
ruby_version_is ""..."2.6" do
it "uncritically return the value of to_int even if it is not an Integer" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_not_receive(:to_i)
Integer(obj).should == "1"
end
end
ruby_version_is "2.6" do
it "raises a TypeError when to_int returns not-an-Integer object and to_i returns nil" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_receive(:to_i).and_return(nil)
lambda { Integer(obj) }.should raise_error(TypeError)
end
it "return a result of to_i when to_int does not return an Integer" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
obj.should_receive(:to_i).and_return(42)
Integer(obj).should == 42
end
end
it "raises a TypeError when passed nil" do
lambda { Integer(nil) }.should raise_error(TypeError)
end
it "returns a Fixnum or Bignum object" do
Integer(2).should be_an_instance_of(Fixnum)
Integer(9**99).should be_an_instance_of(Bignum)
end
it "truncates Floats" do
Integer(3.14).should == 3
Integer(90.8).should == 90
end
it "calls to_i on Rationals" do
Integer(Rational(8,3)).should == 2
Integer(3.quo(2)).should == 1
end
it "returns the value of to_int if the result is a Fixnum" do
obj = mock("object")
obj.should_receive(:to_int).and_return(1)
obj.should_not_receive(:to_i)
Integer(obj).should == 1
end
it "returns the value of to_int if the result is a Bignum" do
obj = mock("object")
obj.should_receive(:to_int).and_return(2 * 10**100)
obj.should_not_receive(:to_i)
Integer(obj).should == 2 * 10**100
end
it "calls to_i on an object whose to_int returns nil" do
obj = mock("object")
obj.should_receive(:to_int).and_return(nil)
obj.should_receive(:to_i).and_return(1)
Integer(obj).should == 1
end
it "raises a TypeError if to_i returns a value that is not an Integer" do
obj = mock("object")
obj.should_receive(:to_i).and_return("1")
lambda { Integer(obj) }.should raise_error(TypeError)
end
it "raises a TypeError if no to_int or to_i methods exist" do
obj = mock("object")
lambda { Integer(obj) }.should raise_error(TypeError)
end
it "raises a TypeError if to_int returns nil and no to_i exists" do
obj = mock("object")
obj.should_receive(:to_i).and_return(nil)
lambda { Integer(obj) }.should raise_error(TypeError)
end
it "raises a FloatDomainError when passed NaN" do
lambda { Integer(nan_value) }.should raise_error(FloatDomainError)
end
it "raises a FloatDomainError when passed Infinity" do
lambda { Integer(infinity_value) }.should raise_error(FloatDomainError)
end
ruby_version_is "2.6" do
describe "when passed exception: false" do
describe "and to_i returns a value that is not an Integer" do
it "swallows an error" do
obj = mock("object")
obj.should_receive(:to_i).and_return("1")
Integer(obj, exception: false).should == nil
end
end
describe "and no to_int or to_i methods exist" do
it "swallows an error" do
obj = mock("object")
Integer(obj, exception: false).should == nil
end
end
describe "and to_int returns nil and no to_i exists" do
it "swallows an error" do
obj = mock("object")
obj.should_receive(:to_i).and_return(nil)
Integer(obj, exception: false).should == nil
end
end
ruby_bug "#15525", "2.6"..."2.6.1" do
describe "and passed NaN" do
it "swallows an error" do
Integer(nan_value, exception: false).should == nil
end
end
describe "and passed Infinity" do
it "swallows an error" do
Integer(infinity_value, exception: false).should == nil
end
end
end
describe "and passed nil" do
it "swallows an error" do
Integer(nil, exception: false).should == nil
end
end
describe "and passed a String that contains numbers" do
it "normally parses it and returns an Integer" do
Integer("42", exception: false).should == 42
end
end
describe "and passed a String that can't be converted to an Integer" do
it "swallows an error" do
Integer("abc", exception: false).should == nil
end
end
end
end
end
describe "Integer() given a String", shared: true do
it "raises an ArgumentError if the String is a null byte" do
lambda { Integer("\0") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String starts with a null byte" do
lambda { Integer("\01") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String ends with a null byte" do
lambda { Integer("1\0") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String contains a null byte" do
lambda { Integer("1\01") }.should raise_error(ArgumentError)
end
it "ignores leading whitespace" do
Integer(" 1").should == 1
Integer(" 1").should == 1
Integer("\t\n1").should == 1
end
it "ignores trailing whitespace" do
Integer("1 ").should == 1
Integer("1 ").should == 1
Integer("1\t\n").should == 1
end
it "raises an ArgumentError if there are leading _s" do
lambda { Integer("_1") }.should raise_error(ArgumentError)
lambda { Integer("___1") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing _s" do
lambda { Integer("1_") }.should raise_error(ArgumentError)
lambda { Integer("1___") }.should raise_error(ArgumentError)
end
it "ignores an embedded _" do
Integer("1_1").should == 11
end
it "raises an ArgumentError if there are multiple embedded _s" do
lambda { Integer("1__1") }.should raise_error(ArgumentError)
lambda { Integer("1___1") }.should raise_error(ArgumentError)
end
it "ignores a single leading +" do
Integer("+1").should == 1
end
it "raises an ArgumentError if there is a space between the + and number" do
lambda { Integer("+ 1") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are multiple leading +s" do
lambda { Integer("++1") }.should raise_error(ArgumentError)
lambda { Integer("+++1") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing +s" do
lambda { Integer("1+") }.should raise_error(ArgumentError)
lambda { Integer("1+++") }.should raise_error(ArgumentError)
end
it "makes the number negative if there's a leading -" do
Integer("-1").should == -1
end
it "raises an ArgumentError if there are multiple leading -s" do
lambda { Integer("--1") }.should raise_error(ArgumentError)
lambda { Integer("---1") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing -s" do
lambda { Integer("1-") }.should raise_error(ArgumentError)
lambda { Integer("1---") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there is a period" do
lambda { Integer("0.0") }.should raise_error(ArgumentError)
end
it "raises an ArgumentError for an empty String" do
lambda { Integer("") }.should raise_error(ArgumentError)
end
ruby_version_is "2.6" do
describe "when passed exception: false" do
describe "and multiple leading -s" do
it "swallows an error" do
Integer("---1", exception: false).should == nil
end
end
describe "and multiple trailing -s" do
it "swallows an error" do
Integer("1---", exception: false).should == nil
end
end
describe "and an argument that contains a period" do
it "swallows an error" do
Integer("0.0", exception: false).should == nil
end
end
describe "and an empty string" do
it "swallows an error" do
Integer("", exception: false).should == nil
end
end
end
end
it "parses the value as 0 if the string consists of a single zero character" do
Integer("0").should == 0
end
%w(x X).each do |x|
it "parses the value as a hex number if there's a leading 0#{x}" do
Integer("0#{x}1").should == 0x1
Integer("0#{x}dd").should == 0xdd
end
it "is a positive hex number if there's a leading +0#{x}" do
Integer("+0#{x}1").should == 0x1
Integer("+0#{x}dd").should == 0xdd
end
it "is a negative hex number if there's a leading -0#{x}" do
Integer("-0#{x}1").should == -0x1
Integer("-0#{x}dd").should == -0xdd
end
it "raises an ArgumentError if the number cannot be parsed as hex" do
lambda { Integer("0#{x}g") }.should raise_error(ArgumentError)
end
end
%w(b B).each do |b|
it "parses the value as a binary number if there's a leading 0#{b}" do
Integer("0#{b}1").should == 0b1
Integer("0#{b}10").should == 0b10
end
it "is a positive binary number if there's a leading +0#{b}" do
Integer("+0#{b}1").should == 0b1
Integer("+0#{b}10").should == 0b10
end
it "is a negative binary number if there's a leading -0#{b}" do
Integer("-0#{b}1").should == -0b1
Integer("-0#{b}10").should == -0b10
end
it "raises an ArgumentError if the number cannot be parsed as binary" do
lambda { Integer("0#{b}2") }.should raise_error(ArgumentError)
end
end
["o", "O", ""].each do |o|
it "parses the value as an octal number if there's a leading 0#{o}" do
Integer("0#{o}1").should == 0O1
Integer("0#{o}10").should == 0O10
end
it "is a positive octal number if there's a leading +0#{o}" do
Integer("+0#{o}1").should == 0O1
Integer("+0#{o}10").should == 0O10
end
it "is a negative octal number if there's a leading -0#{o}" do
Integer("-0#{o}1").should == -0O1
Integer("-0#{o}10").should == -0O10
end
it "raises an ArgumentError if the number cannot be parsed as octal" do
lambda { Integer("0#{o}9") }.should raise_error(ArgumentError)
end
end
%w(D d).each do |d|
it "parses the value as a decimal number if there's a leading 0#{d}" do
Integer("0#{d}1").should == 1
Integer("0#{d}10").should == 10
end
it "is a positive decimal number if there's a leading +0#{d}" do
Integer("+0#{d}1").should == 1
Integer("+0#{d}10").should == 10
end
it "is a negative decimal number if there's a leading -0#{d}" do
Integer("-0#{d}1").should == -1
Integer("-0#{d}10").should == -10
end
it "raises an ArgumentError if the number cannot be parsed as decimal" do
lambda { Integer("0#{d}a") }.should raise_error(ArgumentError)
end
end
end
describe "Integer() given a String and base", shared: true do
it "raises an ArgumentError if the String is a null byte" do
lambda { Integer("\0", 2) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String starts with a null byte" do
lambda { Integer("\01", 3) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String ends with a null byte" do
lambda { Integer("1\0", 4) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if the String contains a null byte" do
lambda { Integer("1\01", 5) }.should raise_error(ArgumentError)
end
it "ignores leading whitespace" do
Integer(" 16", 16).should == 22
Integer(" 16", 16).should == 22
Integer("\t\n16", 16).should == 22
end
it "ignores trailing whitespace" do
Integer("16 ", 16).should == 22
Integer("16 ", 16).should == 22
Integer("16\t\n", 16).should == 22
end
it "raises an ArgumentError if there are leading _s" do
lambda { Integer("_1", 7) }.should raise_error(ArgumentError)
lambda { Integer("___1", 7) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing _s" do
lambda { Integer("1_", 12) }.should raise_error(ArgumentError)
lambda { Integer("1___", 12) }.should raise_error(ArgumentError)
end
it "ignores an embedded _" do
Integer("1_1", 4).should == 5
end
it "raises an ArgumentError if there are multiple embedded _s" do
lambda { Integer("1__1", 4) }.should raise_error(ArgumentError)
lambda { Integer("1___1", 4) }.should raise_error(ArgumentError)
end
it "ignores a single leading +" do
Integer("+10", 3).should == 3
end
it "raises an ArgumentError if there is a space between the + and number" do
lambda { Integer("+ 1", 3) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are multiple leading +s" do
lambda { Integer("++1", 3) }.should raise_error(ArgumentError)
lambda { Integer("+++1", 3) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing +s" do
lambda { Integer("1+", 3) }.should raise_error(ArgumentError)
lambda { Integer("1+++", 12) }.should raise_error(ArgumentError)
end
it "makes the number negative if there's a leading -" do
Integer("-19", 20).should == -29
end
it "raises an ArgumentError if there are multiple leading -s" do
lambda { Integer("--1", 9) }.should raise_error(ArgumentError)
lambda { Integer("---1", 9) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there are trailing -s" do
lambda { Integer("1-", 12) }.should raise_error(ArgumentError)
lambda { Integer("1---", 12) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if there is a period" do
lambda { Integer("0.0", 3) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError for an empty String" do
lambda { Integer("", 12) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError for a base of 1" do
lambda { Integer("1", 1) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError for a base of 37" do
lambda { Integer("1", 37) }.should raise_error(ArgumentError)
end
it "accepts wholly lowercase alphabetic strings for bases > 10" do
Integer('ab',12).should == 131
Integer('af',20).should == 215
Integer('ghj',30).should == 14929
end
it "accepts wholly uppercase alphabetic strings for bases > 10" do
Integer('AB',12).should == 131
Integer('AF',20).should == 215
Integer('GHJ',30).should == 14929
end
it "accepts mixed-case alphabetic strings for bases > 10" do
Integer('Ab',12).should == 131
Integer('aF',20).should == 215
Integer('GhJ',30).should == 14929
end
it "accepts alphanumeric strings for bases > 10" do
Integer('a3e',19).should == 3681
Integer('12q',31).should == 1049
Integer('c00o',29).should == 292692
end
it "raises an ArgumentError for letters invalid in the given base" do
lambda { Integer('z',19) }.should raise_error(ArgumentError)
lambda { Integer('c00o',2) }.should raise_error(ArgumentError)
end
%w(x X).each do |x|
it "parses the value as a hex number if there's a leading 0#{x} and a base of 16" do
Integer("0#{x}10", 16).should == 16
Integer("0#{x}dd", 16).should == 221
end
it "is a positive hex number if there's a leading +0#{x} and base of 16" do
Integer("+0#{x}1", 16).should == 0x1
Integer("+0#{x}dd", 16).should == 0xdd
end
it "is a negative hex number if there's a leading -0#{x} and a base of 16" do
Integer("-0#{x}1", 16).should == -0x1
Integer("-0#{x}dd", 16).should == -0xdd
end
2.upto(15) do |base|
it "raises an ArgumentError if the number begins with 0#{x} and the base is #{base}" do
lambda { Integer("0#{x}1", base) }.should raise_error(ArgumentError)
end
end
it "raises an ArgumentError if the number cannot be parsed as hex and the base is 16" do
lambda { Integer("0#{x}g", 16) }.should raise_error(ArgumentError)
end
end
%w(b B).each do |b|
it "parses the value as a binary number if there's a leading 0#{b} and the base is 2" do
Integer("0#{b}1", 2).should == 0b1
Integer("0#{b}10", 2).should == 0b10
end
it "is a positive binary number if there's a leading +0#{b} and a base of 2" do
Integer("+0#{b}1", 2).should == 0b1
Integer("+0#{b}10", 2).should == 0b10
end
it "is a negative binary number if there's a leading -0#{b} and a base of 2" do
Integer("-0#{b}1", 2).should == -0b1
Integer("-0#{b}10", 2).should == -0b10
end
it "raises an ArgumentError if the number cannot be parsed as binary and the base is 2" do
lambda { Integer("0#{b}2", 2) }.should raise_error(ArgumentError)
end
end
["o", "O"].each do |o|
it "parses the value as an octal number if there's a leading 0#{o} and a base of 8" do
Integer("0#{o}1", 8).should == 0O1
Integer("0#{o}10", 8).should == 0O10
end
it "is a positive octal number if there's a leading +0#{o} and a base of 8" do
Integer("+0#{o}1", 8).should == 0O1
Integer("+0#{o}10", 8).should == 0O10
end
it "is a negative octal number if there's a leading -0#{o} and a base of 8" do
Integer("-0#{o}1", 8).should == -0O1
Integer("-0#{o}10", 8).should == -0O10
end
it "raises an ArgumentError if the number cannot be parsed as octal and the base is 8" do
lambda { Integer("0#{o}9", 8) }.should raise_error(ArgumentError)
end
2.upto(7) do |base|
it "raises an ArgumentError if the number begins with 0#{o} and the base is #{base}" do
lambda { Integer("0#{o}1", base) }.should raise_error(ArgumentError)
end
end
end
%w(D d).each do |d|
it "parses the value as a decimal number if there's a leading 0#{d} and a base of 10" do
Integer("0#{d}1", 10).should == 1
Integer("0#{d}10",10).should == 10
end
it "is a positive decimal number if there's a leading +0#{d} and a base of 10" do
Integer("+0#{d}1", 10).should == 1
Integer("+0#{d}10", 10).should == 10
end
it "is a negative decimal number if there's a leading -0#{d} and a base of 10" do
Integer("-0#{d}1", 10).should == -1
Integer("-0#{d}10", 10).should == -10
end
it "raises an ArgumentError if the number cannot be parsed as decimal and the base is 10" do
lambda { Integer("0#{d}a", 10) }.should raise_error(ArgumentError)
end
2.upto(9) do |base|
it "raises an ArgumentError if the number begins with 0#{d} and the base is #{base}" do
lambda { Integer("0#{d}1", base) }.should raise_error(ArgumentError)
end
end
it "raises an ArgumentError if a base is given for a non-String value" do
lambda { Integer(98, 15) }.should raise_error(ArgumentError)
end
end
ruby_version_is "2.6" do
describe "when passed exception: false" do
describe "and valid argument" do
it "returns an Integer number" do
Integer("100", 10, exception: false).should == 100
Integer("100", 2, exception: false).should == 4
end
end
describe "and invalid argument" do
it "swallows an error" do
Integer("999", 2, exception: false).should == nil
Integer("abc", 10, exception: false).should == nil
end
end
end
end
end
describe :kernel_Integer, shared: true do
it "raises an ArgumentError when the String contains digits out of range of radix 2" do
str = "23456789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 2) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 3" do
str = "3456789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 3) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 4" do
str = "456789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 4) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 5" do
str = "56789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 5) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 6" do
str = "6789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 6) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 7" do
str = "789abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 7) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 8" do
str = "89abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 8) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 9" do
str = "9abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 9) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 10" do
str = "abcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 10) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 11" do
str = "bcdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 11) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 12" do
str = "cdefghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 12) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 13" do
str = "defghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 13) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 14" do
str = "efghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 14) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 15" do
str = "fghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 15) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 16" do
str = "ghijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 16) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 17" do
str = "hijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 17) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 18" do
str = "ijklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 18) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 19" do
str = "jklmnopqrstuvwxyz"
lambda { @object.send(@method, str, 19) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 20" do
str = "klmnopqrstuvwxyz"
lambda { @object.send(@method, str, 20) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 21" do
str = "lmnopqrstuvwxyz"
lambda { @object.send(@method, str, 21) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 22" do
str = "mnopqrstuvwxyz"
lambda { @object.send(@method, str, 22) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 23" do
str = "nopqrstuvwxyz"
lambda { @object.send(@method, str, 23) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 24" do
str = "opqrstuvwxyz"
lambda { @object.send(@method, str, 24) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 25" do
str = "pqrstuvwxyz"
lambda { @object.send(@method, str, 25) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 26" do
str = "qrstuvwxyz"
lambda { @object.send(@method, str, 26) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 27" do
str = "rstuvwxyz"
lambda { @object.send(@method, str, 27) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 28" do
str = "stuvwxyz"
lambda { @object.send(@method, str, 28) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 29" do
str = "tuvwxyz"
lambda { @object.send(@method, str, 29) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 30" do
str = "uvwxyz"
lambda { @object.send(@method, str, 30) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 31" do
str = "vwxyz"
lambda { @object.send(@method, str, 31) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 32" do
str = "wxyz"
lambda { @object.send(@method, str, 32) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 33" do
str = "xyz"
lambda { @object.send(@method, str, 33) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 34" do
str = "yz"
lambda { @object.send(@method, str, 34) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 35" do
str = "z"
lambda { @object.send(@method, str, 35) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 36" do
lambda { @object.send(@method, "{", 36) }.should raise_error(ArgumentError)
end
end
describe "Kernel.Integer" do
it_behaves_like :kernel_Integer, :Integer_method, KernelSpecs
# TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Kernel
it_behaves_like "Integer() given a String", :Integer
it_behaves_like "Integer() given a String and base", :Integer
it "is a public method" do
Kernel.Integer(10).should == 10
end
end
describe "Kernel#Integer" do
it_behaves_like :kernel_Integer, :Integer_function, KernelSpecs
# TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Object.new
it_behaves_like "Integer() given a String", :Integer
it_behaves_like "Integer() given a String and base", :Integer
it "is a private method" do
Kernel.should have_private_instance_method(:Integer)
end
end
|