honkster-addressable 2.1.2

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,3940 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Addressable, Copyright (c) 2006-2007 Bob Aman
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #++
24
+
25
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
26
+ require "addressable/uri"
27
+
28
+ if !"".respond_to?("force_encoding")
29
+ class String
30
+ def force_encoding(encoding)
31
+ @encoding = encoding
32
+ end
33
+
34
+ def encoding
35
+ @encoding ||= Encoding::ASCII_8BIT
36
+ end
37
+ end
38
+
39
+ class Encoding
40
+ def initialize(name)
41
+ @name = name
42
+ end
43
+
44
+ def to_s
45
+ return @name
46
+ end
47
+
48
+ UTF_8 = Encoding.new("UTF-8")
49
+ ASCII_8BIT = Encoding.new("US-ASCII")
50
+ end
51
+ end
52
+
53
+ module URI
54
+ class HTTP
55
+ def initialize(uri)
56
+ @uri = uri
57
+ end
58
+
59
+ def to_s
60
+ return @uri.to_s
61
+ end
62
+ end
63
+ end
64
+
65
+ describe Addressable::URI, "when created with a non-numeric port number" do
66
+ it "should raise an error" do
67
+ (lambda do
68
+ Addressable::URI.new(:port => "bogus")
69
+ end).should raise_error(Addressable::URI::InvalidURIError)
70
+ end
71
+ end
72
+
73
+ describe Addressable::URI, "when created with a non-string scheme" do
74
+ it "should raise an error" do
75
+ (lambda do
76
+ Addressable::URI.new(:scheme => :bogus)
77
+ end).should raise_error(TypeError)
78
+ end
79
+ end
80
+
81
+ describe Addressable::URI, "when created with a non-string user" do
82
+ it "should raise an error" do
83
+ (lambda do
84
+ Addressable::URI.new(:user => :bogus)
85
+ end).should raise_error(TypeError)
86
+ end
87
+ end
88
+
89
+ describe Addressable::URI, "when created with a non-string password" do
90
+ it "should raise an error" do
91
+ (lambda do
92
+ Addressable::URI.new(:password => :bogus)
93
+ end).should raise_error(TypeError)
94
+ end
95
+ end
96
+
97
+ describe Addressable::URI, "when created with a non-string userinfo" do
98
+ it "should raise an error" do
99
+ (lambda do
100
+ Addressable::URI.new(:userinfo => :bogus)
101
+ end).should raise_error(TypeError)
102
+ end
103
+ end
104
+
105
+ describe Addressable::URI, "when created with a non-string host" do
106
+ it "should raise an error" do
107
+ (lambda do
108
+ Addressable::URI.new(:host => :bogus)
109
+ end).should raise_error(TypeError)
110
+ end
111
+ end
112
+
113
+ describe Addressable::URI, "when created with a non-string authority" do
114
+ it "should raise an error" do
115
+ (lambda do
116
+ Addressable::URI.new(:authority => :bogus)
117
+ end).should raise_error(TypeError)
118
+ end
119
+ end
120
+
121
+ describe Addressable::URI, "when created with a non-string authority" do
122
+ it "should raise an error" do
123
+ (lambda do
124
+ Addressable::URI.new(:authority => :bogus)
125
+ end).should raise_error(TypeError)
126
+ end
127
+ end
128
+
129
+ describe Addressable::URI, "when created with a non-string path" do
130
+ it "should raise an error" do
131
+ (lambda do
132
+ Addressable::URI.new(:path => :bogus)
133
+ end).should raise_error(TypeError)
134
+ end
135
+ end
136
+
137
+ describe Addressable::URI, "when created with a non-string query" do
138
+ it "should raise an error" do
139
+ (lambda do
140
+ Addressable::URI.new(:query => :bogus)
141
+ end).should raise_error(TypeError)
142
+ end
143
+ end
144
+
145
+ describe Addressable::URI, "when created with a non-string fragment" do
146
+ it "should raise an error" do
147
+ (lambda do
148
+ Addressable::URI.new(:fragment => :bogus)
149
+ end).should raise_error(TypeError)
150
+ end
151
+ end
152
+
153
+ describe Addressable::URI, "when created with a scheme but no hierarchical " +
154
+ "segment" do
155
+ it "should raise an error" do
156
+ (lambda do
157
+ Addressable::URI.parse("http:")
158
+ end).should raise_error(Addressable::URI::InvalidURIError)
159
+ end
160
+ end
161
+
162
+ describe Addressable::URI, "when created from nil components" do
163
+ before do
164
+ @uri = Addressable::URI.new
165
+ end
166
+
167
+ it "should have an empty path" do
168
+ @uri.path.should == ""
169
+ end
170
+
171
+ it "should be an empty uri" do
172
+ @uri.to_s.should == ""
173
+ end
174
+
175
+ it "should still be an empty uri if the scheme is set to whitespace" do
176
+ @uri.scheme = "\t \n"
177
+ @uri.to_s.should == ""
178
+ end
179
+
180
+ it "should raise an error if set into an invalid state" do
181
+ (lambda do
182
+ @uri.user = "user"
183
+ end).should raise_error(Addressable::URI::InvalidURIError)
184
+ end
185
+
186
+ it "should raise an error if set into an invalid state" do
187
+ (lambda do
188
+ @uri.password = "pass"
189
+ end).should raise_error(Addressable::URI::InvalidURIError)
190
+ end
191
+
192
+ it "should raise an error if set into an invalid state" do
193
+ (lambda do
194
+ @uri.scheme = "http"
195
+ @uri.fragment = "fragment"
196
+ end).should raise_error(Addressable::URI::InvalidURIError)
197
+ end
198
+
199
+ it "should raise an error if set into an invalid state" do
200
+ (lambda do
201
+ @uri.fragment = "fragment"
202
+ @uri.scheme = "http"
203
+ end).should raise_error(Addressable::URI::InvalidURIError)
204
+ end
205
+ end
206
+
207
+ describe Addressable::URI, "when created from string components" do
208
+ before do
209
+ @uri = Addressable::URI.new(
210
+ :scheme => "http", :host => "example.com"
211
+ )
212
+ end
213
+
214
+ it "should be equal to the equivalent parsed URI" do
215
+ @uri.should == Addressable::URI.parse("http://example.com")
216
+ end
217
+
218
+ it "should raise an error if invalid components omitted" do
219
+ (lambda do
220
+ @uri.omit(:bogus)
221
+ end).should raise_error(ArgumentError)
222
+ (lambda do
223
+ @uri.omit(:scheme, :bogus, :path)
224
+ end).should raise_error(ArgumentError)
225
+ end
226
+ end
227
+
228
+ describe Addressable::URI, "when created with a nil host but " +
229
+ "non-nil authority components" do
230
+ it "should raise an error" do
231
+ (lambda do
232
+ Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
233
+ end).should raise_error(Addressable::URI::InvalidURIError)
234
+ end
235
+ end
236
+
237
+ describe Addressable::URI, "when created with both an authority and a user" do
238
+ it "should raise an error" do
239
+ (lambda do
240
+ Addressable::URI.new(
241
+ :user => "user", :authority => "user@example.com:80"
242
+ )
243
+ end).should raise_error(ArgumentError)
244
+ end
245
+ end
246
+
247
+ describe Addressable::URI, "when created with an authority and no port" do
248
+ before do
249
+ @uri = Addressable::URI.new(:authority => "user@example.com")
250
+ end
251
+
252
+ it "should not infer a port" do
253
+ @uri.port.should == nil
254
+ @uri.inferred_port.should == nil
255
+ end
256
+ end
257
+
258
+ describe Addressable::URI, "when created with both a userinfo and a user" do
259
+ it "should raise an error" do
260
+ (lambda do
261
+ Addressable::URI.new(:user => "user", :userinfo => "user:pass")
262
+ end).should raise_error(ArgumentError)
263
+ end
264
+ end
265
+
266
+ describe Addressable::URI, "when created with a path that hasn't been " +
267
+ "prefixed with a '/' but a host specified" do
268
+ it "should prefix a '/' to the path" do
269
+ Addressable::URI.new(
270
+ :scheme => "http", :host => "example.com", :path => "path"
271
+ ).should == Addressable::URI.parse("http://example.com/path")
272
+ end
273
+ end
274
+
275
+ describe Addressable::URI, "when created with a path that hasn't been " +
276
+ "prefixed with a '/' but no host specified" do
277
+ it "should prefix a '/' to the path" do
278
+ Addressable::URI.new(
279
+ :scheme => "http", :path => "path"
280
+ ).should == Addressable::URI.parse("http:path")
281
+ end
282
+ end
283
+
284
+ describe Addressable::URI, "when parsed from an Addressable::URI object" do
285
+ it "should return the object" do
286
+ uri = Addressable::URI.parse("http://example.com/")
287
+ (lambda do
288
+ Addressable::URI.parse(uri).object_id.should == uri.object_id
289
+ end).should_not raise_error
290
+ end
291
+
292
+ it "should return the object" do
293
+ uri = Addressable::URI.parse("http://example.com/")
294
+ (lambda do
295
+ Addressable::URI.heuristic_parse(uri).object_id.should == uri.object_id
296
+ end).should_not raise_error
297
+ end
298
+ end
299
+
300
+ describe Addressable::URI, "when parsed from something that looks " +
301
+ "like a URI object" do
302
+ it "should parse without error" do
303
+ uri = Addressable::URI.parse(URI::HTTP.new("http://example.com/"))
304
+ (lambda do
305
+ Addressable::URI.parse(uri)
306
+ end).should_not raise_error
307
+ end
308
+ end
309
+
310
+ describe Addressable::URI, "when parsed from ''" do
311
+ before do
312
+ @uri = Addressable::URI.parse("")
313
+ end
314
+
315
+ it "should have no scheme" do
316
+ @uri.scheme.should == nil
317
+ end
318
+
319
+ it "should not be considered to be ip-based" do
320
+ @uri.should_not be_ip_based
321
+ end
322
+
323
+ it "should have a path of ''" do
324
+ @uri.path.should == ""
325
+ end
326
+
327
+ it "should have a request URI of '/'" do
328
+ @uri.request_uri.should == "/"
329
+ end
330
+
331
+ it "should be considered relative" do
332
+ @uri.should be_relative
333
+ end
334
+
335
+ it "should be considered to be in normal form" do
336
+ @uri.normalize.should be_eql(@uri)
337
+ end
338
+ end
339
+
340
+ # Section 1.1.2 of RFC 3986
341
+ describe Addressable::URI, "when parsed from " +
342
+ "'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
343
+ before do
344
+ @uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
345
+ end
346
+
347
+ it "should use the 'ftp' scheme" do
348
+ @uri.scheme.should == "ftp"
349
+ end
350
+
351
+ it "should be considered to be ip-based" do
352
+ @uri.should be_ip_based
353
+ end
354
+
355
+ it "should have a host of 'ftp.is.co.za'" do
356
+ @uri.host.should == "ftp.is.co.za"
357
+ end
358
+
359
+ it "should have a path of '/rfc/rfc1808.txt'" do
360
+ @uri.path.should == "/rfc/rfc1808.txt"
361
+ end
362
+
363
+ it "should not have a request URI" do
364
+ @uri.request_uri.should == nil
365
+ end
366
+
367
+ it "should be considered to be in normal form" do
368
+ @uri.normalize.should be_eql(@uri)
369
+ end
370
+ end
371
+
372
+ # Section 1.1.2 of RFC 3986
373
+ describe Addressable::URI, "when parsed from " +
374
+ "'http://www.ietf.org/rfc/rfc2396.txt'" do
375
+ before do
376
+ @uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
377
+ end
378
+
379
+ it "should use the 'http' scheme" do
380
+ @uri.scheme.should == "http"
381
+ end
382
+
383
+ it "should be considered to be ip-based" do
384
+ @uri.should be_ip_based
385
+ end
386
+
387
+ it "should have a host of 'www.ietf.org'" do
388
+ @uri.host.should == "www.ietf.org"
389
+ end
390
+
391
+ it "should have a path of '/rfc/rfc2396.txt'" do
392
+ @uri.path.should == "/rfc/rfc2396.txt"
393
+ end
394
+
395
+ it "should have a request URI of '/rfc/rfc2396.txt'" do
396
+ @uri.request_uri.should == "/rfc/rfc2396.txt"
397
+ end
398
+
399
+ it "should be considered to be in normal form" do
400
+ @uri.normalize.should be_eql(@uri)
401
+ end
402
+
403
+ it "should correctly omit components" do
404
+ @uri.omit(:scheme).to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
405
+ @uri.omit(:path).to_s.should == "http://www.ietf.org"
406
+ end
407
+
408
+ it "should correctly omit components destructively" do
409
+ @uri.omit!(:scheme)
410
+ @uri.to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
411
+ end
412
+ end
413
+
414
+ # Section 1.1.2 of RFC 3986
415
+ describe Addressable::URI, "when parsed from " +
416
+ "'ldap://[2001:db8::7]/c=GB?objectClass?one'" do
417
+ before do
418
+ @uri = Addressable::URI.parse("ldap://[2001:db8::7]/c=GB?objectClass?one")
419
+ end
420
+
421
+ it "should use the 'ldap' scheme" do
422
+ @uri.scheme.should == "ldap"
423
+ end
424
+
425
+ it "should be considered to be ip-based" do
426
+ @uri.should be_ip_based
427
+ end
428
+
429
+ it "should have a host of '[2001:db8::7]'" do
430
+ @uri.host.should == "[2001:db8::7]"
431
+ end
432
+
433
+ it "should have a path of '/c=GB'" do
434
+ @uri.path.should == "/c=GB"
435
+ end
436
+
437
+ it "should not have a request URI" do
438
+ @uri.request_uri.should == nil
439
+ end
440
+
441
+ it "should not allow request URI assignment" do
442
+ (lambda do
443
+ @uri.request_uri = "/"
444
+ end).should raise_error(Addressable::URI::InvalidURIError)
445
+ end
446
+
447
+ it "should have a query of 'objectClass?one'" do
448
+ @uri.query.should == "objectClass?one"
449
+ end
450
+
451
+ it "should be considered to be in normal form" do
452
+ @uri.normalize.should be_eql(@uri)
453
+ end
454
+
455
+ it "should correctly omit components" do
456
+ @uri.omit(:scheme, :authority).to_s.should == "/c=GB?objectClass?one"
457
+ @uri.omit(:path).to_s.should == "ldap://[2001:db8::7]?objectClass?one"
458
+ end
459
+
460
+ it "should correctly omit components destructively" do
461
+ @uri.omit!(:scheme, :authority)
462
+ @uri.to_s.should == "/c=GB?objectClass?one"
463
+ end
464
+
465
+ it "should raise an error if omission would create an invalid URI" do
466
+ (lambda do
467
+ @uri.omit(:authority, :path)
468
+ end).should raise_error(Addressable::URI::InvalidURIError)
469
+ end
470
+ end
471
+
472
+ # Section 1.1.2 of RFC 3986
473
+ describe Addressable::URI, "when parsed from " +
474
+ "'mailto:John.Doe@example.com'" do
475
+ before do
476
+ @uri = Addressable::URI.parse("mailto:John.Doe@example.com")
477
+ end
478
+
479
+ it "should use the 'mailto' scheme" do
480
+ @uri.scheme.should == "mailto"
481
+ end
482
+
483
+ it "should not be considered to be ip-based" do
484
+ @uri.should_not be_ip_based
485
+ end
486
+
487
+ it "should have a path of 'John.Doe@example.com'" do
488
+ @uri.path.should == "John.Doe@example.com"
489
+ end
490
+
491
+ it "should not have a request URI" do
492
+ @uri.request_uri.should == nil
493
+ end
494
+
495
+ it "should be considered to be in normal form" do
496
+ @uri.normalize.should be_eql(@uri)
497
+ end
498
+ end
499
+
500
+ # Section 1.1.2 of RFC 3986
501
+ describe Addressable::URI, "when parsed from " +
502
+ "'news:comp.infosystems.www.servers.unix'" do
503
+ before do
504
+ @uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
505
+ end
506
+
507
+ it "should use the 'news' scheme" do
508
+ @uri.scheme.should == "news"
509
+ end
510
+
511
+ it "should not be considered to be ip-based" do
512
+ @uri.should_not be_ip_based
513
+ end
514
+
515
+ it "should have a path of 'comp.infosystems.www.servers.unix'" do
516
+ @uri.path.should == "comp.infosystems.www.servers.unix"
517
+ end
518
+
519
+ it "should not have a request URI" do
520
+ @uri.request_uri.should == nil
521
+ end
522
+
523
+ it "should be considered to be in normal form" do
524
+ @uri.normalize.should be_eql(@uri)
525
+ end
526
+ end
527
+
528
+ # Section 1.1.2 of RFC 3986
529
+ describe Addressable::URI, "when parsed from " +
530
+ "'tel:+1-816-555-1212'" do
531
+ before do
532
+ @uri = Addressable::URI.parse("tel:+1-816-555-1212")
533
+ end
534
+
535
+ it "should use the 'tel' scheme" do
536
+ @uri.scheme.should == "tel"
537
+ end
538
+
539
+ it "should not be considered to be ip-based" do
540
+ @uri.should_not be_ip_based
541
+ end
542
+
543
+ it "should have a path of '+1-816-555-1212'" do
544
+ @uri.path.should == "+1-816-555-1212"
545
+ end
546
+
547
+ it "should not have a request URI" do
548
+ @uri.request_uri.should == nil
549
+ end
550
+
551
+ it "should be considered to be in normal form" do
552
+ @uri.normalize.should be_eql(@uri)
553
+ end
554
+ end
555
+
556
+ # Section 1.1.2 of RFC 3986
557
+ describe Addressable::URI, "when parsed from " +
558
+ "'telnet://192.0.2.16:80/'" do
559
+ before do
560
+ @uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
561
+ end
562
+
563
+ it "should use the 'telnet' scheme" do
564
+ @uri.scheme.should == "telnet"
565
+ end
566
+
567
+ it "should have a host of '192.0.2.16'" do
568
+ @uri.host.should == "192.0.2.16"
569
+ end
570
+
571
+ it "should have a port of '80'" do
572
+ @uri.port.should == 80
573
+ end
574
+
575
+ it "should be considered to be ip-based" do
576
+ @uri.should be_ip_based
577
+ end
578
+
579
+ it "should have a path of '/'" do
580
+ @uri.path.should == "/"
581
+ end
582
+
583
+ it "should not have a request URI" do
584
+ @uri.request_uri.should == nil
585
+ end
586
+
587
+ it "should be considered to be in normal form" do
588
+ @uri.normalize.should be_eql(@uri)
589
+ end
590
+ end
591
+
592
+ # Section 1.1.2 of RFC 3986
593
+ describe Addressable::URI, "when parsed from " +
594
+ "'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
595
+ before do
596
+ @uri = Addressable::URI.parse(
597
+ "urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
598
+ end
599
+
600
+ it "should use the 'urn' scheme" do
601
+ @uri.scheme.should == "urn"
602
+ end
603
+
604
+ it "should not be considered to be ip-based" do
605
+ @uri.should_not be_ip_based
606
+ end
607
+
608
+ it "should have a path of " +
609
+ "'oasis:names:specification:docbook:dtd:xml:4.1.2'" do
610
+ @uri.path.should == "oasis:names:specification:docbook:dtd:xml:4.1.2"
611
+ end
612
+
613
+ it "should not have a request URI" do
614
+ @uri.request_uri.should == nil
615
+ end
616
+
617
+ it "should be considered to be in normal form" do
618
+ @uri.normalize.should be_eql(@uri)
619
+ end
620
+ end
621
+
622
+ describe Addressable::URI, "when parsed from " +
623
+ "'http://example.com'" do
624
+ before do
625
+ @uri = Addressable::URI.parse("http://example.com")
626
+ end
627
+
628
+ it "when inspected, should have the correct URI" do
629
+ @uri.inspect.should include("http://example.com")
630
+ end
631
+
632
+ it "when inspected, should have the correct class name" do
633
+ @uri.inspect.should include("Addressable::URI")
634
+ end
635
+
636
+ it "when inspected, should have the correct object id" do
637
+ @uri.inspect.should include("%#0x" % @uri.object_id)
638
+ end
639
+
640
+ it "should use the 'http' scheme" do
641
+ @uri.scheme.should == "http"
642
+ end
643
+
644
+ it "should be considered to be ip-based" do
645
+ @uri.should be_ip_based
646
+ end
647
+
648
+ it "should have an authority segment of 'example.com'" do
649
+ @uri.authority.should == "example.com"
650
+ end
651
+
652
+ it "should have a host of 'example.com'" do
653
+ @uri.host.should == "example.com"
654
+ end
655
+
656
+ it "should be considered ip-based" do
657
+ @uri.should be_ip_based
658
+ end
659
+
660
+ it "should have no username" do
661
+ @uri.user.should == nil
662
+ end
663
+
664
+ it "should have no password" do
665
+ @uri.password.should == nil
666
+ end
667
+
668
+ it "should use port 80" do
669
+ @uri.inferred_port.should == 80
670
+ end
671
+
672
+ it "should not have a specified port" do
673
+ @uri.port.should == nil
674
+ end
675
+
676
+ it "should have an empty path" do
677
+ @uri.path.should == ""
678
+ end
679
+
680
+ it "should have no query string" do
681
+ @uri.query.should == nil
682
+ @uri.query_values.should == nil
683
+ end
684
+
685
+ it "should have a request URI of '/'" do
686
+ @uri.request_uri.should == "/"
687
+ end
688
+
689
+ it "should have no fragment" do
690
+ @uri.fragment.should == nil
691
+ end
692
+
693
+ it "should be considered absolute" do
694
+ @uri.should be_absolute
695
+ end
696
+
697
+ it "should not be considered relative" do
698
+ @uri.should_not be_relative
699
+ end
700
+
701
+ it "should not be exactly equal to 42" do
702
+ @uri.eql?(42).should == false
703
+ end
704
+
705
+ it "should not be equal to 42" do
706
+ (@uri == 42).should == false
707
+ end
708
+
709
+ it "should not be roughly equal to 42" do
710
+ (@uri === 42).should == false
711
+ end
712
+
713
+ it "should be exactly equal to http://example.com" do
714
+ @uri.eql?(Addressable::URI.parse("http://example.com")).should == true
715
+ end
716
+
717
+ it "should be roughly equal to http://example.com/" do
718
+ (@uri === Addressable::URI.parse("http://example.com/")).should == true
719
+ end
720
+
721
+ it "should be roughly equal to the string 'http://example.com/'" do
722
+ (@uri === "http://example.com/").should == true
723
+ end
724
+
725
+ it "should not be roughly equal to the string " +
726
+ "'http://example.com:bogus/'" do
727
+ (lambda do
728
+ (@uri === "http://example.com:bogus/").should == false
729
+ end).should_not raise_error
730
+ end
731
+
732
+ it "should result in itself when joined with itself" do
733
+ @uri.join(@uri).to_s.should == "http://example.com"
734
+ @uri.join!(@uri).to_s.should == "http://example.com"
735
+ end
736
+
737
+ # Section 6.2.3 of RFC 3986
738
+ it "should be equivalent to http://example.com/" do
739
+ @uri.should == Addressable::URI.parse("http://example.com/")
740
+ end
741
+
742
+ # Section 6.2.3 of RFC 3986
743
+ it "should be equivalent to http://example.com:/" do
744
+ @uri.should == Addressable::URI.parse("http://example.com:/")
745
+ end
746
+
747
+ # Section 6.2.3 of RFC 3986
748
+ it "should be equivalent to http://example.com:80/" do
749
+ @uri.should == Addressable::URI.parse("http://example.com:80/")
750
+ end
751
+
752
+ # Section 6.2.2.1 of RFC 3986
753
+ it "should be equivalent to http://EXAMPLE.COM/" do
754
+ @uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
755
+ end
756
+
757
+ it "should have a route of '/path/' to 'http://example.com/path/'" do
758
+ @uri.route_to("http://example.com/path/").should ==
759
+ Addressable::URI.parse("/path/")
760
+ end
761
+
762
+ it "should have a route of '/' from 'http://example.com/path/'" do
763
+ @uri.route_from("http://example.com/path/").should ==
764
+ Addressable::URI.parse("/")
765
+ end
766
+
767
+ it "should have a route of '#' to 'http://example.com/'" do
768
+ @uri.route_to("http://example.com/").should ==
769
+ Addressable::URI.parse("#")
770
+ end
771
+
772
+ it "should have a route of 'http://elsewhere.com/' to " +
773
+ "'http://elsewhere.com/'" do
774
+ @uri.route_to("http://elsewhere.com/").should ==
775
+ Addressable::URI.parse("http://elsewhere.com/")
776
+ end
777
+
778
+ it "when joined with 'relative/path' should be " +
779
+ "'http://example.com/relative/path'" do
780
+ @uri.join('relative/path').should ==
781
+ Addressable::URI.parse("http://example.com/relative/path")
782
+ end
783
+
784
+ it "when joined with a bogus object a TypeError should be raised" do
785
+ (lambda do
786
+ @uri.join(42)
787
+ end).should raise_error(TypeError)
788
+ end
789
+
790
+ it "should have the correct username after assignment" do
791
+ @uri.user = "newuser"
792
+ @uri.user.should == "newuser"
793
+ @uri.password.should == nil
794
+ @uri.to_s.should == "http://newuser@example.com"
795
+ end
796
+
797
+ it "should have the correct username after assignment" do
798
+ @uri.user = "user@123!"
799
+ @uri.user.should == "user@123!"
800
+ @uri.normalized_user.should == "user%40123%21"
801
+ @uri.password.should == nil
802
+ @uri.normalize.to_s.should == "http://user%40123%21@example.com/"
803
+ end
804
+
805
+ it "should have the correct password after assignment" do
806
+ @uri.password = "newpass"
807
+ @uri.password.should == "newpass"
808
+ @uri.user.should == ""
809
+ @uri.to_s.should == "http://:newpass@example.com"
810
+ end
811
+
812
+ it "should have the correct password after assignment" do
813
+ @uri.password = "secret@123!"
814
+ @uri.password.should == "secret@123!"
815
+ @uri.normalized_password.should == "secret%40123%21"
816
+ @uri.user.should == ""
817
+ @uri.normalize.to_s.should == "http://:secret%40123%21@example.com/"
818
+ @uri.omit(:password).to_s.should == "http://example.com"
819
+ end
820
+
821
+ it "should have the correct user/pass after repeated assignment" do
822
+ @uri.user = nil
823
+ @uri.user.should == nil
824
+ @uri.password = "newpass"
825
+ @uri.password.should == "newpass"
826
+ # Username cannot be nil if the password is set
827
+ @uri.user.should == ""
828
+ @uri.to_s.should == "http://:newpass@example.com"
829
+ @uri.user = "newuser"
830
+ @uri.user.should == "newuser"
831
+ @uri.password = nil
832
+ @uri.password.should == nil
833
+ @uri.to_s.should == "http://newuser@example.com"
834
+ @uri.user = "newuser"
835
+ @uri.user.should == "newuser"
836
+ @uri.password = ""
837
+ @uri.password.should == ""
838
+ @uri.to_s.should == "http://newuser:@example.com"
839
+ @uri.password = "newpass"
840
+ @uri.password.should == "newpass"
841
+ @uri.user = nil
842
+ # Username cannot be nil if the password is set
843
+ @uri.user.should == ""
844
+ @uri.to_s.should == "http://:newpass@example.com"
845
+ end
846
+
847
+ it "should have the correct user/pass after userinfo assignment" do
848
+ @uri.user = "newuser"
849
+ @uri.user.should == "newuser"
850
+ @uri.password = "newpass"
851
+ @uri.password.should == "newpass"
852
+ @uri.userinfo = nil
853
+ @uri.userinfo.should == nil
854
+ @uri.user.should == nil
855
+ @uri.password.should == nil
856
+ end
857
+
858
+ it "should correctly convert to a hash" do
859
+ @uri.to_hash.should == {
860
+ :scheme => "http",
861
+ :user => nil,
862
+ :password => nil,
863
+ :host => "example.com",
864
+ :port => nil,
865
+ :path => "",
866
+ :query => nil,
867
+ :fragment => nil
868
+ }
869
+ end
870
+
871
+ it "should be identical to its duplicate" do
872
+ @uri.should == @uri.dup
873
+ end
874
+ end
875
+
876
+ # Section 5.1.2 of RFC 2616
877
+ describe Addressable::URI, "when parsed from " +
878
+ "'http://www.w3.org/pub/WWW/TheProject.html'" do
879
+ before do
880
+ @uri = Addressable::URI.parse("http://www.w3.org/pub/WWW/TheProject.html")
881
+ end
882
+
883
+ it "should have the correct request URI" do
884
+ @uri.request_uri.should == "/pub/WWW/TheProject.html"
885
+ end
886
+
887
+ it "should have the correct request URI after assignment" do
888
+ @uri.request_uri = "/some/where/else.html?query?string"
889
+ @uri.request_uri.should == "/some/where/else.html?query?string"
890
+ @uri.path.should == "/some/where/else.html"
891
+ @uri.query.should == "query?string"
892
+ end
893
+
894
+ it "should have the correct request URI after assignment" do
895
+ @uri.request_uri = "?x=y"
896
+ @uri.request_uri.should == "/?x=y"
897
+ @uri.path.should == "/"
898
+ @uri.query.should == "x=y"
899
+ end
900
+
901
+ it "should raise an error if the request URI is set to something bogus" do
902
+ (lambda do
903
+ @uri.request_uri = 42
904
+ end).should raise_error(TypeError)
905
+ end
906
+
907
+ it "should correctly convert to a hash" do
908
+ @uri.to_hash.should == {
909
+ :scheme => "http",
910
+ :user => nil,
911
+ :password => nil,
912
+ :host => "www.w3.org",
913
+ :port => nil,
914
+ :path => "/pub/WWW/TheProject.html",
915
+ :query => nil,
916
+ :fragment => nil
917
+ }
918
+ end
919
+ end
920
+
921
+ describe Addressable::URI, "when parsed from " +
922
+ "'http://example.com/'" do
923
+ before do
924
+ @uri = Addressable::URI.parse("http://example.com/")
925
+ end
926
+
927
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
928
+ it "should be equivalent to http://example.com" do
929
+ @uri.should == Addressable::URI.parse("http://example.com")
930
+ end
931
+
932
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
933
+ it "should be equivalent to HTTP://example.com/" do
934
+ @uri.should == Addressable::URI.parse("HTTP://example.com/")
935
+ end
936
+
937
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
938
+ it "should be equivalent to http://example.com:/" do
939
+ @uri.should == Addressable::URI.parse("http://example.com:/")
940
+ end
941
+
942
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
943
+ it "should be equivalent to http://example.com:80/" do
944
+ @uri.should == Addressable::URI.parse("http://example.com:80/")
945
+ end
946
+
947
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
948
+ it "should be equivalent to http://Example.com/" do
949
+ @uri.should == Addressable::URI.parse("http://Example.com/")
950
+ end
951
+
952
+ it "should have the correct username after assignment" do
953
+ @uri.user = nil
954
+ @uri.user.should == nil
955
+ @uri.password.should == nil
956
+ @uri.to_s.should == "http://example.com/"
957
+ end
958
+
959
+ it "should have the correct password after assignment" do
960
+ @uri.password = nil
961
+ @uri.password.should == nil
962
+ @uri.user.should == nil
963
+ @uri.to_s.should == "http://example.com/"
964
+ end
965
+
966
+ it "should have a request URI of '/'" do
967
+ @uri.request_uri.should == "/"
968
+ end
969
+
970
+ it "should correctly convert to a hash" do
971
+ @uri.to_hash.should == {
972
+ :scheme => "http",
973
+ :user => nil,
974
+ :password => nil,
975
+ :host => "example.com",
976
+ :port => nil,
977
+ :path => "/",
978
+ :query => nil,
979
+ :fragment => nil
980
+ }
981
+ end
982
+
983
+ it "should be identical to its duplicate" do
984
+ @uri.should == @uri.dup
985
+ end
986
+
987
+ it "should have the same hash as its duplicate" do
988
+ @uri.hash.should == @uri.dup.hash
989
+ end
990
+
991
+ it "should have a different hash from its equivalent String value" do
992
+ @uri.hash.should_not == @uri.to_s.hash
993
+ end
994
+
995
+ it "should have the same hash as an equal URI" do
996
+ @uri.hash.should == Addressable::URI.parse("http://example.com/").hash
997
+ end
998
+ end
999
+
1000
+ describe Addressable::URI, "when parsed from " +
1001
+ "'http://@example.com/'" do
1002
+ before do
1003
+ @uri = Addressable::URI.parse("http://@example.com/")
1004
+ end
1005
+
1006
+ it "should be equivalent to http://example.com" do
1007
+ @uri.should == Addressable::URI.parse("http://example.com")
1008
+ end
1009
+
1010
+ it "should correctly convert to a hash" do
1011
+ @uri.to_hash.should == {
1012
+ :scheme => "http",
1013
+ :user => "",
1014
+ :password => nil,
1015
+ :host => "example.com",
1016
+ :port => nil,
1017
+ :path => "/",
1018
+ :query => nil,
1019
+ :fragment => nil
1020
+ }
1021
+ end
1022
+
1023
+ it "should be identical to its duplicate" do
1024
+ @uri.should == @uri.dup
1025
+ end
1026
+ end
1027
+
1028
+ describe Addressable::URI, "when parsed from " +
1029
+ "'http://example.com./'" do
1030
+ before do
1031
+ @uri = Addressable::URI.parse("http://example.com./")
1032
+ end
1033
+
1034
+ it "should be equivalent to http://example.com" do
1035
+ @uri.should == Addressable::URI.parse("http://example.com")
1036
+ end
1037
+
1038
+ it "should not be considered to be in normal form" do
1039
+ @uri.normalize.should_not be_eql(@uri)
1040
+ end
1041
+
1042
+ it "should be identical to its duplicate" do
1043
+ @uri.should == @uri.dup
1044
+ end
1045
+ end
1046
+
1047
+ describe Addressable::URI, "when parsed from " +
1048
+ "'http://:@example.com/'" do
1049
+ before do
1050
+ @uri = Addressable::URI.parse("http://:@example.com/")
1051
+ end
1052
+
1053
+ it "should be equivalent to http://example.com" do
1054
+ @uri.should == Addressable::URI.parse("http://example.com")
1055
+ end
1056
+
1057
+ it "should correctly convert to a hash" do
1058
+ @uri.to_hash.should == {
1059
+ :scheme => "http",
1060
+ :user => "",
1061
+ :password => "",
1062
+ :host => "example.com",
1063
+ :port => nil,
1064
+ :path => "/",
1065
+ :query => nil,
1066
+ :fragment => nil
1067
+ }
1068
+ end
1069
+
1070
+ it "should be identical to its duplicate" do
1071
+ @uri.should == @uri.dup
1072
+ end
1073
+ end
1074
+
1075
+ describe Addressable::URI, "when parsed from " +
1076
+ "'http://example.com/~smith/'" do
1077
+ before do
1078
+ @uri = Addressable::URI.parse("http://example.com/~smith/")
1079
+ end
1080
+
1081
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
1082
+ it "should be equivalent to http://example.com/%7Esmith/" do
1083
+ @uri.should == Addressable::URI.parse("http://example.com/%7Esmith/")
1084
+ end
1085
+
1086
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
1087
+ it "should be equivalent to http://example.com/%7esmith/" do
1088
+ @uri.should == Addressable::URI.parse("http://example.com/%7esmith/")
1089
+ end
1090
+
1091
+ it "should be identical to its duplicate" do
1092
+ @uri.should == @uri.dup
1093
+ end
1094
+ end
1095
+
1096
+ describe Addressable::URI, "when parsed from " +
1097
+ "'http://example.com/%E8'" do
1098
+ before do
1099
+ @uri = Addressable::URI.parse("http://example.com/%E8")
1100
+ end
1101
+
1102
+ it "should not raise an exception when normalized" do
1103
+ (lambda do
1104
+ @uri.normalize
1105
+ end).should_not raise_error(ArgumentError)
1106
+ end
1107
+
1108
+ it "should be considered to be in normal form" do
1109
+ @uri.normalize.should be_eql(@uri)
1110
+ end
1111
+
1112
+ it "should not change if encoded with the normalizing algorithm" do
1113
+ Addressable::URI.normalized_encode(@uri).to_s.should ==
1114
+ "http://example.com/%E8"
1115
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
1116
+ "http://example.com/%E8"
1117
+ end
1118
+ end
1119
+
1120
+ describe Addressable::URI, "when parsed from " +
1121
+ "'http://example.com/path%2Fsegment/'" do
1122
+ before do
1123
+ @uri = Addressable::URI.parse("http://example.com/path%2Fsegment/")
1124
+ end
1125
+
1126
+ it "should be considered to be in normal form" do
1127
+ @uri.normalize.should be_eql(@uri)
1128
+ end
1129
+
1130
+ it "should be equal to 'http://example.com/path%2Fsegment/'" do
1131
+ @uri.normalize.should be_eql(
1132
+ Addressable::URI.parse("http://example.com/path%2Fsegment/")
1133
+ )
1134
+ end
1135
+
1136
+ it "should not be equal to 'http://example.com/path/segment/'" do
1137
+ @uri.should_not ==
1138
+ Addressable::URI.parse("http://example.com/path/segment/")
1139
+ end
1140
+
1141
+ it "should not be equal to 'http://example.com/path/segment/'" do
1142
+ @uri.normalize.should_not be_eql(
1143
+ Addressable::URI.parse("http://example.com/path/segment/")
1144
+ )
1145
+ end
1146
+ end
1147
+
1148
+ describe Addressable::URI, "when parsed from " +
1149
+ "'http://example.com/?%F6'" do
1150
+ before do
1151
+ @uri = Addressable::URI.parse("http://example.com/?%F6")
1152
+ end
1153
+
1154
+ it "should not raise an exception when normalized" do
1155
+ (lambda do
1156
+ @uri.normalize
1157
+ end).should_not raise_error(ArgumentError)
1158
+ end
1159
+
1160
+ it "should be considered to be in normal form" do
1161
+ @uri.normalize.should be_eql(@uri)
1162
+ end
1163
+
1164
+ it "should not change if encoded with the normalizing algorithm" do
1165
+ Addressable::URI.normalized_encode(@uri).to_s.should ==
1166
+ "http://example.com/?%F6"
1167
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
1168
+ "http://example.com/?%F6"
1169
+ end
1170
+ end
1171
+
1172
+ describe Addressable::URI, "when parsed from " +
1173
+ "'http://example.com/#%F6'" do
1174
+ before do
1175
+ @uri = Addressable::URI.parse("http://example.com/#%F6")
1176
+ end
1177
+
1178
+ it "should not raise an exception when normalized" do
1179
+ (lambda do
1180
+ @uri.normalize
1181
+ end).should_not raise_error(ArgumentError)
1182
+ end
1183
+
1184
+ it "should be considered to be in normal form" do
1185
+ @uri.normalize.should be_eql(@uri)
1186
+ end
1187
+
1188
+ it "should not change if encoded with the normalizing algorithm" do
1189
+ Addressable::URI.normalized_encode(@uri).to_s.should ==
1190
+ "http://example.com/#%F6"
1191
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
1192
+ "http://example.com/#%F6"
1193
+ end
1194
+ end
1195
+
1196
+ describe Addressable::URI, "when parsed from " +
1197
+ "'http://example.com/%C3%87'" do
1198
+ before do
1199
+ @uri = Addressable::URI.parse("http://example.com/%C3%87")
1200
+ end
1201
+
1202
+ # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
1203
+ it "should be equivalent to 'http://example.com/C%CC%A7'" do
1204
+ @uri.should == Addressable::URI.parse("http://example.com/C%CC%A7")
1205
+ end
1206
+
1207
+ it "should not change if encoded with the normalizing algorithm" do
1208
+ Addressable::URI.normalized_encode(@uri).to_s.should ==
1209
+ "http://example.com/%C3%87"
1210
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
1211
+ "http://example.com/%C3%87"
1212
+ end
1213
+
1214
+ it "should raise an error if encoding with an unexpected return type" do
1215
+ (lambda do
1216
+ Addressable::URI.normalized_encode(@uri, Integer)
1217
+ end).should raise_error(TypeError)
1218
+ end
1219
+
1220
+ it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
1221
+ Addressable::URI.encode(@uri).to_s.should ==
1222
+ "http://example.com/%25C3%2587"
1223
+ end
1224
+
1225
+ it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
1226
+ Addressable::URI.encode(@uri, Addressable::URI).should ==
1227
+ Addressable::URI.parse("http://example.com/%25C3%2587")
1228
+ end
1229
+
1230
+ it "should raise an error if encoding with an unexpected return type" do
1231
+ (lambda do
1232
+ Addressable::URI.encode(@uri, Integer)
1233
+ end).should raise_error(TypeError)
1234
+ end
1235
+
1236
+ it "should be identical to its duplicate" do
1237
+ @uri.should == @uri.dup
1238
+ end
1239
+ end
1240
+
1241
+ describe Addressable::URI, "when parsed from " +
1242
+ "'http://example.com/?q=string'" do
1243
+ before do
1244
+ @uri = Addressable::URI.parse("http://example.com/?q=string")
1245
+ end
1246
+
1247
+ it "should use the 'http' scheme" do
1248
+ @uri.scheme.should == "http"
1249
+ end
1250
+
1251
+ it "should have an authority segment of 'example.com'" do
1252
+ @uri.authority.should == "example.com"
1253
+ end
1254
+
1255
+ it "should have a host of 'example.com'" do
1256
+ @uri.host.should == "example.com"
1257
+ end
1258
+
1259
+ it "should have no username" do
1260
+ @uri.user.should == nil
1261
+ end
1262
+
1263
+ it "should have no password" do
1264
+ @uri.password.should == nil
1265
+ end
1266
+
1267
+ it "should use port 80" do
1268
+ @uri.inferred_port.should == 80
1269
+ end
1270
+
1271
+ it "should have a path of '/'" do
1272
+ @uri.path.should == "/"
1273
+ end
1274
+
1275
+ it "should have a query string of 'q=string'" do
1276
+ @uri.query.should == "q=string"
1277
+ end
1278
+
1279
+ it "should have a query values of of {q => string}" do
1280
+ @uri.query_values.should == {
1281
+ 'q' => "string"
1282
+ }
1283
+ end
1284
+
1285
+ it "should have no fragment" do
1286
+ @uri.fragment.should == nil
1287
+ end
1288
+
1289
+ it "should be considered absolute" do
1290
+ @uri.should be_absolute
1291
+ end
1292
+
1293
+ it "should not be considered relative" do
1294
+ @uri.should_not be_relative
1295
+ end
1296
+
1297
+ it "should be considered to be in normal form" do
1298
+ @uri.normalize.should be_eql(@uri)
1299
+ end
1300
+
1301
+ it "should be identical to its duplicate" do
1302
+ @uri.should == @uri.dup
1303
+ end
1304
+ end
1305
+
1306
+ describe Addressable::URI, "when parsed from " +
1307
+ "'http://example.com/?&q=string'" do
1308
+ before do
1309
+ @uri = Addressable::URI.parse("http://example.com/?&q=string")
1310
+ end
1311
+
1312
+ it "should use the 'http' scheme" do
1313
+ @uri.scheme.should == "http"
1314
+ end
1315
+
1316
+ it "should have an authority segment of 'example.com'" do
1317
+ @uri.authority.should == "example.com"
1318
+ end
1319
+
1320
+ it "should have a host of 'example.com'" do
1321
+ @uri.host.should == "example.com"
1322
+ end
1323
+
1324
+ it "should have no username" do
1325
+ @uri.user.should == nil
1326
+ end
1327
+
1328
+ it "should have no password" do
1329
+ @uri.password.should == nil
1330
+ end
1331
+
1332
+ it "should use port 80" do
1333
+ @uri.inferred_port.should == 80
1334
+ end
1335
+
1336
+ it "should have a path of '/'" do
1337
+ @uri.path.should == "/"
1338
+ end
1339
+
1340
+ it "should have a query string of 'q=string'" do
1341
+ @uri.query.should == "&q=string"
1342
+ end
1343
+
1344
+ it "should have a query values of of {q => string, nil => true}" do
1345
+ @uri.query_values.should == {
1346
+ 'q' => "string",
1347
+ nil => true
1348
+ }
1349
+ end
1350
+
1351
+ it "should have no fragment" do
1352
+ @uri.fragment.should == nil
1353
+ end
1354
+
1355
+ it "should be considered absolute" do
1356
+ @uri.should be_absolute
1357
+ end
1358
+
1359
+ it "should not be considered relative" do
1360
+ @uri.should_not be_relative
1361
+ end
1362
+
1363
+ it "should be considered to be in normal form" do
1364
+ @uri.normalize.should be_eql(@uri)
1365
+ end
1366
+
1367
+ it "should be identical to its duplicate" do
1368
+ @uri.should == @uri.dup
1369
+ end
1370
+ end
1371
+
1372
+ describe Addressable::URI, "when parsed from " +
1373
+ "'http://example.com:80/'" do
1374
+ before do
1375
+ @uri = Addressable::URI.parse("http://example.com:80/")
1376
+ end
1377
+
1378
+ it "should use the 'http' scheme" do
1379
+ @uri.scheme.should == "http"
1380
+ end
1381
+
1382
+ it "should have an authority segment of 'example.com:80'" do
1383
+ @uri.authority.should == "example.com:80"
1384
+ end
1385
+
1386
+ it "should have a host of 'example.com'" do
1387
+ @uri.host.should == "example.com"
1388
+ end
1389
+
1390
+ it "should have no username" do
1391
+ @uri.user.should == nil
1392
+ end
1393
+
1394
+ it "should have no password" do
1395
+ @uri.password.should == nil
1396
+ end
1397
+
1398
+ it "should use port 80" do
1399
+ @uri.port.should == 80
1400
+ end
1401
+
1402
+ it "should have a path of '/'" do
1403
+ @uri.path.should == "/"
1404
+ end
1405
+
1406
+ it "should have no query string" do
1407
+ @uri.query.should == nil
1408
+ end
1409
+
1410
+ it "should have no fragment" do
1411
+ @uri.fragment.should == nil
1412
+ end
1413
+
1414
+ it "should be considered absolute" do
1415
+ @uri.should be_absolute
1416
+ end
1417
+
1418
+ it "should not be considered relative" do
1419
+ @uri.should_not be_relative
1420
+ end
1421
+
1422
+ it "should be exactly equal to http://example.com:80/" do
1423
+ @uri.eql?(Addressable::URI.parse("http://example.com:80/")).should == true
1424
+ end
1425
+
1426
+ it "should be roughly equal to http://example.com/" do
1427
+ (@uri === Addressable::URI.parse("http://example.com/")).should == true
1428
+ end
1429
+
1430
+ it "should be roughly equal to the string 'http://example.com/'" do
1431
+ (@uri === "http://example.com/").should == true
1432
+ end
1433
+
1434
+ it "should not be roughly equal to the string " +
1435
+ "'http://example.com:bogus/'" do
1436
+ (lambda do
1437
+ (@uri === "http://example.com:bogus/").should == false
1438
+ end).should_not raise_error
1439
+ end
1440
+
1441
+ it "should result in itself when joined with itself" do
1442
+ @uri.join(@uri).to_s.should == "http://example.com:80/"
1443
+ @uri.join!(@uri).to_s.should == "http://example.com:80/"
1444
+ end
1445
+
1446
+ # Section 6.2.3 of RFC 3986
1447
+ it "should be equal to http://example.com/" do
1448
+ @uri.should == Addressable::URI.parse("http://example.com/")
1449
+ end
1450
+
1451
+ # Section 6.2.3 of RFC 3986
1452
+ it "should be equal to http://example.com:/" do
1453
+ @uri.should == Addressable::URI.parse("http://example.com:/")
1454
+ end
1455
+
1456
+ # Section 6.2.3 of RFC 3986
1457
+ it "should be equal to http://example.com:80/" do
1458
+ @uri.should == Addressable::URI.parse("http://example.com:80/")
1459
+ end
1460
+
1461
+ # Section 6.2.2.1 of RFC 3986
1462
+ it "should be equal to http://EXAMPLE.COM/" do
1463
+ @uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
1464
+ end
1465
+
1466
+ it "should correctly convert to a hash" do
1467
+ @uri.to_hash.should == {
1468
+ :scheme => "http",
1469
+ :user => nil,
1470
+ :password => nil,
1471
+ :host => "example.com",
1472
+ :port => 80,
1473
+ :path => "/",
1474
+ :query => nil,
1475
+ :fragment => nil
1476
+ }
1477
+ end
1478
+
1479
+ it "should be identical to its duplicate" do
1480
+ @uri.should == @uri.dup
1481
+ end
1482
+ end
1483
+
1484
+ describe Addressable::URI, "when parsed from " +
1485
+ "'http://example.com:8080/'" do
1486
+ before do
1487
+ @uri = Addressable::URI.parse("http://example.com:8080/")
1488
+ end
1489
+
1490
+ it "should use the 'http' scheme" do
1491
+ @uri.scheme.should == "http"
1492
+ end
1493
+
1494
+ it "should have an authority segment of 'example.com:8080'" do
1495
+ @uri.authority.should == "example.com:8080"
1496
+ end
1497
+
1498
+ it "should have a host of 'example.com'" do
1499
+ @uri.host.should == "example.com"
1500
+ end
1501
+
1502
+ it "should have no username" do
1503
+ @uri.user.should == nil
1504
+ end
1505
+
1506
+ it "should have no password" do
1507
+ @uri.password.should == nil
1508
+ end
1509
+
1510
+ it "should use port 8080" do
1511
+ @uri.port.should == 8080
1512
+ end
1513
+
1514
+ it "should have a path of '/'" do
1515
+ @uri.path.should == "/"
1516
+ end
1517
+
1518
+ it "should have no query string" do
1519
+ @uri.query.should == nil
1520
+ end
1521
+
1522
+ it "should have no fragment" do
1523
+ @uri.fragment.should == nil
1524
+ end
1525
+
1526
+ it "should be considered absolute" do
1527
+ @uri.should be_absolute
1528
+ end
1529
+
1530
+ it "should not be considered relative" do
1531
+ @uri.should_not be_relative
1532
+ end
1533
+
1534
+ it "should be exactly equal to http://example.com:8080/" do
1535
+ @uri.eql?(Addressable::URI.parse(
1536
+ "http://example.com:8080/")).should == true
1537
+ end
1538
+
1539
+ it "should have a route of 'http://example.com:8080/' from " +
1540
+ "'http://example.com/path/to/'" do
1541
+ @uri.route_from("http://example.com/path/to/").should ==
1542
+ Addressable::URI.parse("http://example.com:8080/")
1543
+ end
1544
+
1545
+ it "should have a route of 'http://example.com:8080/' from " +
1546
+ "'http://example.com:80/path/to/'" do
1547
+ @uri.route_from("http://example.com:80/path/to/").should ==
1548
+ Addressable::URI.parse("http://example.com:8080/")
1549
+ end
1550
+
1551
+ it "should have a route of '/' from " +
1552
+ "'http://example.com:8080/path/to/'" do
1553
+ @uri.route_from("http://example.com:8080/path/to/").should ==
1554
+ Addressable::URI.parse("/")
1555
+ end
1556
+
1557
+ it "should have a route of 'http://example.com:8080/' from " +
1558
+ "'http://user:pass@example.com/path/to/'" do
1559
+ @uri.route_from("http://user:pass@example.com/path/to/").should ==
1560
+ Addressable::URI.parse("http://example.com:8080/")
1561
+ end
1562
+
1563
+ it "should correctly convert to a hash" do
1564
+ @uri.to_hash.should == {
1565
+ :scheme => "http",
1566
+ :user => nil,
1567
+ :password => nil,
1568
+ :host => "example.com",
1569
+ :port => 8080,
1570
+ :path => "/",
1571
+ :query => nil,
1572
+ :fragment => nil
1573
+ }
1574
+ end
1575
+
1576
+ it "should be identical to its duplicate" do
1577
+ @uri.should == @uri.dup
1578
+ end
1579
+ end
1580
+
1581
+ describe Addressable::URI, "when parsed from " +
1582
+ "'http://example.com:%38%30/'" do
1583
+ before do
1584
+ @uri = Addressable::URI.parse("http://example.com:%38%30/")
1585
+ end
1586
+
1587
+ it "should have the correct port" do
1588
+ @uri.port.should == 80
1589
+ end
1590
+
1591
+ it "should not be considered to be in normal form" do
1592
+ @uri.normalize.should_not be_eql(@uri)
1593
+ end
1594
+
1595
+ it "should normalize to 'http://example.com/'" do
1596
+ @uri.normalize.should === "http://example.com/"
1597
+ end
1598
+ end
1599
+
1600
+ describe Addressable::URI, "when parsed from " +
1601
+ "'http://example.com/path/to/resource/'" do
1602
+ before do
1603
+ @uri = Addressable::URI.parse("http://example.com/path/to/resource/")
1604
+ end
1605
+
1606
+ it "should use the 'http' scheme" do
1607
+ @uri.scheme.should == "http"
1608
+ end
1609
+
1610
+ it "should have an authority segment of 'example.com'" do
1611
+ @uri.authority.should == "example.com"
1612
+ end
1613
+
1614
+ it "should have a host of 'example.com'" do
1615
+ @uri.host.should == "example.com"
1616
+ end
1617
+
1618
+ it "should have no username" do
1619
+ @uri.user.should == nil
1620
+ end
1621
+
1622
+ it "should have no password" do
1623
+ @uri.password.should == nil
1624
+ end
1625
+
1626
+ it "should use port 80" do
1627
+ @uri.inferred_port.should == 80
1628
+ end
1629
+
1630
+ it "should have a path of '/path/to/resource/'" do
1631
+ @uri.path.should == "/path/to/resource/"
1632
+ end
1633
+
1634
+ it "should have no query string" do
1635
+ @uri.query.should == nil
1636
+ end
1637
+
1638
+ it "should have no fragment" do
1639
+ @uri.fragment.should == nil
1640
+ end
1641
+
1642
+ it "should be considered absolute" do
1643
+ @uri.should be_absolute
1644
+ end
1645
+
1646
+ it "should not be considered relative" do
1647
+ @uri.should_not be_relative
1648
+ end
1649
+
1650
+ it "should be exactly equal to http://example.com:8080/" do
1651
+ @uri.eql?(Addressable::URI.parse(
1652
+ "http://example.com/path/to/resource/")).should == true
1653
+ end
1654
+
1655
+ it "should have a route of 'resource/' from " +
1656
+ "'http://example.com/path/to/'" do
1657
+ @uri.route_from("http://example.com/path/to/").should ==
1658
+ Addressable::URI.parse("resource/")
1659
+ end
1660
+
1661
+ it "should have a route of 'resource/' from " +
1662
+ "'http://example.com:80/path/to/'" do
1663
+ @uri.route_from("http://example.com:80/path/to/").should ==
1664
+ Addressable::URI.parse("resource/")
1665
+ end
1666
+
1667
+ it "should have a route of 'http://example.com/path/to/' from " +
1668
+ "'http://example.com:8080/path/to/'" do
1669
+ @uri.route_from("http://example.com:8080/path/to/").should ==
1670
+ Addressable::URI.parse("http://example.com/path/to/resource/")
1671
+ end
1672
+
1673
+ it "should have a route of 'http://example.com/path/to/' from " +
1674
+ "'http://user:pass@example.com/path/to/'" do
1675
+ @uri.route_from("http://user:pass@example.com/path/to/").should ==
1676
+ Addressable::URI.parse("http://example.com/path/to/resource/")
1677
+ end
1678
+
1679
+ it "should have a route of '/path/to/resource/' from " +
1680
+ "'http://example.com/to/resource/'" do
1681
+ @uri.route_from("http://example.com/to/resource/").should ==
1682
+ Addressable::URI.parse("/path/to/resource/")
1683
+ end
1684
+
1685
+ it "should correctly convert to a hash" do
1686
+ @uri.to_hash.should == {
1687
+ :scheme => "http",
1688
+ :user => nil,
1689
+ :password => nil,
1690
+ :host => "example.com",
1691
+ :port => nil,
1692
+ :path => "/path/to/resource/",
1693
+ :query => nil,
1694
+ :fragment => nil
1695
+ }
1696
+ end
1697
+
1698
+ it "should be identical to its duplicate" do
1699
+ @uri.should == @uri.dup
1700
+ end
1701
+ end
1702
+
1703
+ describe Addressable::URI, "when parsed from " +
1704
+ "'relative/path/to/resource'" do
1705
+ before do
1706
+ @uri = Addressable::URI.parse("relative/path/to/resource")
1707
+ end
1708
+
1709
+ it "should not have a scheme" do
1710
+ @uri.scheme.should == nil
1711
+ end
1712
+
1713
+ it "should not be considered ip-based" do
1714
+ @uri.should_not be_ip_based
1715
+ end
1716
+
1717
+ it "should not have an authority segment" do
1718
+ @uri.authority.should == nil
1719
+ end
1720
+
1721
+ it "should not have a host" do
1722
+ @uri.host.should == nil
1723
+ end
1724
+
1725
+ it "should have no username" do
1726
+ @uri.user.should == nil
1727
+ end
1728
+
1729
+ it "should have no password" do
1730
+ @uri.password.should == nil
1731
+ end
1732
+
1733
+ it "should not have a port" do
1734
+ @uri.port.should == nil
1735
+ end
1736
+
1737
+ it "should have a path of 'relative/path/to/resource'" do
1738
+ @uri.path.should == "relative/path/to/resource"
1739
+ end
1740
+
1741
+ it "should have no query string" do
1742
+ @uri.query.should == nil
1743
+ end
1744
+
1745
+ it "should have no fragment" do
1746
+ @uri.fragment.should == nil
1747
+ end
1748
+
1749
+ it "should not be considered absolute" do
1750
+ @uri.should_not be_absolute
1751
+ end
1752
+
1753
+ it "should be considered relative" do
1754
+ @uri.should be_relative
1755
+ end
1756
+
1757
+ it "should raise an error if routing is attempted" do
1758
+ (lambda do
1759
+ @uri.route_to("http://example.com/")
1760
+ end).should raise_error(ArgumentError, /relative\/path\/to\/resource/)
1761
+ (lambda do
1762
+ @uri.route_from("http://example.com/")
1763
+ end).should raise_error(ArgumentError, /relative\/path\/to\/resource/)
1764
+ end
1765
+
1766
+ it "when joined with 'another/relative/path' should be " +
1767
+ "'relative/path/to/another/relative/path'" do
1768
+ @uri.join('another/relative/path').should ==
1769
+ Addressable::URI.parse("relative/path/to/another/relative/path")
1770
+ end
1771
+
1772
+ it "should be identical to its duplicate" do
1773
+ @uri.should == @uri.dup
1774
+ end
1775
+ end
1776
+
1777
+ describe Addressable::URI, "when parsed from " +
1778
+ "'relative_path_with_no_slashes'" do
1779
+ before do
1780
+ @uri = Addressable::URI.parse("relative_path_with_no_slashes")
1781
+ end
1782
+
1783
+ it "should not have a scheme" do
1784
+ @uri.scheme.should == nil
1785
+ end
1786
+
1787
+ it "should not be considered ip-based" do
1788
+ @uri.should_not be_ip_based
1789
+ end
1790
+
1791
+ it "should not have an authority segment" do
1792
+ @uri.authority.should == nil
1793
+ end
1794
+
1795
+ it "should not have a host" do
1796
+ @uri.host.should == nil
1797
+ end
1798
+
1799
+ it "should have no username" do
1800
+ @uri.user.should == nil
1801
+ end
1802
+
1803
+ it "should have no password" do
1804
+ @uri.password.should == nil
1805
+ end
1806
+
1807
+ it "should not have a port" do
1808
+ @uri.port.should == nil
1809
+ end
1810
+
1811
+ it "should have a path of 'relative_path_with_no_slashes'" do
1812
+ @uri.path.should == "relative_path_with_no_slashes"
1813
+ end
1814
+
1815
+ it "should have no query string" do
1816
+ @uri.query.should == nil
1817
+ end
1818
+
1819
+ it "should have no fragment" do
1820
+ @uri.fragment.should == nil
1821
+ end
1822
+
1823
+ it "should not be considered absolute" do
1824
+ @uri.should_not be_absolute
1825
+ end
1826
+
1827
+ it "should be considered relative" do
1828
+ @uri.should be_relative
1829
+ end
1830
+
1831
+ it "when joined with 'another_relative_path' should be " +
1832
+ "'another_relative_path'" do
1833
+ @uri.join('another_relative_path').should ==
1834
+ Addressable::URI.parse("another_relative_path")
1835
+ end
1836
+ end
1837
+
1838
+ describe Addressable::URI, "when parsed from " +
1839
+ "'http://example.com/file.txt'" do
1840
+ before do
1841
+ @uri = Addressable::URI.parse("http://example.com/file.txt")
1842
+ end
1843
+
1844
+ it "should have a scheme of 'http'" do
1845
+ @uri.scheme.should == "http"
1846
+ end
1847
+
1848
+ it "should have an authority segment of 'example.com'" do
1849
+ @uri.authority.should == "example.com"
1850
+ end
1851
+
1852
+ it "should have a host of 'example.com'" do
1853
+ @uri.host.should == "example.com"
1854
+ end
1855
+
1856
+ it "should have no username" do
1857
+ @uri.user.should == nil
1858
+ end
1859
+
1860
+ it "should have no password" do
1861
+ @uri.password.should == nil
1862
+ end
1863
+
1864
+ it "should use port 80" do
1865
+ @uri.inferred_port.should == 80
1866
+ end
1867
+
1868
+ it "should have a path of '/file.txt'" do
1869
+ @uri.path.should == "/file.txt"
1870
+ end
1871
+
1872
+ it "should have a basename of 'file.txt'" do
1873
+ @uri.basename.should == "file.txt"
1874
+ end
1875
+
1876
+ it "should have an extname of '.txt'" do
1877
+ @uri.extname.should == ".txt"
1878
+ end
1879
+
1880
+ it "should have no query string" do
1881
+ @uri.query.should == nil
1882
+ end
1883
+
1884
+ it "should have no fragment" do
1885
+ @uri.fragment.should == nil
1886
+ end
1887
+ end
1888
+
1889
+ describe Addressable::URI, "when parsed from " +
1890
+ "'http://example.com/file.txt;parameter'" do
1891
+ before do
1892
+ @uri = Addressable::URI.parse("http://example.com/file.txt;parameter")
1893
+ end
1894
+
1895
+ it "should have a scheme of 'http'" do
1896
+ @uri.scheme.should == "http"
1897
+ end
1898
+
1899
+ it "should have an authority segment of 'example.com'" do
1900
+ @uri.authority.should == "example.com"
1901
+ end
1902
+
1903
+ it "should have a host of 'example.com'" do
1904
+ @uri.host.should == "example.com"
1905
+ end
1906
+
1907
+ it "should have no username" do
1908
+ @uri.user.should == nil
1909
+ end
1910
+
1911
+ it "should have no password" do
1912
+ @uri.password.should == nil
1913
+ end
1914
+
1915
+ it "should use port 80" do
1916
+ @uri.inferred_port.should == 80
1917
+ end
1918
+
1919
+ it "should have a path of '/file.txt;parameter'" do
1920
+ @uri.path.should == "/file.txt;parameter"
1921
+ end
1922
+
1923
+ it "should have a basename of 'file.txt'" do
1924
+ @uri.basename.should == "file.txt"
1925
+ end
1926
+
1927
+ it "should have an extname of '.txt'" do
1928
+ @uri.extname.should == ".txt"
1929
+ end
1930
+
1931
+ it "should have no query string" do
1932
+ @uri.query.should == nil
1933
+ end
1934
+
1935
+ it "should have no fragment" do
1936
+ @uri.fragment.should == nil
1937
+ end
1938
+ end
1939
+
1940
+ describe Addressable::URI, "when parsed from " +
1941
+ "'http://example.com/file.txt;x=y'" do
1942
+ before do
1943
+ @uri = Addressable::URI.parse("http://example.com/file.txt;x=y")
1944
+ end
1945
+
1946
+ it "should have a scheme of 'http'" do
1947
+ @uri.scheme.should == "http"
1948
+ end
1949
+
1950
+ it "should have a scheme of 'http'" do
1951
+ @uri.scheme.should == "http"
1952
+ end
1953
+
1954
+ it "should have an authority segment of 'example.com'" do
1955
+ @uri.authority.should == "example.com"
1956
+ end
1957
+
1958
+ it "should have a host of 'example.com'" do
1959
+ @uri.host.should == "example.com"
1960
+ end
1961
+
1962
+ it "should have no username" do
1963
+ @uri.user.should == nil
1964
+ end
1965
+
1966
+ it "should have no password" do
1967
+ @uri.password.should == nil
1968
+ end
1969
+
1970
+ it "should use port 80" do
1971
+ @uri.inferred_port.should == 80
1972
+ end
1973
+
1974
+ it "should have a path of '/file.txt;x=y'" do
1975
+ @uri.path.should == "/file.txt;x=y"
1976
+ end
1977
+
1978
+ it "should have an extname of '.txt'" do
1979
+ @uri.extname.should == ".txt"
1980
+ end
1981
+
1982
+ it "should have no query string" do
1983
+ @uri.query.should == nil
1984
+ end
1985
+
1986
+ it "should have no fragment" do
1987
+ @uri.fragment.should == nil
1988
+ end
1989
+
1990
+ it "should be considered to be in normal form" do
1991
+ @uri.normalize.should be_eql(@uri)
1992
+ end
1993
+ end
1994
+
1995
+ describe Addressable::URI, "when parsed from " +
1996
+ "'svn+ssh://developername@rubyforge.org/var/svn/project'" do
1997
+ before do
1998
+ @uri = Addressable::URI.parse(
1999
+ "svn+ssh://developername@rubyforge.org/var/svn/project"
2000
+ )
2001
+ end
2002
+
2003
+ it "should have a scheme of 'svn+ssh'" do
2004
+ @uri.scheme.should == "svn+ssh"
2005
+ end
2006
+
2007
+ it "should be considered to be ip-based" do
2008
+ @uri.should be_ip_based
2009
+ end
2010
+
2011
+ it "should have a path of '/var/svn/project'" do
2012
+ @uri.path.should == "/var/svn/project"
2013
+ end
2014
+
2015
+ it "should have a username of 'developername'" do
2016
+ @uri.user.should == "developername"
2017
+ end
2018
+
2019
+ it "should have no password" do
2020
+ @uri.password.should == nil
2021
+ end
2022
+
2023
+ it "should be considered to be in normal form" do
2024
+ @uri.normalize.should be_eql(@uri)
2025
+ end
2026
+ end
2027
+
2028
+ describe Addressable::URI, "when parsed from " +
2029
+ "'ssh+svn://developername@rubyforge.org/var/svn/project'" do
2030
+ before do
2031
+ @uri = Addressable::URI.parse(
2032
+ "ssh+svn://developername@rubyforge.org/var/svn/project"
2033
+ )
2034
+ end
2035
+
2036
+ it "should have a scheme of 'ssh+svn'" do
2037
+ @uri.scheme.should == "ssh+svn"
2038
+ end
2039
+
2040
+ it "should have a normalized scheme of 'svn+ssh'" do
2041
+ @uri.normalized_scheme.should == "svn+ssh"
2042
+ end
2043
+
2044
+ it "should not be considered to be ip-based" do
2045
+ @uri.should_not be_ip_based
2046
+ end
2047
+
2048
+ it "should have a path of '/var/svn/project'" do
2049
+ @uri.path.should == "/var/svn/project"
2050
+ end
2051
+
2052
+ it "should have a username of 'developername'" do
2053
+ @uri.user.should == "developername"
2054
+ end
2055
+
2056
+ it "should have no password" do
2057
+ @uri.password.should == nil
2058
+ end
2059
+
2060
+ it "should not be considered to be in normal form" do
2061
+ @uri.normalize.should_not be_eql(@uri)
2062
+ end
2063
+ end
2064
+
2065
+ describe Addressable::URI, "when parsed from " +
2066
+ "'mailto:user@example.com'" do
2067
+ before do
2068
+ @uri = Addressable::URI.parse("mailto:user@example.com")
2069
+ end
2070
+
2071
+ it "should have a scheme of 'mailto'" do
2072
+ @uri.scheme.should == "mailto"
2073
+ end
2074
+
2075
+ it "should not be considered to be ip-based" do
2076
+ @uri.should_not be_ip_based
2077
+ end
2078
+
2079
+ it "should have a path of 'user@example.com'" do
2080
+ @uri.path.should == "user@example.com"
2081
+ end
2082
+
2083
+ it "should have no user" do
2084
+ @uri.user.should == nil
2085
+ end
2086
+
2087
+ it "should be considered to be in normal form" do
2088
+ @uri.normalize.should be_eql(@uri)
2089
+ end
2090
+ end
2091
+
2092
+ describe Addressable::URI, "when parsed from " +
2093
+ "'tag:example.com,2006-08-18:/path/to/something'" do
2094
+ before do
2095
+ @uri = Addressable::URI.parse(
2096
+ "tag:example.com,2006-08-18:/path/to/something")
2097
+ end
2098
+
2099
+ it "should have a scheme of 'tag'" do
2100
+ @uri.scheme.should == "tag"
2101
+ end
2102
+
2103
+ it "should be considered to be ip-based" do
2104
+ @uri.should_not be_ip_based
2105
+ end
2106
+
2107
+ it "should have a path of " +
2108
+ "'example.com,2006-08-18:/path/to/something'" do
2109
+ @uri.path.should == "example.com,2006-08-18:/path/to/something"
2110
+ end
2111
+
2112
+ it "should have no user" do
2113
+ @uri.user.should == nil
2114
+ end
2115
+
2116
+ it "should be considered to be in normal form" do
2117
+ @uri.normalize.should be_eql(@uri)
2118
+ end
2119
+ end
2120
+
2121
+ describe Addressable::URI, "when parsed from " +
2122
+ "'http://example.com/x;y/'" do
2123
+ before do
2124
+ @uri = Addressable::URI.parse("http://example.com/x;y/")
2125
+ end
2126
+
2127
+ it "should be considered to be in normal form" do
2128
+ @uri.normalize.should be_eql(@uri)
2129
+ end
2130
+ end
2131
+
2132
+ describe Addressable::URI, "when parsed from " +
2133
+ "'http://example.com/?x=1&y=2'" do
2134
+ before do
2135
+ @uri = Addressable::URI.parse("http://example.com/?x=1&y=2")
2136
+ end
2137
+
2138
+ it "should be considered to be in normal form" do
2139
+ @uri.normalize.should be_eql(@uri)
2140
+ end
2141
+ end
2142
+
2143
+ describe Addressable::URI, "when parsed from " +
2144
+ "'view-source:http://example.com/'" do
2145
+ before do
2146
+ @uri = Addressable::URI.parse("view-source:http://example.com/")
2147
+ end
2148
+
2149
+ it "should have a scheme of 'view-source'" do
2150
+ @uri.scheme.should == "view-source"
2151
+ end
2152
+
2153
+ it "should have a path of 'http://example.com/'" do
2154
+ @uri.path.should == "http://example.com/"
2155
+ end
2156
+
2157
+ it "should be considered to be in normal form" do
2158
+ @uri.normalize.should be_eql(@uri)
2159
+ end
2160
+ end
2161
+
2162
+ describe Addressable::URI, "when parsed from " +
2163
+ "'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
2164
+ before do
2165
+ @uri = Addressable::URI.parse(
2166
+ "http://user:pass@example.com/path/to/resource?query=x#fragment")
2167
+ end
2168
+
2169
+ it "should use the 'http' scheme" do
2170
+ @uri.scheme.should == "http"
2171
+ end
2172
+
2173
+ it "should have an authority segment of 'user:pass@example.com'" do
2174
+ @uri.authority.should == "user:pass@example.com"
2175
+ end
2176
+
2177
+ it "should have a username of 'user'" do
2178
+ @uri.user.should == "user"
2179
+ end
2180
+
2181
+ it "should have a password of 'pass'" do
2182
+ @uri.password.should == "pass"
2183
+ end
2184
+
2185
+ it "should have a host of 'example.com'" do
2186
+ @uri.host.should == "example.com"
2187
+ end
2188
+
2189
+ it "should use port 80" do
2190
+ @uri.inferred_port.should == 80
2191
+ end
2192
+
2193
+ it "should have a path of '/path/to/resource'" do
2194
+ @uri.path.should == "/path/to/resource"
2195
+ end
2196
+
2197
+ it "should have a query string of 'query=x'" do
2198
+ @uri.query.should == "query=x"
2199
+ end
2200
+
2201
+ it "should have a fragment of 'fragment'" do
2202
+ @uri.fragment.should == "fragment"
2203
+ end
2204
+
2205
+ it "should be considered to be in normal form" do
2206
+ @uri.normalize.should be_eql(@uri)
2207
+ end
2208
+
2209
+ it "should have a route of '/path/' to " +
2210
+ "'http://user:pass@example.com/path/'" do
2211
+ @uri.route_to("http://user:pass@example.com/path/").should ==
2212
+ Addressable::URI.parse("/path/")
2213
+ end
2214
+
2215
+ it "should have a route of '/path/to/resource?query=x#fragment' " +
2216
+ "from 'http://user:pass@example.com/path/'" do
2217
+ @uri.route_from("http://user:pass@example.com/path/").should ==
2218
+ Addressable::URI.parse("to/resource?query=x#fragment")
2219
+ end
2220
+
2221
+ it "should have a route of '?query=x#fragment' " +
2222
+ "from 'http://user:pass@example.com/path/to/resource'" do
2223
+ @uri.route_from("http://user:pass@example.com/path/to/resource").should ==
2224
+ Addressable::URI.parse("?query=x#fragment")
2225
+ end
2226
+
2227
+ it "should have a route of '#fragment' " +
2228
+ "from 'http://user:pass@example.com/path/to/resource?query=x'" do
2229
+ @uri.route_from(
2230
+ "http://user:pass@example.com/path/to/resource?query=x").should ==
2231
+ Addressable::URI.parse("#fragment")
2232
+ end
2233
+
2234
+ it "should have a route of '#fragment' from " +
2235
+ "'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
2236
+ @uri.route_from(
2237
+ "http://user:pass@example.com/path/to/resource?query=x#fragment"
2238
+ ).should == Addressable::URI.parse("#fragment")
2239
+ end
2240
+
2241
+ it "should have a route of 'http://elsewhere.com/' to " +
2242
+ "'http://elsewhere.com/'" do
2243
+ @uri.route_to("http://elsewhere.com/").should ==
2244
+ Addressable::URI.parse("http://elsewhere.com/")
2245
+ end
2246
+
2247
+ it "should have a route of " +
2248
+ "'http://user:pass@example.com/path/to/resource?query=x#fragment' " +
2249
+ "from 'http://example.com/path/to/'" do
2250
+ @uri.route_from("http://elsewhere.com/path/to/").should ==
2251
+ Addressable::URI.parse(
2252
+ "http://user:pass@example.com/path/to/resource?query=x#fragment")
2253
+ end
2254
+
2255
+ it "should have the correct scheme after assignment" do
2256
+ @uri.scheme = "ftp"
2257
+ @uri.scheme.should == "ftp"
2258
+ @uri.to_s.should ==
2259
+ "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
2260
+ @uri.to_str.should ==
2261
+ "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
2262
+ @uri.scheme = "bogus!"
2263
+ @uri.scheme.should == "bogus!"
2264
+ @uri.normalized_scheme.should == "bogus%21"
2265
+ @uri.normalize.to_s.should ==
2266
+ "bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
2267
+ @uri.normalize.to_str.should ==
2268
+ "bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
2269
+ end
2270
+
2271
+ it "should have the correct authority segment after assignment" do
2272
+ @uri.authority = "newuser:newpass@example.com:80"
2273
+ @uri.authority.should == "newuser:newpass@example.com:80"
2274
+ @uri.user.should == "newuser"
2275
+ @uri.password.should == "newpass"
2276
+ @uri.userinfo.should == "newuser:newpass"
2277
+ @uri.normalized_userinfo.should == "newuser:newpass"
2278
+ @uri.host.should == "example.com"
2279
+ @uri.port.should == 80
2280
+ @uri.inferred_port.should == 80
2281
+ @uri.to_s.should ==
2282
+ "http://newuser:newpass@example.com:80" +
2283
+ "/path/to/resource?query=x#fragment"
2284
+ end
2285
+
2286
+ it "should have the correct userinfo segment after assignment" do
2287
+ @uri.userinfo = "newuser:newpass"
2288
+ @uri.userinfo.should == "newuser:newpass"
2289
+ @uri.authority.should == "newuser:newpass@example.com"
2290
+ @uri.user.should == "newuser"
2291
+ @uri.password.should == "newpass"
2292
+ @uri.host.should == "example.com"
2293
+ @uri.port.should == nil
2294
+ @uri.inferred_port.should == 80
2295
+ @uri.to_s.should ==
2296
+ "http://newuser:newpass@example.com" +
2297
+ "/path/to/resource?query=x#fragment"
2298
+ end
2299
+
2300
+ it "should have the correct username after assignment" do
2301
+ @uri.user = "newuser"
2302
+ @uri.user.should == "newuser"
2303
+ @uri.authority.should == "newuser:pass@example.com"
2304
+ end
2305
+
2306
+ it "should have the correct password after assignment" do
2307
+ @uri.password = "newpass"
2308
+ @uri.password.should == "newpass"
2309
+ @uri.authority.should == "user:newpass@example.com"
2310
+ end
2311
+
2312
+ it "should have the correct host after assignment" do
2313
+ @uri.host = "newexample.com"
2314
+ @uri.host.should == "newexample.com"
2315
+ @uri.authority.should == "user:pass@newexample.com"
2316
+ end
2317
+
2318
+ it "should have the correct port after assignment" do
2319
+ @uri.port = 8080
2320
+ @uri.port.should == 8080
2321
+ @uri.authority.should == "user:pass@example.com:8080"
2322
+ end
2323
+
2324
+ it "should have the correct path after assignment" do
2325
+ @uri.path = "/newpath/to/resource"
2326
+ @uri.path.should == "/newpath/to/resource"
2327
+ @uri.to_s.should ==
2328
+ "http://user:pass@example.com/newpath/to/resource?query=x#fragment"
2329
+ end
2330
+
2331
+ it "should have the correct path after nil assignment" do
2332
+ @uri.path = nil
2333
+ @uri.path.should == ""
2334
+ @uri.to_s.should ==
2335
+ "http://user:pass@example.com?query=x#fragment"
2336
+ end
2337
+
2338
+ it "should have the correct query string after assignment" do
2339
+ @uri.query = "newquery=x"
2340
+ @uri.query.should == "newquery=x"
2341
+ @uri.to_s.should ==
2342
+ "http://user:pass@example.com/path/to/resource?newquery=x#fragment"
2343
+ @uri.query = nil
2344
+ @uri.query.should == nil
2345
+ @uri.to_s.should ==
2346
+ "http://user:pass@example.com/path/to/resource#fragment"
2347
+ end
2348
+
2349
+ it "should have the correct query string after hash assignment" do
2350
+ @uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"}
2351
+ @uri.query.split("&").should include("%3Fuestion%20mark=%3Dsign")
2352
+ @uri.query.split("&").should include("hello=g%C3%BCnther")
2353
+ @uri.query_values.should == {
2354
+ "?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"
2355
+ }
2356
+ end
2357
+
2358
+ it "should have the correct query string after flag hash assignment" do
2359
+ @uri.query_values = {'flag?1' => true, 'fl=ag2' => true, 'flag3' => true}
2360
+ @uri.query.split("&").should include("flag%3F1")
2361
+ @uri.query.split("&").should include("fl%3Dag2")
2362
+ @uri.query.split("&").should include("flag3")
2363
+ @uri.query_values.should == {
2364
+ 'flag?1' => true, 'fl=ag2' => true, 'flag3' => true
2365
+ }
2366
+ end
2367
+
2368
+ it "should raise an error if query values are set to a bogus type" do
2369
+ (lambda do
2370
+ @uri.query_values = "bogus"
2371
+ end).should raise_error(TypeError)
2372
+ end
2373
+
2374
+ it "should have the correct fragment after assignment" do
2375
+ @uri.fragment = "newfragment"
2376
+ @uri.fragment.should == "newfragment"
2377
+ @uri.to_s.should ==
2378
+ "http://user:pass@example.com/path/to/resource?query=x#newfragment"
2379
+
2380
+ @uri.fragment = nil
2381
+ @uri.fragment.should == nil
2382
+ @uri.to_s.should ==
2383
+ "http://user:pass@example.com/path/to/resource?query=x"
2384
+ end
2385
+
2386
+ it "should have the correct values after a merge" do
2387
+ @uri.merge(:fragment => "newfragment").to_s.should ==
2388
+ "http://user:pass@example.com/path/to/resource?query=x#newfragment"
2389
+ end
2390
+
2391
+ it "should have the correct values after a merge" do
2392
+ @uri.merge(:fragment => nil).to_s.should ==
2393
+ "http://user:pass@example.com/path/to/resource?query=x"
2394
+ end
2395
+
2396
+ it "should have the correct values after a merge" do
2397
+ @uri.merge(:userinfo => "newuser:newpass").to_s.should ==
2398
+ "http://newuser:newpass@example.com/path/to/resource?query=x#fragment"
2399
+ end
2400
+
2401
+ it "should have the correct values after a merge" do
2402
+ @uri.merge(:userinfo => nil).to_s.should ==
2403
+ "http://example.com/path/to/resource?query=x#fragment"
2404
+ end
2405
+
2406
+ it "should have the correct values after a merge" do
2407
+ @uri.merge(:path => "newpath").to_s.should ==
2408
+ "http://user:pass@example.com/newpath?query=x#fragment"
2409
+ end
2410
+
2411
+ it "should have the correct values after a merge" do
2412
+ @uri.merge(:port => "42", :path => "newpath", :query => "").to_s.should ==
2413
+ "http://user:pass@example.com:42/newpath?#fragment"
2414
+ end
2415
+
2416
+ it "should have the correct values after a merge" do
2417
+ @uri.merge(:authority => "foo:bar@baz:42").to_s.should ==
2418
+ "http://foo:bar@baz:42/path/to/resource?query=x#fragment"
2419
+ @uri.to_s.should ==
2420
+ "http://user:pass@example.com/path/to/resource?query=x#fragment"
2421
+ end
2422
+
2423
+ it "should have the correct values after a destructive merge" do
2424
+ @uri.merge!(:authority => "foo:bar@baz:42")
2425
+ @uri.to_s.should ==
2426
+ "http://foo:bar@baz:42/path/to/resource?query=x#fragment"
2427
+ end
2428
+
2429
+ it "should fail to merge with bogus values" do
2430
+ (lambda do
2431
+ @uri.merge(:port => "bogus")
2432
+ end).should raise_error(Addressable::URI::InvalidURIError)
2433
+ end
2434
+
2435
+ it "should fail to merge with bogus parameters" do
2436
+ (lambda do
2437
+ @uri.merge(42)
2438
+ end).should raise_error(TypeError)
2439
+ end
2440
+
2441
+ it "should fail to merge with bogus parameters" do
2442
+ (lambda do
2443
+ @uri.merge("http://example.com/")
2444
+ end).should raise_error(TypeError)
2445
+ end
2446
+
2447
+ it "should fail to merge with both authority and subcomponents" do
2448
+ (lambda do
2449
+ @uri.merge(:authority => "foo:bar@baz:42", :port => "42")
2450
+ end).should raise_error(ArgumentError)
2451
+ end
2452
+
2453
+ it "should fail to merge with both userinfo and subcomponents" do
2454
+ (lambda do
2455
+ @uri.merge(:userinfo => "foo:bar", :user => "foo")
2456
+ end).should raise_error(ArgumentError)
2457
+ end
2458
+
2459
+ it "should be identical to its duplicate" do
2460
+ @uri.should == @uri.dup
2461
+ end
2462
+ end
2463
+
2464
+ describe Addressable::URI, "when parsed from " +
2465
+ "'http://user@example.com'" do
2466
+ before do
2467
+ @uri = Addressable::URI.parse("http://user@example.com")
2468
+ end
2469
+
2470
+ it "should use the 'http' scheme" do
2471
+ @uri.scheme.should == "http"
2472
+ end
2473
+
2474
+ it "should have a username of 'user'" do
2475
+ @uri.user.should == "user"
2476
+ end
2477
+
2478
+ it "should have no password" do
2479
+ @uri.password.should == nil
2480
+ end
2481
+
2482
+ it "should have a userinfo of 'user'" do
2483
+ @uri.userinfo.should == "user"
2484
+ end
2485
+
2486
+ it "should have a normalized userinfo of 'user'" do
2487
+ @uri.normalized_userinfo.should == "user"
2488
+ end
2489
+
2490
+ it "should have a host of 'example.com'" do
2491
+ @uri.host.should == "example.com"
2492
+ end
2493
+
2494
+ it "should use port 80" do
2495
+ @uri.inferred_port.should == 80
2496
+ end
2497
+
2498
+ it "should have the correct username after assignment" do
2499
+ @uri.user = "newuser"
2500
+ @uri.user.should == "newuser"
2501
+ @uri.password.should == nil
2502
+ @uri.to_s.should == "http://newuser@example.com"
2503
+ end
2504
+
2505
+ it "should have the correct password after assignment" do
2506
+ @uri.password = "newpass"
2507
+ @uri.password.should == "newpass"
2508
+ @uri.to_s.should == "http://user:newpass@example.com"
2509
+ end
2510
+
2511
+ it "should have the correct userinfo segment after assignment" do
2512
+ @uri.userinfo = "newuser:newpass"
2513
+ @uri.userinfo.should == "newuser:newpass"
2514
+ @uri.user.should == "newuser"
2515
+ @uri.password.should == "newpass"
2516
+ @uri.host.should == "example.com"
2517
+ @uri.port.should == nil
2518
+ @uri.inferred_port.should == 80
2519
+ @uri.to_s.should == "http://newuser:newpass@example.com"
2520
+ end
2521
+
2522
+ it "should have the correct userinfo segment after nil assignment" do
2523
+ @uri.userinfo = nil
2524
+ @uri.userinfo.should == nil
2525
+ @uri.user.should == nil
2526
+ @uri.password.should == nil
2527
+ @uri.host.should == "example.com"
2528
+ @uri.port.should == nil
2529
+ @uri.inferred_port.should == 80
2530
+ @uri.to_s.should == "http://example.com"
2531
+ end
2532
+
2533
+ it "should have the correct authority segment after assignment" do
2534
+ @uri.authority = "newuser@example.com"
2535
+ @uri.authority.should == "newuser@example.com"
2536
+ @uri.user.should == "newuser"
2537
+ @uri.password.should == nil
2538
+ @uri.host.should == "example.com"
2539
+ @uri.port.should == nil
2540
+ @uri.inferred_port.should == 80
2541
+ @uri.to_s.should == "http://newuser@example.com"
2542
+ end
2543
+
2544
+ it "should raise an error after nil assignment of authority segment" do
2545
+ (lambda do
2546
+ # This would create an invalid URI
2547
+ @uri.authority = nil
2548
+ end).should raise_error
2549
+ end
2550
+ end
2551
+
2552
+ describe Addressable::URI, "when parsed from " +
2553
+ "'http://user:@example.com'" do
2554
+ before do
2555
+ @uri = Addressable::URI.parse("http://user:@example.com")
2556
+ end
2557
+
2558
+ it "should use the 'http' scheme" do
2559
+ @uri.scheme.should == "http"
2560
+ end
2561
+
2562
+ it "should have a username of 'user'" do
2563
+ @uri.user.should == "user"
2564
+ end
2565
+
2566
+ it "should have a password of ''" do
2567
+ @uri.password.should == ""
2568
+ end
2569
+
2570
+ it "should have a normalized userinfo of 'user:'" do
2571
+ @uri.normalized_userinfo.should == "user:"
2572
+ end
2573
+
2574
+ it "should have a host of 'example.com'" do
2575
+ @uri.host.should == "example.com"
2576
+ end
2577
+
2578
+ it "should use port 80" do
2579
+ @uri.inferred_port.should == 80
2580
+ end
2581
+
2582
+ it "should have the correct username after assignment" do
2583
+ @uri.user = "newuser"
2584
+ @uri.user.should == "newuser"
2585
+ @uri.password.should == ""
2586
+ @uri.to_s.should == "http://newuser:@example.com"
2587
+ end
2588
+
2589
+ it "should have the correct password after assignment" do
2590
+ @uri.password = "newpass"
2591
+ @uri.password.should == "newpass"
2592
+ @uri.to_s.should == "http://user:newpass@example.com"
2593
+ end
2594
+
2595
+ it "should have the correct authority segment after assignment" do
2596
+ @uri.authority = "newuser:@example.com"
2597
+ @uri.authority.should == "newuser:@example.com"
2598
+ @uri.user.should == "newuser"
2599
+ @uri.password.should == ""
2600
+ @uri.host.should == "example.com"
2601
+ @uri.port.should == nil
2602
+ @uri.inferred_port.should == 80
2603
+ @uri.to_s.should == "http://newuser:@example.com"
2604
+ end
2605
+ end
2606
+
2607
+ describe Addressable::URI, "when parsed from " +
2608
+ "'http://:pass@example.com'" do
2609
+ before do
2610
+ @uri = Addressable::URI.parse("http://:pass@example.com")
2611
+ end
2612
+
2613
+ it "should use the 'http' scheme" do
2614
+ @uri.scheme.should == "http"
2615
+ end
2616
+
2617
+ it "should have a username of ''" do
2618
+ @uri.user.should == ""
2619
+ end
2620
+
2621
+ it "should have a password of 'pass'" do
2622
+ @uri.password.should == "pass"
2623
+ end
2624
+
2625
+ it "should have a userinfo of ':pass'" do
2626
+ @uri.userinfo.should == ":pass"
2627
+ end
2628
+
2629
+ it "should have a normalized userinfo of ':pass'" do
2630
+ @uri.normalized_userinfo.should == ":pass"
2631
+ end
2632
+
2633
+ it "should have a host of 'example.com'" do
2634
+ @uri.host.should == "example.com"
2635
+ end
2636
+
2637
+ it "should use port 80" do
2638
+ @uri.inferred_port.should == 80
2639
+ end
2640
+
2641
+ it "should have the correct username after assignment" do
2642
+ @uri.user = "newuser"
2643
+ @uri.user.should == "newuser"
2644
+ @uri.password.should == "pass"
2645
+ @uri.to_s.should == "http://newuser:pass@example.com"
2646
+ end
2647
+
2648
+ it "should have the correct password after assignment" do
2649
+ @uri.password = "newpass"
2650
+ @uri.password.should == "newpass"
2651
+ @uri.user.should == ""
2652
+ @uri.to_s.should == "http://:newpass@example.com"
2653
+ end
2654
+
2655
+ it "should have the correct authority segment after assignment" do
2656
+ @uri.authority = ":newpass@example.com"
2657
+ @uri.authority.should == ":newpass@example.com"
2658
+ @uri.user.should == ""
2659
+ @uri.password.should == "newpass"
2660
+ @uri.host.should == "example.com"
2661
+ @uri.port.should == nil
2662
+ @uri.inferred_port.should == 80
2663
+ @uri.to_s.should == "http://:newpass@example.com"
2664
+ end
2665
+ end
2666
+
2667
+ describe Addressable::URI, "when parsed from " +
2668
+ "'http://:@example.com'" do
2669
+ before do
2670
+ @uri = Addressable::URI.parse("http://:@example.com")
2671
+ end
2672
+
2673
+ it "should use the 'http' scheme" do
2674
+ @uri.scheme.should == "http"
2675
+ end
2676
+
2677
+ it "should have a username of ''" do
2678
+ @uri.user.should == ""
2679
+ end
2680
+
2681
+ it "should have a password of ''" do
2682
+ @uri.password.should == ""
2683
+ end
2684
+
2685
+ it "should have a normalized userinfo of nil" do
2686
+ @uri.normalized_userinfo.should == nil
2687
+ end
2688
+
2689
+ it "should have a host of 'example.com'" do
2690
+ @uri.host.should == "example.com"
2691
+ end
2692
+
2693
+ it "should use port 80" do
2694
+ @uri.inferred_port.should == 80
2695
+ end
2696
+
2697
+ it "should have the correct username after assignment" do
2698
+ @uri.user = "newuser"
2699
+ @uri.user.should == "newuser"
2700
+ @uri.password.should == ""
2701
+ @uri.to_s.should == "http://newuser:@example.com"
2702
+ end
2703
+
2704
+ it "should have the correct password after assignment" do
2705
+ @uri.password = "newpass"
2706
+ @uri.password.should == "newpass"
2707
+ @uri.user.should == ""
2708
+ @uri.to_s.should == "http://:newpass@example.com"
2709
+ end
2710
+
2711
+ it "should have the correct authority segment after assignment" do
2712
+ @uri.authority = ":@newexample.com"
2713
+ @uri.authority.should == ":@newexample.com"
2714
+ @uri.user.should == ""
2715
+ @uri.password.should == ""
2716
+ @uri.host.should == "newexample.com"
2717
+ @uri.port.should == nil
2718
+ @uri.inferred_port.should == 80
2719
+ @uri.to_s.should == "http://:@newexample.com"
2720
+ end
2721
+ end
2722
+
2723
+ describe Addressable::URI, "when parsed from " +
2724
+ "'#example'" do
2725
+ before do
2726
+ @uri = Addressable::URI.parse("#example")
2727
+ end
2728
+
2729
+ it "should be considered relative" do
2730
+ @uri.should be_relative
2731
+ end
2732
+
2733
+ it "should have a host of nil" do
2734
+ @uri.host.should == nil
2735
+ end
2736
+
2737
+ it "should have a path of ''" do
2738
+ @uri.path.should == ""
2739
+ end
2740
+
2741
+ it "should have a query string of nil" do
2742
+ @uri.query.should == nil
2743
+ end
2744
+
2745
+ it "should have a fragment of 'example'" do
2746
+ @uri.fragment.should == "example"
2747
+ end
2748
+ end
2749
+
2750
+ describe Addressable::URI, "when parsed from " +
2751
+ "the network-path reference '//example.com/'" do
2752
+ before do
2753
+ @uri = Addressable::URI.parse("//example.com/")
2754
+ end
2755
+
2756
+ it "should be considered relative" do
2757
+ @uri.should be_relative
2758
+ end
2759
+
2760
+ it "should have a host of 'example.com'" do
2761
+ @uri.host.should == "example.com"
2762
+ end
2763
+
2764
+ it "should have a path of '/'" do
2765
+ @uri.path.should == "/"
2766
+ end
2767
+
2768
+ it "should raise an error if routing is attempted" do
2769
+ (lambda do
2770
+ @uri.route_to("http://example.com/")
2771
+ end).should raise_error(ArgumentError, /\/\/example.com\//)
2772
+ (lambda do
2773
+ @uri.route_from("http://example.com/")
2774
+ end).should raise_error(ArgumentError, /\/\/example.com\//)
2775
+ end
2776
+ end
2777
+
2778
+ describe Addressable::URI, "when parsed from " +
2779
+ "'feed://http://example.com/'" do
2780
+ before do
2781
+ @uri = Addressable::URI.parse("feed://http://example.com/")
2782
+ end
2783
+
2784
+ it "should have a host of 'http'" do
2785
+ @uri.host.should == "http"
2786
+ end
2787
+
2788
+ it "should have a path of '//example.com/'" do
2789
+ @uri.path.should == "//example.com/"
2790
+ end
2791
+ end
2792
+
2793
+ describe Addressable::URI, "when parsed from " +
2794
+ "'feed:http://example.com/'" do
2795
+ before do
2796
+ @uri = Addressable::URI.parse("feed:http://example.com/")
2797
+ end
2798
+
2799
+ it "should have a path of 'http://example.com/'" do
2800
+ @uri.path.should == "http://example.com/"
2801
+ end
2802
+
2803
+ it "should normalize to 'http://example.com/'" do
2804
+ @uri.normalize.to_s.should == "http://example.com/"
2805
+ @uri.normalize!.to_s.should == "http://example.com/"
2806
+ end
2807
+ end
2808
+
2809
+ describe Addressable::URI, "when parsed from " +
2810
+ "'example://a/b/c/%7Bfoo%7D'" do
2811
+ before do
2812
+ @uri = Addressable::URI.parse("example://a/b/c/%7Bfoo%7D")
2813
+ end
2814
+
2815
+ # Section 6.2.2 of RFC 3986
2816
+ it "should be equivalent to eXAMPLE://a/./b/../b/%63/%7bfoo%7d" do
2817
+ @uri.should ==
2818
+ Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
2819
+ end
2820
+ end
2821
+
2822
+ describe Addressable::URI, "when parsed from " +
2823
+ "'http://example.com/indirect/path/./to/../resource/'" do
2824
+ before do
2825
+ @uri = Addressable::URI.parse(
2826
+ "http://example.com/indirect/path/./to/../resource/")
2827
+ end
2828
+
2829
+ it "should use the 'http' scheme" do
2830
+ @uri.scheme.should == "http"
2831
+ end
2832
+
2833
+ it "should have a host of 'example.com'" do
2834
+ @uri.host.should == "example.com"
2835
+ end
2836
+
2837
+ it "should use port 80" do
2838
+ @uri.inferred_port.should == 80
2839
+ end
2840
+
2841
+ it "should have a path of '/indirect/path/./to/../resource/'" do
2842
+ @uri.path.should == "/indirect/path/./to/../resource/"
2843
+ end
2844
+
2845
+ # Section 6.2.2.3 of RFC 3986
2846
+ it "should have a normalized path of '/indirect/path/resource/'" do
2847
+ @uri.normalize.path.should == "/indirect/path/resource/"
2848
+ @uri.normalize!.path.should == "/indirect/path/resource/"
2849
+ end
2850
+ end
2851
+
2852
+ describe Addressable::URI, "when parsed from " +
2853
+ "'http://under_score.example.com/'" do
2854
+ it "should not cause an error" do
2855
+ (lambda do
2856
+ Addressable::URI.parse("http://under_score.example.com/")
2857
+ end).should_not raise_error
2858
+ end
2859
+ end
2860
+
2861
+ describe Addressable::URI, "when parsed from " +
2862
+ "'./this:that'" do
2863
+ before do
2864
+ @uri = Addressable::URI.parse("./this:that")
2865
+ end
2866
+
2867
+ it "should be considered relative" do
2868
+ @uri.should be_relative
2869
+ end
2870
+
2871
+ it "should have no scheme" do
2872
+ @uri.scheme.should == nil
2873
+ end
2874
+ end
2875
+
2876
+ describe Addressable::URI, "when parsed from " +
2877
+ "'this:that'" do
2878
+ before do
2879
+ @uri = Addressable::URI.parse("this:that")
2880
+ end
2881
+
2882
+ it "should be considered absolute" do
2883
+ @uri.should be_absolute
2884
+ end
2885
+
2886
+ it "should have a scheme of 'this'" do
2887
+ @uri.scheme.should == "this"
2888
+ end
2889
+ end
2890
+
2891
+ describe Addressable::URI, "when parsed from '?'" do
2892
+ before do
2893
+ @uri = Addressable::URI.parse("?")
2894
+ end
2895
+
2896
+ it "should have the correct subscript notation query values" do
2897
+ @uri.query_values.should == {}
2898
+ @uri.query_values(:notation => :subscript).should == {}
2899
+ end
2900
+
2901
+ it "should have the correct dot notation query values" do
2902
+ @uri.query_values(:notation => :dot).should == {}
2903
+ end
2904
+
2905
+ it "should have the correct flat notation query values" do
2906
+ @uri.query_values(:notation => :flat).should == {}
2907
+ end
2908
+ end
2909
+
2910
+ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
2911
+ before do
2912
+ @uri = Addressable::URI.parse("?one=1&two=2&three=3")
2913
+ end
2914
+
2915
+ it "should have the correct query values" do
2916
+ @uri.query_values.should == {"one" => "1", "two" => "2", "three" => "3"}
2917
+ end
2918
+
2919
+ it "should raise an error for invalid query value notations" do
2920
+ (lambda do
2921
+ @uri.query_values(:notation => :bogus)
2922
+ end).should raise_error(ArgumentError)
2923
+ end
2924
+ end
2925
+
2926
+ describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
2927
+ before do
2928
+ @uri = Addressable::URI.parse("?one[two][three]=four")
2929
+ end
2930
+
2931
+ it "should have the correct query values" do
2932
+ @uri.query_values.should == {"one" => {"two" => {"three" => "four"}}}
2933
+ end
2934
+
2935
+ it "should have the correct flat notation query values" do
2936
+ @uri.query_values(:notation => :flat).should == {
2937
+ "one[two][three]" => "four"
2938
+ }
2939
+ end
2940
+ end
2941
+
2942
+ describe Addressable::URI, "when parsed from '?one.two.three=four'" do
2943
+ before do
2944
+ @uri = Addressable::URI.parse("?one.two.three=four")
2945
+ end
2946
+
2947
+ it "should have the correct dot notation query values" do
2948
+ @uri.query_values(:notation => :dot).should == {
2949
+ "one" => {"two" => {"three" => "four"}}
2950
+ }
2951
+ end
2952
+
2953
+ it "should have the correct flat notation query values" do
2954
+ @uri.query_values(:notation => :flat).should == {
2955
+ "one.two.three" => "four"
2956
+ }
2957
+ end
2958
+ end
2959
+
2960
+ describe Addressable::URI, "when parsed from " +
2961
+ "'?one[two][three]=four&one[two][five]=six'" do
2962
+ before do
2963
+ @uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
2964
+ end
2965
+
2966
+ it "should have the correct dot notation query values" do
2967
+ @uri.query_values(:notation => :subscript).should == {
2968
+ "one" => {"two" => {"three" => "four", "five" => "six"}}
2969
+ }
2970
+ end
2971
+
2972
+ it "should have the correct flat notation query values" do
2973
+ @uri.query_values(:notation => :flat).should == {
2974
+ "one[two][three]" => "four",
2975
+ "one[two][five]" => "six"
2976
+ }
2977
+ end
2978
+ end
2979
+
2980
+ describe Addressable::URI, "when parsed from " +
2981
+ "'?one.two.three=four&one.two.five=six'" do
2982
+ before do
2983
+ @uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
2984
+ end
2985
+
2986
+ it "should have the correct dot notation query values" do
2987
+ @uri.query_values(:notation => :dot).should == {
2988
+ "one" => {"two" => {"three" => "four", "five" => "six"}}
2989
+ }
2990
+ end
2991
+
2992
+ it "should have the correct flat notation query values" do
2993
+ @uri.query_values(:notation => :flat).should == {
2994
+ "one.two.three" => "four",
2995
+ "one.two.five" => "six"
2996
+ }
2997
+ end
2998
+ end
2999
+
3000
+ describe Addressable::URI, "when parsed from " +
3001
+ "'?one[two][three][]=four&one[two][three][]=five'" do
3002
+ before do
3003
+ @uri = Addressable::URI.parse(
3004
+ "?one[two][three][]=four&one[two][three][]=five"
3005
+ )
3006
+ end
3007
+
3008
+ it "should have the correct subscript notation query values" do
3009
+ @uri.query_values(:notation => :subscript).should == {
3010
+ "one" => {"two" => {"three" => ["four", "five"]}}
3011
+ }
3012
+ end
3013
+
3014
+ it "should raise an error if a key is repeated in the flat notation" do
3015
+ (lambda do
3016
+ @uri.query_values(:notation => :flat)
3017
+ end).should raise_error(ArgumentError)
3018
+ end
3019
+ end
3020
+
3021
+ describe Addressable::URI, "when parsed from " +
3022
+ "'?one[two][three][0]=four&one[two][three][1]=five'" do
3023
+ before do
3024
+ @uri = Addressable::URI.parse(
3025
+ "?one[two][three][0]=four&one[two][three][1]=five"
3026
+ )
3027
+ end
3028
+
3029
+ it "should have the correct subscript notation query values" do
3030
+ @uri.query_values(:notation => :subscript).should == {
3031
+ "one" => {"two" => {"three" => ["four", "five"]}}
3032
+ }
3033
+ end
3034
+ end
3035
+
3036
+ describe Addressable::URI, "when parsed from " +
3037
+ "'http://www.詹姆斯.com/'" do
3038
+ before do
3039
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/")
3040
+ end
3041
+
3042
+ it "should be equivalent to 'http://www.xn--8ws00zhy3a.com/'" do
3043
+ @uri.should ==
3044
+ Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
3045
+ end
3046
+
3047
+ it "should not have domain name encoded during normalization" do
3048
+ Addressable::URI.normalized_encode(@uri.to_s).should ==
3049
+ "http://www.詹姆斯.com/"
3050
+ end
3051
+ end
3052
+
3053
+ describe Addressable::URI, "when parsed from " +
3054
+ "'http://www.詹姆斯.com/ some spaces /'" do
3055
+ before do
3056
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
3057
+ end
3058
+
3059
+ it "should be equivalent to " +
3060
+ "'http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/'" do
3061
+ @uri.should ==
3062
+ Addressable::URI.parse(
3063
+ "http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/")
3064
+ end
3065
+
3066
+ it "should not have domain name encoded during normalization" do
3067
+ Addressable::URI.normalized_encode(@uri.to_s).should ==
3068
+ "http://www.詹姆斯.com/%20some%20spaces%20/"
3069
+ end
3070
+ end
3071
+
3072
+ describe Addressable::URI, "when parsed from " +
3073
+ "'http://www.xn--8ws00zhy3a.com/'" do
3074
+ before do
3075
+ @uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
3076
+ end
3077
+
3078
+ it "should be displayed as http://www.詹姆斯.com/" do
3079
+ @uri.display_uri.to_s.should == "http://www.詹姆斯.com/"
3080
+ end
3081
+
3082
+ it "should properly force the encoding" do
3083
+ display_string = @uri.display_uri.to_str
3084
+ display_string.should == "http://www.詹姆斯.com/"
3085
+ if display_string.respond_to?(:encoding)
3086
+ display_string.encoding.to_s.should == Encoding::UTF_8.to_s
3087
+ end
3088
+ end
3089
+ end
3090
+
3091
+ describe Addressable::URI, "when parsed from " +
3092
+ "'http://www.詹姆斯.com/atomtests/iri/詹.html'" do
3093
+ before do
3094
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
3095
+ end
3096
+
3097
+ it "should normalize to " +
3098
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html" do
3099
+ @uri.normalize.to_s.should ==
3100
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
3101
+ @uri.normalize!.to_s.should ==
3102
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
3103
+ end
3104
+ end
3105
+
3106
+ describe Addressable::URI, "when parsed from a percent-encoded IRI" do
3107
+ before do
3108
+ @uri = Addressable::URI.parse(
3109
+ "http://www.%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA" +
3110
+ "%E3%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3" +
3111
+ "%82%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82" +
3112
+ "%81%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0" +
3113
+ "%E3%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3" +
3114
+ "%81%9F%E3%82%8A%E3%81%AA%E3%81%84.w3.mag.keio.ac.jp"
3115
+ )
3116
+ end
3117
+
3118
+ it "should normalize to something sane" do
3119
+ @uri.normalize.to_s.should ==
3120
+ "http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
3121
+ "g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
3122
+ @uri.normalize!.to_s.should ==
3123
+ "http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
3124
+ "g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
3125
+ end
3126
+ end
3127
+
3128
+ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
3129
+ before do
3130
+ @uri = Addressable::URI.parse("http://a/b/c/d;p?q")
3131
+ end
3132
+
3133
+ # Section 5.4.1 of RFC 3986
3134
+ it "when joined with 'g:h' should resolve to g:h" do
3135
+ (@uri + "g:h").to_s.should == "g:h"
3136
+ Addressable::URI.join(@uri, "g:h").to_s.should == "g:h"
3137
+ end
3138
+
3139
+ # Section 5.4.1 of RFC 3986
3140
+ it "when joined with 'g' should resolve to http://a/b/c/g" do
3141
+ (@uri + "g").to_s.should == "http://a/b/c/g"
3142
+ Addressable::URI.join(@uri.to_s, "g").to_s.should == "http://a/b/c/g"
3143
+ end
3144
+
3145
+ # Section 5.4.1 of RFC 3986
3146
+ it "when joined with './g' should resolve to http://a/b/c/g" do
3147
+ (@uri + "./g").to_s.should == "http://a/b/c/g"
3148
+ Addressable::URI.join(@uri.to_s, "./g").to_s.should == "http://a/b/c/g"
3149
+ end
3150
+
3151
+ # Section 5.4.1 of RFC 3986
3152
+ it "when joined with 'g/' should resolve to http://a/b/c/g/" do
3153
+ (@uri + "g/").to_s.should == "http://a/b/c/g/"
3154
+ Addressable::URI.join(@uri.to_s, "g/").to_s.should == "http://a/b/c/g/"
3155
+ end
3156
+
3157
+ # Section 5.4.1 of RFC 3986
3158
+ it "when joined with '/g' should resolve to http://a/g" do
3159
+ (@uri + "/g").to_s.should == "http://a/g"
3160
+ Addressable::URI.join(@uri.to_s, "/g").to_s.should == "http://a/g"
3161
+ end
3162
+
3163
+ # Section 5.4.1 of RFC 3986
3164
+ it "when joined with '//g' should resolve to http://g" do
3165
+ (@uri + "//g").to_s.should == "http://g"
3166
+ Addressable::URI.join(@uri.to_s, "//g").to_s.should == "http://g"
3167
+ end
3168
+
3169
+ # Section 5.4.1 of RFC 3986
3170
+ it "when joined with '?y' should resolve to http://a/b/c/d;p?y" do
3171
+ (@uri + "?y").to_s.should == "http://a/b/c/d;p?y"
3172
+ Addressable::URI.join(@uri.to_s, "?y").to_s.should == "http://a/b/c/d;p?y"
3173
+ end
3174
+
3175
+ # Section 5.4.1 of RFC 3986
3176
+ it "when joined with 'g?y' should resolve to http://a/b/c/g?y" do
3177
+ (@uri + "g?y").to_s.should == "http://a/b/c/g?y"
3178
+ Addressable::URI.join(@uri.to_s, "g?y").to_s.should == "http://a/b/c/g?y"
3179
+ end
3180
+
3181
+ # Section 5.4.1 of RFC 3986
3182
+ it "when joined with '#s' should resolve to http://a/b/c/d;p?q#s" do
3183
+ (@uri + "#s").to_s.should == "http://a/b/c/d;p?q#s"
3184
+ Addressable::URI.join(@uri.to_s, "#s").to_s.should ==
3185
+ "http://a/b/c/d;p?q#s"
3186
+ end
3187
+
3188
+ # Section 5.4.1 of RFC 3986
3189
+ it "when joined with 'g#s' should resolve to http://a/b/c/g#s" do
3190
+ (@uri + "g#s").to_s.should == "http://a/b/c/g#s"
3191
+ Addressable::URI.join(@uri.to_s, "g#s").to_s.should == "http://a/b/c/g#s"
3192
+ end
3193
+
3194
+ # Section 5.4.1 of RFC 3986
3195
+ it "when joined with 'g?y#s' should resolve to http://a/b/c/g?y#s" do
3196
+ (@uri + "g?y#s").to_s.should == "http://a/b/c/g?y#s"
3197
+ Addressable::URI.join(
3198
+ @uri.to_s, "g?y#s").to_s.should == "http://a/b/c/g?y#s"
3199
+ end
3200
+
3201
+ # Section 5.4.1 of RFC 3986
3202
+ it "when joined with ';x' should resolve to http://a/b/c/;x" do
3203
+ (@uri + ";x").to_s.should == "http://a/b/c/;x"
3204
+ Addressable::URI.join(@uri.to_s, ";x").to_s.should == "http://a/b/c/;x"
3205
+ end
3206
+
3207
+ # Section 5.4.1 of RFC 3986
3208
+ it "when joined with 'g;x' should resolve to http://a/b/c/g;x" do
3209
+ (@uri + "g;x").to_s.should == "http://a/b/c/g;x"
3210
+ Addressable::URI.join(@uri.to_s, "g;x").to_s.should == "http://a/b/c/g;x"
3211
+ end
3212
+
3213
+ # Section 5.4.1 of RFC 3986
3214
+ it "when joined with 'g;x?y#s' should resolve to http://a/b/c/g;x?y#s" do
3215
+ (@uri + "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
3216
+ Addressable::URI.join(
3217
+ @uri.to_s, "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
3218
+ end
3219
+
3220
+ # Section 5.4.1 of RFC 3986
3221
+ it "when joined with '' should resolve to http://a/b/c/d;p?q" do
3222
+ (@uri + "").to_s.should == "http://a/b/c/d;p?q"
3223
+ Addressable::URI.join(@uri.to_s, "").to_s.should == "http://a/b/c/d;p?q"
3224
+ end
3225
+
3226
+ # Section 5.4.1 of RFC 3986
3227
+ it "when joined with '.' should resolve to http://a/b/c/" do
3228
+ (@uri + ".").to_s.should == "http://a/b/c/"
3229
+ Addressable::URI.join(@uri.to_s, ".").to_s.should == "http://a/b/c/"
3230
+ end
3231
+
3232
+ # Section 5.4.1 of RFC 3986
3233
+ it "when joined with './' should resolve to http://a/b/c/" do
3234
+ (@uri + "./").to_s.should == "http://a/b/c/"
3235
+ Addressable::URI.join(@uri.to_s, "./").to_s.should == "http://a/b/c/"
3236
+ end
3237
+
3238
+ # Section 5.4.1 of RFC 3986
3239
+ it "when joined with '..' should resolve to http://a/b/" do
3240
+ (@uri + "..").to_s.should == "http://a/b/"
3241
+ Addressable::URI.join(@uri.to_s, "..").to_s.should == "http://a/b/"
3242
+ end
3243
+
3244
+ # Section 5.4.1 of RFC 3986
3245
+ it "when joined with '../' should resolve to http://a/b/" do
3246
+ (@uri + "../").to_s.should == "http://a/b/"
3247
+ Addressable::URI.join(@uri.to_s, "../").to_s.should == "http://a/b/"
3248
+ end
3249
+
3250
+ # Section 5.4.1 of RFC 3986
3251
+ it "when joined with '../g' should resolve to http://a/b/g" do
3252
+ (@uri + "../g").to_s.should == "http://a/b/g"
3253
+ Addressable::URI.join(@uri.to_s, "../g").to_s.should == "http://a/b/g"
3254
+ end
3255
+
3256
+ # Section 5.4.1 of RFC 3986
3257
+ it "when joined with '../..' should resolve to http://a/" do
3258
+ (@uri + "../..").to_s.should == "http://a/"
3259
+ Addressable::URI.join(@uri.to_s, "../..").to_s.should == "http://a/"
3260
+ end
3261
+
3262
+ # Section 5.4.1 of RFC 3986
3263
+ it "when joined with '../../' should resolve to http://a/" do
3264
+ (@uri + "../../").to_s.should == "http://a/"
3265
+ Addressable::URI.join(@uri.to_s, "../../").to_s.should == "http://a/"
3266
+ end
3267
+
3268
+ # Section 5.4.1 of RFC 3986
3269
+ it "when joined with '../../g' should resolve to http://a/g" do
3270
+ (@uri + "../../g").to_s.should == "http://a/g"
3271
+ Addressable::URI.join(@uri.to_s, "../../g").to_s.should == "http://a/g"
3272
+ end
3273
+
3274
+ # Section 5.4.2 of RFC 3986
3275
+ it "when joined with '../../../g' should resolve to http://a/g" do
3276
+ (@uri + "../../../g").to_s.should == "http://a/g"
3277
+ Addressable::URI.join(@uri.to_s, "../../../g").to_s.should == "http://a/g"
3278
+ end
3279
+
3280
+ it "when joined with '../.././../g' should resolve to http://a/g" do
3281
+ (@uri + "../.././../g").to_s.should == "http://a/g"
3282
+ Addressable::URI.join(@uri.to_s, "../.././../g").to_s.should ==
3283
+ "http://a/g"
3284
+ end
3285
+
3286
+ # Section 5.4.2 of RFC 3986
3287
+ it "when joined with '../../../../g' should resolve to http://a/g" do
3288
+ (@uri + "../../../../g").to_s.should == "http://a/g"
3289
+ Addressable::URI.join(
3290
+ @uri.to_s, "../../../../g").to_s.should == "http://a/g"
3291
+ end
3292
+
3293
+ # Section 5.4.2 of RFC 3986
3294
+ it "when joined with '/./g' should resolve to http://a/g" do
3295
+ (@uri + "/./g").to_s.should == "http://a/g"
3296
+ Addressable::URI.join(@uri.to_s, "/./g").to_s.should == "http://a/g"
3297
+ end
3298
+
3299
+ # Section 5.4.2 of RFC 3986
3300
+ it "when joined with '/../g' should resolve to http://a/g" do
3301
+ (@uri + "/../g").to_s.should == "http://a/g"
3302
+ Addressable::URI.join(@uri.to_s, "/../g").to_s.should == "http://a/g"
3303
+ end
3304
+
3305
+ # Section 5.4.2 of RFC 3986
3306
+ it "when joined with 'g.' should resolve to http://a/b/c/g." do
3307
+ (@uri + "g.").to_s.should == "http://a/b/c/g."
3308
+ Addressable::URI.join(@uri.to_s, "g.").to_s.should == "http://a/b/c/g."
3309
+ end
3310
+
3311
+ # Section 5.4.2 of RFC 3986
3312
+ it "when joined with '.g' should resolve to http://a/b/c/.g" do
3313
+ (@uri + ".g").to_s.should == "http://a/b/c/.g"
3314
+ Addressable::URI.join(@uri.to_s, ".g").to_s.should == "http://a/b/c/.g"
3315
+ end
3316
+
3317
+ # Section 5.4.2 of RFC 3986
3318
+ it "when joined with 'g..' should resolve to http://a/b/c/g.." do
3319
+ (@uri + "g..").to_s.should == "http://a/b/c/g.."
3320
+ Addressable::URI.join(@uri.to_s, "g..").to_s.should == "http://a/b/c/g.."
3321
+ end
3322
+
3323
+ # Section 5.4.2 of RFC 3986
3324
+ it "when joined with '..g' should resolve to http://a/b/c/..g" do
3325
+ (@uri + "..g").to_s.should == "http://a/b/c/..g"
3326
+ Addressable::URI.join(@uri.to_s, "..g").to_s.should == "http://a/b/c/..g"
3327
+ end
3328
+
3329
+ # Section 5.4.2 of RFC 3986
3330
+ it "when joined with './../g' should resolve to http://a/b/g" do
3331
+ (@uri + "./../g").to_s.should == "http://a/b/g"
3332
+ Addressable::URI.join(@uri.to_s, "./../g").to_s.should == "http://a/b/g"
3333
+ end
3334
+
3335
+ # Section 5.4.2 of RFC 3986
3336
+ it "when joined with './g/.' should resolve to http://a/b/c/g/" do
3337
+ (@uri + "./g/.").to_s.should == "http://a/b/c/g/"
3338
+ Addressable::URI.join(@uri.to_s, "./g/.").to_s.should == "http://a/b/c/g/"
3339
+ end
3340
+
3341
+ # Section 5.4.2 of RFC 3986
3342
+ it "when joined with 'g/./h' should resolve to http://a/b/c/g/h" do
3343
+ (@uri + "g/./h").to_s.should == "http://a/b/c/g/h"
3344
+ Addressable::URI.join(@uri.to_s, "g/./h").to_s.should == "http://a/b/c/g/h"
3345
+ end
3346
+
3347
+ # Section 5.4.2 of RFC 3986
3348
+ it "when joined with 'g/../h' should resolve to http://a/b/c/h" do
3349
+ (@uri + "g/../h").to_s.should == "http://a/b/c/h"
3350
+ Addressable::URI.join(@uri.to_s, "g/../h").to_s.should == "http://a/b/c/h"
3351
+ end
3352
+
3353
+ # Section 5.4.2 of RFC 3986
3354
+ it "when joined with 'g;x=1/./y' " +
3355
+ "should resolve to http://a/b/c/g;x=1/y" do
3356
+ (@uri + "g;x=1/./y").to_s.should == "http://a/b/c/g;x=1/y"
3357
+ Addressable::URI.join(
3358
+ @uri.to_s, "g;x=1/./y").to_s.should == "http://a/b/c/g;x=1/y"
3359
+ end
3360
+
3361
+ # Section 5.4.2 of RFC 3986
3362
+ it "when joined with 'g;x=1/../y' should resolve to http://a/b/c/y" do
3363
+ (@uri + "g;x=1/../y").to_s.should == "http://a/b/c/y"
3364
+ Addressable::URI.join(
3365
+ @uri.to_s, "g;x=1/../y").to_s.should == "http://a/b/c/y"
3366
+ end
3367
+
3368
+ # Section 5.4.2 of RFC 3986
3369
+ it "when joined with 'g?y/./x' " +
3370
+ "should resolve to http://a/b/c/g?y/./x" do
3371
+ (@uri + "g?y/./x").to_s.should == "http://a/b/c/g?y/./x"
3372
+ Addressable::URI.join(
3373
+ @uri.to_s, "g?y/./x").to_s.should == "http://a/b/c/g?y/./x"
3374
+ end
3375
+
3376
+ # Section 5.4.2 of RFC 3986
3377
+ it "when joined with 'g?y/../x' " +
3378
+ "should resolve to http://a/b/c/g?y/../x" do
3379
+ (@uri + "g?y/../x").to_s.should == "http://a/b/c/g?y/../x"
3380
+ Addressable::URI.join(
3381
+ @uri.to_s, "g?y/../x").to_s.should == "http://a/b/c/g?y/../x"
3382
+ end
3383
+
3384
+ # Section 5.4.2 of RFC 3986
3385
+ it "when joined with 'g#s/./x' " +
3386
+ "should resolve to http://a/b/c/g#s/./x" do
3387
+ (@uri + "g#s/./x").to_s.should == "http://a/b/c/g#s/./x"
3388
+ Addressable::URI.join(
3389
+ @uri.to_s, "g#s/./x").to_s.should == "http://a/b/c/g#s/./x"
3390
+ end
3391
+
3392
+ # Section 5.4.2 of RFC 3986
3393
+ it "when joined with 'g#s/../x' " +
3394
+ "should resolve to http://a/b/c/g#s/../x" do
3395
+ (@uri + "g#s/../x").to_s.should == "http://a/b/c/g#s/../x"
3396
+ Addressable::URI.join(
3397
+ @uri.to_s, "g#s/../x").to_s.should == "http://a/b/c/g#s/../x"
3398
+ end
3399
+
3400
+ # Section 5.4.2 of RFC 3986
3401
+ it "when joined with 'http:g' should resolve to http:g" do
3402
+ (@uri + "http:g").to_s.should == "http:g"
3403
+ Addressable::URI.join(@uri.to_s, "http:g").to_s.should == "http:g"
3404
+ end
3405
+
3406
+ # Edge case to be sure
3407
+ it "when joined with '//example.com/' should " +
3408
+ "resolve to http://example.com/" do
3409
+ (@uri + "//example.com/").to_s.should == "http://example.com/"
3410
+ Addressable::URI.join(
3411
+ @uri.to_s, "//example.com/").to_s.should == "http://example.com/"
3412
+ end
3413
+
3414
+ it "when joined with a bogus object a TypeError should be raised" do
3415
+ (lambda do
3416
+ Addressable::URI.join(@uri, 42)
3417
+ end).should raise_error(TypeError)
3418
+ end
3419
+ end
3420
+
3421
+ describe Addressable::URI, "when converting the path " +
3422
+ "'relative/path/to/something'" do
3423
+ before do
3424
+ @path = 'relative/path/to/something'
3425
+ end
3426
+
3427
+ it "should convert to " +
3428
+ "\'relative/path/to/something\'" do
3429
+ @uri = Addressable::URI.convert_path(@path)
3430
+ @uri.to_str.should == "relative/path/to/something"
3431
+ end
3432
+
3433
+ it "should join with an absolute file path correctly" do
3434
+ @base = Addressable::URI.convert_path("/absolute/path/")
3435
+ @uri = Addressable::URI.convert_path(@path)
3436
+ (@base + @uri).to_str.should ==
3437
+ "file:///absolute/path/relative/path/to/something"
3438
+ end
3439
+ end
3440
+
3441
+ describe Addressable::URI, "when converting a bogus path" do
3442
+ it "should raise a TypeError" do
3443
+ (lambda do
3444
+ Addressable::URI.convert_path(42)
3445
+ end).should raise_error(TypeError)
3446
+ end
3447
+ end
3448
+
3449
+ describe Addressable::URI, "when given a UNIX root directory" do
3450
+ before do
3451
+ @path = "/"
3452
+ end
3453
+
3454
+ it "should convert to \'file:///\'" do
3455
+ @uri = Addressable::URI.convert_path(@path)
3456
+ @uri.to_str.should == "file:///"
3457
+ end
3458
+ end
3459
+
3460
+ describe Addressable::URI, "when given a Windows root directory" do
3461
+ before do
3462
+ @path = "C:\\"
3463
+ end
3464
+
3465
+ it "should convert to \'file:///c:/\'" do
3466
+ @uri = Addressable::URI.convert_path(@path)
3467
+ @uri.to_str.should == "file:///c:/"
3468
+ end
3469
+ end
3470
+
3471
+ describe Addressable::URI, "when given the path '/home/user/'" do
3472
+ before do
3473
+ @path = '/home/user/'
3474
+ end
3475
+
3476
+ it "should convert to " +
3477
+ "\'file:///home/user/\'" do
3478
+ @uri = Addressable::URI.convert_path(@path)
3479
+ @uri.to_str.should == "file:///home/user/"
3480
+ end
3481
+ end
3482
+
3483
+ describe Addressable::URI, "when given the path " +
3484
+ "'c:\\windows\\My Documents 100%20\\foo.txt'" do
3485
+ before do
3486
+ @path = "c:\\windows\\My Documents 100%20\\foo.txt"
3487
+ end
3488
+
3489
+ it "should convert to " +
3490
+ "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3491
+ @uri = Addressable::URI.convert_path(@path)
3492
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3493
+ end
3494
+ end
3495
+
3496
+ describe Addressable::URI, "when given the path " +
3497
+ "'file://c:\\windows\\My Documents 100%20\\foo.txt'" do
3498
+ before do
3499
+ @path = "file://c:\\windows\\My Documents 100%20\\foo.txt"
3500
+ end
3501
+
3502
+ it "should convert to " +
3503
+ "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3504
+ @uri = Addressable::URI.convert_path(@path)
3505
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3506
+ end
3507
+ end
3508
+
3509
+ describe Addressable::URI, "when given the path " +
3510
+ "'file:c:\\windows\\My Documents 100%20\\foo.txt'" do
3511
+ before do
3512
+ @path = "file:c:\\windows\\My Documents 100%20\\foo.txt"
3513
+ end
3514
+
3515
+ it "should convert to " +
3516
+ "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3517
+ @uri = Addressable::URI.convert_path(@path)
3518
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3519
+ end
3520
+ end
3521
+
3522
+ describe Addressable::URI, "when given the path " +
3523
+ "'file:/c:\\windows\\My Documents 100%20\\foo.txt'" do
3524
+ before do
3525
+ @path = "file:/c:\\windows\\My Documents 100%20\\foo.txt"
3526
+ end
3527
+
3528
+ it "should convert to " +
3529
+ "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3530
+ @uri = Addressable::URI.convert_path(@path)
3531
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3532
+ end
3533
+ end
3534
+
3535
+ describe Addressable::URI, "when given the path " +
3536
+ "'file:///c|/windows/My%20Documents%20100%20/foo.txt'" do
3537
+ before do
3538
+ @path = "file:///c|/windows/My%20Documents%20100%20/foo.txt"
3539
+ end
3540
+
3541
+ it "should convert to " +
3542
+ "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3543
+ @uri = Addressable::URI.convert_path(@path)
3544
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3545
+ end
3546
+ end
3547
+
3548
+ describe Addressable::URI, "when given an http protocol URI" do
3549
+ before do
3550
+ @path = "http://example.com/"
3551
+ end
3552
+
3553
+ it "should not do any conversion at all" do
3554
+ @uri = Addressable::URI.convert_path(@path)
3555
+ @uri.to_str.should == "http://example.com/"
3556
+ end
3557
+ end
3558
+
3559
+ class SuperString
3560
+ def initialize(string)
3561
+ @string = string.to_s
3562
+ end
3563
+
3564
+ def to_str
3565
+ return @string
3566
+ end
3567
+ end
3568
+
3569
+ describe Addressable::URI, "when parsing a non-String object" do
3570
+ it "should correctly parse anything with a 'to_str' method" do
3571
+ Addressable::URI.parse(SuperString.new(42))
3572
+ end
3573
+
3574
+ it "should raise a TypeError for objects than cannot be converted" do
3575
+ (lambda do
3576
+ Addressable::URI.parse(42)
3577
+ end).should raise_error(TypeError, "Can't convert Fixnum into String.")
3578
+ end
3579
+
3580
+ it "should correctly parse heuristically anything with a 'to_str' method" do
3581
+ Addressable::URI.heuristic_parse(SuperString.new(42))
3582
+ end
3583
+
3584
+ it "should raise a TypeError for objects than cannot be converted" do
3585
+ (lambda do
3586
+ Addressable::URI.heuristic_parse(42)
3587
+ end).should raise_error(TypeError, "Can't convert Fixnum into String.")
3588
+ end
3589
+ end
3590
+
3591
+ describe Addressable::URI, "when normalizing a non-String object" do
3592
+ it "should correctly parse anything with a 'to_str' method" do
3593
+ Addressable::URI.normalize_component(SuperString.new(42))
3594
+ end
3595
+
3596
+ it "should raise a TypeError for objects than cannot be converted" do
3597
+ (lambda do
3598
+ Addressable::URI.normalize_component(42)
3599
+ end).should raise_error(TypeError, "Can't convert Fixnum into String.")
3600
+ end
3601
+
3602
+ it "should raise a TypeError for objects than cannot be converted" do
3603
+ (lambda do
3604
+ Addressable::URI.normalize_component("component", 42)
3605
+ end).should raise_error(TypeError)
3606
+ end
3607
+ end
3608
+
3609
+ describe Addressable::URI, "when normalizing a path with an encoded slash" do
3610
+ it "should result in correct percent encoded sequence" do
3611
+ Addressable::URI.parse("/path%2Fsegment/").normalize.path.should ==
3612
+ "/path%2Fsegment/"
3613
+ end
3614
+ end
3615
+
3616
+ describe Addressable::URI, "when normalizing a partially encoded string" do
3617
+ it "should result in correct percent encoded sequence" do
3618
+ Addressable::URI.normalize_component(
3619
+ "partially % encoded%21"
3620
+ ).should == "partially%20%25%20encoded!"
3621
+ end
3622
+
3623
+ it "should result in correct percent encoded sequence" do
3624
+ Addressable::URI.normalize_component(
3625
+ "partially %25 encoded!"
3626
+ ).should == "partially%20%25%20encoded!"
3627
+ end
3628
+ end
3629
+
3630
+ describe Addressable::URI, "when normalizing a unicode sequence" do
3631
+ it "should result in correct percent encoded sequence" do
3632
+ Addressable::URI.normalize_component(
3633
+ "/C%CC%A7"
3634
+ ).should == "/%C3%87"
3635
+ end
3636
+
3637
+ it "should result in correct percent encoded sequence" do
3638
+ Addressable::URI.normalize_component(
3639
+ "/%C3%87"
3640
+ ).should == "/%C3%87"
3641
+ end
3642
+ end
3643
+
3644
+ describe Addressable::URI, "when normalizing a multibyte string" do
3645
+ it "should result in correct percent encoded sequence" do
3646
+ Addressable::URI.normalize_component("günther").should ==
3647
+ "g%C3%BCnther"
3648
+ end
3649
+
3650
+ it "should result in correct percent encoded sequence" do
3651
+ Addressable::URI.normalize_component("g%C3%BCnther").should ==
3652
+ "g%C3%BCnther"
3653
+ end
3654
+ end
3655
+
3656
+ describe Addressable::URI, "when encoding a multibyte string" do
3657
+ it "should result in correct percent encoded sequence" do
3658
+ Addressable::URI.encode_component("günther").should == "g%C3%BCnther"
3659
+ end
3660
+
3661
+ it "should result in correct percent encoded sequence" do
3662
+ Addressable::URI.encode_component(
3663
+ "günther", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
3664
+ ).should == "g%C3%BCnther"
3665
+ end
3666
+ end
3667
+
3668
+ describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
3669
+ it "should result in correct percent encoded sequence" do
3670
+ Addressable::URI.encode_component("one\ntwo").should == "one%0Atwo"
3671
+ end
3672
+
3673
+ it "should result in correct percent encoded sequence" do
3674
+ Addressable::URI.encode_component(
3675
+ "one\ntwo", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
3676
+ ).should == "one%0Atwo"
3677
+ end
3678
+ end
3679
+
3680
+ describe Addressable::URI, "when unencoding a multibyte string" do
3681
+ it "should result in correct percent encoded sequence" do
3682
+ Addressable::URI.unencode_component("g%C3%BCnther").should == "günther"
3683
+ end
3684
+
3685
+ it "should result in correct percent encoded sequence as a URI" do
3686
+ Addressable::URI.unencode(
3687
+ "/path?g%C3%BCnther", ::Addressable::URI
3688
+ ).should == Addressable::URI.new(
3689
+ :path => "/path", :query => "günther"
3690
+ )
3691
+ end
3692
+ end
3693
+
3694
+ describe Addressable::URI, "when unencoding a bogus object" do
3695
+ it "should raise a TypeError" do
3696
+ (lambda do
3697
+ Addressable::URI.unencode_component(42)
3698
+ end).should raise_error(TypeError)
3699
+ end
3700
+
3701
+ it "should raise a TypeError" do
3702
+ (lambda do
3703
+ Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
3704
+ end).should raise_error(TypeError)
3705
+ end
3706
+ end
3707
+
3708
+ describe Addressable::URI, "when encoding a bogus object" do
3709
+ it "should raise a TypeError" do
3710
+ (lambda do
3711
+ Addressable::URI.encode(42)
3712
+ end).should raise_error(TypeError)
3713
+ end
3714
+
3715
+ it "should raise a TypeError" do
3716
+ (lambda do
3717
+ Addressable::URI.normalized_encode(42)
3718
+ end).should raise_error(TypeError)
3719
+ end
3720
+
3721
+ it "should raise a TypeError" do
3722
+ (lambda do
3723
+ Addressable::URI.encode_component("günther", 42)
3724
+ end).should raise_error(TypeError)
3725
+ end
3726
+
3727
+ it "should raise a TypeError" do
3728
+ (lambda do
3729
+ Addressable::URI.encode_component(42)
3730
+ end).should raise_error(TypeError)
3731
+ end
3732
+ end
3733
+
3734
+ describe Addressable::URI, "when given the input " +
3735
+ "'http://example.com/'" do
3736
+ before do
3737
+ @input = "http://example.com/"
3738
+ end
3739
+
3740
+ it "should heuristically parse to 'http://example.com/'" do
3741
+ @uri = Addressable::URI.heuristic_parse(@input)
3742
+ @uri.to_s.should == "http://example.com/"
3743
+ end
3744
+ end
3745
+
3746
+
3747
+ describe Addressable::URI, "when given the input " +
3748
+ "'http:example.com/'" do
3749
+ before do
3750
+ @input = "http:example.com/"
3751
+ end
3752
+
3753
+ it "should heuristically parse to 'http://example.com/'" do
3754
+ @uri = Addressable::URI.heuristic_parse(@input)
3755
+ @uri.to_s.should == "http://example.com/"
3756
+ end
3757
+
3758
+ it "should heuristically parse to 'http://example.com/' " +
3759
+ "even with a scheme hint of 'ftp'" do
3760
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
3761
+ @uri.to_s.should == "http://example.com/"
3762
+ end
3763
+ end
3764
+
3765
+ describe Addressable::URI, "when given the input " +
3766
+ "'http://example.com/example.com/'" do
3767
+ before do
3768
+ @input = "http://example.com/example.com/"
3769
+ end
3770
+
3771
+ it "should heuristically parse to 'http://example.com/example.com/'" do
3772
+ @uri = Addressable::URI.heuristic_parse(@input)
3773
+ @uri.to_s.should == "http://example.com/example.com/"
3774
+ end
3775
+ end
3776
+
3777
+ describe Addressable::URI, "when given the input " +
3778
+ "'/path/to/resource'" do
3779
+ before do
3780
+ @input = "/path/to/resource"
3781
+ end
3782
+
3783
+ it "should heuristically parse to '/path/to/resource'" do
3784
+ @uri = Addressable::URI.heuristic_parse(@input)
3785
+ @uri.to_s.should == "/path/to/resource"
3786
+ end
3787
+ end
3788
+
3789
+ describe Addressable::URI, "when given the input " +
3790
+ "'relative/path/to/resource'" do
3791
+ before do
3792
+ @input = "relative/path/to/resource"
3793
+ end
3794
+
3795
+ it "should heuristically parse to 'relative/path/to/resource'" do
3796
+ @uri = Addressable::URI.heuristic_parse(@input)
3797
+ @uri.to_s.should == "relative/path/to/resource"
3798
+ end
3799
+ end
3800
+
3801
+ describe Addressable::URI, "when given the input " +
3802
+ "'example.com'" do
3803
+ before do
3804
+ @input = "example.com"
3805
+ end
3806
+
3807
+ it "should heuristically parse to 'http://example.com'" do
3808
+ @uri = Addressable::URI.heuristic_parse(@input)
3809
+ @uri.to_s.should == "http://example.com"
3810
+ end
3811
+ end
3812
+
3813
+ describe Addressable::URI, "when given the input " +
3814
+ "'example.com' and a scheme hint of 'ftp'" do
3815
+ before do
3816
+ @input = "example.com"
3817
+ @hints = {:scheme => 'ftp'}
3818
+ end
3819
+
3820
+ it "should heuristically parse to 'http://example.com'" do
3821
+ @uri = Addressable::URI.heuristic_parse(@input, @hints)
3822
+ @uri.to_s.should == "ftp://example.com"
3823
+ end
3824
+ end
3825
+
3826
+ describe Addressable::URI, "when given the input " +
3827
+ "'example.com:21' and a scheme hint of 'ftp'" do
3828
+ before do
3829
+ @input = "example.com:21"
3830
+ @hints = {:scheme => 'ftp'}
3831
+ end
3832
+
3833
+ it "should heuristically parse to 'http://example.com:21'" do
3834
+ @uri = Addressable::URI.heuristic_parse(@input, @hints)
3835
+ @uri.to_s.should == "ftp://example.com:21"
3836
+ end
3837
+ end
3838
+
3839
+ describe Addressable::URI, "when given the input " +
3840
+ "'example.com/path/to/resource'" do
3841
+ before do
3842
+ @input = "example.com/path/to/resource"
3843
+ end
3844
+
3845
+ it "should heuristically parse to 'http://example.com/path/to/resource'" do
3846
+ @uri = Addressable::URI.heuristic_parse(@input)
3847
+ @uri.to_s.should == "http://example.com/path/to/resource"
3848
+ end
3849
+ end
3850
+
3851
+ describe Addressable::URI, "when given the input " +
3852
+ "'http:///example.com'" do
3853
+ before do
3854
+ @input = "http:///example.com"
3855
+ end
3856
+
3857
+ it "should heuristically parse to 'http://example.com'" do
3858
+ @uri = Addressable::URI.heuristic_parse(@input)
3859
+ @uri.to_s.should == "http://example.com"
3860
+ end
3861
+ end
3862
+
3863
+ describe Addressable::URI, "when given the input " +
3864
+ "'feed:///example.com'" do
3865
+ before do
3866
+ @input = "feed:///example.com"
3867
+ end
3868
+
3869
+ it "should heuristically parse to 'feed://example.com'" do
3870
+ @uri = Addressable::URI.heuristic_parse(@input)
3871
+ @uri.to_s.should == "feed://example.com"
3872
+ end
3873
+ end
3874
+
3875
+ describe Addressable::URI, "when given the input " +
3876
+ "'file://path/to/resource/'" do
3877
+ before do
3878
+ @input = "file://path/to/resource/"
3879
+ end
3880
+
3881
+ it "should heuristically parse to 'file:///path/to/resource/'" do
3882
+ @uri = Addressable::URI.heuristic_parse(@input)
3883
+ @uri.to_s.should == "file:///path/to/resource/"
3884
+ end
3885
+ end
3886
+
3887
+ describe Addressable::URI, "when given the input " +
3888
+ "'feed://http://example.com'" do
3889
+ before do
3890
+ @input = "feed://http://example.com"
3891
+ end
3892
+
3893
+ it "should heuristically parse to 'feed:http://example.com'" do
3894
+ @uri = Addressable::URI.heuristic_parse(@input)
3895
+ @uri.to_s.should == "feed:http://example.com"
3896
+ end
3897
+ end
3898
+
3899
+ describe Addressable::URI, "when assigning query values" do
3900
+ before do
3901
+ @uri = Addressable::URI.new
3902
+ end
3903
+
3904
+ it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
3905
+ @uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
3906
+ @uri.query.should == "a=a&b[0]=c&b[1]=d&b[2]=e"
3907
+ end
3908
+
3909
+ it "should correctly assign " +
3910
+ "{:a => 'a', :b => [{:c => 'c', :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
3911
+ @uri.query_values = {
3912
+ :a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
3913
+ }
3914
+ @uri.query.should == "a=a&b[0][c]=c&b[0][d]=d&b[1][e]=e&b[1][f]=f"
3915
+ end
3916
+
3917
+ it "should correctly assign " +
3918
+ "{:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
3919
+ @uri.query_values = {
3920
+ :a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
3921
+ }
3922
+ @uri.query.should == "a=a&b[0][c]&b[0][d]=d&b[1][e]=e&b[1][f]=f"
3923
+ end
3924
+
3925
+ it "should correctly assign " +
3926
+ "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
3927
+ @uri.query_values = {
3928
+ :a => 'a', :b => {:c => true, :d => 'd'}
3929
+ }
3930
+ @uri.query.should == "a=a&b[c]&b[d]=d"
3931
+ end
3932
+
3933
+ it "should correctly assign " +
3934
+ "{:a => 'a', :b => {:c => true, :d => 'd'}, :e => []}" do
3935
+ @uri.query_values = {
3936
+ :a => 'a', :b => {:c => true, :d => 'd'}
3937
+ }
3938
+ @uri.query.should == "a=a&b[c]&b[d]=d"
3939
+ end
3940
+ end