addressable 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module Addressable
25
25
  module ADDRESSABLE_VERSION #:nodoc:
26
26
  MAJOR = 0
27
27
  MINOR = 1
28
- TINY = 1
28
+ TINY = 2
29
29
 
30
30
  STRING = [MAJOR, MINOR, TINY].join('.')
31
31
  end
data/rakefile CHANGED
@@ -91,8 +91,8 @@ gem_spec = Gem::Specification.new do |s|
91
91
  s.extra_rdoc_files = %w( README )
92
92
  s.rdoc_options.concat ['--main', 'README']
93
93
 
94
- s.add_dependency('rake', '>= 0.7.2')
95
- s.add_dependency('rspec', '>= 0.7.1')
94
+ s.add_dependency('rake', '>= 0.7.3')
95
+ s.add_dependency('rspec', '>= 1.0.8')
96
96
 
97
97
  s.require_path = 'lib'
98
98
 
@@ -112,7 +112,7 @@ Rake::RDocTask.new do |rdoc|
112
112
  rdoc.rdoc_dir = 'doc'
113
113
  rdoc.title = "Addressable -- URI Implementation"
114
114
  rdoc.options << '--line-numbers' << '--inline-source' <<
115
- '--accessor' << 'cattr_accessor=object'
115
+ '--accessor' << 'cattr_accessor=object' << '--charset' << 'utf-8'
116
116
  rdoc.template = "#{ENV['template']}.rb" if ENV['template']
117
117
  rdoc.rdoc_files.include('README', 'CHANGELOG', 'LICENSE')
118
118
  rdoc.rdoc_files.include('lib/**/*.rb')
@@ -181,10 +181,10 @@ namespace :spec do
181
181
  Dir.mkdir(File.expand_path(File.dirname(__FILE__) + '/specdoc/'))
182
182
  end
183
183
 
184
- t.spec_files = FileList['spec/**/*_spec.rb']
185
- t.spec_opts = ["--format", "html"]
186
- t.out = File.expand_path(
184
+ output_file = File.expand_path(
187
185
  File.dirname(__FILE__) + '/specdoc/index.html')
186
+ t.spec_files = FileList['spec/**/*_spec.rb']
187
+ t.spec_opts = ["--format", "html:#{output_file}"]
188
188
  end
189
189
 
190
190
  desc 'Open the RSpec HTML specifications in a browser.'
@@ -48,408 +48,424 @@ class ExampleProcessor
48
48
  end
49
49
  end
50
50
 
51
- context "A completely nil URI" do
52
- specify "should raise an error" do
51
+ describe Addressable::URI, "when created from nil components" do
52
+ it "should raise an error" do
53
53
  (lambda do
54
54
  Addressable::URI.new(nil, nil, nil, nil, nil, nil, nil, nil)
55
- end).should.raise(Addressable::URI::InvalidURIError)
55
+ end).should raise_error(Addressable::URI::InvalidURIError)
56
56
  end
57
57
  end
58
58
 
59
- context "A URI with a non-numeric port number" do
60
- specify "should raise an error" do
59
+ describe Addressable::URI, "when created with a non-numeric port number" do
60
+ it "should raise an error" do
61
61
  (lambda do
62
62
  Addressable::URI.new(nil, nil, nil, nil, "bogus", nil, nil, nil)
63
- end).should.raise(Addressable::URI::InvalidURIError)
63
+ end).should raise_error(Addressable::URI::InvalidURIError)
64
64
  end
65
65
  end
66
66
 
67
- context "A URI with a scheme but no hierarchical segment" do
68
- specify "should raise an error" do
67
+ describe Addressable::URI, "when created with a scheme but no hierarchical " +
68
+ "segment" do
69
+ it "should raise an error" do
69
70
  (lambda do
70
71
  Addressable::URI.parse("http:")
71
- end).should.raise(Addressable::URI::InvalidURIError)
72
+ end).should raise_error(Addressable::URI::InvalidURIError)
72
73
  end
73
74
  end
74
75
 
75
- context "A constructed URI" do
76
- setup do
76
+ describe Addressable::URI, "when created from string components" do
77
+ before do
77
78
  @uri = Addressable::URI.new(
78
79
  "http", nil, nil, "example.com", nil, nil, nil, nil)
79
80
  end
80
81
 
81
- specify "should be equal to the equivalent parsed URI" do
82
+ it "should be equal to the equivalent parsed URI" do
82
83
  @uri.should == Addressable::URI.parse("http://example.com")
83
84
  end
84
85
  end
85
86
 
86
87
  # Section 1.1.2 of RFC 3986
87
- context "ftp://ftp.is.co.za/rfc/rfc1808.txt" do
88
- setup do
88
+ describe Addressable::URI, " when parsed from " +
89
+ "'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
90
+ before do
89
91
  @uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
90
92
  end
91
93
 
92
- specify "should use the 'ftp' scheme" do
94
+ it "should use the 'ftp' scheme" do
93
95
  @uri.scheme.should == "ftp"
94
96
  end
95
97
 
96
- specify "should be considered to be ip-based" do
97
- @uri.should.be.ip_based
98
+ it "should be considered to be ip-based" do
99
+ @uri.should be_ip_based
98
100
  end
99
101
 
100
- specify "should have a host of 'ftp.is.co.za'" do
102
+ it "should have a host of 'ftp.is.co.za'" do
101
103
  @uri.host.should == "ftp.is.co.za"
102
104
  end
103
105
 
104
- specify "should have a path of '/rfc/rfc1808.txt'" do
106
+ it "should have a path of '/rfc/rfc1808.txt'" do
105
107
  @uri.path.should == "/rfc/rfc1808.txt"
106
108
  end
107
109
 
108
- specify "should be considered to be in normal form" do
109
- @uri.normalize.should.be.eql @uri
110
+ it "should be considered to be in normal form" do
111
+ @uri.normalize.should be_eql(@uri)
110
112
  end
111
113
  end
112
114
 
113
115
  # Section 1.1.2 of RFC 3986
114
- context "http://www.ietf.org/rfc/rfc2396.txt" do
115
- setup do
116
+ describe Addressable::URI, " when parsed from " +
117
+ "'http://www.ietf.org/rfc/rfc2396.txt'" do
118
+ before do
116
119
  @uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
117
120
  end
118
121
 
119
- specify "should use the 'http' scheme" do
122
+ it "should use the 'http' scheme" do
120
123
  @uri.scheme.should == "http"
121
124
  end
122
125
 
123
- specify "should be considered to be ip-based" do
124
- @uri.should.be.ip_based
126
+ it "should be considered to be ip-based" do
127
+ @uri.should be_ip_based
125
128
  end
126
129
 
127
- specify "should have a host of 'www.ietf.org'" do
130
+ it "should have a host of 'www.ietf.org'" do
128
131
  @uri.host.should == "www.ietf.org"
129
132
  end
130
133
 
131
- specify "should have a path of '/rfc/rfc2396.txt'" do
134
+ it "should have a path of '/rfc/rfc2396.txt'" do
132
135
  @uri.path.should == "/rfc/rfc2396.txt"
133
136
  end
134
137
 
135
- specify "should be considered to be in normal form" do
136
- @uri.normalize.should.be.eql @uri
138
+ it "should be considered to be in normal form" do
139
+ @uri.normalize.should be_eql(@uri)
137
140
  end
138
141
  end
139
142
 
140
143
  # Section 1.1.2 of RFC 3986
141
- context "ldap://[2001:db8::7]/c=GB?objectClass?one" do
142
- setup do
144
+ describe Addressable::URI, "when parsed from " +
145
+ "'ldap://[2001:db8::7]/c=GB?objectClass?one'" do
146
+ before do
143
147
  @uri = Addressable::URI.parse("ldap://[2001:db8::7]/c=GB?objectClass?one")
144
148
  end
145
149
 
146
- specify "should use the 'ldap' scheme" do
150
+ it "should use the 'ldap' scheme" do
147
151
  @uri.scheme.should == "ldap"
148
152
  end
149
153
 
150
- specify "should be considered to be ip-based" do
151
- @uri.should.be.ip_based
154
+ it "should be considered to be ip-based" do
155
+ @uri.should be_ip_based
152
156
  end
153
157
 
154
- specify "should have a host of '[2001:db8::7]'" do
158
+ it "should have a host of '[2001:db8::7]'" do
155
159
  @uri.host.should == "[2001:db8::7]"
156
160
  end
157
161
 
158
- specify "should have a path of '/c=GB'" do
162
+ it "should have a path of '/c=GB'" do
159
163
  @uri.path.should == "/c=GB"
160
164
  end
161
165
 
162
- specify "should have a query of 'objectClass?one'" do
166
+ it "should have a query of 'objectClass?one'" do
163
167
  @uri.query.should == "objectClass?one"
164
168
  end
165
169
 
166
- specify "should be considered to be in normal form" do
167
- @uri.normalize.should.be.eql @uri
170
+ it "should be considered to be in normal form" do
171
+ @uri.normalize.should be_eql(@uri)
168
172
  end
169
173
  end
170
174
 
171
175
  # Section 1.1.2 of RFC 3986
172
- context "mailto:John.Doe@example.com" do
173
- setup do
176
+ describe Addressable::URI, " when parsed from " +
177
+ "'mailto:John.Doe@example.com'" do
178
+ before do
174
179
  @uri = Addressable::URI.parse("mailto:John.Doe@example.com")
175
180
  end
176
181
 
177
- specify "should use the 'mailto' scheme" do
182
+ it "should use the 'mailto' scheme" do
178
183
  @uri.scheme.should == "mailto"
179
184
  end
180
185
 
181
- specify "should not be considered to be ip-based" do
182
- @uri.should.not.be.ip_based
186
+ it "should not be considered to be ip-based" do
187
+ @uri.should_not be_ip_based
183
188
  end
184
189
 
185
- specify "should have a path of 'John.Doe@example.com'" do
190
+ it "should have a path of 'John.Doe@example.com'" do
186
191
  @uri.path.should == "John.Doe@example.com"
187
192
  end
188
193
 
189
- specify "should be considered to be in normal form" do
190
- @uri.normalize.should.be.eql @uri
194
+ it "should be considered to be in normal form" do
195
+ @uri.normalize.should be_eql(@uri)
191
196
  end
192
197
  end
193
198
 
194
199
  # Section 1.1.2 of RFC 3986
195
- context "news:comp.infosystems.www.servers.unix" do
196
- setup do
200
+ describe Addressable::URI, " when parsed from " +
201
+ "'news:comp.infosystems.www.servers.unix'" do
202
+ before do
197
203
  @uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
198
204
  end
199
205
 
200
- specify "should use the 'news' scheme" do
206
+ it "should use the 'news' scheme" do
201
207
  @uri.scheme.should == "news"
202
208
  end
203
209
 
204
- specify "should not be considered to be ip-based" do
205
- @uri.should.not.be.ip_based
210
+ it "should not be considered to be ip-based" do
211
+ @uri.should_not be_ip_based
206
212
  end
207
213
 
208
- specify "should have a path of 'comp.infosystems.www.servers.unix'" do
214
+ it "should have a path of 'comp.infosystems.www.servers.unix'" do
209
215
  @uri.path.should == "comp.infosystems.www.servers.unix"
210
216
  end
211
217
 
212
- specify "should be considered to be in normal form" do
213
- @uri.normalize.should.be.eql @uri
218
+ it "should be considered to be in normal form" do
219
+ @uri.normalize.should be_eql(@uri)
214
220
  end
215
221
  end
216
222
 
217
223
  # Section 1.1.2 of RFC 3986
218
- context "tel:+1-816-555-1212" do
219
- setup do
224
+ describe Addressable::URI, "when parsed from " +
225
+ "'tel:+1-816-555-1212'" do
226
+ before do
220
227
  @uri = Addressable::URI.parse("tel:+1-816-555-1212")
221
228
  end
222
229
 
223
- specify "should use the 'tel' scheme" do
230
+ it "should use the 'tel' scheme" do
224
231
  @uri.scheme.should == "tel"
225
232
  end
226
233
 
227
- specify "should not be considered to be ip-based" do
228
- @uri.should.not.be.ip_based
234
+ it "should not be considered to be ip-based" do
235
+ @uri.should_not be_ip_based
229
236
  end
230
237
 
231
- specify "should have a path of '+1-816-555-1212'" do
238
+ it "should have a path of '+1-816-555-1212'" do
232
239
  @uri.path.should == "+1-816-555-1212"
233
240
  end
234
241
 
235
- specify "should be considered to be in normal form" do
236
- @uri.normalize.should.be.eql @uri
242
+ it "should be considered to be in normal form" do
243
+ @uri.normalize.should be_eql(@uri)
237
244
  end
238
245
  end
239
246
 
240
247
  # Section 1.1.2 of RFC 3986
241
- context "telnet://192.0.2.16:80/" do
242
- setup do
248
+ describe Addressable::URI, " when parsed from " +
249
+ "'telnet://192.0.2.16:80/'" do
250
+ before do
243
251
  @uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
244
252
  end
245
253
 
246
- specify "should use the 'telnet' scheme" do
254
+ it "should use the 'telnet' scheme" do
247
255
  @uri.scheme.should == "telnet"
248
256
  end
249
257
 
250
- specify "should have a host of '192.0.2.16'" do
258
+ it "should have a host of '192.0.2.16'" do
251
259
  @uri.host.should == "192.0.2.16"
252
260
  end
253
261
 
254
- specify "should have a port of '80'" do
262
+ it "should have a port of '80'" do
255
263
  @uri.port.should == 80
256
264
  end
257
265
 
258
- specify "should be considered to be ip-based" do
259
- @uri.should.be.ip_based
266
+ it "should be considered to be ip-based" do
267
+ @uri.should be_ip_based
260
268
  end
261
269
 
262
- specify "should have a path of '/'" do
270
+ it "should have a path of '/'" do
263
271
  @uri.path.should == "/"
264
272
  end
265
273
 
266
- specify "should be considered to be in normal form" do
267
- @uri.normalize.should.be.eql @uri
274
+ it "should be considered to be in normal form" do
275
+ @uri.normalize.should be_eql(@uri)
268
276
  end
269
277
  end
270
278
 
271
279
  # Section 1.1.2 of RFC 3986
272
- context "urn:oasis:names:specification:docbook:dtd:xml:4.1.2" do
273
- setup do
280
+ describe Addressable::URI, " when parsed from " +
281
+ "'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
282
+ before do
274
283
  @uri = Addressable::URI.parse(
275
284
  "urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
276
285
  end
277
286
 
278
- specify "should use the 'urn' scheme" do
287
+ it "should use the 'urn' scheme" do
279
288
  @uri.scheme.should == "urn"
280
289
  end
281
290
 
282
- specify "should not be considered to be ip-based" do
283
- @uri.should.not.be.ip_based
291
+ it "should not be considered to be ip-based" do
292
+ @uri.should_not be_ip_based
284
293
  end
285
294
 
286
- specify "should have a path of " +
295
+ it "should have a path of " +
287
296
  "'oasis:names:specification:docbook:dtd:xml:4.1.2'" do
288
297
  @uri.path.should == "oasis:names:specification:docbook:dtd:xml:4.1.2"
289
298
  end
290
299
 
291
- specify "should be considered to be in normal form" do
292
- @uri.normalize.should.be.eql @uri
300
+ it "should be considered to be in normal form" do
301
+ @uri.normalize.should be_eql(@uri)
293
302
  end
294
303
  end
295
304
 
296
- context "http://example.com" do
297
- setup do
305
+ describe Addressable::URI, " when parsed from " +
306
+ "'http://example.com'" do
307
+ before do
298
308
  @uri = Addressable::URI.parse("http://example.com")
299
309
  end
300
310
 
301
- specify "when inspected, should have the correct URI" do
302
- @uri.inspect.should.include "http://example.com"
311
+ it "when inspected, should have the correct URI" do
312
+ @uri.inspect.should include("http://example.com")
303
313
  end
304
314
 
305
- specify "should use the 'http' scheme" do
315
+ it "should use the 'http' scheme" do
306
316
  @uri.scheme.should == "http"
307
317
  end
308
318
 
309
- specify "should be considered to be ip-based" do
310
- @uri.should.be.ip_based
319
+ it "should be considered to be ip-based" do
320
+ @uri.should be_ip_based
311
321
  end
312
322
 
313
- specify "should have an authority segment of 'example.com'" do
323
+ it "should have an authority segment of 'example.com'" do
314
324
  @uri.authority.should == "example.com"
315
325
  end
316
326
 
317
- specify "should have a host of 'example.com'" do
327
+ it "should have a host of 'example.com'" do
318
328
  @uri.host.should == "example.com"
319
329
  end
320
330
 
321
- specify "should be considered ip-based" do
322
- @uri.should.be.ip_based
331
+ it "should be considered ip-based" do
332
+ @uri.should be_ip_based
323
333
  end
324
334
 
325
- specify "should have no username" do
335
+ it "should have no username" do
326
336
  @uri.user.should == nil
327
337
  end
328
338
 
329
- specify "should have no password" do
339
+ it "should have no password" do
330
340
  @uri.password.should == nil
331
341
  end
332
342
 
333
- specify "should use port 80" do
343
+ it "should use port 80" do
334
344
  @uri.port.should == 80
335
345
  end
336
346
 
337
- specify "should not have a specified port" do
347
+ it "should not have a specified port" do
338
348
  @uri.specified_port.should == nil
339
349
  end
340
350
 
341
- specify "should have an empty path" do
351
+ it "should have an empty path" do
342
352
  @uri.path.should == ""
343
353
  end
344
354
 
345
- specify "should have no query string" do
355
+ it "should have no query string" do
346
356
  @uri.query.should == nil
347
357
  end
348
358
 
349
- specify "should have no fragment" do
359
+ it "should have no fragment" do
350
360
  @uri.fragment.should == nil
351
361
  end
352
362
 
353
- specify "should be considered absolute" do
354
- @uri.should.be.absolute
363
+ it "should be considered absolute" do
364
+ @uri.should be_absolute
355
365
  end
356
366
 
357
- specify "should not be considered relative" do
358
- @uri.should.not.be.relative
367
+ it "should not be considered relative" do
368
+ @uri.should_not be_relative
359
369
  end
360
370
 
361
- specify "should not be exactly equal to 42" do
371
+ it "should not be exactly equal to 42" do
362
372
  @uri.eql?(42).should == false
363
373
  end
364
374
 
365
- specify "should not be equal to 42" do
375
+ it "should not be equal to 42" do
366
376
  (@uri == 42).should == false
367
377
  end
368
378
 
369
- specify "should not be roughly equal to 42" do
379
+ it "should not be roughly equal to 42" do
370
380
  (@uri === 42).should == false
371
381
  end
372
382
 
373
- specify "should be exactly equal to http://example.com" do
383
+ it "should be exactly equal to http://example.com" do
374
384
  @uri.eql?(Addressable::URI.parse("http://example.com")).should == true
375
385
  end
376
386
 
377
- specify "should be roughly equal to http://example.com/" do
387
+ it "should be roughly equal to http://example.com/" do
378
388
  (@uri === Addressable::URI.parse("http://example.com/")).should == true
379
389
  end
380
390
 
381
- specify "should be roughly equal to the string 'http://example.com/'" do
391
+ it "should be roughly equal to the string 'http://example.com/'" do
382
392
  (@uri === "http://example.com/").should == true
383
393
  end
384
394
 
385
- specify "should not be roughly equal to the string " +
395
+ it "should not be roughly equal to the string " +
386
396
  "'http://example.com:bogus/'" do
387
397
  (lambda do
388
398
  (@uri === "http://example.com:bogus/").should == false
389
- end).should.not.raise
399
+ end).should_not raise_error
390
400
  end
391
401
 
392
- specify "should result in itself when merged with itself" do
402
+ it "should result in itself when merged with itself" do
393
403
  @uri.merge(@uri).to_s.should == "http://example.com"
394
404
  @uri.merge!(@uri).to_s.should == "http://example.com"
395
405
  end
396
406
 
397
407
  # Section 6.2.3 of RFC 3986
398
- specify "should be equivalent to http://example.com/" do
408
+ it "should be equivalent to http://example.com/" do
399
409
  @uri.should == Addressable::URI.parse("http://example.com/")
400
410
  end
401
411
 
402
412
  # Section 6.2.3 of RFC 3986
403
- specify "should be equivalent to http://example.com:/" do
413
+ it "should be equivalent to http://example.com:/" do
404
414
  @uri.should == Addressable::URI.parse("http://example.com:/")
405
415
  end
406
416
 
407
417
  # Section 6.2.3 of RFC 3986
408
- specify "should be equivalent to http://example.com:80/" do
418
+ it "should be equivalent to http://example.com:80/" do
409
419
  @uri.should == Addressable::URI.parse("http://example.com:80/")
410
420
  end
411
421
 
412
422
  # Section 6.2.2.1 of RFC 3986
413
- specify "should be equivalent to http://EXAMPLE.COM/" do
423
+ it "should be equivalent to http://EXAMPLE.COM/" do
414
424
  @uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
415
425
  end
416
426
 
417
- specify "should have a route of '/path/' to 'http://example.com/path/'" do
427
+ it "should have a route of '/path/' to 'http://example.com/path/'" do
418
428
  @uri.route_to("http://example.com/path/").should ==
419
429
  Addressable::URI.parse("/path/")
420
430
  end
421
431
 
422
- specify "should have a route of '/' from 'http://example.com/path/'" do
432
+ it "should have a route of '/' from 'http://example.com/path/'" do
423
433
  @uri.route_from("http://example.com/path/").should ==
424
434
  Addressable::URI.parse("/")
425
435
  end
426
436
 
427
- specify "should have a route of '#' to 'http://example.com/'" do
437
+ it "should have a route of '#' to 'http://example.com/'" do
428
438
  @uri.route_to("http://example.com/").should ==
429
439
  Addressable::URI.parse("#")
430
440
  end
431
441
 
432
- specify "should have a route of 'http://elsewhere.com/' to " +
442
+ it "should have a route of 'http://elsewhere.com/' to " +
433
443
  "'http://elsewhere.com/'" do
434
444
  @uri.route_to("http://elsewhere.com/").should ==
435
445
  Addressable::URI.parse("http://elsewhere.com/")
436
446
  end
437
447
 
438
- specify "should have the correct username after assignment" do
448
+ it "when joined with 'relative/path' should be " +
449
+ "'http://example.com/relative/path'" do
450
+ @uri.join('relative/path').should ==
451
+ Addressable::URI.parse("http://example.com/relative/path")
452
+ end
453
+
454
+ it "should have the correct username after assignment" do
439
455
  @uri.user = "newuser"
440
456
  @uri.user.should == "newuser"
441
457
  @uri.password.should == nil
442
458
  @uri.to_s.should == "http://newuser@example.com"
443
459
  end
444
460
 
445
- specify "should have the correct password after assignment" do
461
+ it "should have the correct password after assignment" do
446
462
  @uri.password = "newpass"
447
463
  @uri.password.should == "newpass"
448
464
  @uri.user.should == ""
449
465
  @uri.to_s.should == "http://:newpass@example.com"
450
466
  end
451
467
 
452
- specify "should have the correct user/pass after repeated assignment" do
468
+ it "should have the correct user/pass after repeated assignment" do
453
469
  @uri.user = nil
454
470
  @uri.user.should == nil
455
471
  @uri.password = "newpass"
@@ -475,7 +491,7 @@ context "http://example.com" do
475
491
  @uri.to_s.should == "http://:newpass@example.com"
476
492
  end
477
493
 
478
- specify "should have the correct user/pass after userinfo assignment" do
494
+ it "should have the correct user/pass after userinfo assignment" do
479
495
  @uri.user = "newuser"
480
496
  @uri.user.should == "newuser"
481
497
  @uri.password = "newpass"
@@ -486,7 +502,7 @@ context "http://example.com" do
486
502
  @uri.password.should == nil
487
503
  end
488
504
 
489
- specify "should correctly convert to a hash" do
505
+ it "should correctly convert to a hash" do
490
506
  @uri.to_h.should == {
491
507
  :scheme => "http",
492
508
  :user => nil,
@@ -500,51 +516,52 @@ context "http://example.com" do
500
516
  end
501
517
  end
502
518
 
503
- context "http://example.com/" do
504
- setup do
519
+ describe Addressable::URI, " when parsed from " +
520
+ "'http://example.com/'" do
521
+ before do
505
522
  @uri = Addressable::URI.parse("http://example.com/")
506
523
  end
507
524
 
508
525
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
509
- specify "should be equivalent to http://example.com" do
526
+ it "should be equivalent to http://example.com" do
510
527
  @uri.should == Addressable::URI.parse("http://example.com")
511
528
  end
512
529
 
513
530
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
514
- specify "should be equivalent to HTTP://example.com/" do
531
+ it "should be equivalent to HTTP://example.com/" do
515
532
  @uri.should == Addressable::URI.parse("HTTP://example.com/")
516
533
  end
517
534
 
518
535
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
519
- specify "should be equivalent to http://example.com:/" do
536
+ it "should be equivalent to http://example.com:/" do
520
537
  @uri.should == Addressable::URI.parse("http://example.com:/")
521
538
  end
522
539
 
523
540
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
524
- specify "should be equivalent to http://example.com:80/" do
541
+ it "should be equivalent to http://example.com:80/" do
525
542
  @uri.should == Addressable::URI.parse("http://example.com:80/")
526
543
  end
527
544
 
528
545
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
529
- specify "should be equivalent to http://Example.com/" do
546
+ it "should be equivalent to http://Example.com/" do
530
547
  @uri.should == Addressable::URI.parse("http://Example.com/")
531
548
  end
532
549
 
533
- specify "should have the correct username after assignment" do
550
+ it "should have the correct username after assignment" do
534
551
  @uri.user = nil
535
552
  @uri.user.should == nil
536
553
  @uri.password.should == nil
537
554
  @uri.to_s.should == "http://example.com/"
538
555
  end
539
556
 
540
- specify "should have the correct password after assignment" do
557
+ it "should have the correct password after assignment" do
541
558
  @uri.password = nil
542
559
  @uri.password.should == nil
543
560
  @uri.user.should == nil
544
561
  @uri.to_s.should == "http://example.com/"
545
562
  end
546
563
 
547
- specify "should correctly convert to a hash" do
564
+ it "should correctly convert to a hash" do
548
565
  @uri.to_h.should == {
549
566
  :scheme => "http",
550
567
  :user => nil,
@@ -558,538 +575,681 @@ context "http://example.com/" do
558
575
  end
559
576
  end
560
577
 
561
- context "http://example.com/~smith/" do
562
- setup do
578
+ describe Addressable::URI, " when parsed from " +
579
+ "'http://@example.com/'" do
580
+ before do
581
+ @uri = Addressable::URI.parse("http://@example.com/")
582
+ end
583
+
584
+ it "should be equivalent to http://example.com" do
585
+ @uri.should == Addressable::URI.parse("http://example.com")
586
+ end
587
+
588
+ it "should correctly convert to a hash" do
589
+ @uri.to_h.should == {
590
+ :scheme => "http",
591
+ :user => "",
592
+ :password => nil,
593
+ :host => "example.com",
594
+ :port => nil,
595
+ :path => "/",
596
+ :query => nil,
597
+ :fragment => nil
598
+ }
599
+ end
600
+ end
601
+
602
+ describe Addressable::URI, " when parsed from " +
603
+ "'http://example.com./'" do
604
+ before do
605
+ @uri = Addressable::URI.parse("http://example.com./")
606
+ end
607
+
608
+ it "should be equivalent to http://example.com" do
609
+ @uri.should == Addressable::URI.parse("http://example.com")
610
+ end
611
+
612
+ it "should not be considered to be in normal form" do
613
+ @uri.normalize.should_not be_eql(@uri)
614
+ end
615
+ end
616
+
617
+ describe Addressable::URI, " when parsed from " +
618
+ "'http://:@example.com/'" do
619
+ before do
620
+ @uri = Addressable::URI.parse("http://:@example.com/")
621
+ end
622
+
623
+ it "should be equivalent to http://example.com" do
624
+ @uri.should == Addressable::URI.parse("http://example.com")
625
+ end
626
+
627
+ it "should correctly convert to a hash" do
628
+ @uri.to_h.should == {
629
+ :scheme => "http",
630
+ :user => "",
631
+ :password => "",
632
+ :host => "example.com",
633
+ :port => nil,
634
+ :path => "/",
635
+ :query => nil,
636
+ :fragment => nil
637
+ }
638
+ end
639
+ end
640
+
641
+ describe Addressable::URI, " when parsed from " +
642
+ "'http://example.com/~smith/'" do
643
+ before do
563
644
  @uri = Addressable::URI.parse("http://example.com/~smith/")
564
645
  end
565
646
 
566
647
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
567
- specify "should be equivalent to http://example.com/%7Esmith/" do
648
+ it "should be equivalent to http://example.com/%7Esmith/" do
568
649
  @uri.should == Addressable::URI.parse("http://example.com/%7Esmith/")
569
650
  end
570
651
 
571
652
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
572
- specify "should be equivalent to http://example.com/%7esmith/" do
653
+ it "should be equivalent to http://example.com/%7esmith/" do
573
654
  @uri.should == Addressable::URI.parse("http://example.com/%7esmith/")
574
655
  end
575
656
  end
576
657
 
577
- context "http://example.com/%C3%87" do
578
- setup do
658
+ describe Addressable::URI, " when parsed from " +
659
+ "'http://example.com/%C3%87'" do
660
+ before do
579
661
  @uri = Addressable::URI.parse("http://example.com/%C3%87")
580
662
  end
581
663
 
582
664
  # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
583
- specify "should be equivalent to 'http://example.com/C%CC%A7'" do
665
+ it "should be equivalent to 'http://example.com/C%CC%A7'" do
584
666
  @uri.should == Addressable::URI.parse("http://example.com/C%CC%A7")
585
667
  end
586
668
 
587
- specify "should not change if encoded with the normalizing algorithm" do
669
+ it "should not change if encoded with the normalizing algorithm" do
588
670
  Addressable::URI.normalized_encode(@uri).to_s.should ==
589
671
  "http://example.com/%C3%87"
590
672
  end
591
673
 
592
- specify "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
674
+ it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
593
675
  Addressable::URI.encode(@uri).to_s.should ==
594
676
  "http://example.com/%25C3%2587"
595
677
  end
596
678
  end
597
679
 
598
- context "http://example.com/?q=string" do
599
- setup do
680
+ describe Addressable::URI, " when parsed from " +
681
+ "'http://example.com/?q=string'" do
682
+ before do
600
683
  @uri = Addressable::URI.parse("http://example.com/?q=string")
601
684
  end
602
685
 
603
- specify "should use the 'http' scheme" do
686
+ it "should use the 'http' scheme" do
604
687
  @uri.scheme.should == "http"
605
688
  end
606
689
 
607
- specify "should have an authority segment of 'example.com'" do
690
+ it "should have an authority segment of 'example.com'" do
608
691
  @uri.authority.should == "example.com"
609
692
  end
610
693
 
611
- specify "should have a host of 'example.com'" do
694
+ it "should have a host of 'example.com'" do
612
695
  @uri.host.should == "example.com"
613
696
  end
614
697
 
615
- specify "should have no username" do
698
+ it "should have no username" do
616
699
  @uri.user.should == nil
617
700
  end
618
701
 
619
- specify "should have no password" do
702
+ it "should have no password" do
620
703
  @uri.password.should == nil
621
704
  end
622
705
 
623
- specify "should use port 80" do
706
+ it "should use port 80" do
624
707
  @uri.port.should == 80
625
708
  end
626
709
 
627
- specify "should have a path of '/'" do
710
+ it "should have a path of '/'" do
628
711
  @uri.path.should == "/"
629
712
  end
630
713
 
631
- specify "should have a query string of 'q=string'" do
714
+ it "should have a query string of 'q=string'" do
632
715
  @uri.query.should == "q=string"
633
716
  end
634
717
 
635
- specify "should have no fragment" do
718
+ it "should have no fragment" do
636
719
  @uri.fragment.should == nil
637
720
  end
638
721
 
639
- specify "should be considered absolute" do
640
- @uri.should.be.absolute
722
+ it "should be considered absolute" do
723
+ @uri.should be_absolute
641
724
  end
642
725
 
643
- specify "should not be considered relative" do
644
- @uri.should.not.be.relative
726
+ it "should not be considered relative" do
727
+ @uri.should_not be_relative
645
728
  end
646
729
 
647
- specify "should be considered to be in normal form" do
648
- @uri.normalize.should.be.eql @uri
730
+ it "should be considered to be in normal form" do
731
+ @uri.normalize.should be_eql(@uri)
649
732
  end
650
733
  end
651
734
 
652
- context "http://example.com:80/" do
653
- setup do
735
+ describe Addressable::URI, " when parsed from " +
736
+ "'http://example.com:80/'" do
737
+ before do
654
738
  @uri = Addressable::URI.parse("http://example.com:80/")
655
739
  end
656
740
 
657
- specify "should use the 'http' scheme" do
741
+ it "should use the 'http' scheme" do
658
742
  @uri.scheme.should == "http"
659
743
  end
660
744
 
661
- specify "should have an authority segment of 'example.com:80'" do
745
+ it "should have an authority segment of 'example.com:80'" do
662
746
  @uri.authority.should == "example.com:80"
663
747
  end
664
748
 
665
- specify "should have a host of 'example.com'" do
749
+ it "should have a host of 'example.com'" do
666
750
  @uri.host.should == "example.com"
667
751
  end
668
752
 
669
- specify "should have no username" do
753
+ it "should have no username" do
670
754
  @uri.user.should == nil
671
755
  end
672
756
 
673
- specify "should have no password" do
757
+ it "should have no password" do
674
758
  @uri.password.should == nil
675
759
  end
676
760
 
677
- specify "should use port 80" do
761
+ it "should use port 80" do
678
762
  @uri.port.should == 80
679
763
  end
680
764
 
681
- specify "should have a path of '/'" do
765
+ it "should have a path of '/'" do
682
766
  @uri.path.should == "/"
683
767
  end
684
768
 
685
- specify "should have no query string" do
769
+ it "should have no query string" do
686
770
  @uri.query.should == nil
687
771
  end
688
772
 
689
- specify "should have no fragment" do
773
+ it "should have no fragment" do
690
774
  @uri.fragment.should == nil
691
775
  end
692
776
 
693
- specify "should be considered absolute" do
694
- @uri.should.be.absolute
777
+ it "should be considered absolute" do
778
+ @uri.should be_absolute
695
779
  end
696
780
 
697
- specify "should not be considered relative" do
698
- @uri.should.not.be.relative
781
+ it "should not be considered relative" do
782
+ @uri.should_not be_relative
699
783
  end
700
784
 
701
- specify "should be exactly equal to http://example.com:80/" do
785
+ it "should be exactly equal to http://example.com:80/" do
702
786
  @uri.eql?(Addressable::URI.parse("http://example.com:80/")).should == true
703
787
  end
704
788
 
705
- specify "should be roughly equal to http://example.com/" do
789
+ it "should be roughly equal to http://example.com/" do
706
790
  (@uri === Addressable::URI.parse("http://example.com/")).should == true
707
791
  end
708
792
 
709
- specify "should be roughly equal to the string 'http://example.com/'" do
793
+ it "should be roughly equal to the string 'http://example.com/'" do
710
794
  (@uri === "http://example.com/").should == true
711
795
  end
712
796
 
713
- specify "should not be roughly equal to the string " +
797
+ it "should not be roughly equal to the string " +
714
798
  "'http://example.com:bogus/'" do
715
799
  (lambda do
716
800
  (@uri === "http://example.com:bogus/").should == false
717
- end).should.not.raise
801
+ end).should_not raise_error
718
802
  end
719
803
 
720
- specify "should result in itself when merged with itself" do
804
+ it "should result in itself when merged with itself" do
721
805
  @uri.merge(@uri).to_s.should == "http://example.com:80/"
722
806
  @uri.merge!(@uri).to_s.should == "http://example.com:80/"
723
807
  end
724
808
 
725
809
  # Section 6.2.3 of RFC 3986
726
- specify "should be equal to http://example.com/" do
810
+ it "should be equal to http://example.com/" do
727
811
  @uri.should == Addressable::URI.parse("http://example.com/")
728
812
  end
729
813
 
730
814
  # Section 6.2.3 of RFC 3986
731
- specify "should be equal to http://example.com:/" do
815
+ it "should be equal to http://example.com:/" do
732
816
  @uri.should == Addressable::URI.parse("http://example.com:/")
733
817
  end
734
818
 
735
819
  # Section 6.2.3 of RFC 3986
736
- specify "should be equal to http://example.com:80/" do
820
+ it "should be equal to http://example.com:80/" do
737
821
  @uri.should == Addressable::URI.parse("http://example.com:80/")
738
822
  end
739
823
 
740
824
  # Section 6.2.2.1 of RFC 3986
741
- specify "should be equal to http://EXAMPLE.COM/" do
825
+ it "should be equal to http://EXAMPLE.COM/" do
742
826
  @uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
743
827
  end
744
828
  end
745
829
 
746
- context "relative/path/to/resource" do
747
- setup do
830
+ describe Addressable::URI, "when parsed from " +
831
+ "'relative/path/to/resource'" do
832
+ before do
748
833
  @uri = Addressable::URI.parse("relative/path/to/resource")
749
834
  end
750
835
 
751
- specify "should not have a scheme" do
836
+ it "should not have a scheme" do
752
837
  @uri.scheme.should == nil
753
838
  end
754
839
 
755
- specify "should not be considered ip-based" do
756
- @uri.should.not.be.ip_based
840
+ it "should not be considered ip-based" do
841
+ @uri.should_not be_ip_based
757
842
  end
758
843
 
759
- specify "should not have an authority segment" do
844
+ it "should not have an authority segment" do
760
845
  @uri.authority.should == nil
761
846
  end
762
847
 
763
- specify "should not have a host" do
848
+ it "should not have a host" do
764
849
  @uri.host.should == nil
765
850
  end
766
851
 
767
- specify "should have no username" do
852
+ it "should have no username" do
768
853
  @uri.user.should == nil
769
854
  end
770
855
 
771
- specify "should have no password" do
856
+ it "should have no password" do
772
857
  @uri.password.should == nil
773
858
  end
774
859
 
775
- specify "should not have a port" do
860
+ it "should not have a port" do
776
861
  @uri.port.should == nil
777
862
  end
778
863
 
779
- specify "should have a path of 'relative/path/to/resource'" do
864
+ it "should have a path of 'relative/path/to/resource'" do
780
865
  @uri.path.should == "relative/path/to/resource"
781
866
  end
782
867
 
783
- specify "should have no query string" do
868
+ it "should have no query string" do
784
869
  @uri.query.should == nil
785
870
  end
786
871
 
787
- specify "should have no fragment" do
872
+ it "should have no fragment" do
788
873
  @uri.fragment.should == nil
789
874
  end
790
875
 
791
- specify "should not be considered absolute" do
792
- @uri.should.not.be.absolute
876
+ it "should not be considered absolute" do
877
+ @uri.should_not be_absolute
793
878
  end
794
879
 
795
- specify "should be considered relative" do
796
- @uri.should.be.relative
880
+ it "should be considered relative" do
881
+ @uri.should be_relative
797
882
  end
798
883
 
799
- specify "should raise an error if routing is attempted" do
884
+ it "should raise an error if routing is attempted" do
800
885
  (lambda do
801
886
  @uri.route_to("http://example.com/")
802
- end).should.raise
887
+ end).should raise_error
803
888
  (lambda do
804
889
  @uri.route_from("http://example.com/")
805
- end).should.raise
890
+ end).should raise_error
891
+ end
892
+
893
+ it "when joined with 'another/relative/path' should be " +
894
+ "'relative/path/to/another/relative/path'" do
895
+ @uri.join('another/relative/path').should ==
896
+ Addressable::URI.parse("relative/path/to/another/relative/path")
806
897
  end
807
898
  end
808
899
 
809
- context "http://example.com/file.txt" do
810
- setup do
900
+ describe Addressable::URI, "when parsed from " +
901
+ "'relative_path_with_no_slashes'" do
902
+ before do
903
+ @uri = Addressable::URI.parse("relative_path_with_no_slashes")
904
+ end
905
+
906
+ it "should not have a scheme" do
907
+ @uri.scheme.should == nil
908
+ end
909
+
910
+ it "should not be considered ip-based" do
911
+ @uri.should_not be_ip_based
912
+ end
913
+
914
+ it "should not have an authority segment" do
915
+ @uri.authority.should == nil
916
+ end
917
+
918
+ it "should not have a host" do
919
+ @uri.host.should == nil
920
+ end
921
+
922
+ it "should have no username" do
923
+ @uri.user.should == nil
924
+ end
925
+
926
+ it "should have no password" do
927
+ @uri.password.should == nil
928
+ end
929
+
930
+ it "should not have a port" do
931
+ @uri.port.should == nil
932
+ end
933
+
934
+ it "should have a path of 'relative_path_with_no_slashes'" do
935
+ @uri.path.should == "relative_path_with_no_slashes"
936
+ end
937
+
938
+ it "should have no query string" do
939
+ @uri.query.should == nil
940
+ end
941
+
942
+ it "should have no fragment" do
943
+ @uri.fragment.should == nil
944
+ end
945
+
946
+ it "should not be considered absolute" do
947
+ @uri.should_not be_absolute
948
+ end
949
+
950
+ it "should be considered relative" do
951
+ @uri.should be_relative
952
+ end
953
+
954
+ it "when joined with 'another_relative_path' should be " +
955
+ "'another_relative_path'" do
956
+ @uri.join('another_relative_path').should ==
957
+ Addressable::URI.parse("another_relative_path")
958
+ end
959
+ end
960
+
961
+ describe Addressable::URI, " when parsed from " +
962
+ "'http://example.com/file.txt'" do
963
+ before do
811
964
  @uri = Addressable::URI.parse("http://example.com/file.txt")
812
965
  end
813
966
 
814
- specify "should have a scheme of 'http'" do
967
+ it "should have a scheme of 'http'" do
815
968
  @uri.scheme.should == "http"
816
969
  end
817
970
 
818
- specify "should have an authority segment of 'example.com'" do
971
+ it "should have an authority segment of 'example.com'" do
819
972
  @uri.authority.should == "example.com"
820
973
  end
821
974
 
822
- specify "should have a host of 'example.com'" do
975
+ it "should have a host of 'example.com'" do
823
976
  @uri.host.should == "example.com"
824
977
  end
825
978
 
826
- specify "should have no username" do
979
+ it "should have no username" do
827
980
  @uri.user.should == nil
828
981
  end
829
982
 
830
- specify "should have no password" do
983
+ it "should have no password" do
831
984
  @uri.password.should == nil
832
985
  end
833
986
 
834
- specify "should use port 80" do
987
+ it "should use port 80" do
835
988
  @uri.port.should == 80
836
989
  end
837
990
 
838
- specify "should have a path of '/file.txt'" do
991
+ it "should have a path of '/file.txt'" do
839
992
  @uri.path.should == "/file.txt"
840
993
  end
841
994
 
842
- specify "should have an extname of '.txt'" do
995
+ it "should have an extname of '.txt'" do
843
996
  @uri.extname.should == ".txt"
844
997
  end
845
998
 
846
- specify "should have no query string" do
999
+ it "should have no query string" do
847
1000
  @uri.query.should == nil
848
1001
  end
849
1002
 
850
- specify "should have no fragment" do
1003
+ it "should have no fragment" do
851
1004
  @uri.fragment.should == nil
852
1005
  end
853
1006
  end
854
1007
 
855
- context "http://example.com/file.txt;x=y" do
856
- setup do
1008
+ describe Addressable::URI, " when parsed from " +
1009
+ "'http://example.com/file.txt;x=y'" do
1010
+ before do
857
1011
  @uri = Addressable::URI.parse("http://example.com/file.txt;x=y")
858
1012
  end
859
1013
 
860
- specify "should have a scheme of 'http'" do
1014
+ it "should have a scheme of 'http'" do
861
1015
  @uri.scheme.should == "http"
862
1016
  end
863
1017
 
864
- specify "should have a scheme of 'http'" do
1018
+ it "should have a scheme of 'http'" do
865
1019
  @uri.scheme.should == "http"
866
1020
  end
867
1021
 
868
- specify "should have an authority segment of 'example.com'" do
1022
+ it "should have an authority segment of 'example.com'" do
869
1023
  @uri.authority.should == "example.com"
870
1024
  end
871
1025
 
872
- specify "should have a host of 'example.com'" do
1026
+ it "should have a host of 'example.com'" do
873
1027
  @uri.host.should == "example.com"
874
1028
  end
875
1029
 
876
- specify "should have no username" do
1030
+ it "should have no username" do
877
1031
  @uri.user.should == nil
878
1032
  end
879
1033
 
880
- specify "should have no password" do
1034
+ it "should have no password" do
881
1035
  @uri.password.should == nil
882
1036
  end
883
1037
 
884
- specify "should use port 80" do
1038
+ it "should use port 80" do
885
1039
  @uri.port.should == 80
886
1040
  end
887
1041
 
888
- specify "should have a path of '/file.txt;x=y'" do
1042
+ it "should have a path of '/file.txt;x=y'" do
889
1043
  @uri.path.should == "/file.txt;x=y"
890
1044
  end
891
1045
 
892
- specify "should have an extname of '.txt'" do
1046
+ it "should have an extname of '.txt'" do
893
1047
  @uri.extname.should == ".txt"
894
1048
  end
895
1049
 
896
- specify "should have no query string" do
1050
+ it "should have no query string" do
897
1051
  @uri.query.should == nil
898
1052
  end
899
1053
 
900
- specify "should have no fragment" do
1054
+ it "should have no fragment" do
901
1055
  @uri.fragment.should == nil
902
1056
  end
903
1057
 
904
- specify "should be considered to be in normal form" do
905
- @uri.normalize.should.be.eql @uri
1058
+ it "should be considered to be in normal form" do
1059
+ @uri.normalize.should be_eql(@uri)
906
1060
  end
907
1061
  end
908
1062
 
909
- context "mailto:user@example.com" do
910
- setup do
1063
+ describe Addressable::URI, " when parsed from " +
1064
+ "'mailto:user@example.com'" do
1065
+ before do
911
1066
  @uri = Addressable::URI.parse("mailto:user@example.com")
912
1067
  end
913
1068
 
914
- specify "should have a scheme of 'mailto'" do
1069
+ it "should have a scheme of 'mailto'" do
915
1070
  @uri.scheme.should == "mailto"
916
1071
  end
917
1072
 
918
- specify "should not be considered to be ip-based" do
919
- @uri.should.not.be.ip_based
1073
+ it "should not be considered to be ip-based" do
1074
+ @uri.should_not be_ip_based
920
1075
  end
921
1076
 
922
- specify "should have a path of 'user@example.com'" do
1077
+ it "should have a path of 'user@example.com'" do
923
1078
  @uri.path.should == "user@example.com"
924
1079
  end
925
1080
 
926
- specify "should have no user" do
1081
+ it "should have no user" do
927
1082
  @uri.user.should == nil
928
1083
  end
929
1084
 
930
- specify "should be considered to be in normal form" do
931
- @uri.normalize.should.be.eql @uri
1085
+ it "should be considered to be in normal form" do
1086
+ @uri.normalize.should be_eql(@uri)
932
1087
  end
933
1088
  end
934
1089
 
935
- context "tag:example.com,2006-08-18:/path/to/something" do
936
- setup do
1090
+ describe Addressable::URI, " when parsed from " +
1091
+ "'tag:example.com,2006-08-18:/path/to/something'" do
1092
+ before do
937
1093
  @uri = Addressable::URI.parse(
938
1094
  "tag:example.com,2006-08-18:/path/to/something")
939
1095
  end
940
1096
 
941
- specify "should have a scheme of 'tag'" do
1097
+ it "should have a scheme of 'tag'" do
942
1098
  @uri.scheme.should == "tag"
943
1099
  end
944
1100
 
945
- specify "should be considered to be ip-based" do
946
- @uri.should.not.be.ip_based
1101
+ it "should be considered to be ip-based" do
1102
+ @uri.should_not be_ip_based
947
1103
  end
948
1104
 
949
- specify "should have a path of " +
1105
+ it "should have a path of " +
950
1106
  "'example.com,2006-08-18:/path/to/something'" do
951
1107
  @uri.path.should == "example.com,2006-08-18:/path/to/something"
952
1108
  end
953
1109
 
954
- specify "should have no user" do
1110
+ it "should have no user" do
955
1111
  @uri.user.should == nil
956
1112
  end
957
1113
 
958
- specify "should be considered to be in normal form" do
959
- @uri.normalize.should.be.eql @uri
1114
+ it "should be considered to be in normal form" do
1115
+ @uri.normalize.should be_eql(@uri)
960
1116
  end
961
1117
  end
962
1118
 
963
- context "http://example.com/x;y/" do
964
- setup do
1119
+ describe Addressable::URI, " when parsed from " +
1120
+ "'http://example.com/x;y/'" do
1121
+ before do
965
1122
  @uri = Addressable::URI.parse("http://example.com/x;y/")
966
1123
  end
967
1124
 
968
- specify "should be considered to be in normal form" do
969
- @uri.normalize.should.be.eql @uri
1125
+ it "should be considered to be in normal form" do
1126
+ @uri.normalize.should be_eql(@uri)
970
1127
  end
971
1128
  end
972
1129
 
973
- context "http://example.com/?x=1&y=2" do
974
- setup do
1130
+ describe Addressable::URI, " when parsed from " +
1131
+ "'http://example.com/?x=1&y=2'" do
1132
+ before do
975
1133
  @uri = Addressable::URI.parse("http://example.com/?x=1&y=2")
976
1134
  end
977
1135
 
978
- specify "should be considered to be in normal form" do
979
- @uri.normalize.should.be.eql @uri
1136
+ it "should be considered to be in normal form" do
1137
+ @uri.normalize.should be_eql(@uri)
980
1138
  end
981
1139
  end
982
1140
 
983
- context "view-source:http://example.com/" do
984
- setup do
1141
+ describe Addressable::URI, " when parsed from " +
1142
+ "'view-source:http://example.com/'" do
1143
+ before do
985
1144
  @uri = Addressable::URI.parse("view-source:http://example.com/")
986
1145
  end
987
1146
 
988
- specify "should have a scheme of 'view-source'" do
1147
+ it "should have a scheme of 'view-source'" do
989
1148
  @uri.scheme.should == "view-source"
990
1149
  end
991
1150
 
992
- specify "should have a path of 'http://example.com/'" do
1151
+ it "should have a path of 'http://example.com/'" do
993
1152
  @uri.path.should == "http://example.com/"
994
1153
  end
995
1154
 
996
- specify "should be considered to be in normal form" do
997
- @uri.normalize.should.be.eql @uri
1155
+ it "should be considered to be in normal form" do
1156
+ @uri.normalize.should be_eql(@uri)
998
1157
  end
999
1158
  end
1000
1159
 
1001
- context "http://user:pass@example.com/path/to/resource?query=x#fragment" do
1002
- setup do
1160
+ describe Addressable::URI, " when parsed from " +
1161
+ "'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
1162
+ before do
1003
1163
  @uri = Addressable::URI.parse(
1004
1164
  "http://user:pass@example.com/path/to/resource?query=x#fragment")
1005
1165
  end
1006
1166
 
1007
- specify "should use the 'http' scheme" do
1167
+ it "should use the 'http' scheme" do
1008
1168
  @uri.scheme.should == "http"
1009
1169
  end
1010
1170
 
1011
- specify "should have an authority segment of 'user:pass@example.com'" do
1171
+ it "should have an authority segment of 'user:pass@example.com'" do
1012
1172
  @uri.authority.should == "user:pass@example.com"
1013
1173
  end
1014
1174
 
1015
- specify "should have a username of 'user'" do
1175
+ it "should have a username of 'user'" do
1016
1176
  @uri.user.should == "user"
1017
1177
  end
1018
1178
 
1019
- specify "should have a password of 'pass'" do
1179
+ it "should have a password of 'pass'" do
1020
1180
  @uri.password.should == "pass"
1021
1181
  end
1022
1182
 
1023
- specify "should have a host of 'example.com'" do
1183
+ it "should have a host of 'example.com'" do
1024
1184
  @uri.host.should == "example.com"
1025
1185
  end
1026
1186
 
1027
- specify "should use port 80" do
1187
+ it "should use port 80" do
1028
1188
  @uri.port.should == 80
1029
1189
  end
1030
1190
 
1031
- specify "should have a path of '/path/to/resource'" do
1191
+ it "should have a path of '/path/to/resource'" do
1032
1192
  @uri.path.should == "/path/to/resource"
1033
1193
  end
1034
1194
 
1035
- specify "should have a query string of 'query=x'" do
1195
+ it "should have a query string of 'query=x'" do
1036
1196
  @uri.query.should == "query=x"
1037
1197
  end
1038
1198
 
1039
- specify "should have a fragment of 'fragment'" do
1199
+ it "should have a fragment of 'fragment'" do
1040
1200
  @uri.fragment.should == "fragment"
1041
1201
  end
1042
1202
 
1043
- specify "should be considered to be in normal form" do
1044
- @uri.normalize.should.be.eql @uri
1203
+ it "should be considered to be in normal form" do
1204
+ @uri.normalize.should be_eql(@uri)
1045
1205
  end
1046
1206
 
1047
- specify "should have a route of '/path/' to " +
1207
+ it "should have a route of '/path/' to " +
1048
1208
  "'http://user:pass@example.com/path/'" do
1049
1209
  @uri.route_to("http://user:pass@example.com/path/").should ==
1050
1210
  Addressable::URI.parse("/path/")
1051
1211
  end
1052
1212
 
1053
- specify "should have a route of '/path/to/resource?query=x#fragment' " +
1213
+ it "should have a route of '/path/to/resource?query=x#fragment' " +
1054
1214
  "from 'http://user:pass@example.com/path/'" do
1055
1215
  @uri.route_from("http://user:pass@example.com/path/").should ==
1056
1216
  Addressable::URI.parse("/path/to/resource?query=x#fragment")
1057
1217
  end
1058
1218
 
1059
- specify "should have a route of '?query=x#fragment' " +
1219
+ it "should have a route of '?query=x#fragment' " +
1060
1220
  "from 'http://user:pass@example.com/path/to/resource'" do
1061
1221
  @uri.route_from("http://user:pass@example.com/path/to/resource").should ==
1062
1222
  Addressable::URI.parse("?query=x#fragment")
1063
1223
  end
1064
1224
 
1065
- specify "should have a route of '#fragment' " +
1225
+ it "should have a route of '#fragment' " +
1066
1226
  "from 'http://user:pass@example.com/path/to/resource?query=x'" do
1067
1227
  @uri.route_from(
1068
1228
  "http://user:pass@example.com/path/to/resource?query=x").should ==
1069
1229
  Addressable::URI.parse("#fragment")
1070
1230
  end
1071
1231
 
1072
- specify "should have a route of '#fragment' from " +
1232
+ it "should have a route of '#fragment' from " +
1073
1233
  "'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
1074
1234
  @uri.route_from(
1075
1235
  "http://user:pass@example.com/path/to/resource?query=x#fragment"
1076
1236
  ).should == Addressable::URI.parse("#fragment")
1077
1237
  end
1078
1238
 
1079
- specify "should have a route of 'http://elsewhere.com/' to " +
1239
+ it "should have a route of 'http://elsewhere.com/' to " +
1080
1240
  "'http://elsewhere.com/'" do
1081
1241
  @uri.route_to("http://elsewhere.com/").should ==
1082
1242
  Addressable::URI.parse("http://elsewhere.com/")
1083
1243
  end
1084
1244
 
1085
- specify "should have the correct scheme after assignment" do
1245
+ it "should have the correct scheme after assignment" do
1086
1246
  @uri.scheme = "ftp"
1087
1247
  @uri.scheme.should == "ftp"
1088
1248
  @uri.to_s.should ==
1089
1249
  "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
1090
1250
  end
1091
1251
 
1092
- specify "should have the correct authority segment after assignment" do
1252
+ it "should have the correct authority segment after assignment" do
1093
1253
  @uri.authority = "newuser:newpass@example.com:80"
1094
1254
  @uri.authority.should == "newuser:newpass@example.com:80"
1095
1255
  @uri.user.should == "newuser"
@@ -1102,7 +1262,7 @@ context "http://user:pass@example.com/path/to/resource?query=x#fragment" do
1102
1262
  "/path/to/resource?query=x#fragment"
1103
1263
  end
1104
1264
 
1105
- specify "should have the correct userinfo segment after assignment" do
1265
+ it "should have the correct userinfo segment after assignment" do
1106
1266
  @uri.userinfo = "newuser:newpass"
1107
1267
  @uri.userinfo.should == "newuser:newpass"
1108
1268
  @uri.authority.should == "newuser:newpass@example.com"
@@ -1116,45 +1276,45 @@ context "http://user:pass@example.com/path/to/resource?query=x#fragment" do
1116
1276
  "/path/to/resource?query=x#fragment"
1117
1277
  end
1118
1278
 
1119
- specify "should have the correct username after assignment" do
1279
+ it "should have the correct username after assignment" do
1120
1280
  @uri.user = "newuser"
1121
1281
  @uri.user.should == "newuser"
1122
1282
  @uri.authority.should == "newuser:pass@example.com"
1123
1283
  end
1124
1284
 
1125
- specify "should have the correct password after assignment" do
1285
+ it "should have the correct password after assignment" do
1126
1286
  @uri.password = "newpass"
1127
1287
  @uri.password.should == "newpass"
1128
1288
  @uri.authority.should == "user:newpass@example.com"
1129
1289
  end
1130
1290
 
1131
- specify "should have the correct host after assignment" do
1291
+ it "should have the correct host after assignment" do
1132
1292
  @uri.host = "newexample.com"
1133
1293
  @uri.host.should == "newexample.com"
1134
1294
  @uri.authority.should == "user:pass@newexample.com"
1135
1295
  end
1136
1296
 
1137
- specify "should have the correct port after assignment" do
1297
+ it "should have the correct port after assignment" do
1138
1298
  @uri.port = 8080
1139
1299
  @uri.port.should == 8080
1140
1300
  @uri.authority.should == "user:pass@example.com:8080"
1141
1301
  end
1142
1302
 
1143
- specify "should have the correct path after assignment" do
1303
+ it "should have the correct path after assignment" do
1144
1304
  @uri.path = "/newpath/to/resource"
1145
1305
  @uri.path.should == "/newpath/to/resource"
1146
1306
  @uri.to_s.should ==
1147
1307
  "http://user:pass@example.com/newpath/to/resource?query=x#fragment"
1148
1308
  end
1149
1309
 
1150
- specify "should have the correct query string after assignment" do
1310
+ it "should have the correct query string after assignment" do
1151
1311
  @uri.query = "newquery=x"
1152
1312
  @uri.query.should == "newquery=x"
1153
1313
  @uri.to_s.should ==
1154
1314
  "http://user:pass@example.com/path/to/resource?newquery=x#fragment"
1155
1315
  end
1156
1316
 
1157
- specify "should have the correct fragment after assignment" do
1317
+ it "should have the correct fragment after assignment" do
1158
1318
  @uri.fragment = "newfragment"
1159
1319
  @uri.fragment.should == "newfragment"
1160
1320
  @uri.to_s.should ==
@@ -1162,45 +1322,46 @@ context "http://user:pass@example.com/path/to/resource?query=x#fragment" do
1162
1322
  end
1163
1323
  end
1164
1324
 
1165
- context "http://user@example.com" do
1166
- setup do
1325
+ describe Addressable::URI, " when parsed from " +
1326
+ "'http://user@example.com'" do
1327
+ before do
1167
1328
  @uri = Addressable::URI.parse("http://user@example.com")
1168
1329
  end
1169
1330
 
1170
- specify "should use the 'http' scheme" do
1331
+ it "should use the 'http' scheme" do
1171
1332
  @uri.scheme.should == "http"
1172
1333
  end
1173
1334
 
1174
- specify "should have a username of 'user'" do
1335
+ it "should have a username of 'user'" do
1175
1336
  @uri.user.should == "user"
1176
1337
  end
1177
1338
 
1178
- specify "should have no password" do
1339
+ it "should have no password" do
1179
1340
  @uri.password.should == nil
1180
1341
  end
1181
1342
 
1182
- specify "should have a host of 'example.com'" do
1343
+ it "should have a host of 'example.com'" do
1183
1344
  @uri.host.should == "example.com"
1184
1345
  end
1185
1346
 
1186
- specify "should use port 80" do
1347
+ it "should use port 80" do
1187
1348
  @uri.port.should == 80
1188
1349
  end
1189
1350
 
1190
- specify "should have the correct username after assignment" do
1351
+ it "should have the correct username after assignment" do
1191
1352
  @uri.user = "newuser"
1192
1353
  @uri.user.should == "newuser"
1193
1354
  @uri.password.should == nil
1194
1355
  @uri.to_s.should == "http://newuser@example.com"
1195
1356
  end
1196
1357
 
1197
- specify "should have the correct password after assignment" do
1358
+ it "should have the correct password after assignment" do
1198
1359
  @uri.password = "newpass"
1199
1360
  @uri.password.should == "newpass"
1200
1361
  @uri.to_s.should == "http://user:newpass@example.com"
1201
1362
  end
1202
1363
 
1203
- specify "should have the correct userinfo segment after assignment" do
1364
+ it "should have the correct userinfo segment after assignment" do
1204
1365
  @uri.userinfo = "newuser:newpass"
1205
1366
  @uri.userinfo.should == "newuser:newpass"
1206
1367
  @uri.user.should == "newuser"
@@ -1211,7 +1372,7 @@ context "http://user@example.com" do
1211
1372
  @uri.to_s.should == "http://newuser:newpass@example.com"
1212
1373
  end
1213
1374
 
1214
- specify "should have the correct userinfo segment after nil assignment" do
1375
+ it "should have the correct userinfo segment after nil assignment" do
1215
1376
  @uri.userinfo = nil
1216
1377
  @uri.userinfo.should == nil
1217
1378
  @uri.user.should == nil
@@ -1222,7 +1383,7 @@ context "http://user@example.com" do
1222
1383
  @uri.to_s.should == "http://example.com"
1223
1384
  end
1224
1385
 
1225
- specify "should have the correct authority segment after assignment" do
1386
+ it "should have the correct authority segment after assignment" do
1226
1387
  @uri.authority = "newuser@example.com"
1227
1388
  @uri.authority.should == "newuser@example.com"
1228
1389
  @uri.user.should == "newuser"
@@ -1233,53 +1394,54 @@ context "http://user@example.com" do
1233
1394
  @uri.to_s.should == "http://newuser@example.com"
1234
1395
  end
1235
1396
 
1236
- specify "should raise an error after nil assignment of authority segment" do
1397
+ it "should raise an error after nil assignment of authority segment" do
1237
1398
  (lambda do
1238
1399
  # This would create an invalid URI
1239
1400
  @uri.authority = nil
1240
- end).should.raise
1401
+ end).should raise_error
1241
1402
  end
1242
1403
  end
1243
1404
 
1244
- context "http://user:@example.com" do
1245
- setup do
1405
+ describe Addressable::URI, " when parsed from " +
1406
+ "'http://user:@example.com'" do
1407
+ before do
1246
1408
  @uri = Addressable::URI.parse("http://user:@example.com")
1247
1409
  end
1248
1410
 
1249
- specify "should use the 'http' scheme" do
1411
+ it "should use the 'http' scheme" do
1250
1412
  @uri.scheme.should == "http"
1251
1413
  end
1252
1414
 
1253
- specify "should have a username of 'user'" do
1415
+ it "should have a username of 'user'" do
1254
1416
  @uri.user.should == "user"
1255
1417
  end
1256
1418
 
1257
- specify "should have a password of ''" do
1419
+ it "should have a password of ''" do
1258
1420
  @uri.password.should == ""
1259
1421
  end
1260
1422
 
1261
- specify "should have a host of 'example.com'" do
1423
+ it "should have a host of 'example.com'" do
1262
1424
  @uri.host.should == "example.com"
1263
1425
  end
1264
1426
 
1265
- specify "should use port 80" do
1427
+ it "should use port 80" do
1266
1428
  @uri.port.should == 80
1267
1429
  end
1268
1430
 
1269
- specify "should have the correct username after assignment" do
1431
+ it "should have the correct username after assignment" do
1270
1432
  @uri.user = "newuser"
1271
1433
  @uri.user.should == "newuser"
1272
1434
  @uri.password.should == ""
1273
1435
  @uri.to_s.should == "http://newuser:@example.com"
1274
1436
  end
1275
1437
 
1276
- specify "should have the correct password after assignment" do
1438
+ it "should have the correct password after assignment" do
1277
1439
  @uri.password = "newpass"
1278
1440
  @uri.password.should == "newpass"
1279
1441
  @uri.to_s.should == "http://user:newpass@example.com"
1280
1442
  end
1281
1443
 
1282
- specify "should have the correct authority segment after assignment" do
1444
+ it "should have the correct authority segment after assignment" do
1283
1445
  @uri.authority = "newuser:@example.com"
1284
1446
  @uri.authority.should == "newuser:@example.com"
1285
1447
  @uri.user.should == "newuser"
@@ -1291,50 +1453,51 @@ context "http://user:@example.com" do
1291
1453
  end
1292
1454
  end
1293
1455
 
1294
- context "http://:pass@example.com" do
1295
- setup do
1456
+ describe Addressable::URI, " when parsed from " +
1457
+ "'http://:pass@example.com'" do
1458
+ before do
1296
1459
  @uri = Addressable::URI.parse("http://:pass@example.com")
1297
1460
  end
1298
1461
 
1299
- specify "should use the 'http' scheme" do
1462
+ it "should use the 'http' scheme" do
1300
1463
  @uri.scheme.should == "http"
1301
1464
  end
1302
1465
 
1303
- specify "should have a username of ''" do
1466
+ it "should have a username of ''" do
1304
1467
  @uri.user.should == ""
1305
1468
  end
1306
1469
 
1307
- specify "should have a password of 'pass'" do
1470
+ it "should have a password of 'pass'" do
1308
1471
  @uri.password.should == "pass"
1309
1472
  end
1310
1473
 
1311
- specify "should have a userinfo of ':pass'" do
1474
+ it "should have a userinfo of ':pass'" do
1312
1475
  @uri.userinfo.should == ":pass"
1313
1476
  end
1314
1477
 
1315
- specify "should have a host of 'example.com'" do
1478
+ it "should have a host of 'example.com'" do
1316
1479
  @uri.host.should == "example.com"
1317
1480
  end
1318
1481
 
1319
- specify "should use port 80" do
1482
+ it "should use port 80" do
1320
1483
  @uri.port.should == 80
1321
1484
  end
1322
1485
 
1323
- specify "should have the correct username after assignment" do
1486
+ it "should have the correct username after assignment" do
1324
1487
  @uri.user = "newuser"
1325
1488
  @uri.user.should == "newuser"
1326
1489
  @uri.password.should == "pass"
1327
1490
  @uri.to_s.should == "http://newuser:pass@example.com"
1328
1491
  end
1329
1492
 
1330
- specify "should have the correct password after assignment" do
1493
+ it "should have the correct password after assignment" do
1331
1494
  @uri.password = "newpass"
1332
1495
  @uri.password.should == "newpass"
1333
1496
  @uri.user.should == ""
1334
1497
  @uri.to_s.should == "http://:newpass@example.com"
1335
1498
  end
1336
1499
 
1337
- specify "should have the correct authority segment after assignment" do
1500
+ it "should have the correct authority segment after assignment" do
1338
1501
  @uri.authority = ":newpass@example.com"
1339
1502
  @uri.authority.should == ":newpass@example.com"
1340
1503
  @uri.user.should == ""
@@ -1346,46 +1509,47 @@ context "http://:pass@example.com" do
1346
1509
  end
1347
1510
  end
1348
1511
 
1349
- context "http://:@example.com" do
1350
- setup do
1512
+ describe Addressable::URI, " when parsed from " +
1513
+ "'http://:@example.com'" do
1514
+ before do
1351
1515
  @uri = Addressable::URI.parse("http://:@example.com")
1352
1516
  end
1353
1517
 
1354
- specify "should use the 'http' scheme" do
1518
+ it "should use the 'http' scheme" do
1355
1519
  @uri.scheme.should == "http"
1356
1520
  end
1357
1521
 
1358
- specify "should have a username of ''" do
1522
+ it "should have a username of ''" do
1359
1523
  @uri.user.should == ""
1360
1524
  end
1361
1525
 
1362
- specify "should have a password of ''" do
1526
+ it "should have a password of ''" do
1363
1527
  @uri.password.should == ""
1364
1528
  end
1365
1529
 
1366
- specify "should have a host of 'example.com'" do
1530
+ it "should have a host of 'example.com'" do
1367
1531
  @uri.host.should == "example.com"
1368
1532
  end
1369
1533
 
1370
- specify "should use port 80" do
1534
+ it "should use port 80" do
1371
1535
  @uri.port.should == 80
1372
1536
  end
1373
1537
 
1374
- specify "should have the correct username after assignment" do
1538
+ it "should have the correct username after assignment" do
1375
1539
  @uri.user = "newuser"
1376
1540
  @uri.user.should == "newuser"
1377
1541
  @uri.password.should == ""
1378
1542
  @uri.to_s.should == "http://newuser:@example.com"
1379
1543
  end
1380
1544
 
1381
- specify "should have the correct password after assignment" do
1545
+ it "should have the correct password after assignment" do
1382
1546
  @uri.password = "newpass"
1383
1547
  @uri.password.should == "newpass"
1384
1548
  @uri.user.should == ""
1385
1549
  @uri.to_s.should == "http://:newpass@example.com"
1386
1550
  end
1387
1551
 
1388
- specify "should have the correct authority segment after assignment" do
1552
+ it "should have the correct authority segment after assignment" do
1389
1553
  @uri.authority = ":@newexample.com"
1390
1554
  @uri.authority.should == ":@newexample.com"
1391
1555
  @uri.user.should == ""
@@ -1397,346 +1561,469 @@ context "http://:@example.com" do
1397
1561
  end
1398
1562
  end
1399
1563
 
1400
- context "#example" do
1401
- setup do
1564
+ describe Addressable::URI, " when parsed from " +
1565
+ "'#example'" do
1566
+ before do
1402
1567
  @uri = Addressable::URI.parse("#example")
1403
1568
  end
1404
1569
 
1405
- specify "should be considered relative" do
1406
- @uri.should.be.relative
1570
+ it "should be considered relative" do
1571
+ @uri.should be_relative
1407
1572
  end
1408
1573
 
1409
- specify "should have a host of nil" do
1574
+ it "should have a host of nil" do
1410
1575
  @uri.host.should == nil
1411
1576
  end
1412
1577
 
1413
- specify "should have a path of ''" do
1578
+ it "should have a path of ''" do
1414
1579
  @uri.path.should == ""
1415
1580
  end
1416
1581
 
1417
- specify "should have a query string of nil" do
1582
+ it "should have a query string of nil" do
1418
1583
  @uri.query.should == nil
1419
1584
  end
1420
1585
 
1421
- specify "should have a fragment of 'example'" do
1586
+ it "should have a fragment of 'example'" do
1422
1587
  @uri.fragment.should == "example"
1423
1588
  end
1424
1589
  end
1425
1590
 
1426
- context "The network-path reference //example.com/" do
1427
- setup do
1591
+ describe Addressable::URI, " when parsed from " +
1592
+ "the network-path reference '//example.com/'" do
1593
+ before do
1428
1594
  @uri = Addressable::URI.parse("//example.com/")
1429
1595
  end
1430
1596
 
1431
- specify "should be considered relative" do
1432
- @uri.should.be.relative
1597
+ it "should be considered relative" do
1598
+ @uri.should be_relative
1433
1599
  end
1434
1600
 
1435
- specify "should have a host of 'example.com'" do
1601
+ it "should have a host of 'example.com'" do
1436
1602
  @uri.host.should == "example.com"
1437
1603
  end
1438
1604
 
1439
- specify "should have a path of '/'" do
1605
+ it "should have a path of '/'" do
1440
1606
  @uri.path.should == "/"
1441
1607
  end
1442
1608
  end
1443
1609
 
1444
- context "feed://http://example.com/" do
1445
- setup do
1610
+ describe Addressable::URI, " when parsed from " +
1611
+ "'feed://http://example.com/'" do
1612
+ before do
1446
1613
  @uri = Addressable::URI.parse("feed://http://example.com/")
1447
1614
  end
1448
1615
 
1449
- specify "should have a path of 'http://example.com/'" do
1616
+ it "should have a path of 'http://example.com/'" do
1450
1617
  @uri.path.should == "http://example.com/"
1451
1618
  end
1452
1619
 
1453
- specify "should normalize to 'http://example.com/'" do
1620
+ it "should normalize to 'http://example.com/'" do
1454
1621
  @uri.normalize.to_s.should == "http://example.com/"
1455
1622
  @uri.normalize!.to_s.should == "http://example.com/"
1456
1623
  end
1457
1624
  end
1458
1625
 
1459
- context "feed:http://example.com/" do
1460
- setup do
1626
+ describe Addressable::URI, " when parsed from " +
1627
+ "'feed:http://example.com/'" do
1628
+ before do
1461
1629
  @uri = Addressable::URI.parse("feed:http://example.com/")
1462
1630
  end
1463
1631
 
1464
- specify "should have a path of 'http://example.com/'" do
1632
+ it "should have a path of 'http://example.com/'" do
1465
1633
  @uri.path.should == "http://example.com/"
1466
1634
  end
1467
1635
 
1468
- specify "should normalize to 'http://example.com/'" do
1636
+ it "should normalize to 'http://example.com/'" do
1469
1637
  @uri.normalize.to_s.should == "http://example.com/"
1470
1638
  @uri.normalize!.to_s.should == "http://example.com/"
1471
1639
  end
1472
1640
  end
1473
1641
 
1474
- context "example://a/b/c/%7Bfoo%7D" do
1475
- setup do
1642
+ describe Addressable::URI, "when parsed from " +
1643
+ "'example://a/b/c/%7Bfoo%7D'" do
1644
+ before do
1476
1645
  @uri = Addressable::URI.parse("example://a/b/c/%7Bfoo%7D")
1477
1646
  end
1478
1647
 
1479
1648
  # Section 6.2.2 of RFC 3986
1480
- specify "should be equivalent to eXAMPLE://a/./b/../b/%63/%7bfoo%7d" do
1649
+ it "should be equivalent to eXAMPLE://a/./b/../b/%63/%7bfoo%7d" do
1481
1650
  @uri.should ==
1482
1651
  Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
1483
1652
  end
1484
1653
  end
1485
1654
 
1486
- context "http://example.com/indirect/path/./to/../resource/" do
1487
- setup do
1655
+ describe Addressable::URI, " when parsed from " +
1656
+ "'http://example.com/indirect/path/./to/../resource/'" do
1657
+ before do
1488
1658
  @uri = Addressable::URI.parse(
1489
1659
  "http://example.com/indirect/path/./to/../resource/")
1490
1660
  end
1491
1661
 
1492
- specify "should use the 'http' scheme" do
1662
+ it "should use the 'http' scheme" do
1493
1663
  @uri.scheme.should == "http"
1494
1664
  end
1495
1665
 
1496
- specify "should have a host of 'example.com'" do
1666
+ it "should have a host of 'example.com'" do
1497
1667
  @uri.host.should == "example.com"
1498
1668
  end
1499
1669
 
1500
- specify "should use port 80" do
1670
+ it "should use port 80" do
1501
1671
  @uri.port.should == 80
1502
1672
  end
1503
1673
 
1504
- specify "should have a path of '/indirect/path/./to/../resource/'" do
1674
+ it "should have a path of '/indirect/path/./to/../resource/'" do
1505
1675
  @uri.path.should == "/indirect/path/./to/../resource/"
1506
1676
  end
1507
1677
 
1508
1678
  # Section 6.2.2.3 of RFC 3986
1509
- specify "should have a normalized path of '/indirect/path/resource/'" do
1679
+ it "should have a normalized path of '/indirect/path/resource/'" do
1510
1680
  @uri.normalize.path.should == "/indirect/path/resource/"
1511
1681
  @uri.normalize!.path.should == "/indirect/path/resource/"
1512
1682
  end
1513
1683
  end
1514
1684
 
1515
- context "A base uri of http://a/b/c/d;p?q" do
1516
- setup do
1685
+ describe Addressable::URI, " when parsed from " +
1686
+ "'http://under_score.example.com/'" do
1687
+ it "should not cause an error" do
1688
+ (lambda do
1689
+ Addressable::URI.parse("http://under_score.example.com/")
1690
+ end).should_not raise_error
1691
+ end
1692
+ end
1693
+
1694
+ describe Addressable::URI, " when parsed from " +
1695
+ "'./this:that'" do
1696
+ before do
1697
+ @uri = Addressable::URI.parse("./this:that")
1698
+ end
1699
+
1700
+ it "should be considered relative" do
1701
+ @uri.should be_relative
1702
+ end
1703
+
1704
+ it "should have no scheme" do
1705
+ @uri.scheme.should == nil
1706
+ end
1707
+ end
1708
+
1709
+ describe Addressable::URI, "when parsed from " +
1710
+ "'this:that'" do
1711
+ before do
1712
+ @uri = Addressable::URI.parse("this:that")
1713
+ end
1714
+
1715
+ it "should be considered absolute" do
1716
+ @uri.should be_absolute
1717
+ end
1718
+
1719
+ it "should have a scheme of 'this'" do
1720
+ @uri.scheme.should == "this"
1721
+ end
1722
+ end
1723
+
1724
+ describe Addressable::URI, " when parsed from " +
1725
+ "'http://www.詹姆斯.com/'" do
1726
+ before do
1727
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/")
1728
+ end
1729
+
1730
+ it "should be equivalent to 'http://www.xn--8ws00zhy3a.com/'" do
1731
+ if Addressable::URI::IDNA.send(:use_libidn?)
1732
+ @uri.should ==
1733
+ Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
1734
+ else
1735
+ puts "\nSkipping IDN specification because GNU libidn is unavailable."
1736
+ end
1737
+ end
1738
+
1739
+ it "should not have domain name encoded during normalization" do
1740
+ Addressable::URI.normalized_encode(@uri.to_s).should ==
1741
+ "http://www.詹姆斯.com/"
1742
+ end
1743
+ end
1744
+
1745
+ describe Addressable::URI, " when parsed from " +
1746
+ "'http://www.詹姆斯.com/ some spaces /'" do
1747
+ before do
1748
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
1749
+ end
1750
+
1751
+ it "should be equivalent to " +
1752
+ "'http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/'" do
1753
+ if Addressable::URI::IDNA.send(:use_libidn?)
1754
+ @uri.should ==
1755
+ Addressable::URI.parse(
1756
+ "http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/")
1757
+ else
1758
+ puts "\nSkipping IDN specification because GNU libidn is unavailable."
1759
+ end
1760
+ end
1761
+
1762
+ it "should not have domain name encoded during normalization" do
1763
+ Addressable::URI.normalized_encode(@uri.to_s).should ==
1764
+ "http://www.詹姆斯.com/%20some%20spaces%20/"
1765
+ end
1766
+ end
1767
+
1768
+ describe Addressable::URI, " when parsed from " +
1769
+ "'http://www.xn--8ws00zhy3a.com/'" do
1770
+ before do
1771
+ @uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
1772
+ end
1773
+
1774
+ it "should be displayed as http://www.詹姆斯.com/" do
1775
+ if Addressable::URI::IDNA.send(:use_libidn?)
1776
+ @uri.display_uri.to_s.should == "http://www.詹姆斯.com/"
1777
+ else
1778
+ puts "\nSkipping IDN specification because GNU libidn is unavailable."
1779
+ end
1780
+ end
1781
+ end
1782
+
1783
+ describe Addressable::URI, " when parsed from " +
1784
+ "'http://www.詹姆斯.com/atomtests/iri/詹.html'" do
1785
+ before do
1786
+ @uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
1787
+ end
1788
+
1789
+ it "should normalize to " +
1790
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html" do
1791
+ if Addressable::URI::IDNA.send(:use_libidn?)
1792
+ @uri.normalize.to_s.should ==
1793
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
1794
+ @uri.normalize!.to_s.should ==
1795
+ "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
1796
+ else
1797
+ puts "\nSkipping IDN specification because GNU libidn is unavailable."
1798
+ end
1799
+ end
1800
+ end
1801
+
1802
+ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
1803
+ before do
1517
1804
  @uri = Addressable::URI.parse("http://a/b/c/d;p?q")
1518
1805
  end
1519
1806
 
1520
1807
  # Section 5.4.1 of RFC 3986
1521
- specify "when joined with 'g:h' should resolve to g:h" do
1808
+ it "when joined with 'g:h' should resolve to g:h" do
1522
1809
  (@uri + "g:h").to_s.should == "g:h"
1523
1810
  Addressable::URI.join(@uri, "g:h").to_s.should == "g:h"
1524
1811
  end
1525
1812
 
1526
1813
  # Section 5.4.1 of RFC 3986
1527
- specify "when joined with 'g' should resolve to http://a/b/c/g" do
1814
+ it "when joined with 'g' should resolve to http://a/b/c/g" do
1528
1815
  (@uri + "g").to_s.should == "http://a/b/c/g"
1529
1816
  Addressable::URI.join(@uri.to_s, "g").to_s.should == "http://a/b/c/g"
1530
1817
  end
1531
1818
 
1532
1819
  # Section 5.4.1 of RFC 3986
1533
- specify "when joined with './g' should resolve to http://a/b/c/g" do
1820
+ it "when joined with './g' should resolve to http://a/b/c/g" do
1534
1821
  (@uri + "./g").to_s.should == "http://a/b/c/g"
1535
1822
  Addressable::URI.join(@uri.to_s, "./g").to_s.should == "http://a/b/c/g"
1536
1823
  end
1537
1824
 
1538
1825
  # Section 5.4.1 of RFC 3986
1539
- specify "when joined with 'g/' should resolve to http://a/b/c/g/" do
1826
+ it "when joined with 'g/' should resolve to http://a/b/c/g/" do
1540
1827
  (@uri + "g/").to_s.should == "http://a/b/c/g/"
1541
1828
  Addressable::URI.join(@uri.to_s, "g/").to_s.should == "http://a/b/c/g/"
1542
1829
  end
1543
1830
 
1544
1831
  # Section 5.4.1 of RFC 3986
1545
- specify "when joined with '/g' should resolve to http://a/g" do
1832
+ it "when joined with '/g' should resolve to http://a/g" do
1546
1833
  (@uri + "/g").to_s.should == "http://a/g"
1547
1834
  Addressable::URI.join(@uri.to_s, "/g").to_s.should == "http://a/g"
1548
1835
  end
1549
1836
 
1550
1837
  # Section 5.4.1 of RFC 3986
1551
- specify "when joined with '//g' should resolve to http://g" do
1838
+ it "when joined with '//g' should resolve to http://g" do
1552
1839
  (@uri + "//g").to_s.should == "http://g"
1553
1840
  Addressable::URI.join(@uri.to_s, "//g").to_s.should == "http://g"
1554
1841
  end
1555
1842
 
1556
1843
  # Section 5.4.1 of RFC 3986
1557
- specify "when joined with '?y' should resolve to http://a/b/c/d;p?y" do
1844
+ it "when joined with '?y' should resolve to http://a/b/c/d;p?y" do
1558
1845
  (@uri + "?y").to_s.should == "http://a/b/c/d;p?y"
1559
1846
  Addressable::URI.join(@uri.to_s, "?y").to_s.should == "http://a/b/c/d;p?y"
1560
1847
  end
1561
1848
 
1562
1849
  # Section 5.4.1 of RFC 3986
1563
- specify "when joined with 'g?y' should resolve to http://a/b/c/g?y" do
1850
+ it "when joined with 'g?y' should resolve to http://a/b/c/g?y" do
1564
1851
  (@uri + "g?y").to_s.should == "http://a/b/c/g?y"
1565
1852
  Addressable::URI.join(@uri.to_s, "g?y").to_s.should == "http://a/b/c/g?y"
1566
1853
  end
1567
1854
 
1568
1855
  # Section 5.4.1 of RFC 3986
1569
- specify "when joined with '#s' should resolve to http://a/b/c/d;p?q#s" do
1856
+ it "when joined with '#s' should resolve to http://a/b/c/d;p?q#s" do
1570
1857
  (@uri + "#s").to_s.should == "http://a/b/c/d;p?q#s"
1571
1858
  Addressable::URI.join(@uri.to_s, "#s").to_s.should == "http://a/b/c/d;p?q#s"
1572
1859
  end
1573
1860
 
1574
1861
  # Section 5.4.1 of RFC 3986
1575
- specify "when joined with 'g#s' should resolve to http://a/b/c/g#s" do
1862
+ it "when joined with 'g#s' should resolve to http://a/b/c/g#s" do
1576
1863
  (@uri + "g#s").to_s.should == "http://a/b/c/g#s"
1577
1864
  Addressable::URI.join(@uri.to_s, "g#s").to_s.should == "http://a/b/c/g#s"
1578
1865
  end
1579
1866
 
1580
1867
  # Section 5.4.1 of RFC 3986
1581
- specify "when joined with 'g?y#s' should resolve to http://a/b/c/g?y#s" do
1868
+ it "when joined with 'g?y#s' should resolve to http://a/b/c/g?y#s" do
1582
1869
  (@uri + "g?y#s").to_s.should == "http://a/b/c/g?y#s"
1583
1870
  Addressable::URI.join(
1584
1871
  @uri.to_s, "g?y#s").to_s.should == "http://a/b/c/g?y#s"
1585
1872
  end
1586
1873
 
1587
1874
  # Section 5.4.1 of RFC 3986
1588
- specify "when joined with ';x' should resolve to http://a/b/c/;x" do
1875
+ it "when joined with ';x' should resolve to http://a/b/c/;x" do
1589
1876
  (@uri + ";x").to_s.should == "http://a/b/c/;x"
1590
1877
  Addressable::URI.join(@uri.to_s, ";x").to_s.should == "http://a/b/c/;x"
1591
1878
  end
1592
1879
 
1593
1880
  # Section 5.4.1 of RFC 3986
1594
- specify "when joined with 'g;x' should resolve to http://a/b/c/g;x" do
1881
+ it "when joined with 'g;x' should resolve to http://a/b/c/g;x" do
1595
1882
  (@uri + "g;x").to_s.should == "http://a/b/c/g;x"
1596
1883
  Addressable::URI.join(@uri.to_s, "g;x").to_s.should == "http://a/b/c/g;x"
1597
1884
  end
1598
1885
 
1599
1886
  # Section 5.4.1 of RFC 3986
1600
- specify "when joined with 'g;x?y#s' should resolve to http://a/b/c/g;x?y#s" do
1887
+ it "when joined with 'g;x?y#s' should resolve to http://a/b/c/g;x?y#s" do
1601
1888
  (@uri + "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
1602
1889
  Addressable::URI.join(
1603
1890
  @uri.to_s, "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
1604
1891
  end
1605
1892
 
1606
1893
  # Section 5.4.1 of RFC 3986
1607
- specify "when joined with '' should resolve to http://a/b/c/d;p?q" do
1894
+ it "when joined with '' should resolve to http://a/b/c/d;p?q" do
1608
1895
  (@uri + "").to_s.should == "http://a/b/c/d;p?q"
1609
1896
  Addressable::URI.join(@uri.to_s, "").to_s.should == "http://a/b/c/d;p?q"
1610
1897
  end
1611
1898
 
1612
1899
  # Section 5.4.1 of RFC 3986
1613
- specify "when joined with '.' should resolve to http://a/b/c/" do
1900
+ it "when joined with '.' should resolve to http://a/b/c/" do
1614
1901
  (@uri + ".").to_s.should == "http://a/b/c/"
1615
1902
  Addressable::URI.join(@uri.to_s, ".").to_s.should == "http://a/b/c/"
1616
1903
  end
1617
1904
 
1618
1905
  # Section 5.4.1 of RFC 3986
1619
- specify "when joined with './' should resolve to http://a/b/c/" do
1906
+ it "when joined with './' should resolve to http://a/b/c/" do
1620
1907
  (@uri + "./").to_s.should == "http://a/b/c/"
1621
1908
  Addressable::URI.join(@uri.to_s, "./").to_s.should == "http://a/b/c/"
1622
1909
  end
1623
1910
 
1624
1911
  # Section 5.4.1 of RFC 3986
1625
- specify "when joined with '..' should resolve to http://a/b/" do
1912
+ it "when joined with '..' should resolve to http://a/b/" do
1626
1913
  (@uri + "..").to_s.should == "http://a/b/"
1627
1914
  Addressable::URI.join(@uri.to_s, "..").to_s.should == "http://a/b/"
1628
1915
  end
1629
1916
 
1630
1917
  # Section 5.4.1 of RFC 3986
1631
- specify "when joined with '../' should resolve to http://a/b/" do
1918
+ it "when joined with '../' should resolve to http://a/b/" do
1632
1919
  (@uri + "../").to_s.should == "http://a/b/"
1633
1920
  Addressable::URI.join(@uri.to_s, "../").to_s.should == "http://a/b/"
1634
1921
  end
1635
1922
 
1636
1923
  # Section 5.4.1 of RFC 3986
1637
- specify "when joined with '../g' should resolve to http://a/b/g" do
1924
+ it "when joined with '../g' should resolve to http://a/b/g" do
1638
1925
  (@uri + "../g").to_s.should == "http://a/b/g"
1639
1926
  Addressable::URI.join(@uri.to_s, "../g").to_s.should == "http://a/b/g"
1640
1927
  end
1641
1928
 
1642
1929
  # Section 5.4.1 of RFC 3986
1643
- specify "when joined with '../..' should resolve to http://a/" do
1930
+ it "when joined with '../..' should resolve to http://a/" do
1644
1931
  (@uri + "../..").to_s.should == "http://a/"
1645
1932
  Addressable::URI.join(@uri.to_s, "../..").to_s.should == "http://a/"
1646
1933
  end
1647
1934
 
1648
1935
  # Section 5.4.1 of RFC 3986
1649
- specify "when joined with '../../' should resolve to http://a/" do
1936
+ it "when joined with '../../' should resolve to http://a/" do
1650
1937
  (@uri + "../../").to_s.should == "http://a/"
1651
1938
  Addressable::URI.join(@uri.to_s, "../../").to_s.should == "http://a/"
1652
1939
  end
1653
1940
 
1654
1941
  # Section 5.4.1 of RFC 3986
1655
- specify "when joined with '../../g' should resolve to http://a/g" do
1942
+ it "when joined with '../../g' should resolve to http://a/g" do
1656
1943
  (@uri + "../../g").to_s.should == "http://a/g"
1657
1944
  Addressable::URI.join(@uri.to_s, "../../g").to_s.should == "http://a/g"
1658
1945
  end
1659
1946
 
1660
1947
  # Section 5.4.2 of RFC 3986
1661
- specify "when joined with '../../../g' should resolve to http://a/g" do
1948
+ it "when joined with '../../../g' should resolve to http://a/g" do
1662
1949
  (@uri + "../../../g").to_s.should == "http://a/g"
1663
1950
  Addressable::URI.join(@uri.to_s, "../../../g").to_s.should == "http://a/g"
1664
1951
  end
1665
1952
 
1666
- specify "when joined with '../.././../g' should resolve to http://a/g" do
1953
+ it "when joined with '../.././../g' should resolve to http://a/g" do
1667
1954
  (@uri + "../.././../g").to_s.should == "http://a/g"
1668
1955
  Addressable::URI.join(@uri.to_s, "../.././../g").to_s.should == "http://a/g"
1669
1956
  end
1670
1957
 
1671
1958
  # Section 5.4.2 of RFC 3986
1672
- specify "when joined with '../../../../g' should resolve to http://a/g" do
1959
+ it "when joined with '../../../../g' should resolve to http://a/g" do
1673
1960
  (@uri + "../../../../g").to_s.should == "http://a/g"
1674
1961
  Addressable::URI.join(
1675
1962
  @uri.to_s, "../../../../g").to_s.should == "http://a/g"
1676
1963
  end
1677
1964
 
1678
1965
  # Section 5.4.2 of RFC 3986
1679
- specify "when joined with '/./g' should resolve to http://a/g" do
1966
+ it "when joined with '/./g' should resolve to http://a/g" do
1680
1967
  (@uri + "/./g").to_s.should == "http://a/g"
1681
1968
  Addressable::URI.join(@uri.to_s, "/./g").to_s.should == "http://a/g"
1682
1969
  end
1683
1970
 
1684
1971
  # Section 5.4.2 of RFC 3986
1685
- specify "when joined with '/../g' should resolve to http://a/g" do
1972
+ it "when joined with '/../g' should resolve to http://a/g" do
1686
1973
  (@uri + "/../g").to_s.should == "http://a/g"
1687
1974
  Addressable::URI.join(@uri.to_s, "/../g").to_s.should == "http://a/g"
1688
1975
  end
1689
1976
 
1690
1977
  # Section 5.4.2 of RFC 3986
1691
- specify "when joined with 'g.' should resolve to http://a/b/c/g." do
1978
+ it "when joined with 'g.' should resolve to http://a/b/c/g." do
1692
1979
  (@uri + "g.").to_s.should == "http://a/b/c/g."
1693
1980
  Addressable::URI.join(@uri.to_s, "g.").to_s.should == "http://a/b/c/g."
1694
1981
  end
1695
1982
 
1696
1983
  # Section 5.4.2 of RFC 3986
1697
- specify "when joined with '.g' should resolve to http://a/b/c/.g" do
1984
+ it "when joined with '.g' should resolve to http://a/b/c/.g" do
1698
1985
  (@uri + ".g").to_s.should == "http://a/b/c/.g"
1699
1986
  Addressable::URI.join(@uri.to_s, ".g").to_s.should == "http://a/b/c/.g"
1700
1987
  end
1701
1988
 
1702
1989
  # Section 5.4.2 of RFC 3986
1703
- specify "when joined with 'g..' should resolve to http://a/b/c/g.." do
1990
+ it "when joined with 'g..' should resolve to http://a/b/c/g.." do
1704
1991
  (@uri + "g..").to_s.should == "http://a/b/c/g.."
1705
1992
  Addressable::URI.join(@uri.to_s, "g..").to_s.should == "http://a/b/c/g.."
1706
1993
  end
1707
1994
 
1708
1995
  # Section 5.4.2 of RFC 3986
1709
- specify "when joined with '..g' should resolve to http://a/b/c/..g" do
1996
+ it "when joined with '..g' should resolve to http://a/b/c/..g" do
1710
1997
  (@uri + "..g").to_s.should == "http://a/b/c/..g"
1711
1998
  Addressable::URI.join(@uri.to_s, "..g").to_s.should == "http://a/b/c/..g"
1712
1999
  end
1713
2000
 
1714
2001
  # Section 5.4.2 of RFC 3986
1715
- specify "when joined with './../g' should resolve to http://a/b/g" do
2002
+ it "when joined with './../g' should resolve to http://a/b/g" do
1716
2003
  (@uri + "./../g").to_s.should == "http://a/b/g"
1717
2004
  Addressable::URI.join(@uri.to_s, "./../g").to_s.should == "http://a/b/g"
1718
2005
  end
1719
2006
 
1720
2007
  # Section 5.4.2 of RFC 3986
1721
- specify "when joined with './g/.' should resolve to http://a/b/c/g/" do
2008
+ it "when joined with './g/.' should resolve to http://a/b/c/g/" do
1722
2009
  (@uri + "./g/.").to_s.should == "http://a/b/c/g/"
1723
2010
  Addressable::URI.join(@uri.to_s, "./g/.").to_s.should == "http://a/b/c/g/"
1724
2011
  end
1725
2012
 
1726
2013
  # Section 5.4.2 of RFC 3986
1727
- specify "when joined with 'g/./h' should resolve to http://a/b/c/g/h" do
2014
+ it "when joined with 'g/./h' should resolve to http://a/b/c/g/h" do
1728
2015
  (@uri + "g/./h").to_s.should == "http://a/b/c/g/h"
1729
2016
  Addressable::URI.join(@uri.to_s, "g/./h").to_s.should == "http://a/b/c/g/h"
1730
2017
  end
1731
2018
 
1732
2019
  # Section 5.4.2 of RFC 3986
1733
- specify "when joined with 'g/../h' should resolve to http://a/b/c/h" do
2020
+ it "when joined with 'g/../h' should resolve to http://a/b/c/h" do
1734
2021
  (@uri + "g/../h").to_s.should == "http://a/b/c/h"
1735
2022
  Addressable::URI.join(@uri.to_s, "g/../h").to_s.should == "http://a/b/c/h"
1736
2023
  end
1737
2024
 
1738
2025
  # Section 5.4.2 of RFC 3986
1739
- specify "when joined with 'g;x=1/./y' " +
2026
+ it "when joined with 'g;x=1/./y' " +
1740
2027
  "should resolve to http://a/b/c/g;x=1/y" do
1741
2028
  (@uri + "g;x=1/./y").to_s.should == "http://a/b/c/g;x=1/y"
1742
2029
  Addressable::URI.join(
@@ -1744,14 +2031,14 @@ context "A base uri of http://a/b/c/d;p?q" do
1744
2031
  end
1745
2032
 
1746
2033
  # Section 5.4.2 of RFC 3986
1747
- specify "when joined with 'g;x=1/../y' should resolve to http://a/b/c/y" do
2034
+ it "when joined with 'g;x=1/../y' should resolve to http://a/b/c/y" do
1748
2035
  (@uri + "g;x=1/../y").to_s.should == "http://a/b/c/y"
1749
2036
  Addressable::URI.join(
1750
2037
  @uri.to_s, "g;x=1/../y").to_s.should == "http://a/b/c/y"
1751
2038
  end
1752
2039
 
1753
2040
  # Section 5.4.2 of RFC 3986
1754
- specify "when joined with 'g?y/./x' " +
2041
+ it "when joined with 'g?y/./x' " +
1755
2042
  "should resolve to http://a/b/c/g?y/./x" do
1756
2043
  (@uri + "g?y/./x").to_s.should == "http://a/b/c/g?y/./x"
1757
2044
  Addressable::URI.join(
@@ -1759,7 +2046,7 @@ context "A base uri of http://a/b/c/d;p?q" do
1759
2046
  end
1760
2047
 
1761
2048
  # Section 5.4.2 of RFC 3986
1762
- specify "when joined with 'g?y/../x' " +
2049
+ it "when joined with 'g?y/../x' " +
1763
2050
  "should resolve to http://a/b/c/g?y/../x" do
1764
2051
  (@uri + "g?y/../x").to_s.should == "http://a/b/c/g?y/../x"
1765
2052
  Addressable::URI.join(
@@ -1767,7 +2054,7 @@ context "A base uri of http://a/b/c/d;p?q" do
1767
2054
  end
1768
2055
 
1769
2056
  # Section 5.4.2 of RFC 3986
1770
- specify "when joined with 'g#s/./x' " +
2057
+ it "when joined with 'g#s/./x' " +
1771
2058
  "should resolve to http://a/b/c/g#s/./x" do
1772
2059
  (@uri + "g#s/./x").to_s.should == "http://a/b/c/g#s/./x"
1773
2060
  Addressable::URI.join(
@@ -1775,7 +2062,7 @@ context "A base uri of http://a/b/c/d;p?q" do
1775
2062
  end
1776
2063
 
1777
2064
  # Section 5.4.2 of RFC 3986
1778
- specify "when joined with 'g#s/../x' " +
2065
+ it "when joined with 'g#s/../x' " +
1779
2066
  "should resolve to http://a/b/c/g#s/../x" do
1780
2067
  (@uri + "g#s/../x").to_s.should == "http://a/b/c/g#s/../x"
1781
2068
  Addressable::URI.join(
@@ -1783,13 +2070,13 @@ context "A base uri of http://a/b/c/d;p?q" do
1783
2070
  end
1784
2071
 
1785
2072
  # Section 5.4.2 of RFC 3986
1786
- specify "when joined with 'http:g' should resolve to http:g" do
2073
+ it "when joined with 'http:g' should resolve to http:g" do
1787
2074
  (@uri + "http:g").to_s.should == "http:g"
1788
2075
  Addressable::URI.join(@uri.to_s, "http:g").to_s.should == "http:g"
1789
2076
  end
1790
2077
 
1791
2078
  # Edge case to be sure
1792
- specify "when joined with '//example.com/' should " +
2079
+ it "when joined with '//example.com/' should " +
1793
2080
  "resolve to http://example.com/" do
1794
2081
  (@uri + "//example.com/").to_s.should == "http://example.com/"
1795
2082
  Addressable::URI.join(
@@ -1797,119 +2084,44 @@ context "A base uri of http://a/b/c/d;p?q" do
1797
2084
  end
1798
2085
  end
1799
2086
 
1800
- context "http://www.詹姆斯.com/" do
1801
- setup do
1802
- @uri = Addressable::URI.parse("http://www.詹姆斯.com/")
1803
- end
1804
-
1805
- specify "should be equivalent to 'http://www.xn--8ws00zhy3a.com/'" do
1806
- if Addressable::URI::IDNA.send(:use_libidn?)
1807
- @uri.should ==
1808
- Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
1809
- else
1810
- puts "\nSkipping IDN specification because GNU libidn is unavailable."
1811
- end
1812
- end
1813
-
1814
- specify "should not have domain name encoded during normalization" do
1815
- Addressable::URI.normalized_encode(@uri.to_s).should ==
1816
- "http://www.詹姆斯.com/"
1817
- end
1818
- end
1819
-
1820
- context "http://www.詹姆斯.com/ some spaces /" do
1821
- setup do
1822
- @uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
1823
- end
1824
-
1825
- specify "should be equivalent to " +
1826
- "'http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/'" do
1827
- if Addressable::URI::IDNA.send(:use_libidn?)
1828
- @uri.should ==
1829
- Addressable::URI.parse(
1830
- "http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/")
1831
- else
1832
- puts "\nSkipping IDN specification because GNU libidn is unavailable."
1833
- end
1834
- end
1835
-
1836
- specify "should not have domain name encoded during normalization" do
1837
- Addressable::URI.normalized_encode(@uri.to_s).should ==
1838
- "http://www.詹姆斯.com/%20some%20spaces%20/"
1839
- end
1840
- end
1841
-
1842
- context "http://www.xn--8ws00zhy3a.com/" do
1843
- setup do
1844
- @uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
1845
- end
1846
-
1847
- specify "should be displayed as http://www.詹姆斯.com/" do
1848
- if Addressable::URI::IDNA.send(:use_libidn?)
1849
- @uri.display_uri.to_s.should == "http://www.詹姆斯.com/"
1850
- else
1851
- puts "\nSkipping IDN specification because GNU libidn is unavailable."
1852
- end
1853
- end
1854
- end
1855
-
1856
- context "http://www.詹姆斯.com/atomtests/iri/詹.html" do
1857
- setup do
1858
- @uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
1859
- end
1860
-
1861
- specify "should normalize to " +
1862
- "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html" do
1863
- if Addressable::URI::IDNA.send(:use_libidn?)
1864
- @uri.normalize.to_s.should ==
1865
- "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
1866
- @uri.normalize!.to_s.should ==
1867
- "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
1868
- else
1869
- puts "\nSkipping IDN specification because GNU libidn is unavailable."
1870
- end
1871
- end
1872
- end
1873
-
1874
- context "Unavailable libidn bindings" do
1875
- setup do
2087
+ describe Addressable::URI::IDNA, "without libidn bindings" do
2088
+ before do
1876
2089
  Addressable::URI::IDNA.instance_variable_set("@use_libidn", false)
1877
2090
  end
1878
2091
 
1879
- teardown do
1880
- Addressable::URI::IDNA.instance_variable_set("@use_libidn", nil)
1881
- Addressable::URI::IDNA.send(:use_libidn?)
1882
- end
1883
-
1884
- specify "should cause the URI::IDNA module to raise an exception when " +
1885
- "an operation is attempted" do
2092
+ it "should raise an exception when an operation is attempted" do
1886
2093
  (lambda do
1887
2094
  Addressable::URI::IDNA.to_ascii("www.詹姆斯.com")
1888
- end).should.raise
2095
+ end).should raise_error
1889
2096
  (lambda do
1890
2097
  Addressable::URI::IDNA.to_unicode("www.xn--8ws00zhy3a.com")
1891
- end).should.raise
2098
+ end).should raise_error
1892
2099
  end
1893
2100
 
1894
- specify "should not cause normalization routines to error out" do
2101
+ it "should not cause normalization routines to error out" do
1895
2102
  (lambda do
1896
2103
  uri = Addressable::URI.parse(
1897
2104
  "http://www.詹姆斯.com/atomtests/iri/詹.html")
1898
2105
  uri.normalize
1899
- end).should.not.raise
2106
+ end).should_not raise_error
1900
2107
  end
1901
2108
 
1902
- specify "should not cause display uri routines to error out" do
2109
+ it "should not cause display uri routines to error out" do
1903
2110
  (lambda do
1904
2111
  uri = Addressable::URI.parse(
1905
2112
  "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html")
1906
2113
  uri.display_uri
1907
- end).should.not.raise
2114
+ end).should_not raise_error
2115
+ end
2116
+
2117
+ after do
2118
+ Addressable::URI::IDNA.instance_variable_set("@use_libidn", nil)
2119
+ Addressable::URI::IDNA.send(:use_libidn?)
1908
2120
  end
1909
2121
  end
1910
2122
 
1911
- context "The URI::IDNA module with rubygems and idn missing" do
1912
- setup do
2123
+ describe Addressable::URI::IDNA, "with rubygems and idn missing" do
2124
+ before do
1913
2125
  module Kernel
1914
2126
  alias_method :saved_require, :require
1915
2127
  def require(path)
@@ -1920,101 +2132,66 @@ context "The URI::IDNA module with rubygems and idn missing" do
1920
2132
  Addressable::URI::IDNA.instance_variable_set("@use_libidn", nil)
1921
2133
  end
1922
2134
 
1923
- teardown do
1924
- module Kernel
1925
- def require(path)
1926
- saved_require(path)
1927
- end
1928
- alias_method :require, :saved_require
1929
- end
1930
- Addressable::URI::IDNA.instance_variable_set("@use_libidn", nil)
1931
- Addressable::URI::IDNA.send(:use_libidn?)
1932
- end
1933
-
1934
- specify "should not raise an exception while checking " +
2135
+ it "should not raise an exception while checking " +
1935
2136
  "if libidn is available" do
1936
2137
  (lambda do
1937
2138
  Addressable::URI::IDNA.send(:use_libidn?)
1938
- end).should.not.raise
2139
+ end).should_not raise_error
1939
2140
  end
1940
2141
 
1941
- specify "should not cause normalization routines to error out" do
2142
+ it "should not cause normalization routines to error out" do
1942
2143
  (lambda do
1943
2144
  uri = Addressable::URI.parse(
1944
2145
  "http://www.詹姆斯.com/atomtests/iri/詹.html")
1945
2146
  uri.normalize
1946
- end).should.not.raise
2147
+ end).should_not raise_error
1947
2148
  end
1948
2149
 
1949
- specify "should not cause display uri routines to error out" do
2150
+ it "should not cause display uri routines to error out" do
1950
2151
  (lambda do
1951
2152
  uri = Addressable::URI.parse(
1952
2153
  "http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html")
1953
2154
  uri.display_uri
1954
- end).should.not.raise
1955
- end
1956
- end
1957
-
1958
- context "http://under_score.example.com/" do
1959
- specify "should not cause an error" do
1960
- (lambda do
1961
- Addressable::URI.parse("http://under_score.example.com/")
1962
- end).should.not.raise
1963
- end
1964
- end
1965
-
1966
- context "./this:that" do
1967
- setup do
1968
- @uri = Addressable::URI.parse("./this:that")
1969
- end
1970
-
1971
- specify "should be considered relative" do
1972
- @uri.should.be.relative
1973
- end
1974
-
1975
- specify "should have no scheme" do
1976
- @uri.scheme.should == nil
1977
- end
1978
- end
1979
-
1980
- context "this:that" do
1981
- setup do
1982
- @uri = Addressable::URI.parse("this:that")
2155
+ end).should_not raise_error
1983
2156
  end
1984
-
1985
- specify "should be considered absolute" do
1986
- @uri.should.be.absolute
1987
- end
1988
-
1989
- specify "should have a scheme of 'this'" do
1990
- @uri.scheme.should == "this"
2157
+
2158
+ after do
2159
+ module Kernel
2160
+ def require(path)
2161
+ saved_require(path)
2162
+ end
2163
+ alias_method :require, :saved_require
2164
+ end
2165
+ Addressable::URI::IDNA.instance_variable_set("@use_libidn", nil)
2166
+ Addressable::URI::IDNA.send(:use_libidn?)
1991
2167
  end
1992
2168
  end
1993
2169
 
1994
- context "A large body of arbitrary text" do
1995
- setup do
2170
+ describe Addressable::URI, "when extracting from an arbitrary text" do
2171
+ before do
1996
2172
  @text = File.open(File.expand_path(
1997
2173
  File.dirname(__FILE__) + "/../data/rfc3986.txt")) { |file| file.read }
1998
2174
  end
1999
2175
 
2000
- specify "should have all obvious URIs extractable from it" do
2176
+ it "should have all obvious URIs extractable from it" do
2001
2177
  @uris = Addressable::URI.extract(@text)
2002
- @uris.should.include "http://www.w3.org/People/Berners-Lee/"
2003
- @uris.should.include "http://roy.gbiv.com/"
2004
- @uris.should.include "http://larry.masinter.net/"
2178
+ @uris.should include("http://www.w3.org/People/Berners-Lee/")
2179
+ @uris.should include("http://roy.gbiv.com/")
2180
+ @uris.should include("http://larry.masinter.net/")
2005
2181
  @uris = Addressable::URI.extract(@text,
2006
2182
  :base => "http://example.com/", :parse => true)
2007
- @uris.should.include(
2183
+ @uris.should include(
2008
2184
  Addressable::URI.parse("http://www.w3.org/People/Berners-Lee/"))
2009
- @uris.should.include(
2185
+ @uris.should include(
2010
2186
  Addressable::URI.parse("http://roy.gbiv.com/"))
2011
- @uris.should.include(
2187
+ @uris.should include(
2012
2188
  Addressable::URI.parse("http://larry.masinter.net/"))
2013
2189
  end
2014
2190
  end
2015
2191
 
2016
- context "Arbitrary text containing invalid URIs" do
2017
- setup do
2192
+ describe Addressable::URI, "when extracting from an arbitrary text " +
2193
+ "containing invalid URIs" do
2194
+ before do
2018
2195
  @text = <<-TEXT
2019
2196
  This is an invalid URI:
2020
2197
  http://example.com:bogus/path/to/something/
@@ -2023,28 +2200,29 @@ context "Arbitrary text containing invalid URIs" do
2023
2200
  TEXT
2024
2201
  end
2025
2202
 
2026
- specify "should ignore invalid URIs when extracting" do
2203
+ it "should ignore invalid URIs when extracting" do
2027
2204
  @uris = Addressable::URI.extract(@text)
2028
- @uris.should.include "http://example.com:80/path/to/something/"
2029
- @uris.should.not.include "http://example.com:bogus/path/to/something/"
2205
+ @uris.should include("http://example.com:80/path/to/something/")
2206
+ @uris.should_not include("http://example.com:bogus/path/to/something/")
2030
2207
  @uris.size.should == 1
2031
2208
  end
2032
2209
  end
2033
2210
 
2034
- context "A relative path" do
2035
- setup do
2211
+ describe Addressable::URI, "when converting the path " +
2212
+ "'relative/path/to/something'" do
2213
+ before do
2036
2214
  @path = 'relative/path/to/something'
2037
2215
  end
2038
2216
 
2039
- specify "should convert to " +
2217
+ it "should convert to " +
2040
2218
  "\'relative/path/to/something\'" do
2041
2219
  @uri = Addressable::URI.convert_path(@path)
2042
2220
  @uri.to_s.should == "relative/path/to/something"
2043
2221
  end
2044
2222
  end
2045
2223
 
2046
- context "The root directory" do
2047
- setup do
2224
+ describe Addressable::URI, "when given the root directory" do
2225
+ before do
2048
2226
  if RUBY_PLATFORM =~ /mswin/
2049
2227
  @path = "C:\\"
2050
2228
  else
@@ -2053,96 +2231,88 @@ context "The root directory" do
2053
2231
  end
2054
2232
 
2055
2233
  if RUBY_PLATFORM =~ /mswin/
2056
- specify "should convert to \'file:///c:/\'" do
2234
+ it "should convert to \'file:///c:/\'" do
2057
2235
  @uri = Addressable::URI.convert_path(@path)
2058
2236
  @uri.to_s.should == "file:///c:/"
2059
2237
  end
2060
2238
  else
2061
- specify "should convert to \'file:///\'" do
2239
+ it "should convert to \'file:///\'" do
2062
2240
  @uri = Addressable::URI.convert_path(@path)
2063
2241
  @uri.to_s.should == "file:///"
2064
2242
  end
2065
2243
  end
2066
2244
  end
2067
2245
 
2068
- context "A unix-style path" do
2069
- setup do
2246
+ describe Addressable::URI, "when given the path '/home/user/'" do
2247
+ before do
2070
2248
  @path = '/home/user/'
2071
2249
  end
2072
2250
 
2073
- specify "should convert to " +
2251
+ it "should convert to " +
2074
2252
  "\'file:///home/user/\'" do
2075
2253
  @uri = Addressable::URI.convert_path(@path)
2076
2254
  @uri.to_s.should == "file:///home/user/"
2077
2255
  end
2078
2256
  end
2079
2257
 
2080
- context "A windows-style path" do
2081
- setup do
2258
+ describe Addressable::URI, " when given the path " +
2259
+ "'c:\\windows\\My Documents 100%20\\foo.txt'" do
2260
+ before do
2082
2261
  @path = "c:\\windows\\My Documents 100%20\\foo.txt"
2083
2262
  end
2084
2263
 
2085
- specify "should convert to " +
2264
+ it "should convert to " +
2086
2265
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
2087
2266
  @uri = Addressable::URI.convert_path(@path)
2088
2267
  @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
2089
2268
  end
2090
2269
  end
2091
2270
 
2092
- context "A windows-style file protocol URI with backslashes" do
2093
- setup do
2271
+ describe Addressable::URI, " when given the path " +
2272
+ "'file://c:\\windows\\My Documents 100%20\\foo.txt'" do
2273
+ before do
2094
2274
  @path = "file://c:\\windows\\My Documents 100%20\\foo.txt"
2095
2275
  end
2096
2276
 
2097
- specify "should convert to " +
2277
+ it "should convert to " +
2098
2278
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
2099
2279
  @uri = Addressable::URI.convert_path(@path)
2100
2280
  @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
2101
2281
  end
2102
2282
  end
2103
2283
 
2104
- context "A windows-style file protocol URI with pipe" do
2105
- setup do
2284
+ describe Addressable::URI, " when given the path " +
2285
+ "'file:///c|/windows/My%20Documents%20100%20/foo.txt'" do
2286
+ before do
2106
2287
  @path = "file:///c|/windows/My%20Documents%20100%20/foo.txt"
2107
2288
  end
2108
2289
 
2109
- specify "should convert to " +
2110
- "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
2111
- @uri = Addressable::URI.convert_path(@path)
2112
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
2113
- end
2114
- end
2115
-
2116
- context "A windows-style file protocol URI" do
2117
- setup do
2118
- @path = "file:///c:/windows/My%20Documents%20100%20/foo.txt"
2119
- end
2120
-
2121
- specify "should convert to " +
2290
+ it "should convert to " +
2122
2291
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
2123
2292
  @uri = Addressable::URI.convert_path(@path)
2124
2293
  @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
2125
2294
  end
2126
2295
  end
2127
2296
 
2128
- context "An http protocol URI" do
2129
- setup do
2297
+ describe Addressable::URI, "when given an http protocol URI" do
2298
+ before do
2130
2299
  @path = "http://example.com/"
2131
2300
  end
2132
2301
 
2133
- specify "should not be converted at all" do
2302
+ it "should not do any conversion at all" do
2134
2303
  @uri = Addressable::URI.convert_path(@path)
2135
2304
  @uri.to_s.should == "http://example.com/"
2136
2305
  end
2137
2306
  end
2138
2307
 
2139
- context "The template pattern 'http://example.com/search/{query}/' " +
2140
- "when processed with the ExampleProcessor" do
2141
- setup do
2308
+ describe Addressable::URI, " when given the template pattern " +
2309
+ "'http://example.com/search/{query}/' " +
2310
+ "to be processed with the ExampleProcessor" do
2311
+ before do
2142
2312
  @pattern = "http://example.com/search/{query}/"
2143
2313
  end
2144
2314
 
2145
- specify "should expand to " +
2315
+ it "should expand to " +
2146
2316
  "'http://example.com/search/an+example+search+query/' " +
2147
2317
  "with a mapping of {\"query\" => \"an example search query\"} " do
2148
2318
  Addressable::URI.expand_template(
@@ -2152,20 +2322,21 @@ context "The template pattern 'http://example.com/search/{query}/' " +
2152
2322
  "http://example.com/search/an+example+search+query/"
2153
2323
  end
2154
2324
 
2155
- specify "should raise an error " +
2325
+ it "should raise an error " +
2156
2326
  "with a mapping of {\"query\" => \"invalid!\"}" do
2157
2327
  (lambda do
2158
2328
  Addressable::URI.expand_template(
2159
2329
  "http://example.com/search/{query}/",
2160
2330
  {"query" => "invalid!"},
2161
2331
  ExampleProcessor).to_s
2162
- end).should.raise
2332
+ end).should raise_error
2163
2333
  end
2164
2334
  end
2165
2335
 
2166
2336
  # Section 3.3.1 of the URI Template draft
2167
- context "The mapping supplied in Section 3.3.1 of the URI Template draft" do
2168
- setup do
2337
+ describe Addressable::URI, " when given the mapping supplied in " +
2338
+ "Section 3.3.1 of the URI Template draft" do
2339
+ before do
2169
2340
  @mapping = {
2170
2341
  "a" => "fred",
2171
2342
  "b" => "barney",
@@ -2180,122 +2351,125 @@ context "The mapping supplied in Section 3.3.1 of the URI Template draft" do
2180
2351
  }
2181
2352
  end
2182
2353
 
2183
- specify "when used to expand 'http://example.org/page1\#{a}' should " +
2184
- "result in 'http://example.org/page1#fred'" do
2354
+ it "should result in 'http://example.org/page1#fred' " +
2355
+ "when used to expand 'http://example.org/page1\#{a}'" do
2185
2356
  Addressable::URI.expand_template(
2186
2357
  "http://example.org/page1\#{a}",
2187
2358
  @mapping).to_s.should == "http://example.org/page1#fred"
2188
2359
  end
2189
2360
 
2190
- specify "when used to expand 'http://example.org/{a}/{b}/' should " +
2191
- "result in 'http://example.org/fred/barney/'" do
2361
+ it "should result in 'http://example.org/fred/barney/' " +
2362
+ "when used to expand 'http://example.org/{a}/{b}/'" do
2192
2363
  Addressable::URI.expand_template(
2193
2364
  "http://example.org/{a}/{b}/",
2194
2365
  @mapping).to_s.should == "http://example.org/fred/barney/"
2195
2366
  end
2196
2367
 
2197
- specify "when used to expand 'http://example.org/{a}{b}/' should " +
2198
- "result in 'http://example.org/fredbarney/'" do
2368
+ it "should result in 'http://example.org/fredbarney/' " +
2369
+ "when used to expand 'http://example.org/{a}{b}/'" do
2199
2370
  Addressable::URI.expand_template(
2200
2371
  "http://example.org/{a}{b}/",
2201
2372
  @mapping).to_s.should == "http://example.org/fredbarney/"
2202
2373
  end
2203
2374
 
2204
- specify "when used to expand 'http://example.com/order/{c}/{c}/{c}/' " +
2205
- "should result in " +
2206
- "'http://example.com/order/cheeseburger/cheeseburger/cheeseburger/'" do
2375
+ it "should result in " +
2376
+ "'http://example.com/order/cheeseburger/cheeseburger/cheeseburger/' " +
2377
+ "when used to expand 'http://example.com/order/{c}/{c}/{c}/'" do
2207
2378
  Addressable::URI.expand_template(
2208
2379
  "http://example.com/order/{c}/{c}/{c}/",
2209
2380
  @mapping).to_s.should ==
2210
2381
  "http://example.com/order/cheeseburger/cheeseburger/cheeseburger/"
2211
2382
  end
2212
2383
 
2213
- specify "when used to expand 'http://example.org/{d}' " +
2214
- "should result in 'http://example.org/one%20two%20three'" do
2384
+ it "should result in 'http://example.org/one%20two%20three' " +
2385
+ "when used to expand 'http://example.org/{d}'" do
2215
2386
  Addressable::URI.expand_template(
2216
2387
  "http://example.org/{d}",
2217
2388
  @mapping).to_s.should == "http://example.org/one%20two%20three"
2218
2389
  end
2219
2390
 
2220
- specify "when used to expand 'http://example.org/{e}' " +
2221
- "should result in 'http://example.org/20%25%20tricky'" do
2391
+ it "should result in 'http://example.org/20%25%20tricky' " +
2392
+ "when used to expand 'http://example.org/{e}'" do
2222
2393
  Addressable::URI.expand_template(
2223
2394
  "http://example.org/{e}",
2224
2395
  @mapping).to_s.should == "http://example.org/20%25%20tricky"
2225
2396
  end
2226
2397
 
2227
- specify "when used to expand 'http://example.com/{f}/' " +
2228
- "should result in 'http://example.com//'" do
2398
+ it "should result in 'http://example.com//' " +
2399
+ "when used to expand 'http://example.com/{f}/'" do
2229
2400
  Addressable::URI.expand_template(
2230
2401
  "http://example.com/{f}/",
2231
2402
  @mapping).to_s.should == "http://example.com//"
2232
2403
  end
2233
2404
 
2234
- specify "when used to expand " +
2235
- "'{scheme}://{20}.example.org?date={wilma}&option={a}' " +
2236
- "should result in " +
2237
- "'https://this-is-spinal-tap.example.org?date=&option=fred'" do
2405
+ it "should result in " +
2406
+ "'https://this-is-spinal-tap.example.org?date=&option=fred' " +
2407
+ "when used to expand " +
2408
+ "'{scheme}://{20}.example.org?date={wilma}&option={a}'" do
2238
2409
  Addressable::URI.expand_template(
2239
2410
  "{scheme}://{20}.example.org?date={wilma}&option={a}",
2240
2411
  @mapping).to_s.should ==
2241
2412
  "https://this-is-spinal-tap.example.org?date=&option=fred"
2242
2413
  end
2243
2414
 
2244
- specify "when used to expand 'http://example.org?{p}' " +
2245
- "should result in 'http://example.org?quote=to+be+or+not+to+be'" do
2415
+ it "should result in 'http://example.org?quote=to+be+or+not+to+be' " +
2416
+ "when used to expand 'http://example.org?{p}'" do
2246
2417
  Addressable::URI.expand_template(
2247
2418
  "http://example.org?{p}",
2248
2419
  @mapping).to_s.should == "http://example.org?quote=to+be+or+not+to+be"
2249
2420
  end
2250
2421
 
2251
- specify "when used to expand 'http://example.com/{q}' " +
2252
- "should result in 'http://example.com/hullo#world'" do
2422
+ it "should result in 'http://example.com/hullo#world' " +
2423
+ "when used to expand 'http://example.com/{q}'" do
2253
2424
  Addressable::URI.expand_template(
2254
2425
  "http://example.com/{q}",
2255
2426
  @mapping).to_s.should == "http://example.com/hullo#world"
2256
2427
  end
2257
2428
  end
2258
2429
 
2259
- context "A mapping that contains a template-var within a value" do
2260
- setup do
2430
+ describe Addressable::URI, "when given a mapping that contains a " +
2431
+ "template-var within a value" do
2432
+ before do
2261
2433
  @mapping = {
2262
2434
  "a" => "{b}",
2263
2435
  "b" => "barney",
2264
2436
  }
2265
2437
  end
2266
2438
 
2267
- specify "when used to expand 'http://example.com/{a}/{b}/' " +
2268
- "should result in 'http://example.com/%7Bb%7D/barney/'" do
2439
+ it "should result in 'http://example.com/%7Bb%7D/barney/' " +
2440
+ "when used to expand 'http://example.com/{a}/{b}/'" do
2269
2441
  Addressable::URI.expand_template(
2270
2442
  "http://example.com/{a}/{b}/",
2271
2443
  @mapping).to_s.should == "http://example.com/%7Bb%7D/barney/"
2272
2444
  end
2273
2445
  end
2274
2446
 
2275
- context "A mapping that contains values that are already percent-encoded" do
2276
- setup do
2447
+ describe Addressable::URI, "when given a mapping that contains values " +
2448
+ "that are already percent-encoded" do
2449
+ before do
2277
2450
  @mapping = {
2278
2451
  "a" => "%7Bb%7D"
2279
2452
  }
2280
2453
  end
2281
2454
 
2282
- specify "when used to expand 'http://example.com/{a}/' " +
2283
- "should result in 'http://example.com/%257Bb%257D/'" do
2455
+ it "should result in 'http://example.com/%257Bb%257D/' " +
2456
+ "when used to expand 'http://example.com/{a}/'" do
2284
2457
  Addressable::URI.expand_template(
2285
2458
  "http://example.com/{a}/",
2286
2459
  @mapping).to_s.should == "http://example.com/%257Bb%257D/"
2287
2460
  end
2288
2461
  end
2289
2462
 
2290
- context "http://example.com/search/an+example+search+query/" do
2291
- setup do
2463
+ describe Addressable::URI, " when parsed from " +
2464
+ "'http://example.com/search/an+example+search+query/'" do
2465
+ before do
2292
2466
  @uri = Addressable::URI.parse(
2293
2467
  "http://example.com/search/an+example+search+query/")
2294
2468
  end
2295
2469
 
2296
- specify "when extracting using the pattern " +
2297
- "'http://example.com/search/{query}/' with the " +
2298
- "ExampleProcessor to extract values should have the correct mapping" do
2470
+ it "should have the correct mapping when extracting values using " +
2471
+ "the pattern 'http://example.com/search/{query}/' with the " +
2472
+ "ExampleProcessor" do
2299
2473
  @uri.extract_mapping(
2300
2474
  "http://example.com/search/{query}/", ExampleProcessor
2301
2475
  ).should == {
@@ -2303,22 +2477,24 @@ context "http://example.com/search/an+example+search+query/" do
2303
2477
  }
2304
2478
  end
2305
2479
 
2306
- specify "when extracting using a non-matching pattern should return nil" do
2480
+ it "should return nil when extracting values using " +
2481
+ "a non-matching pattern" do
2307
2482
  @uri.extract_mapping(
2308
2483
  "http://bogus.com/{thingy}/"
2309
2484
  ).should == nil
2310
2485
  end
2311
2486
  end
2312
2487
 
2313
- context "http://example.com/a/b/c/" do
2314
- setup do
2488
+ describe Addressable::URI, " when parsed from " +
2489
+ "'http://example.com/a/b/c/'" do
2490
+ before do
2315
2491
  @uri = Addressable::URI.parse(
2316
2492
  "http://example.com/a/b/c/")
2317
2493
  end
2318
2494
 
2319
- specify "when extracting using the pattern " +
2320
- "'http://example.com/{first}/{second}/' with the " +
2321
- "ExampleProcessor to extract values should have the correct mapping" do
2495
+ it "should have the correct mapping when extracting values " +
2496
+ "using the pattern " +
2497
+ "'http://example.com/{first}/{second}/' with the ExampleProcessor" do
2322
2498
  @uri.extract_mapping(
2323
2499
  "http://example.com/{first}/{second}/", ExampleProcessor
2324
2500
  ).should == {
@@ -2328,14 +2504,15 @@ context "http://example.com/a/b/c/" do
2328
2504
  end
2329
2505
  end
2330
2506
 
2331
- context "http://example.com/one/spacer/two/" do
2332
- setup do
2507
+ describe Addressable::URI, " when parsed from " +
2508
+ "'http://example.com/one/spacer/two/'" do
2509
+ before do
2333
2510
  @uri = Addressable::URI.parse("http://example.com/one/spacer/two/")
2334
2511
  end
2335
2512
 
2336
- specify "when extracting using the pattern " +
2337
- "'http://example.com/{first}/spacer/{second}/' to extract values " +
2338
- "should have the correct mapping" do
2513
+ it "should have the correct mapping when extracting values " +
2514
+ "using the pattern " +
2515
+ "'http://example.com/{first}/spacer/{second}/'" do
2339
2516
  @uri.extract_mapping(
2340
2517
  "http://example.com/{first}/spacer/{second}/").should == {
2341
2518
  "first" => "one",