cerberus 0.7.6 → 0.7.7

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