nobiru 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,271 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ describe "#camelize(!)" do
6
+ it "to be ExampleString" do
7
+ expect("example_string".camelize).to eq("ExampleString")
8
+ expect("example_string".camelize!).to eq("ExampleString")
9
+ end
10
+
11
+ it "to be exampleString" do
12
+ expect("example_string".camelize(:lower)).to eq("exampleString")
13
+ expect("example_string".camelize!(:lower)).to eq("exampleString")
14
+ end
15
+ end
16
+
17
+ describe "#ends_with?" do
18
+ it "to be true" do
19
+ expect("".ends_with?("")).to eq(true)
20
+ expect(" ".ends_with?(" ")).to eq(true)
21
+ expect(" ".ends_with?("")).to eq(true)
22
+ expect("example string".ends_with?("g")).to eq(true)
23
+ expect("example string".ends_with?("ng")).to eq(true)
24
+ end
25
+
26
+ it "to be false" do
27
+ expect("".ends_with?(" ")).to eq(false)
28
+ expect("e ".ends_with?("e")).to eq(false)
29
+ expect("example string".ends_with?("x")).to eq(false)
30
+ end
31
+ end
32
+
33
+ describe "#humanize(!)" do
34
+ it "to be Example string test" do
35
+ expect("example_string_test".humanize).to eq("Example string test")
36
+ expect("example_string_test".humanize!).to eq("Example string test")
37
+ expect("exampleStringTest".humanize).to eq("Example string test")
38
+ expect("exampleStringTest".humanize!).to eq("Example string test")
39
+ expect("ExampleStringTest".humanize).to eq("Example string test")
40
+ expect("ExampleStringTest".humanize!).to eq("Example string test")
41
+ end
42
+ end
43
+
44
+ describe "#starts_with?" do
45
+ it "to be true" do
46
+ expect("".starts_with?("")).to eq(true)
47
+ expect(" ".starts_with?(" ")).to eq(true)
48
+ expect(" ".starts_with?("")).to eq(true)
49
+ expect("example string".starts_with?("e")).to eq(true)
50
+ expect("example string".starts_with?("ex")).to eq(true)
51
+ end
52
+
53
+ it "to be false" do
54
+ expect("".starts_with?(" ")).to eq(false)
55
+ expect(" e".starts_with?("e")).to eq(false)
56
+ expect("example string".starts_with?("x")).to eq(false)
57
+ end
58
+ end
59
+
60
+ describe "#titleize(!)" do
61
+ it "to be Example String Test" do
62
+ expect("example string test".titleize).to eq("Example String Test")
63
+ expect("example string test".titleize!).to eq("Example String Test")
64
+ expect("Example string Test".titleize).to eq("Example String Test")
65
+ expect("Example string Test".titleize!).to eq("Example String Test")
66
+ expect("ExampleStringTest".titleize).to eq("Example String Test")
67
+ expect("ExampleStringTest".titleize!).to eq("Example String Test")
68
+ expect("Example_string_test".titleize).to eq("Example String Test")
69
+ expect("Example_string_test".titleize!).to eq("Example String Test")
70
+ end
71
+ end
72
+
73
+ describe "#underscore(!)" do
74
+ it "to be example_string" do
75
+ expect("ExampleString".underscore).to eq("example_string")
76
+ expect("ExampleString".underscore!).to eq("example_string")
77
+ expect("exampleString".underscore).to eq("example_string")
78
+ expect("exampleString".underscore!).to eq("example_string")
79
+ expect("example_string".underscore).to eq("example_string")
80
+ expect("example_string".underscore!).to eq("example_string")
81
+ expect("example_String".underscore).to eq("example_string")
82
+ expect("example_String".underscore!).to eq("example_string")
83
+ end
84
+ end
85
+
86
+ describe "#domain" do
87
+ it "to be test" do
88
+ expect("".domain).to eq("")
89
+ expect(" ".domain).to eq(" ")
90
+ expect("example string".domain).to eq("example string")
91
+ expect("http://www.example.com".domain).to eq("www.example.com")
92
+ expect("http://www.example.com/fake-page".domain).to eq("www.example.com")
93
+ end
94
+ end
95
+
96
+ describe "#downcase?" do
97
+ it "to be true" do
98
+ expect("downcase".downcase?).to eq(true)
99
+ expect("downcase string".downcase?).to eq(true)
100
+ end
101
+
102
+ it "to be false" do
103
+ expect("Mixedcase".downcase?).to eq(false)
104
+ expect("UPCASE".downcase?).to eq(false)
105
+ expect("Mixedcase string".downcase?).to eq(false)
106
+ end
107
+ end
108
+
109
+ describe "#ellipsize" do
110
+ it "to be example string" do
111
+ expect("example string".ellipsize).to eq("example string")
112
+ end
113
+
114
+ it "to be 0123...WXYZ" do
115
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize).to eq("0123...WXYZ")
116
+ end
117
+
118
+ it "to be 012...XYZ" do
119
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(length: 50)).to eq("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
120
+ end
121
+
122
+ it "to be 012...XYZ" do
123
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(offset: 3)).to eq("012...XYZ")
124
+ end
125
+
126
+ it "to be 0123+++WXYZ" do
127
+ expect("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(separator: "+++")).to eq("0123+++WXYZ")
128
+ end
129
+ end
130
+
131
+ describe "#gnix(!)" do
132
+ it "to be this that " do
133
+ expect("this thing that thing".gnix("thing")).to eq("this that ")
134
+ expect("this thing that thing".gnix!("thing")).to eq("this that ")
135
+ end
136
+ end
137
+
138
+ describe "#mixedcase?" do
139
+ it "to be true" do
140
+ expect("Mixedcase".mixedcase?).to eq(true)
141
+ expect("Mixedcase STRING type".mixedcase?).to eq(true)
142
+ end
143
+
144
+ it "to be false" do
145
+ expect("downcase".mixedcase?).to eq(false)
146
+ expect("UPCASE".mixedcase?).to eq(false)
147
+ end
148
+ end
149
+
150
+ describe "#nix(!)" do
151
+ it "to be this that thing" do
152
+ expect("this thing that thing".nix("thing")).to eq("this that thing")
153
+ expect("this thing that thing".nix!("thing")).to eq("this that thing")
154
+ end
155
+ end
156
+
157
+ describe "#pollute" do
158
+ it "to be t^--^--^e^--^--^s^--^--^t^--^--^" do
159
+ expect("test".pollute).to eq("t^--^--^e^--^--^s^--^--^t^--^--^")
160
+ end
161
+
162
+ it "to be t-e-s-t-" do
163
+ expect("test".pollute("-")).to eq("t-e-s-t-")
164
+ end
165
+ end
166
+
167
+ describe "#unpollute" do
168
+ it "to be test" do
169
+ expect("test".unpollute).to eq("test")
170
+ end
171
+
172
+ it "to be test" do
173
+ expect("t-e-s-t-".unpollute("-")).to eq("test")
174
+ end
175
+ end
176
+
177
+ describe "#pollute then #unpollute" do
178
+ it "to be test" do
179
+ expect("test".pollute.unpollute).to eq("test")
180
+ end
181
+
182
+ it "to be test" do
183
+ expect("t-e-s-t-".pollute("-").unpollute("-")).to eq("test")
184
+ end
185
+ end
186
+
187
+ describe "#slugify(!)" do
188
+ it "to be example" do
189
+ expect("example".slugify).to eq("example")
190
+ expect("example".slugify!).to eq("example")
191
+ end
192
+
193
+ it "to be example-string" do
194
+ expect("example string".slugify).to eq("example-string")
195
+ expect("example string".slugify!).to eq("example-string")
196
+ end
197
+
198
+ it "to be example-string-test" do
199
+ expect("Example string @@@ test!".slugify).to eq("example-string-test")
200
+ expect("Example string @@@ test!".slugify!).to eq("example-string-test")
201
+ end
202
+
203
+ it "to be a-real-doozie" do
204
+ expect(" A REal Doozi\"e? \' ".slugify).to eq("a-real-doozie")
205
+ expect(" A REal Doozi\"e? \' ".slugify!).to eq("a-real-doozie")
206
+ end
207
+ end
208
+
209
+ describe "#squish(!)" do
210
+ it "to be example test" do
211
+ expect("example test".squish).to eq("example test")
212
+ expect("example test".squish!).to eq("example test")
213
+ expect(" example test ".squish).to eq("example test")
214
+ expect(" example test ".squish!).to eq("example test")
215
+ end
216
+ end
217
+
218
+ describe "#strip_tags(!)" do
219
+ it "to be example" do
220
+ expect("example".strip_tags).to eq("example")
221
+ expect("example".strip_tags!).to eq("example")
222
+ end
223
+
224
+ it "to be click" do
225
+ expect("<a href='http://example.com'>click</a>".strip_tags).to eq("click")
226
+ expect("<a href='http://example.com'>click</a>".strip_tags!).to eq("click")
227
+ end
228
+
229
+ it "to be this is bold and emphatic" do
230
+ expect("this is <b>bold</b> and <em>emphatic</em>".strip_tags).to eq("this is bold and emphatic")
231
+ expect("this is <b>bold</b> and <em>emphatic</em>".strip_tags!).to eq("this is bold and emphatic")
232
+ end
233
+ end
234
+
235
+ describe "#strip_whitespace(!)" do
236
+ it "to be example" do
237
+ expect("example string test".strip_whitespace).to eq("example string test")
238
+ expect("example string test".strip_whitespace!).to eq("example string test")
239
+ expect(" this \t is also a test ".strip_whitespace).to eq("this is also a test")
240
+ expect(" this \t is also a test ".strip_whitespace!).to eq("this is also a test")
241
+ end
242
+ end
243
+
244
+ describe "#truncate_preserving_words" do
245
+ it "to be example string" do
246
+ expect("example string".truncate_preserving_words).to eq("example string")
247
+ expect("example string".truncate_preserving_words(max_words: 10)).to eq("example string")
248
+ expect("example string".truncate_preserving_words(:max_chars => 15, :end_string => "..")).to eq("example string")
249
+ end
250
+
251
+ it "to be example string" do
252
+ expect("example string test another1 another2 another3".truncate_preserving_words).to eq("example string test another1 ...")
253
+ expect("example string test".truncate_preserving_words(max_words: 2)).to eq("example string ...")
254
+ expect("example string test".truncate_preserving_words(max_chars: 10, separator: "+++")).to eq("example +++")
255
+ end
256
+ end
257
+
258
+ describe "#upcase?" do
259
+ it "to be true" do
260
+ expect("UPCASE".upcase?).to eq(true)
261
+ expect("UPCASE STRING".upcase?).to eq(true)
262
+ end
263
+
264
+ it "to be false" do
265
+ expect("downcase".upcase?).to eq(false)
266
+ expect("Mixedcase".upcase?).to eq(false)
267
+ expect("Mixedcase string".upcase?).to eq(false)
268
+ end
269
+ end
270
+
271
+ end