active_object 1.0.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.
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+
5
+ describe "#blank?" do
6
+ it "to be true" do
7
+ expect("".blank?).to eq(true)
8
+ expect(" ".blank?).to eq(true)
9
+ expect([].blank?).to eq(true)
10
+ expect({}.blank?).to eq(true)
11
+ expect(false.blank?).to eq(true)
12
+ end
13
+
14
+ it "to be false" do
15
+ expect("x".blank?).to eq(false)
16
+ expect("foo bar".blank?).to eq(false)
17
+ expect("19".blank?).to eq(false)
18
+ expect(true.blank?).to eq(false)
19
+ end
20
+ end
21
+
22
+ describe "#numeric?" do
23
+ it "to be true" do
24
+ expect(5.numeric?).to eq(true)
25
+ expect(0.numeric?).to eq(true)
26
+ expect(-37.3.numeric?).to eq(true)
27
+ expect(51.45.numeric?).to eq(true)
28
+ expect("+256.375".numeric?).to eq(true)
29
+ expect("-37.3".numeric?).to eq(true)
30
+ end
31
+
32
+ it "to be false" do
33
+ expect("".numeric?).to eq(false)
34
+ expect(" ".numeric?).to eq(false)
35
+ expect("2.3.3".numeric?).to eq(false)
36
+ expect("$9.86".numeric?).to eq(false)
37
+ expect("x".numeric?).to eq(false)
38
+ expect("foo".numeric?).to eq(false)
39
+ end
40
+ end
41
+
42
+ describe "#palindrome?" do
43
+ it "to be true" do
44
+ expect("racecar".palindrome?).to eq(true)
45
+ expect(12321.palindrome?).to eq(true)
46
+ end
47
+
48
+ it "to be false" do
49
+ expect("example".palindrome?).to eq(false)
50
+ expect(12345.palindrome?).to eq(false)
51
+ end
52
+ end
53
+
54
+ describe "#present?" do
55
+ it "to be true" do
56
+ expect("x".present?).to eq(true)
57
+ expect("foo bar".present?).to eq(true)
58
+ expect("19".present?).to eq(true)
59
+ expect(true.present?).to eq(true)
60
+ end
61
+
62
+ it "to be false" do
63
+ expect("".present?).to eq(false)
64
+ expect([].present?).to eq(false)
65
+ expect({}.present?).to eq(false)
66
+ expect(false.present?).to eq(false)
67
+ end
68
+ end
69
+
70
+ describe "#try(!)" do
71
+ it "to be nil" do
72
+ expect("example".try(:fake_method)).to eq(nil)
73
+ end
74
+
75
+ it "to be upcase" do
76
+ expect("example".try(:upcase)).to eq("EXAMPLE")
77
+ expect("example".try!(:upcase)).to eq("EXAMPLE")
78
+ end
79
+
80
+ it "to raise error" do
81
+ expect { "example".try!(:fake_method) }.to raise_error
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,459 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ describe "#at" do
6
+ it "to be e" do
7
+ expect("example".at(0)).to eq("e")
8
+ expect("example".at(-1)).to eq("e")
9
+ end
10
+
11
+ it "to be m" do
12
+ expect("example".at(3)).to eq("m")
13
+ end
14
+
15
+ it "to be xam" do
16
+ expect("example".at(1..3)).to eq("xam")
17
+ end
18
+
19
+ it "to be ''" do
20
+ expect("example".at(7..-1)).to eq("")
21
+ end
22
+
23
+ it "to be pl" do
24
+ expect("example".at("pl")).to eq("pl")
25
+ expect("example".at(/pl/)).to eq("pl")
26
+ end
27
+
28
+ it "to be nil" do
29
+ expect("example".at("xp")).to eq(nil)
30
+ expect("example".at(/xp/)).to eq(nil)
31
+ end
32
+ end
33
+
34
+ describe "#camelize(!)" do
35
+ it "to be ExampleString" do
36
+ expect("example_string".camelize).to eq("ExampleString")
37
+ expect("example_string".camelcase).to eq("ExampleString")
38
+ expect("example_string".camelize!).to eq("ExampleString")
39
+ expect("example_string".camelcase!).to eq("ExampleString")
40
+ end
41
+
42
+ it "to be exampleString" do
43
+ expect("example_string".camelize(:lower)).to eq("exampleString")
44
+ expect("example_string".camelcase(:lower)).to eq("exampleString")
45
+ expect("example_string".camelize!(:lower)).to eq("exampleString")
46
+ expect("example_string".camelcase!(:lower)).to eq("exampleString")
47
+ end
48
+ end
49
+
50
+ describe "#classify" do
51
+ it "to be ExampleString" do
52
+ expect("example_string".classify).to eq("ExampleString")
53
+ expect("example_string".classify!).to eq("ExampleString")
54
+ end
55
+
56
+ it "to be ExampleString::Test" do
57
+ expect("example_string/test".classify).to eq("ExampleString::Test")
58
+ expect("example_string/test".classify!).to eq("ExampleString::Test")
59
+ end
60
+
61
+ it "to be Test" do
62
+ expect("example_string.test".classify).to eq("Test")
63
+ expect("example_string.test".classify!).to eq("Test")
64
+ end
65
+ end
66
+
67
+ describe "#demodulize" do
68
+ it "to be String" do
69
+ expect("Example::String".demodulize).to eq("String")
70
+ expect("Example::String".demodulize!).to eq("String")
71
+ expect("String".demodulize).to eq("String")
72
+ expect("String".demodulize!).to eq("String")
73
+ end
74
+ end
75
+
76
+ describe "#dasherize" do
77
+ it "to be example-string" do
78
+ expect("example_string".dasherize).to eq("example-string")
79
+ expect("example_string".dasherize!).to eq("example-string")
80
+ end
81
+ end
82
+
83
+ describe "#domain" do
84
+ it "to be ''" do
85
+ expect("".domain).to eq("")
86
+ end
87
+
88
+ it "to be ' '" do
89
+ expect(" ".domain).to eq(" ")
90
+ end
91
+
92
+ it "to be example string" do
93
+ expect("example string".domain).to eq("example string")
94
+ end
95
+
96
+ it "to be www.example.com" do
97
+ expect("http://www.example.com".domain).to eq("www.example.com")
98
+ expect("http://www.example.com/fake-page".domain).to eq("www.example.com")
99
+ end
100
+ end
101
+
102
+ describe "#downcase?" do
103
+ it "to be true" do
104
+ expect("downcase".downcase?).to eq(true)
105
+ expect("downcase string".downcase?).to eq(true)
106
+ end
107
+
108
+ it "to be false" do
109
+ expect("Mixedcase".downcase?).to eq(false)
110
+ expect("UPCASE".downcase?).to eq(false)
111
+ expect("Mixedcase string".downcase?).to eq(false)
112
+ end
113
+ end
114
+
115
+ describe "#ellipsize" do
116
+ it "to be 0123...WXYZ" do
117
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(30)).to eq("0123...WXYZ")
118
+ end
119
+
120
+ it "to be 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" do
121
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(50)).to eq("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
122
+ end
123
+
124
+ it "to be 012...XYZ" do
125
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(30, offset: 3)).to eq("012...XYZ")
126
+ end
127
+
128
+ it "to be 0123+++WXYZ" do
129
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(30, separator: "+++")).to eq("0123+++WXYZ")
130
+ end
131
+ end
132
+
133
+ describe "#exclude?" do
134
+ it "to be true" do
135
+ expect("example_string".exclude?("xxx")).to eq(true)
136
+ end
137
+
138
+ it "to be false" do
139
+ expect("example_string".exclude?("exa")).to eq(false)
140
+ end
141
+ end
142
+
143
+ describe "#first" do
144
+ it "to be e" do
145
+ expect("example".first).to eq("e")
146
+ end
147
+
148
+ it "to be ''" do
149
+ expect("example".first(0)).to eq("")
150
+ end
151
+
152
+ it "to be exa" do
153
+ expect("example".first(3)).to eq("exa")
154
+ end
155
+ end
156
+
157
+ describe "#from" do
158
+ it "to be example" do
159
+ expect("example".from(0)).to eq("example")
160
+ end
161
+
162
+ it "to be mple" do
163
+ expect("example".from(3)).to eq("mple")
164
+ end
165
+ end
166
+
167
+ describe "#humanize(!)" do
168
+ it "to be Example string test" do
169
+ expect("example_string_test".humanize).to eq("Example string test")
170
+ expect("example_string_test".humanize!).to eq("Example string test")
171
+ expect("exampleStringTest".humanize).to eq("Example string test")
172
+ expect("exampleStringTest".humanize!).to eq("Example string test")
173
+ expect("ExampleStringTest".humanize).to eq("Example string test")
174
+ expect("ExampleStringTest".humanize!).to eq("Example string test")
175
+ end
176
+
177
+ it "to be example string test" do
178
+ expect("example_string_test".humanize(capitalize: false)).to eq("example string test")
179
+ expect("example_string_test".humanize!(capitalize: false)).to eq("example string test")
180
+ expect("exampleStringTest".humanize(capitalize: false)).to eq("example string test")
181
+ expect("exampleStringTest".humanize!(capitalize: false)).to eq("example string test")
182
+ expect("ExampleStringTest".humanize(capitalize: false)).to eq("example string test")
183
+ expect("ExampleStringTest".humanize!(capitalize: false)).to eq("example string test")
184
+ end
185
+ end
186
+
187
+ describe "#indent(!)" do
188
+ it "to be ' example'" do
189
+ expect("example".indent(2)).to eq(" example")
190
+ expect("example".indent!(2)).to eq(" example")
191
+ end
192
+
193
+ it "to be '\t\texample'" do
194
+ expect("example".indent(2, "\t")).to eq("\t\texample")
195
+ expect("example".indent!(2, "\t")).to eq("\t\texample")
196
+ end
197
+ end
198
+
199
+ describe "#last" do
200
+ it "to be e" do
201
+ expect("example".last).to eq("e")
202
+ end
203
+
204
+ it "to be ''" do
205
+ expect("example".last(0)).to eq("")
206
+ end
207
+
208
+ it "to be ple" do
209
+ expect("example".last(3)).to eq("ple")
210
+ end
211
+ end
212
+
213
+ describe "#mixedcase?" do
214
+ it "to be true" do
215
+ expect("Mixedcase".mixedcase?).to eq(true)
216
+ expect("Mixedcase STRING type".mixedcase?).to eq(true)
217
+ end
218
+
219
+ it "to be false" do
220
+ expect("downcase".mixedcase?).to eq(false)
221
+ expect("UPCASE".mixedcase?).to eq(false)
222
+ end
223
+ end
224
+
225
+ describe "#ordinal" do
226
+ it "to be st" do
227
+ expect("1".ordinal).to eq("st")
228
+ end
229
+
230
+ it "to be nd" do
231
+ expect("2".ordinal).to eq("nd")
232
+ end
233
+
234
+ it "to be rd" do
235
+ expect("3".ordinal).to eq("rd")
236
+ end
237
+
238
+ it "to be th" do
239
+ expect("11".ordinal).to eq("th")
240
+ end
241
+ end
242
+
243
+ describe "#ordinalize" do
244
+ it "to be st" do
245
+ expect("1".ordinalize).to eq("1st")
246
+ end
247
+
248
+ it "to be nd" do
249
+ expect("2".ordinalize).to eq("2nd")
250
+ end
251
+
252
+ it "to be rd" do
253
+ expect("3".ordinalize).to eq("3rd")
254
+ end
255
+
256
+ it "to be th" do
257
+ expect("11".ordinalize).to eq("11th")
258
+ end
259
+ end
260
+
261
+ describe "#parameterize(!)" do
262
+ it "to be example-string" do
263
+ expect("example_string".parameterize).to eq("example-string")
264
+ expect("example_string".parameterize!).to eq("example-string")
265
+ end
266
+
267
+ it "to be example_string" do
268
+ expect("example_string".parameterize("?")).to eq("example?string")
269
+ expect("example_string".parameterize!("?")).to eq("example?string")
270
+ end
271
+ end
272
+
273
+ describe "#pollute" do
274
+ it "to be t^--^--^e^--^--^s^--^--^t^--^--^" do
275
+ expect("test".pollute).to eq("t^--^--^e^--^--^s^--^--^t^--^--^")
276
+ end
277
+
278
+ it "to be t-e-s-t-" do
279
+ expect("test".pollute("-")).to eq("t-e-s-t-")
280
+ end
281
+ end
282
+
283
+ describe "#remove(!)" do
284
+ it "to be 'this that '" do
285
+ expect("this thing that thing".remove("thing")).to eq("this that ")
286
+ expect("this thing that thing".remove!("thing")).to eq("this that ")
287
+ expect("this thing that them".remove("thing", "them")).to eq("this that ")
288
+ expect("this thing that them".remove!("thing", "them")).to eq("this that ")
289
+ end
290
+ end
291
+
292
+ describe "#remove_tags(!)" do
293
+ it "to be example" do
294
+ expect("example".remove_tags).to eq("example")
295
+ expect("example".remove_tags!).to eq("example")
296
+ end
297
+
298
+ it "to be click" do
299
+ expect("<a href='http://example.com'>click</a>".remove_tags).to eq("click")
300
+ expect("<a href='http://example.com'>click</a>".remove_tags!).to eq("click")
301
+ end
302
+
303
+ it "to be this is bold and emphatic" do
304
+ expect("this is <b>bold</b> and <em>emphatic</em>".remove_tags).to eq("this is bold and emphatic")
305
+ expect("this is <b>bold</b> and <em>emphatic</em>".remove_tags!).to eq("this is bold and emphatic")
306
+ end
307
+ end
308
+
309
+ describe "#shift(!)" do
310
+ it "to be 'this that thing'" do
311
+ expect("this thing that thing".shift("thing")).to eq("this that thing")
312
+ expect("this thing that thing".shift!("thing")).to eq("this that thing")
313
+ end
314
+
315
+ it "to be ' thing thing'" do
316
+ expect("this thing that thing".shift("this", "that")).to eq(" thing thing")
317
+ expect("this thing that thing".shift!("this", "that")).to eq(" thing thing")
318
+ end
319
+ end
320
+
321
+ describe "#slugify(!)" do
322
+ it "to be example" do
323
+ expect("example".slugify).to eq("example")
324
+ expect("example".slugify!).to eq("example")
325
+ end
326
+
327
+ it "to be example-string" do
328
+ expect("example string".slugify).to eq("example-string")
329
+ expect("example string".slugify!).to eq("example-string")
330
+ end
331
+
332
+ it "to be example-string-test" do
333
+ expect("Example string @@@ test!".slugify).to eq("example-string-test")
334
+ expect("Example string @@@ test!".slugify!).to eq("example-string-test")
335
+ end
336
+
337
+ it "to be a-real-doozie" do
338
+ expect(" A REal Doozi\"e? \' ".slugify).to eq("a-real-doozie")
339
+ expect(" A REal Doozi\"e? \' ".slugify!).to eq("a-real-doozie")
340
+ end
341
+ end
342
+
343
+ describe "#squish(!)" do
344
+ it "to be example test" do
345
+ expect("example test".squish).to eq("example test")
346
+ expect("example \n \t test".squish!).to eq("example test")
347
+ expect(" example \n \t test ".squish).to eq("example test")
348
+ expect(" example test ".squish!).to eq("example test")
349
+ end
350
+ end
351
+
352
+ describe "#titleize(!)" do
353
+ it "to be Example String Test" do
354
+ expect("example string test".titleize).to eq("Example String Test")
355
+ expect("example string test".titlecase).to eq("Example String Test")
356
+ expect("example string test".titleize!).to eq("Example String Test")
357
+ expect("example string test".titlecase!).to eq("Example String Test")
358
+ expect("Example string Test".titleize).to eq("Example String Test")
359
+ expect("Example string Test".titleize!).to eq("Example String Test")
360
+ expect("ExampleStringTest".titleize).to eq("Example String Test")
361
+ expect("ExampleStringTest".titleize!).to eq("Example String Test")
362
+ expect("Example_string_test".titleize).to eq("Example String Test")
363
+ expect("Example_string_test".titleize!).to eq("Example String Test")
364
+ end
365
+ end
366
+
367
+ describe "#to" do
368
+ it "to be e" do
369
+ expect("example".to(0)).to eq("e")
370
+ end
371
+
372
+ it "to be exampl" do
373
+ expect("example".to(-2)).to eq("exampl")
374
+ end
375
+
376
+ it "to be exam" do
377
+ expect("example".to(3)).to eq("exam")
378
+ end
379
+ end
380
+
381
+ describe "#truncate" do
382
+ it "to be ..." do
383
+ expect("example string".truncate(3)).to eq("...")
384
+ end
385
+
386
+ it "to be exa..." do
387
+ expect("example string".truncate(6)).to eq("exa...")
388
+ end
389
+
390
+ it "to be example..." do
391
+ expect("example string".truncate(12, separator: " ")).to eq("example...")
392
+ end
393
+
394
+ it "to be exa... (more)" do
395
+ expect("example string".truncate(13, omission: "... (more)")).to eq("exa... (more)")
396
+ end
397
+
398
+ it "to be example string" do
399
+ expect("example string".truncate(15)).to eq("example string")
400
+ end
401
+ end
402
+
403
+ describe "#truncate_words" do
404
+ it "to be example..." do
405
+ expect("example string test".truncate_words(1)).to eq("example...")
406
+ end
407
+
408
+ it "to be Once<br>upon<br>a<br>time<br>in..." do
409
+ expect('Once<br>upon<br>a<br>time<br>in<br>a<br>world'.truncate_words(5, separator: '<br>')).to eq("Once<br>upon<br>a<br>time<br>in...")
410
+ end
411
+
412
+ it "to be And they found that many... (continued)" do
413
+ expect('And they found that many people were sleeping better.'.truncate_words(5, omission: '... (continued)')).to eq("And they found that many... (continued)")
414
+ end
415
+ end
416
+
417
+ describe "#underscore(!)" do
418
+ it "to be example_string" do
419
+ expect("ExampleString".underscore).to eq("example_string")
420
+ expect("ExampleString".underscore!).to eq("example_string")
421
+ expect("exampleString".underscore).to eq("example_string")
422
+ expect("exampleString".underscore!).to eq("example_string")
423
+ expect("example_string".underscore).to eq("example_string")
424
+ expect("example_string".underscore!).to eq("example_string")
425
+ expect("example_String".underscore).to eq("example_string")
426
+ expect("example_String".underscore!).to eq("example_string")
427
+ expect("EXAMPLE_String".underscore!).to eq("example_string")
428
+ end
429
+
430
+ it "to be example_string/test" do
431
+ expect("ExampleString::Test".underscore).to eq("example_string/test")
432
+ expect("ExampleString::Test".underscore!).to eq("example_string/test")
433
+ end
434
+ end
435
+
436
+ describe "#unpollute" do
437
+ it "to be test" do
438
+ expect("test".unpollute).to eq("test")
439
+ end
440
+
441
+ it "to be test" do
442
+ expect("t-e-s-t-".unpollute("-")).to eq("test")
443
+ end
444
+ end
445
+
446
+ describe "#upcase?" do
447
+ it "to be true" do
448
+ expect("UPCASE".upcase?).to eq(true)
449
+ expect("UPCASE STRING".upcase?).to eq(true)
450
+ end
451
+
452
+ it "to be false" do
453
+ expect("downcase".upcase?).to eq(false)
454
+ expect("Mixedcase".upcase?).to eq(false)
455
+ expect("Mixedcase string".upcase?).to eq(false)
456
+ end
457
+ end
458
+
459
+ end