impuri 0.8.0 → 0.9.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,918 @@
1
+ # test/ImpURI/class_methods.rb
2
+
3
+ gem 'minitest'
4
+
5
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib')))
6
+
7
+ require 'ImpURI'
8
+ require 'minitest/global_expectations/autorun'
9
+
10
+ describe ImpURI do
11
+ describe 'ImpURI class methods' do
12
+
13
+ describe 'parse()' do
14
+ it 'must return an object of class ImpURI' do
15
+ ImpURI.parse('http://example.com').class.must_equal ImpURI
16
+ end
17
+ end
18
+
19
+ describe 'a very simple http URI' do
20
+ before do
21
+ @http_uri = 'http://example.com'
22
+ end
23
+
24
+ it 'must parse out the scheme' do
25
+ ImpURI.scheme(@http_uri).must_equal 'http'
26
+ ImpURI.protocol(@http_uri).must_equal 'http'
27
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
28
+ end
29
+
30
+ it 'must parse out the domain name' do
31
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
32
+ ImpURI.host(@http_uri).must_equal 'example.com'
33
+ end
34
+
35
+ it 'must return nil if there is no path' do
36
+ ImpURI.path(@http_uri).must_be_nil
37
+ end
38
+
39
+ it 'must return nil if there are no GET request parameters' do
40
+ ImpURI.parameter_string(@http_uri).must_be_nil
41
+ ImpURI.parameters(@http_uri).must_be_nil
42
+ end
43
+
44
+ it 'must return false for has_userinfo?()' do
45
+ ImpURI.has_userinfo?(@http_uri).must_equal false
46
+ ImpURI.has_credentials?(@http_uri).must_equal false
47
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
48
+ ImpURI.has_user_info?(@http_uri).must_equal false
49
+ ImpURI.userinfo?(@http_uri).must_equal false
50
+ ImpURI.credentials?(@http_uri).must_equal false
51
+ ImpURI.username_and_password?(@http_uri).must_equal false
52
+ ImpURI.user_info?(@http_uri).must_equal false
53
+ end
54
+
55
+ it 'must return true for has_scheme?()' do
56
+ ImpURI.has_scheme?(@http_uri).must_equal true
57
+ ImpURI.has_protocol?(@http_uri).must_equal true
58
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
59
+ ImpURI.scheme?(@http_uri).must_equal true
60
+ ImpURI.protocol?(@http_uri).must_equal true
61
+ ImpURI.scheme_name?(@http_uri).must_equal true
62
+ end
63
+
64
+ it 'must return false for has_colon_path_separator?()' do
65
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
66
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
67
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
68
+ end
69
+
70
+ it 'must return false for has_port_number?()' do
71
+ ImpURI.has_port_number?(@http_uri).must_equal false
72
+ ImpURI.has_port?(@http_uri).must_equal false
73
+ ImpURI.has_portnumber?(@http_uri).must_equal false
74
+ ImpURI.port_number?(@http_uri).must_equal false
75
+ ImpURI.port?(@http_uri).must_equal false
76
+ ImpURI.portnumber?(@http_uri).must_equal false
77
+ end
78
+
79
+ it 'must return false for is_ssh?()' do
80
+ ImpURI.is_ssh?(@http_uri).must_equal false
81
+ end
82
+
83
+ it 'must return nil if there is no request URI' do
84
+ ImpURI.request_uri(@http_uri).must_be_nil
85
+ end
86
+ end # describe 'a very simple http URI'
87
+
88
+ describe 'an http URI with a port number' do
89
+ before do
90
+ @http_uri = 'http://example.com:8080'
91
+ end
92
+
93
+ it 'must parse out the scheme' do
94
+ ImpURI.scheme(@http_uri).must_equal 'http'
95
+ ImpURI.protocol(@http_uri).must_equal 'http'
96
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
97
+ end
98
+
99
+ it 'must parse out the domain name' do
100
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
101
+ ImpURI.host(@http_uri).must_equal 'example.com'
102
+ end
103
+
104
+ it 'must return nil if there is no path' do
105
+ ImpURI.path(@http_uri).must_be_nil
106
+ end
107
+
108
+ it 'must parse out the port number' do
109
+ ImpURI.port(@http_uri).must_equal '8080'
110
+ ImpURI.portnumber(@http_uri).must_equal '8080'
111
+ ImpURI.port_number(@http_uri).must_equal '8080'
112
+ end
113
+
114
+ it 'must return nil if there are no GET request parameters' do
115
+ ImpURI.parameter_string(@http_uri).must_be_nil
116
+ ImpURI.parameters(@http_uri).must_be_nil
117
+ end
118
+
119
+ it 'must return false for has_userinfo?()' do
120
+ ImpURI.has_userinfo?(@http_uri).must_equal false
121
+ ImpURI.has_credentials?(@http_uri).must_equal false
122
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
123
+ ImpURI.has_user_info?(@http_uri).must_equal false
124
+ ImpURI.userinfo?(@http_uri).must_equal false
125
+ ImpURI.credentials?(@http_uri).must_equal false
126
+ ImpURI.username_and_password?(@http_uri).must_equal false
127
+ ImpURI.user_info?(@http_uri).must_equal false
128
+ end
129
+
130
+ it 'must return true for has_scheme?()' do
131
+ ImpURI.has_scheme?(@http_uri).must_equal true
132
+ ImpURI.has_protocol?(@http_uri).must_equal true
133
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
134
+ ImpURI.scheme?(@http_uri).must_equal true
135
+ ImpURI.protocol?(@http_uri).must_equal true
136
+ ImpURI.scheme_name?(@http_uri).must_equal true
137
+ end
138
+
139
+ it 'must return false for has_colon_path_separator?()' do
140
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
141
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
142
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
143
+ end
144
+
145
+ it 'must return true for has_port_number?()' do
146
+ ImpURI.has_port_number?(@http_uri).must_equal true
147
+ ImpURI.has_port?(@http_uri).must_equal true
148
+ ImpURI.has_portnumber?(@http_uri).must_equal true
149
+ ImpURI.port_number?(@http_uri).must_equal true
150
+ ImpURI.port?(@http_uri).must_equal true
151
+ ImpURI.portnumber?(@http_uri).must_equal true
152
+ end
153
+
154
+ it 'must return false for is_ssh?()' do
155
+ ImpURI.is_ssh?(@http_uri).must_equal false
156
+ end
157
+
158
+ it 'must return nil if there is no request URI' do
159
+ ImpURI.request_uri(@http_uri).must_be_nil
160
+ end
161
+ end # describe 'an http URI with a port number'
162
+
163
+ describe 'an http URI with a path' do
164
+ before do
165
+ @http_uri = 'http://example.com/path/to/resource'
166
+ end
167
+
168
+ it 'must parse out the scheme' do
169
+ ImpURI.scheme(@http_uri).must_equal 'http'
170
+ ImpURI.protocol(@http_uri).must_equal 'http'
171
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
172
+ end
173
+
174
+ it 'must parse out the domain name' do
175
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
176
+ ImpURI.host(@http_uri).must_equal 'example.com'
177
+ end
178
+
179
+ it 'must parse out the path' do
180
+ ImpURI.path(@http_uri).must_equal '/path/to/resource'
181
+ end
182
+
183
+ it 'must return nil if there are no GET request parameters' do
184
+ ImpURI.parameter_string(@http_uri).must_be_nil
185
+ ImpURI.parameters(@http_uri).must_be_nil
186
+ end
187
+
188
+ it 'must return false for has_userinfo?()' do
189
+ ImpURI.has_userinfo?(@http_uri).must_equal false
190
+ ImpURI.has_credentials?(@http_uri).must_equal false
191
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
192
+ ImpURI.has_user_info?(@http_uri).must_equal false
193
+ ImpURI.userinfo?(@http_uri).must_equal false
194
+ ImpURI.credentials?(@http_uri).must_equal false
195
+ ImpURI.username_and_password?(@http_uri).must_equal false
196
+ ImpURI.user_info?(@http_uri).must_equal false
197
+ end
198
+
199
+ it 'must return true for has_scheme?()' do
200
+ ImpURI.has_scheme?(@http_uri).must_equal true
201
+ ImpURI.has_protocol?(@http_uri).must_equal true
202
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
203
+ ImpURI.scheme?(@http_uri).must_equal true
204
+ ImpURI.protocol?(@http_uri).must_equal true
205
+ ImpURI.scheme_name?(@http_uri).must_equal true
206
+ end
207
+
208
+ it 'must return false for has_colon_path_separator?()' do
209
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
210
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
211
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
212
+ end
213
+
214
+ it 'must return false for has_port_number?()' do
215
+ ImpURI.has_port_number?(@http_uri).must_equal false
216
+ ImpURI.has_port?(@http_uri).must_equal false
217
+ ImpURI.has_portnumber?(@http_uri).must_equal false
218
+ ImpURI.port_number?(@http_uri).must_equal false
219
+ ImpURI.port?(@http_uri).must_equal false
220
+ ImpURI.portnumber?(@http_uri).must_equal false
221
+ end
222
+
223
+ it 'must return false for is_ssh?()' do
224
+ ImpURI.is_ssh?(@http_uri).must_equal false
225
+ end
226
+
227
+ it 'must return the request URI' do
228
+ ImpURI.request_uri(@http_uri).must_equal '/path/to/resource'
229
+ end
230
+ end # describe 'an http URI with a path'
231
+
232
+ describe 'an http URI with a username' do
233
+ before do
234
+ @http_uri = 'http://user@example.com/'
235
+ end
236
+
237
+ it 'must parse out the scheme' do
238
+ ImpURI.scheme(@http_uri).must_equal 'http'
239
+ ImpURI.protocol(@http_uri).must_equal 'http'
240
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
241
+ end
242
+
243
+ it 'must parse out the domain name' do
244
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
245
+ ImpURI.host(@http_uri).must_equal 'example.com'
246
+ end
247
+
248
+ it 'must parse out the username' do
249
+ ImpURI.username(@http_uri).must_equal 'user'
250
+ end
251
+
252
+ it 'must return the userinfo string' do
253
+ ImpURI.userinfo(@http_uri).must_equal 'user'
254
+ ImpURI.credentials(@http_uri).must_equal 'user'
255
+ ImpURI.username_and_password(@http_uri).must_equal 'user'
256
+ ImpURI.user_info(@http_uri).must_equal 'user'
257
+ end
258
+
259
+ it 'must return nil if there are no GET request parameters' do
260
+ ImpURI.parameter_string(@http_uri).must_be_nil
261
+ ImpURI.parameters(@http_uri).must_be_nil
262
+ end
263
+
264
+ it 'must return true for has_userinfo?()' do
265
+ ImpURI.has_userinfo?(@http_uri).must_equal true
266
+ ImpURI.has_credentials?(@http_uri).must_equal true
267
+ ImpURI.has_username_and_password?(@http_uri).must_equal true
268
+ ImpURI.has_user_info?(@http_uri).must_equal true
269
+ ImpURI.userinfo?(@http_uri).must_equal true
270
+ ImpURI.credentials?(@http_uri).must_equal true
271
+ ImpURI.username_and_password?(@http_uri).must_equal true
272
+ ImpURI.user_info?(@http_uri).must_equal true
273
+ end
274
+
275
+ it 'must return true for has_scheme?()' do
276
+ ImpURI.has_scheme?(@http_uri).must_equal true
277
+ ImpURI.has_protocol?(@http_uri).must_equal true
278
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
279
+ ImpURI.scheme?(@http_uri).must_equal true
280
+ ImpURI.protocol?(@http_uri).must_equal true
281
+ ImpURI.scheme_name?(@http_uri).must_equal true
282
+ end
283
+
284
+ it 'must return false for has_colon_path_separator?()' do
285
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
286
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
287
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
288
+ end
289
+
290
+ it 'must return false for has_port_number?()' do
291
+ ImpURI.has_port_number?(@http_uri).must_equal false
292
+ ImpURI.has_port?(@http_uri).must_equal false
293
+ ImpURI.has_portnumber?(@http_uri).must_equal false
294
+ ImpURI.port_number?(@http_uri).must_equal false
295
+ ImpURI.port?(@http_uri).must_equal false
296
+ ImpURI.portnumber?(@http_uri).must_equal false
297
+ end
298
+
299
+ it 'must return false for is_ssh?()' do
300
+ ImpURI.is_ssh?(@http_uri).must_equal false
301
+ end
302
+
303
+ it 'must return nil if there is no request URI' do
304
+ ImpURI.request_uri(@http_uri).must_be_nil
305
+ end
306
+ end # describe 'an http URI with a username'
307
+
308
+ describe 'an http URI with a username and password' do
309
+ before do
310
+ @http_uri = 'http://user:pass@example.com/'
311
+ end
312
+
313
+ it 'must parse out the scheme' do
314
+ ImpURI.scheme(@http_uri).must_equal 'http'
315
+ ImpURI.protocol(@http_uri).must_equal 'http'
316
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
317
+ end
318
+
319
+ it 'must parse out the domain name' do
320
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
321
+ ImpURI.host(@http_uri).must_equal 'example.com'
322
+ end
323
+
324
+ it 'must parse out the username' do
325
+ ImpURI.username(@http_uri).must_equal 'user'
326
+ ImpURI.user(@http_uri).must_equal 'user'
327
+ end
328
+
329
+ it 'must parse out the password' do
330
+ ImpURI.password(@http_uri).must_equal 'pass'
331
+ ImpURI.pass(@http_uri).must_equal 'pass'
332
+ ImpURI.passwd(@http_uri).must_equal 'pass'
333
+ end
334
+
335
+ it 'must return the userinfo string' do
336
+ ImpURI.userinfo(@http_uri).must_equal 'user:pass'
337
+ ImpURI.credentials(@http_uri).must_equal 'user:pass'
338
+ ImpURI.username_and_password(@http_uri).must_equal 'user:pass'
339
+ ImpURI.user_info(@http_uri).must_equal 'user:pass'
340
+ end
341
+
342
+ it 'must return nil if there are no GET request parameters' do
343
+ ImpURI.parameter_string(@http_uri).must_be_nil
344
+ ImpURI.parameters(@http_uri).must_be_nil
345
+ end
346
+
347
+ it 'must return true for has_userinfo?()' do
348
+ ImpURI.has_userinfo?(@http_uri).must_equal true
349
+ ImpURI.has_credentials?(@http_uri).must_equal true
350
+ ImpURI.has_username_and_password?(@http_uri).must_equal true
351
+ ImpURI.has_user_info?(@http_uri).must_equal true
352
+ ImpURI.userinfo?(@http_uri).must_equal true
353
+ ImpURI.credentials?(@http_uri).must_equal true
354
+ ImpURI.username_and_password?(@http_uri).must_equal true
355
+ ImpURI.user_info?(@http_uri).must_equal true
356
+ end
357
+
358
+ it 'must return true for has_scheme?()' do
359
+ ImpURI.has_scheme?(@http_uri).must_equal true
360
+ ImpURI.has_protocol?(@http_uri).must_equal true
361
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
362
+ ImpURI.scheme?(@http_uri).must_equal true
363
+ ImpURI.protocol?(@http_uri).must_equal true
364
+ ImpURI.scheme_name?(@http_uri).must_equal true
365
+ end
366
+
367
+ it 'must return false for has_colon_path_separator?()' do
368
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
369
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
370
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
371
+ end
372
+
373
+ it 'must return false for has_port_number?()' do
374
+ ImpURI.has_port_number?(@http_uri).must_equal false
375
+ ImpURI.has_port?(@http_uri).must_equal false
376
+ ImpURI.has_portnumber?(@http_uri).must_equal false
377
+ ImpURI.port_number?(@http_uri).must_equal false
378
+ ImpURI.port?(@http_uri).must_equal false
379
+ ImpURI.portnumber?(@http_uri).must_equal false
380
+ end
381
+
382
+ it 'must return false for is_ssh?()' do
383
+ ImpURI.is_ssh?(@http_uri).must_equal false
384
+ end
385
+
386
+ it 'must return nil if there is no request URI' do
387
+ ImpURI.request_uri(@http_uri).must_be_nil
388
+ end
389
+ end # describe 'an http URI with a username and password'
390
+
391
+ describe 'an http URI with one GET query parameter' do
392
+ before do
393
+ @http_uri = 'http://example.com/?q=param'
394
+ end
395
+
396
+ it 'must parse out the scheme' do
397
+ ImpURI.scheme(@http_uri).must_equal 'http'
398
+ ImpURI.protocol(@http_uri).must_equal 'http'
399
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
400
+ end
401
+
402
+ it 'must parse out the domain name' do
403
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
404
+ ImpURI.host(@http_uri).must_equal 'example.com'
405
+ end
406
+
407
+ it 'must parse out the paramter string' do
408
+ ImpURI.parameter_string(@http_uri).must_equal 'q=param'
409
+ end
410
+
411
+ it 'must parse out the parameter as a hash' do
412
+ ImpURI.parameters(@http_uri).must_equal({'q' => 'param'})
413
+ end
414
+
415
+ it 'must return false for has_userinfo?()' do
416
+ ImpURI.has_userinfo?(@http_uri).must_equal false
417
+ ImpURI.has_credentials?(@http_uri).must_equal false
418
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
419
+ ImpURI.has_user_info?(@http_uri).must_equal false
420
+ ImpURI.userinfo?(@http_uri).must_equal false
421
+ ImpURI.credentials?(@http_uri).must_equal false
422
+ ImpURI.username_and_password?(@http_uri).must_equal false
423
+ ImpURI.user_info?(@http_uri).must_equal false
424
+ end
425
+
426
+ it 'must return true for has_scheme?()' do
427
+ ImpURI.has_scheme?(@http_uri).must_equal true
428
+ ImpURI.has_protocol?(@http_uri).must_equal true
429
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
430
+ ImpURI.scheme?(@http_uri).must_equal true
431
+ ImpURI.protocol?(@http_uri).must_equal true
432
+ ImpURI.scheme_name?(@http_uri).must_equal true
433
+ end
434
+
435
+ it 'must return false for has_colon_path_separator?()' do
436
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
437
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
438
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
439
+ end
440
+
441
+ it 'must return false for has_port_number?()' do
442
+ ImpURI.has_port_number?(@http_uri).must_equal false
443
+ ImpURI.has_port?(@http_uri).must_equal false
444
+ ImpURI.has_portnumber?(@http_uri).must_equal false
445
+ ImpURI.port_number?(@http_uri).must_equal false
446
+ ImpURI.port?(@http_uri).must_equal false
447
+ ImpURI.portnumber?(@http_uri).must_equal false
448
+ end
449
+
450
+ it 'must return false for is_ssh?()' do
451
+ ImpURI.is_ssh?(@http_uri).must_equal false
452
+ end
453
+
454
+ it 'must return the request URI' do
455
+ ImpURI.request_uri(@http_uri).must_equal '/?q=param'
456
+ end
457
+ end # describe 'an http URI with one GET query parameter'
458
+
459
+ describe 'an http URI with two GET query parameters' do
460
+ before do
461
+ @http_uri = 'http://example.com/?q=param1&r=param2'
462
+ end
463
+
464
+ it 'must parse out the scheme' do
465
+ ImpURI.scheme(@http_uri).must_equal 'http'
466
+ ImpURI.protocol(@http_uri).must_equal 'http'
467
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
468
+ end
469
+
470
+ it 'must parse out the domain name' do
471
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
472
+ ImpURI.host(@http_uri).must_equal 'example.com'
473
+ end
474
+
475
+ it 'must parse out the paramter string' do
476
+ ImpURI.parameter_string(@http_uri).must_equal 'q=param1&r=param2'
477
+ end
478
+
479
+ it 'must parse out the parameter as a hash' do
480
+ ImpURI.parameters(@http_uri).must_equal({'q' => 'param1', 'r' => 'param2'})
481
+ end
482
+
483
+ it 'must return false for has_userinfo?()' do
484
+ ImpURI.has_userinfo?(@http_uri).must_equal false
485
+ ImpURI.has_credentials?(@http_uri).must_equal false
486
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
487
+ ImpURI.has_user_info?(@http_uri).must_equal false
488
+ ImpURI.userinfo?(@http_uri).must_equal false
489
+ ImpURI.credentials?(@http_uri).must_equal false
490
+ ImpURI.username_and_password?(@http_uri).must_equal false
491
+ ImpURI.user_info?(@http_uri).must_equal false
492
+ end
493
+
494
+ it 'must return true for has_scheme?()' do
495
+ ImpURI.has_scheme?(@http_uri).must_equal true
496
+ ImpURI.has_protocol?(@http_uri).must_equal true
497
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
498
+ ImpURI.scheme?(@http_uri).must_equal true
499
+ ImpURI.protocol?(@http_uri).must_equal true
500
+ ImpURI.scheme_name?(@http_uri).must_equal true
501
+ end
502
+
503
+ it 'must return false for has_colon_path_separator?()' do
504
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
505
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
506
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
507
+ end
508
+
509
+ it 'must return false for has_port_number?()' do
510
+ ImpURI.has_port_number?(@http_uri).must_equal false
511
+ ImpURI.has_port?(@http_uri).must_equal false
512
+ ImpURI.has_portnumber?(@http_uri).must_equal false
513
+ ImpURI.port_number?(@http_uri).must_equal false
514
+ ImpURI.port?(@http_uri).must_equal false
515
+ ImpURI.portnumber?(@http_uri).must_equal false
516
+ end
517
+
518
+ it 'must return false for is_ssh?()' do
519
+ ImpURI.is_ssh?(@http_uri).must_equal false
520
+ end
521
+
522
+ it 'must return the request URI' do
523
+ ImpURI.request_uri(@http_uri).must_equal '/?q=param1&r=param2'
524
+ end
525
+ end # describe 'an http URI with two GET query parameters'
526
+
527
+ describe 'an http URI with two GET query parameters separated by a semicolon' do
528
+ before do
529
+ @http_uri = 'http://example.com/?q=param1;r=param2'
530
+ end
531
+
532
+ it 'must parse out the scheme' do
533
+ ImpURI.scheme(@http_uri).must_equal 'http'
534
+ ImpURI.protocol(@http_uri).must_equal 'http'
535
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
536
+ end
537
+
538
+ it 'must parse out the domain name' do
539
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
540
+ ImpURI.host(@http_uri).must_equal 'example.com'
541
+ end
542
+
543
+ it 'must parse out the paramter string' do
544
+ ImpURI.parameter_string(@http_uri).must_equal 'q=param1;r=param2'
545
+ end
546
+
547
+ it 'must parse out the parameter as a hash' do
548
+ ImpURI.parameters(@http_uri).must_equal({'q' => 'param1', 'r' => 'param2'})
549
+ end
550
+
551
+ it 'must return false for has_userinfo?()' do
552
+ ImpURI.has_userinfo?(@http_uri).must_equal false
553
+ ImpURI.has_credentials?(@http_uri).must_equal false
554
+ ImpURI.has_username_and_password?(@http_uri).must_equal false
555
+ ImpURI.has_user_info?(@http_uri).must_equal false
556
+ ImpURI.userinfo?(@http_uri).must_equal false
557
+ ImpURI.credentials?(@http_uri).must_equal false
558
+ ImpURI.username_and_password?(@http_uri).must_equal false
559
+ ImpURI.user_info?(@http_uri).must_equal false
560
+ end
561
+
562
+ it 'must return true for has_scheme?()' do
563
+ ImpURI.has_scheme?(@http_uri).must_equal true
564
+ ImpURI.has_protocol?(@http_uri).must_equal true
565
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
566
+ ImpURI.scheme?(@http_uri).must_equal true
567
+ ImpURI.protocol?(@http_uri).must_equal true
568
+ ImpURI.scheme_name?(@http_uri).must_equal true
569
+ end
570
+
571
+ it 'must return false for has_colon_path_separator?()' do
572
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
573
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
574
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
575
+ end
576
+
577
+ it 'must return false for has_port_number?()' do
578
+ ImpURI.has_port_number?(@http_uri).must_equal false
579
+ ImpURI.has_port?(@http_uri).must_equal false
580
+ ImpURI.has_portnumber?(@http_uri).must_equal false
581
+ ImpURI.port_number?(@http_uri).must_equal false
582
+ ImpURI.port?(@http_uri).must_equal false
583
+ ImpURI.portnumber?(@http_uri).must_equal false
584
+ end
585
+
586
+ it 'must return false for is_ssh?()' do
587
+ ImpURI.is_ssh?(@http_uri).must_equal false
588
+ end
589
+
590
+ it 'must return the request URI' do
591
+ ImpURI.request_uri(@http_uri).must_equal '/?q=param1;r=param2'
592
+ end
593
+ end # describe 'an http URI with two GET query parameters separated by a semicolon'
594
+
595
+ describe 'an http URI with the lot' do
596
+ before do
597
+ @http_uri = 'http://user:pass@example.com:8080/path/to/resource?q=param1&r=param2'
598
+ end
599
+
600
+ it 'must parse out the scheme' do
601
+ ImpURI.scheme(@http_uri).must_equal 'http'
602
+ ImpURI.protocol(@http_uri).must_equal 'http'
603
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
604
+ end
605
+
606
+ it 'must parse out the domain name' do
607
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
608
+ ImpURI.host(@http_uri).must_equal 'example.com'
609
+ end
610
+
611
+ it 'must parse out the path' do
612
+ ImpURI.path(@http_uri).must_equal '/path/to/resource'
613
+ end
614
+
615
+ it 'must parse out the port number' do
616
+ ImpURI.port(@http_uri).must_equal '8080'
617
+ ImpURI.port_number(@http_uri).must_equal '8080'
618
+ ImpURI.port_number(@http_uri).must_equal '8080'
619
+ end
620
+
621
+ it 'must parse out the username' do
622
+ ImpURI.username(@http_uri).must_equal 'user'
623
+ ImpURI.user(@http_uri).must_equal 'user'
624
+ end
625
+
626
+ it 'must parse out the password' do
627
+ ImpURI.password(@http_uri).must_equal 'pass'
628
+ ImpURI.pass(@http_uri).must_equal 'pass'
629
+ ImpURI.passwd(@http_uri).must_equal 'pass'
630
+ end
631
+
632
+ it 'must return the userinfo string' do
633
+ ImpURI.userinfo(@http_uri).must_equal 'user:pass'
634
+ ImpURI.credentials(@http_uri).must_equal 'user:pass'
635
+ ImpURI.username_and_password(@http_uri).must_equal 'user:pass'
636
+ ImpURI.user_info(@http_uri).must_equal 'user:pass'
637
+ end
638
+
639
+ it 'must parse out the paramter string' do
640
+ ImpURI.parameter_string(@http_uri).must_equal 'q=param1&r=param2'
641
+ end
642
+
643
+ it 'must parse out the parameter as a hash' do
644
+ ImpURI.parameters(@http_uri).must_equal({'q' => 'param1', 'r' => 'param2'})
645
+ end
646
+
647
+ it 'must return true for has_userinfo?()' do
648
+ ImpURI.has_userinfo?(@http_uri).must_equal true
649
+ ImpURI.has_credentials?(@http_uri).must_equal true
650
+ ImpURI.has_username_and_password?(@http_uri).must_equal true
651
+ ImpURI.has_user_info?(@http_uri).must_equal true
652
+ ImpURI.userinfo?(@http_uri).must_equal true
653
+ ImpURI.credentials?(@http_uri).must_equal true
654
+ ImpURI.username_and_password?(@http_uri).must_equal true
655
+ ImpURI.user_info?(@http_uri).must_equal true
656
+ end
657
+
658
+ it 'must return true for has_scheme?()' do
659
+ ImpURI.has_scheme?(@http_uri).must_equal true
660
+ ImpURI.has_protocol?(@http_uri).must_equal true
661
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
662
+ ImpURI.scheme?(@http_uri).must_equal true
663
+ ImpURI.protocol?(@http_uri).must_equal true
664
+ ImpURI.scheme_name?(@http_uri).must_equal true
665
+ end
666
+
667
+ it 'must return false for has_colon_path_separator?()' do
668
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
669
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
670
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
671
+ end
672
+
673
+ it 'must return true for has_port_number?()' do
674
+ ImpURI.has_port_number?(@http_uri).must_equal true
675
+ ImpURI.has_port?(@http_uri).must_equal true
676
+ ImpURI.has_portnumber?(@http_uri).must_equal true
677
+ ImpURI.port_number?(@http_uri).must_equal true
678
+ ImpURI.port?(@http_uri).must_equal true
679
+ ImpURI.portnumber?(@http_uri).must_equal true
680
+ end
681
+
682
+ it 'must return false for is_ssh?()' do
683
+ ImpURI.is_ssh?(@http_uri).must_equal false
684
+ end
685
+
686
+ it 'must return the request URI' do
687
+ ImpURI.request_uri(@http_uri).must_equal '/path/to/resource?q=param1&r=param2'
688
+ end
689
+ end # describe 'an http URI with the lot'
690
+
691
+ describe 'an http URI with the lot and a semicolon path separator' do
692
+ before do
693
+ @http_uri = 'http://user:pass@example.com:8080/path/to/resource?q=param1;r=param2'
694
+ end
695
+
696
+ it 'must parse out the scheme' do
697
+ ImpURI.scheme(@http_uri).must_equal 'http'
698
+ ImpURI.protocol(@http_uri).must_equal 'http'
699
+ ImpURI.scheme_name(@http_uri).must_equal 'http'
700
+ end
701
+
702
+ it 'must parse out the domain name' do
703
+ ImpURI.hostname(@http_uri).must_equal 'example.com'
704
+ ImpURI.host(@http_uri).must_equal 'example.com'
705
+ end
706
+
707
+ it 'must parse out the path' do
708
+ ImpURI.path(@http_uri).must_equal '/path/to/resource'
709
+ end
710
+
711
+ it 'must parse out the port number' do
712
+ ImpURI.port(@http_uri).must_equal '8080'
713
+ ImpURI.port_number(@http_uri).must_equal '8080'
714
+ ImpURI.port_number(@http_uri).must_equal '8080'
715
+ end
716
+
717
+ it 'must parse out the username' do
718
+ ImpURI.username(@http_uri).must_equal 'user'
719
+ ImpURI.user(@http_uri).must_equal 'user'
720
+ end
721
+
722
+ it 'must parse out the password' do
723
+ ImpURI.password(@http_uri).must_equal 'pass'
724
+ ImpURI.pass(@http_uri).must_equal 'pass'
725
+ ImpURI.passwd(@http_uri).must_equal 'pass'
726
+ end
727
+
728
+ it 'must return the userinfo string' do
729
+ ImpURI.userinfo(@http_uri).must_equal 'user:pass'
730
+ ImpURI.credentials(@http_uri).must_equal 'user:pass'
731
+ ImpURI.username_and_password(@http_uri).must_equal 'user:pass'
732
+ ImpURI.user_info(@http_uri).must_equal 'user:pass'
733
+ end
734
+
735
+ it 'must parse out the paramter string' do
736
+ ImpURI.parameter_string(@http_uri).must_equal 'q=param1;r=param2'
737
+ end
738
+
739
+ it 'must parse out the parameter as a hash' do
740
+ ImpURI.parameters(@http_uri).must_equal({'q' => 'param1', 'r' => 'param2'})
741
+ end
742
+
743
+ it 'must return true for has_userinfo?()' do
744
+ ImpURI.has_userinfo?(@http_uri).must_equal true
745
+ ImpURI.has_credentials?(@http_uri).must_equal true
746
+ ImpURI.has_username_and_password?(@http_uri).must_equal true
747
+ ImpURI.has_user_info?(@http_uri).must_equal true
748
+ ImpURI.userinfo?(@http_uri).must_equal true
749
+ ImpURI.credentials?(@http_uri).must_equal true
750
+ ImpURI.username_and_password?(@http_uri).must_equal true
751
+ ImpURI.user_info?(@http_uri).must_equal true
752
+ end
753
+
754
+ it 'must return true for has_scheme?()' do
755
+ ImpURI.has_scheme?(@http_uri).must_equal true
756
+ ImpURI.has_protocol?(@http_uri).must_equal true
757
+ ImpURI.has_scheme_name?(@http_uri).must_equal true
758
+ ImpURI.scheme?(@http_uri).must_equal true
759
+ ImpURI.protocol?(@http_uri).must_equal true
760
+ ImpURI.scheme_name?(@http_uri).must_equal true
761
+ end
762
+
763
+ it 'must return false for has_colon_path_separator?()' do
764
+ ImpURI.colon_path_separator?(@http_uri).must_equal false
765
+ ImpURI.has_colon_path_separator?(@http_uri).must_equal false
766
+ ImpURI.uses_colon_path_separator?(@http_uri).must_equal false
767
+ end
768
+
769
+ it 'must return true for has_port_number?()' do
770
+ ImpURI.has_port_number?(@http_uri).must_equal true
771
+ ImpURI.has_port?(@http_uri).must_equal true
772
+ ImpURI.has_portnumber?(@http_uri).must_equal true
773
+ ImpURI.port_number?(@http_uri).must_equal true
774
+ ImpURI.port?(@http_uri).must_equal true
775
+ ImpURI.portnumber?(@http_uri).must_equal true
776
+ end
777
+
778
+ it 'must return false for is_ssh?()' do
779
+ ImpURI.is_ssh?(@http_uri).must_equal false
780
+ end
781
+
782
+ it 'must return the request URI' do
783
+ ImpURI.request_uri(@http_uri).must_equal '/path/to/resource?q=param1;r=param2'
784
+ end
785
+ end # describe 'an http URI with the lot and a semicolon path separator'
786
+
787
+ describe 'an ssh identifier' do
788
+ before do
789
+ @ssh_identifier = 'username@example.com:~account'
790
+ end
791
+
792
+ it 'must return a username' do
793
+ ImpURI.username(@ssh_identifier).must_equal 'username'
794
+ end
795
+
796
+ it 'must correctly determine if it has user info' do
797
+ ImpURI.credentials?(@ssh_identifier).must_equal false
798
+ ImpURI.username_and_password?(@ssh_identifier).must_equal false
799
+ ImpURI.user_info?(@ssh_identifier).must_equal false
800
+ ImpURI.userinfo?(@ssh_identifier).must_equal false
801
+ ImpURI.has_credentials?(@ssh_identifier).must_equal false
802
+ ImpURI.has_username_and_password?(@ssh_identifier).must_equal false
803
+ ImpURI.has_user_info?(@ssh_identifier).must_equal false
804
+ ImpURI.has_userinfo?(@ssh_identifier).must_equal false
805
+ end
806
+
807
+ it 'must correctly determine if it has a scheme' do
808
+ ImpURI.has_scheme?(@ssh_identifier).must_equal false
809
+ ImpURI.has_protocol?(@ssh_identifier).must_equal false
810
+ ImpURI.has_scheme_name?(@ssh_identifier).must_equal false
811
+ ImpURI.scheme?(@ssh_identifier).must_equal false
812
+ ImpURI.protocol?(@ssh_identifier).must_equal false
813
+ ImpURI.scheme_name?(@ssh_identifier).must_equal false
814
+ end
815
+
816
+ it 'must correctly determine if it has a colon path separator' do
817
+ ImpURI.colon_path_separator?(@ssh_identifier).must_equal true
818
+ ImpURI.has_colon_path_separator?(@ssh_identifier).must_equal true
819
+ ImpURI.uses_colon_path_separator?(@ssh_identifier).must_equal true
820
+ end
821
+
822
+ it 'must correctly determine if it has a port number' do
823
+ ImpURI.has_port_number?(@ssh_identifier).must_equal false
824
+ ImpURI.has_port?(@ssh_identifier).must_equal false
825
+ ImpURI.has_portnumber?(@ssh_identifier).must_equal false
826
+ ImpURI.port_number?(@ssh_identifier).must_equal false
827
+ ImpURI.port?(@ssh_identifier).must_equal false
828
+ ImpURI.portnumber?(@ssh_identifier).must_equal false
829
+ end
830
+
831
+ it 'must return true for is_ssh?()' do
832
+ ImpURI.is_ssh?(@ssh_identifier).must_equal true
833
+ end
834
+
835
+ it 'must return hostname_and_path when requested' do
836
+ ImpURI.hostname_and_path(@ssh_identifier).must_equal 'example.com:~account'
837
+ end
838
+
839
+ it 'must return hostname_and_port_number when requested' do
840
+ ImpURI.hostname_and_port_number(@ssh_identifier).must_equal 'example.com'
841
+ end
842
+
843
+ it 'must return a hostname' do
844
+ ImpURI.hostname(@ssh_identifier).must_equal 'example.com'
845
+ end
846
+
847
+ it 'must return a path' do
848
+ ImpURI.path(@ssh_identifier).must_equal '~account'
849
+ end
850
+ end # describe 'an ssh identifier'
851
+
852
+ describe 'an ssh identifier as per Github' do
853
+ before do
854
+ @ssh_identifier = 'git@github.com:thoran/ImpURI.git'
855
+ end
856
+
857
+ it 'must return a username' do
858
+ ImpURI.username(@ssh_identifier).must_equal 'git'
859
+ end
860
+
861
+ it 'must correctly determine if it has user info' do
862
+ ImpURI.credentials?(@ssh_identifier).must_equal false
863
+ ImpURI.username_and_password?(@ssh_identifier).must_equal false
864
+ ImpURI.user_info?(@ssh_identifier).must_equal false
865
+ ImpURI.userinfo?(@ssh_identifier).must_equal false
866
+ ImpURI.has_credentials?(@ssh_identifier).must_equal false
867
+ ImpURI.has_username_and_password?(@ssh_identifier).must_equal false
868
+ ImpURI.has_user_info?(@ssh_identifier).must_equal false
869
+ ImpURI.has_userinfo?(@ssh_identifier).must_equal false
870
+ end
871
+
872
+ it 'must correctly determine if it has a scheme' do
873
+ ImpURI.has_scheme?(@ssh_identifier).must_equal false
874
+ ImpURI.has_protocol?(@ssh_identifier).must_equal false
875
+ ImpURI.has_scheme_name?(@ssh_identifier).must_equal false
876
+ ImpURI.scheme?(@ssh_identifier).must_equal false
877
+ ImpURI.protocol?(@ssh_identifier).must_equal false
878
+ ImpURI.scheme_name?(@ssh_identifier).must_equal false
879
+ end
880
+
881
+ it 'must correctly determine if it has a colon path separator' do
882
+ ImpURI.colon_path_separator?(@ssh_identifier).must_equal true
883
+ ImpURI.has_colon_path_separator?(@ssh_identifier).must_equal true
884
+ ImpURI.uses_colon_path_separator?(@ssh_identifier).must_equal true
885
+ end
886
+
887
+ it 'must correctly determine if it has a port number' do
888
+ ImpURI.has_port_number?(@ssh_identifier).must_equal false
889
+ ImpURI.has_port?(@ssh_identifier).must_equal false
890
+ ImpURI.has_portnumber?(@ssh_identifier).must_equal false
891
+ ImpURI.port_number?(@ssh_identifier).must_equal false
892
+ ImpURI.port?(@ssh_identifier).must_equal false
893
+ ImpURI.portnumber?(@ssh_identifier).must_equal false
894
+ end
895
+
896
+ it 'must return true for is_ssh?()' do
897
+ ImpURI.is_ssh?(@ssh_identifier).must_equal true
898
+ end
899
+
900
+ it 'must return hostname_and_path when requested' do
901
+ ImpURI.hostname_and_path(@ssh_identifier).must_equal 'github.com:thoran/ImpURI.git'
902
+ end
903
+
904
+ it 'must return hostname_and_port_number when requested' do
905
+ ImpURI.hostname_and_port_number(@ssh_identifier).must_equal 'github.com'
906
+ end
907
+
908
+ it 'must return a hostname' do
909
+ ImpURI.hostname(@ssh_identifier).must_equal 'github.com'
910
+ end
911
+
912
+ it 'must return a path' do
913
+ ImpURI.path(@ssh_identifier).must_equal 'thoran/ImpURI.git'
914
+ end
915
+ end # describe 'an ssh identifier as per Github'
916
+
917
+ end
918
+ end