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