string_foundation 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -9
- data/Gemfile.lock +19 -19
- data/{LICENSE.txt → LICENSE} +1 -1
- data/PULL_REQUEST_TEMPLATE.md +14 -0
- data/README.md +244 -104
- data/Rakefile +3 -3
- data/bin/console +1 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/application.css +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/application.js +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/border.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/controls.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/loading.gif +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/loading_background.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_green.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_red.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_yellow.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/loading.gif +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/magnify.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +5885 -3160
- data/lib/string_foundation.rb +4 -2
- data/lib/string_foundation/blank.rb +17 -0
- data/lib/string_foundation/case.rb +28 -38
- data/lib/string_foundation/convert.rb +9 -9
- data/lib/string_foundation/convertible.rb +4 -4
- data/lib/string_foundation/is.rb +13 -0
- data/lib/string_foundation/length.rb +56 -0
- data/lib/string_foundation/like.rb +4 -4
- data/lib/string_foundation/version.rb +2 -2
- data/lib/string_foundation/with.rb +7 -7
- data/pkg/string_foundation-1.1.0.gem +0 -0
- data/spec/spec_helper.rb +10 -10
- data/spec/string_foundation/blank_spec.rb +91 -0
- data/spec/string_foundation/case_spec.rb +398 -433
- data/spec/string_foundation/convert_spec.rb +98 -98
- data/spec/string_foundation/convertible_spec.rb +286 -0
- data/spec/string_foundation/is_spec.rb +62 -0
- data/spec/string_foundation/length_spec.rb +226 -0
- data/spec/string_foundation/like_spec.rb +103 -103
- data/spec/string_foundation/version_spec.rb +4 -4
- data/spec/string_foundation/with_spec.rb +48 -48
- data/spec/support/enhanced_matchers_extension.rb +1 -0
- data/string_foundation.gemspec +15 -14
- metadata +46 -37
- data/circle.yml +0 -14
- data/pkg/string_foundation-1.0.0.gem +0 -0
- data/spec/string_foundation/convertaile_spec.rb +0 -286
@@ -1,30 +1,30 @@
|
|
1
1
|
# ==============================================================================
|
2
|
-
# SPEC - STRING FOUNDATION - CONVERT
|
3
|
-
# ==============================================================================
|
2
|
+
# SPEC - STRING FOUNDATION - CONVERT SPEC
|
4
3
|
# frozen_string_literal: true
|
5
|
-
|
4
|
+
# ==============================================================================
|
5
|
+
describe "[ Convert Methods ]" do
|
6
6
|
|
7
7
|
# ----------------------------------------------------------------------------
|
8
8
|
# Convert To TrueClass Or FalseClass
|
9
9
|
# ----------------------------------------------------------------------------
|
10
|
-
describe
|
10
|
+
describe "CONVERT TO TRUECLASS OR FALSE CLASS" do
|
11
11
|
let(:string) { nil }
|
12
12
|
subject { string.to_bool }
|
13
13
|
|
14
|
-
context
|
15
|
-
let(:string) {
|
14
|
+
context "when a string is \"true\"," do
|
15
|
+
let(:string) { "true" }
|
16
16
|
|
17
|
-
it { is_expected.to
|
17
|
+
it { is_expected.to be true }
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
let(:string) {
|
20
|
+
context "when a string is \"false\"," do
|
21
|
+
let(:string) { "false" }
|
22
22
|
|
23
|
-
it { is_expected.to
|
23
|
+
it { is_expected.to be false }
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
27
|
-
let(:string) {
|
26
|
+
context "when a string is invalid," do
|
27
|
+
let(:string) { "dummy" }
|
28
28
|
|
29
29
|
it { is_expected_as_block.to raise_error(TypeError) }
|
30
30
|
end
|
@@ -34,68 +34,68 @@ describe '[ Convert Methods ]' do
|
|
34
34
|
# ----------------------------------------------------------------------------
|
35
35
|
# Convert A BOOLY STRING To TrueClass Or FalseClass
|
36
36
|
# ----------------------------------------------------------------------------
|
37
|
-
describe
|
37
|
+
describe "CONVERT A BOOLY STRING TO TRUECLASS OR FALSE CLASS" do
|
38
38
|
let(:string) { nil }
|
39
39
|
subject { string.to_booly }
|
40
40
|
|
41
|
-
context
|
42
|
-
let(:string) {
|
41
|
+
context "when a string is \"true\"," do
|
42
|
+
let(:string) { "true" }
|
43
43
|
|
44
|
-
it { is_expected.to
|
44
|
+
it { is_expected.to be true }
|
45
45
|
end
|
46
46
|
|
47
|
-
context
|
48
|
-
let(:string) {
|
47
|
+
context "when a string is \"false\"," do
|
48
|
+
let(:string) { "false" }
|
49
49
|
|
50
|
-
it { is_expected.to
|
50
|
+
it { is_expected.to be false }
|
51
51
|
end
|
52
52
|
|
53
|
-
context
|
54
|
-
let(:string) {
|
53
|
+
context "when a string is invalid," do
|
54
|
+
let(:string) { "dummy" }
|
55
55
|
|
56
56
|
it { is_expected_as_block.to raise_error(TypeError) }
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
60
|
-
let(:string) {
|
59
|
+
context "when a string is a positive integral number," do
|
60
|
+
let(:string) { "1" }
|
61
61
|
|
62
|
-
it { is_expected.to
|
62
|
+
it { is_expected.to be true }
|
63
63
|
end
|
64
64
|
|
65
|
-
context
|
66
|
-
let(:string) {
|
65
|
+
context "when a string is a negative integral number," do
|
66
|
+
let(:string) { "-1" }
|
67
67
|
|
68
|
-
it { is_expected.to
|
68
|
+
it { is_expected.to be false }
|
69
69
|
end
|
70
70
|
|
71
|
-
context
|
72
|
-
let(:string) {
|
71
|
+
context "when a string is a positive floating point number," do
|
72
|
+
let(:string) { "0.1" }
|
73
73
|
|
74
|
-
it { is_expected.to
|
74
|
+
it { is_expected.to be true }
|
75
75
|
end
|
76
76
|
|
77
|
-
context
|
78
|
-
let(:string) {
|
77
|
+
context "when a string is a negative floating point number," do
|
78
|
+
let(:string) { "-0.1" }
|
79
79
|
|
80
|
-
it { is_expected.to
|
80
|
+
it { is_expected.to be false }
|
81
81
|
end
|
82
82
|
|
83
|
-
context
|
84
|
-
let(:string) {
|
83
|
+
context "when a string is 0," do
|
84
|
+
let(:string) { "0" }
|
85
85
|
|
86
|
-
it { is_expected.to
|
86
|
+
it { is_expected.to be false }
|
87
87
|
end
|
88
88
|
|
89
|
-
context
|
90
|
-
let(:string) {
|
89
|
+
context "when a string is 0.0," do
|
90
|
+
let(:string) { "0.0" }
|
91
91
|
|
92
|
-
it { is_expected.to
|
92
|
+
it { is_expected.to be false }
|
93
93
|
end
|
94
94
|
|
95
|
-
context
|
96
|
-
let(:string) {
|
95
|
+
context "when a string is an empty string," do
|
96
|
+
let(:string) { "" }
|
97
97
|
|
98
|
-
it { is_expected.to
|
98
|
+
it { is_expected.to be false }
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -103,62 +103,62 @@ describe '[ Convert Methods ]' do
|
|
103
103
|
# ----------------------------------------------------------------------------
|
104
104
|
# Convert To Proper Class From String
|
105
105
|
# ----------------------------------------------------------------------------
|
106
|
-
describe
|
106
|
+
describe "CONVER TO PROPER CLASS FROM STRING" do
|
107
107
|
let(:string) { nil }
|
108
108
|
subject { string.to_pretty }
|
109
109
|
|
110
|
-
context
|
111
|
-
let(:string) {
|
110
|
+
context "when a string is \"0\"," do
|
111
|
+
let(:string) { "0" }
|
112
112
|
|
113
|
-
it { is_expected.to eq
|
113
|
+
it { is_expected.to eq(0) }
|
114
114
|
end
|
115
115
|
|
116
|
-
context
|
117
|
-
let(:string) {
|
116
|
+
context "when a string is \"1\"," do
|
117
|
+
let(:string) { "1" }
|
118
118
|
|
119
|
-
it { is_expected.to eq
|
119
|
+
it { is_expected.to eq(1) }
|
120
120
|
end
|
121
121
|
|
122
|
-
context
|
123
|
-
let(:string) {
|
122
|
+
context "when a string is \"000123\"," do
|
123
|
+
let(:string) { "000123" }
|
124
124
|
|
125
|
-
it { is_expected.to eq
|
125
|
+
it { is_expected.to eq(123) }
|
126
126
|
end
|
127
127
|
|
128
|
-
context
|
129
|
-
let(:string) {
|
128
|
+
context "when a string is \"0.0\"," do
|
129
|
+
let(:string) { "0.0" }
|
130
130
|
|
131
|
-
it { is_expected.to eq
|
131
|
+
it { is_expected.to eq(0.0) }
|
132
132
|
end
|
133
133
|
|
134
|
-
context
|
135
|
-
let(:string) {
|
134
|
+
context "when a string is \"000.00123\"," do
|
135
|
+
let(:string) { "000.00123" }
|
136
136
|
|
137
|
-
it { is_expected.to eq
|
137
|
+
it { is_expected.to eq(0.00123) }
|
138
138
|
end
|
139
139
|
|
140
|
-
context
|
141
|
-
let(:string) {
|
140
|
+
context "when a string is \"true\"," do
|
141
|
+
let(:string) { "true" }
|
142
142
|
|
143
|
-
it { is_expected.to
|
143
|
+
it { is_expected.to be true }
|
144
144
|
end
|
145
145
|
|
146
|
-
context
|
147
|
-
let(:string) {
|
146
|
+
context "when a string is \"false\"," do
|
147
|
+
let(:string) { "false" }
|
148
148
|
|
149
|
-
it { is_expected.to
|
149
|
+
it { is_expected.to be false }
|
150
150
|
end
|
151
151
|
|
152
|
-
context
|
153
|
-
let(:string) {
|
152
|
+
context "when a string is \"dummy\"," do
|
153
|
+
let(:string) { "dummy" }
|
154
154
|
|
155
|
-
it { is_expected.to eq
|
155
|
+
it { is_expected.to eq(string) }
|
156
156
|
end
|
157
157
|
|
158
|
-
context
|
159
|
-
let(:string) {
|
158
|
+
context "when a string is an empty string," do
|
159
|
+
let(:string) { "" }
|
160
160
|
|
161
|
-
it { is_expected.to
|
161
|
+
it { is_expected.to be_nil }
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -166,43 +166,43 @@ describe '[ Convert Methods ]' do
|
|
166
166
|
# ----------------------------------------------------------------------------
|
167
167
|
# Convert From Newline To Characters
|
168
168
|
# ----------------------------------------------------------------------------
|
169
|
-
describe
|
170
|
-
let(:string) { "
|
171
|
-
let(:char) {
|
169
|
+
describe "CONVERT FROM NEWLINE TO CHARACTERS" do
|
170
|
+
let(:string) { "I am Jaga Apple.\nI am Jaga Apple." }
|
171
|
+
let(:char) { "<br>" }
|
172
172
|
subject { string.nl_to(char) }
|
173
173
|
|
174
|
-
context
|
175
|
-
it { is_expected.to eq
|
174
|
+
context "when a string has newlines \"\\n\"," do
|
175
|
+
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
|
176
176
|
end
|
177
177
|
|
178
|
-
context
|
179
|
-
let(:string) { "
|
178
|
+
context "when a string has newlines \"\\r\\n\"," do
|
179
|
+
let(:string) { "I am Jaga Apple.\r\nI am Jaga Apple." }
|
180
180
|
|
181
|
-
it { is_expected.to eq
|
181
|
+
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
|
182
182
|
end
|
183
183
|
|
184
|
-
context
|
185
|
-
let(:string) { "
|
184
|
+
context "when a string does not have newlines," do
|
185
|
+
let(:string) { "I am Jaga Apple. I am Jaga Apple." }
|
186
186
|
|
187
|
-
it { is_expected.to eq
|
187
|
+
it { is_expected.to eq(string) }
|
188
188
|
end
|
189
189
|
|
190
|
-
context
|
191
|
-
subject { string.nl_to
|
190
|
+
context "when an argument is not set," do
|
191
|
+
subject { string.nl_to }
|
192
192
|
|
193
193
|
it { is_expected_as_block.to raise_error(ArgumentError) }
|
194
194
|
end
|
195
195
|
|
196
|
-
context
|
196
|
+
context "when an argument is nil," do
|
197
197
|
let(:char) { nil }
|
198
198
|
|
199
|
-
it { is_expected.to eq
|
199
|
+
it { is_expected.to eq("I am Jaga Apple.I am Jaga Apple.") }
|
200
200
|
end
|
201
201
|
|
202
|
-
context
|
203
|
-
let(:char) {
|
202
|
+
context "when an argument is an empty string," do
|
203
|
+
let(:char) { "" }
|
204
204
|
|
205
|
-
it { is_expected.to eq
|
205
|
+
it { is_expected.to eq("I am Jaga Apple.I am Jaga Apple.") }
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
@@ -210,24 +210,24 @@ describe '[ Convert Methods ]' do
|
|
210
210
|
# ----------------------------------------------------------------------------
|
211
211
|
# Convert From Newline To <br>
|
212
212
|
# ----------------------------------------------------------------------------
|
213
|
-
describe
|
214
|
-
let(:string) { "
|
213
|
+
describe "CONVERT FROM NEWLINE TO `<br>`" do
|
214
|
+
let(:string) { "I am Jaga Apple.\nI am Jaga Apple." }
|
215
215
|
subject { string.nl_to_br }
|
216
216
|
|
217
|
-
context
|
218
|
-
it { is_expected.to eq
|
217
|
+
context "when a string has newlines \"\n\"," do
|
218
|
+
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
|
219
219
|
end
|
220
220
|
|
221
|
-
context
|
222
|
-
let(:string) { "
|
221
|
+
context "when a string has newlines \"\\r\\n\"," do
|
222
|
+
let(:string) { "I am Jaga Apple.\r\nI am Jaga Apple." }
|
223
223
|
|
224
|
-
it { is_expected.to eq
|
224
|
+
it { is_expected.to eq("I am Jaga Apple.<br>I am Jaga Apple.") }
|
225
225
|
end
|
226
226
|
|
227
|
-
context
|
228
|
-
let(:string) { "
|
227
|
+
context "when a string does not have newlines," do
|
228
|
+
let(:string) { "I am Jaga Apple. I am Jaga Apple." }
|
229
229
|
|
230
|
-
it { is_expected.to eq
|
230
|
+
it { is_expected.to eq(string) }
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -0,0 +1,286 @@
|
|
1
|
+
# ==============================================================================
|
2
|
+
# SPEC - STRING FOUNDATION - CONVERTIBLE SPEC
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# ==============================================================================
|
5
|
+
describe "[ Convertible Methods ]" do
|
6
|
+
|
7
|
+
# ----------------------------------------------------------------------------
|
8
|
+
# Check Convertible To Integer
|
9
|
+
# ----------------------------------------------------------------------------
|
10
|
+
describe "CHECK CONVERTIBLE TO INTEGER" do
|
11
|
+
let(:string) { nil }
|
12
|
+
subject { string.to_i? }
|
13
|
+
|
14
|
+
context "when a string is an integral number," do
|
15
|
+
context "it is a positive number," do
|
16
|
+
let(:string) { "123" }
|
17
|
+
|
18
|
+
it { is_expected.to be true }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "it is a positive number with a sign," do
|
22
|
+
let(:string) { "+123" }
|
23
|
+
|
24
|
+
it { is_expected.to be true }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "it is a negative number," do
|
28
|
+
let(:string) { "-5" }
|
29
|
+
|
30
|
+
it { is_expected.to be true }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when a string is a floating point number," do
|
35
|
+
context "it is a positive number," do
|
36
|
+
let(:string) { "0.123" }
|
37
|
+
|
38
|
+
it { is_expected.to be true }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "it is a positive number with a sign," do
|
42
|
+
let(:string) { "+0.123" }
|
43
|
+
|
44
|
+
it { is_expected.to be true }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "it is a negative number," do
|
48
|
+
let(:string) { "-5.123" }
|
49
|
+
|
50
|
+
it { is_expected.to be true }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when a string is a floating point number without an integer," do
|
55
|
+
context "it is a positive number," do
|
56
|
+
let(:string) { ".123" }
|
57
|
+
|
58
|
+
it { is_expected.to be true }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "it is a positive number with a sign," do
|
62
|
+
let(:string) { "+.123" }
|
63
|
+
|
64
|
+
it { is_expected.to be true }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "it is a negative number," do
|
68
|
+
let(:string) { "-.123" }
|
69
|
+
|
70
|
+
it { is_expected.to be true }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when a string a number has leading zeros," do
|
75
|
+
context "it is a positive number," do
|
76
|
+
let(:string) { "00000123" }
|
77
|
+
|
78
|
+
it { is_expected.to be true }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "it is a positive number with a sign," do
|
82
|
+
let(:string) { "+00000123" }
|
83
|
+
|
84
|
+
it { is_expected.to be true }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "it is a negative number," do
|
88
|
+
let(:string) { "-00000123" }
|
89
|
+
|
90
|
+
it { is_expected.to be true }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when a string is not a number," do
|
95
|
+
let(:string) { "abc" }
|
96
|
+
|
97
|
+
it { is_expected.to be false }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# ----------------------------------------------------------------------------
|
103
|
+
# Check Convertible To Float
|
104
|
+
# ----------------------------------------------------------------------------
|
105
|
+
describe "CHECK CONVERTIBLE TO FLOAT" do
|
106
|
+
let(:string) { nil }
|
107
|
+
subject { string.to_f? }
|
108
|
+
|
109
|
+
context "when a string is an integral number," do
|
110
|
+
context "it is a positive number," do
|
111
|
+
let(:string) { "123" }
|
112
|
+
|
113
|
+
it { is_expected.to be true }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "it is a positive number with a sign," do
|
117
|
+
let(:string) { "+123" }
|
118
|
+
|
119
|
+
it { is_expected.to be true }
|
120
|
+
end
|
121
|
+
|
122
|
+
context "it is a negative number," do
|
123
|
+
let(:string) { "-5" }
|
124
|
+
|
125
|
+
it { is_expected.to be true }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "when a string is a floating point number," do
|
130
|
+
context "it is a positive number," do
|
131
|
+
let(:string) { "0.123" }
|
132
|
+
|
133
|
+
it { is_expected.to be true }
|
134
|
+
end
|
135
|
+
|
136
|
+
context "it is a positive number with a sign," do
|
137
|
+
let(:string) { "+0.123" }
|
138
|
+
|
139
|
+
it { is_expected.to be true }
|
140
|
+
end
|
141
|
+
|
142
|
+
context "it is a negative number," do
|
143
|
+
let(:string) { "-5.123" }
|
144
|
+
|
145
|
+
it { is_expected.to be true }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when a string is a floating point number without an integer," do
|
150
|
+
context "it is a positive number," do
|
151
|
+
let(:string) { ".123" }
|
152
|
+
|
153
|
+
it { is_expected.to be true }
|
154
|
+
end
|
155
|
+
|
156
|
+
context "it is a positive number with a sign," do
|
157
|
+
let(:string) { "+.123" }
|
158
|
+
|
159
|
+
it { is_expected.to be true }
|
160
|
+
end
|
161
|
+
|
162
|
+
context "it is a negative number," do
|
163
|
+
let(:string) { "-.123" }
|
164
|
+
|
165
|
+
it { is_expected.to be true }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "when a string a number has leading zeros," do
|
170
|
+
context "it is a positive number," do
|
171
|
+
let(:string) { "00000123" }
|
172
|
+
|
173
|
+
it { is_expected.to be true }
|
174
|
+
end
|
175
|
+
|
176
|
+
context "it is a positive number with a sign," do
|
177
|
+
let(:string) { "+00000123" }
|
178
|
+
|
179
|
+
it { is_expected.to be true }
|
180
|
+
end
|
181
|
+
|
182
|
+
context "it is a negative number," do
|
183
|
+
let(:string) { "-00000123" }
|
184
|
+
|
185
|
+
it { is_expected.to be true }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "when a string is not a number," do
|
190
|
+
let(:string) { "abc" }
|
191
|
+
|
192
|
+
it { is_expected.to be false }
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# ----------------------------------------------------------------------------
|
198
|
+
# Check Convertible To Boolean
|
199
|
+
# ----------------------------------------------------------------------------
|
200
|
+
describe "CHECK CONVERTIBLE TO BOOLEAN" do
|
201
|
+
let(:string) { nil }
|
202
|
+
subject { string.to_bool? }
|
203
|
+
|
204
|
+
context "when a string is \"true\"," do
|
205
|
+
let(:string) { "true" }
|
206
|
+
|
207
|
+
it { is_expected.to be true }
|
208
|
+
end
|
209
|
+
|
210
|
+
context "when a string is \"false\"," do
|
211
|
+
let(:string) { "false" }
|
212
|
+
|
213
|
+
it { is_expected.to be true }
|
214
|
+
end
|
215
|
+
|
216
|
+
context "when a string is empty," do
|
217
|
+
let(:string) { "" }
|
218
|
+
|
219
|
+
it { is_expected.to be false }
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when a string is a positive number," do
|
223
|
+
let(:string) { "1" }
|
224
|
+
|
225
|
+
it { is_expected.to be false }
|
226
|
+
end
|
227
|
+
|
228
|
+
context "when a string is a negative number," do
|
229
|
+
let(:string) { "-1" }
|
230
|
+
|
231
|
+
it { is_expected.to be false }
|
232
|
+
end
|
233
|
+
|
234
|
+
context "when a string is not a number," do
|
235
|
+
let(:string) { "abc" }
|
236
|
+
|
237
|
+
it { is_expected.to be false }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# ----------------------------------------------------------------------------
|
243
|
+
# Check Convertaile To Booly
|
244
|
+
# ----------------------------------------------------------------------------
|
245
|
+
describe "CHECK CONVERTIBLE TO BOOLYs" do
|
246
|
+
let(:string) { nil }
|
247
|
+
subject { string.to_booly? }
|
248
|
+
|
249
|
+
context "when a string is \"true\"," do
|
250
|
+
let(:string) { "true" }
|
251
|
+
|
252
|
+
it { is_expected.to be true }
|
253
|
+
end
|
254
|
+
|
255
|
+
context "when a string is \"false\"," do
|
256
|
+
let(:string) { "false" }
|
257
|
+
|
258
|
+
it { is_expected.to be true }
|
259
|
+
end
|
260
|
+
|
261
|
+
context "when a string is empty," do
|
262
|
+
let(:string) { "" }
|
263
|
+
|
264
|
+
it { is_expected.to be true }
|
265
|
+
end
|
266
|
+
|
267
|
+
context "when a string is a positive number," do
|
268
|
+
let(:string) { "1" }
|
269
|
+
|
270
|
+
it { is_expected.to be true }
|
271
|
+
end
|
272
|
+
|
273
|
+
context "when a string is a negative number," do
|
274
|
+
let(:string) { "-1" }
|
275
|
+
|
276
|
+
it { is_expected.to be true }
|
277
|
+
end
|
278
|
+
|
279
|
+
context "when a string is not a number," do
|
280
|
+
let(:string) { "abc" }
|
281
|
+
|
282
|
+
it { is_expected.to be false }
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|