|
11 | 11 | end
|
12 | 12 |
|
13 | 13 | describe "#__numeric__" do
|
14 |
| - |
15 | 14 | let(:actual) { host.__numeric__(str) }
|
16 | 15 |
|
17 | 16 | context "when the string is a whole number" do
|
18 |
| - |
19 | 17 | let(:str) { '123' }
|
20 | 18 |
|
21 |
| - it "returns the value as integer" do |
| 19 | + it "returns the value as an integer" do |
22 | 20 | expect(actual).to eq(123)
|
| 21 | + expect(actual).to be_a Integer |
23 | 22 | end
|
24 | 23 | end
|
25 | 24 |
|
26 | 25 | context "when the string is a floating point number" do
|
27 |
| - |
28 | 26 | let(:str) { '123.45' }
|
29 | 27 |
|
30 | 28 | it "returns the value as a float" do
|
31 | 29 | expect(actual).to eq(123.45)
|
| 30 | + expect(actual).to be_a Float |
32 | 31 | end
|
33 | 32 | end
|
34 | 33 |
|
35 |
| - context "when the string is a dot only" do |
| 34 | + context "when the string is a floating point number with a leading dot" do |
| 35 | + let(:str) { '.45' } |
36 | 36 |
|
| 37 | + it "returns the value as a float" do |
| 38 | + expect(actual).to eq(0.45) |
| 39 | + expect(actual).to be_a Float |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context "when the string is a dot only" do |
37 | 44 | let(:str) { '.' }
|
38 | 45 |
|
39 | 46 | it "returns zero" do
|
40 | 47 | expect(actual).to eq(0)
|
| 48 | + expect(actual).to be_a Integer |
41 | 49 | end
|
42 | 50 | end
|
43 | 51 |
|
44 |
| - context "when the string is a number with fractional part consisting of zeros" do |
| 52 | + context "when the string is a number with a trailing dot" do |
| 53 | + let(:str) { '123.' } |
45 | 54 |
|
| 55 | + it "returns zero" do |
| 56 | + expect(actual).to eq(123) |
| 57 | + expect(actual).to be_a Integer |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + context "when the string is a number with fractional part consisting of zeros" do |
46 | 62 | let(:str) { '12.000' }
|
47 | 63 |
|
48 |
| - it "returns the value as integer" do |
| 64 | + it "returns the value as an integer" do |
49 | 65 | expect(actual).to eq(12)
|
| 66 | + expect(actual).to be_a Integer |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + context "when the string is a number with leading dot then zeros" do |
| 71 | + let(:str) { '.000' } |
| 72 | + |
| 73 | + it "returns the value as an integer" do |
| 74 | + expect(actual).to eq(0) |
| 75 | + expect(actual).to be_a Integer |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + context "when the string is non-numeric" do |
| 80 | + let(:str) { 'foo' } |
| 81 | + |
| 82 | + it "raises ArgumentError" do |
| 83 | + expect { actual }.to raise_error(ArgumentError) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + context "when the string is non-numeric with leading dot" do |
| 88 | + let(:str) { '.foo' } |
| 89 | + |
| 90 | + it "raises ArgumentError" do |
| 91 | + expect { actual }.to raise_error(ArgumentError) |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + context "when the string is non-numeric with trailing dot" do |
| 96 | + let(:str) { 'foo.' } |
| 97 | + |
| 98 | + it "raises ArgumentError" do |
| 99 | + expect { actual }.to raise_error(ArgumentError) |
| 100 | + end |
| 101 | + end |
| 102 | + |
| 103 | + context "when the string is non-numeric with trailing dot and zeroes" do |
| 104 | + let(:str) { 'foo.000' } |
| 105 | + |
| 106 | + it "raises ArgumentError" do |
| 107 | + expect { actual }.to raise_error(ArgumentError) |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + context "when the string is empty" do |
| 112 | + let(:str) { '' } |
| 113 | + |
| 114 | + it "raises ArgumentError" do |
| 115 | + expect { actual }.to raise_error(ArgumentError) |
50 | 116 | end
|
51 | 117 | end
|
52 | 118 | end
|
|
0 commit comments