fields-addressable 2.2.3.1

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