| @@ -277,154 +277,161 @@ class DocsUrlTest < MiniTest::Spec · 276 unmodified lines |
| 277 | 277 | end |
| 278 | 278 | |
| 279 | 279 | describe "#relative_path_to" do |
| 280 | | − context "when the URL is relative" do |
| 280 | + context "when the URL is '/'" do |
| 281 | 281 | let :url do |
| 282 | 282 | URL.parse '/' |
| 283 | 283 | end |
| 284 | 284 | |
| 285 | | − it "raises an error with a relative url" do |
| 286 | | − assert_raises(ArgumentError) { url.relative_path_to '/' } |
| 285 | + it "returns '.' with '/'" do |
| 286 | + assert_equal '.', url.relative_path_to('/') |
| 287 | 287 | end |
| 288 | 288 | |
| 289 | | − it "raises an error with an absolute url" do |
| 290 | | − assert_raises(ArgumentError) { url.relative_path_to 'http://example.com' } |
| 289 | + it "returns 'file' with '/file'" do |
| 290 | + assert_equal 'file', url.relative_path_to('/file') |
| 291 | 291 | end |
| 292 | | − end |
| 293 | 292 | |
| 294 | | − context "when the URL is 'http://example.com'" do |
| 295 | | − let :url do |
| 296 | | − URL.parse 'http://example.com' |
| 293 | + it "returns 'file/' with '/file/'" do |
| 294 | + assert_equal 'file/', url.relative_path_to('/file/') |
| 297 | 295 | end |
| 298 | 296 | |
| 299 | | − it "raises an error with a relative url" do |
| 300 | | − assert_raises(ArgumentError) { url.relative_path_to '/' } |
| 297 | + it "raises an error with 'file'" do |
| 298 | + assert_raises ArgumentError do |
| 299 | + url.relative_path_to 'file' |
| 300 | + end |
| 301 | 301 | end |
| 302 | + end |
| 302 | 303 | |
| 303 | | − it "returns '.' with 'http://example.com'" do |
| 304 | | − assert_equal '.', url.relative_path_to('http://example.com') |
| 304 | + context "when the URL is '/path/to'" do |
| 305 | + let :url do |
| 306 | + URL.parse '/path/to' |
| 305 | 307 | end |
| 306 | 308 | |
| 307 | | − it "returns '.' with 'http://example.com/'" do |
| 308 | | − assert_equal '.', url.relative_path_to('http://example.com/') |
| 309 | + it "returns '../' with '/'" do |
| 310 | + assert_equal '../', url.relative_path_to('/') |
| 309 | 311 | end |
| 310 | 312 | |
| 311 | | − it "returns 'file' with 'http://example.com/file'" do |
| 312 | | − assert_equal 'file', url.relative_path_to('http://example.com/file') |
| 313 | + it "returns '../path' with '/path'" do |
| 314 | + assert_equal '../path', url.relative_path_to('/path') |
| 313 | 315 | end |
| 314 | 316 | |
| 315 | | − it "returns 'file/' with 'http://example.com/file/'" do |
| 316 | | − assert_equal 'file/', url.relative_path_to('http://example.com/file/') |
| 317 | + it "returns '.' with '/path/'" do |
| 318 | + assert_equal '.', url.relative_path_to('/path/') |
| 317 | 319 | end |
| 318 | 320 | |
| 319 | | − it "returns nil with 'https://example.com'" do |
| 320 | | − assert_nil url.relative_path_to('https://example.com') |
| 321 | + it "returns 'to' with '/path/to'" do |
| 322 | + assert_equal 'to', url.relative_path_to('/path/to') |
| 321 | 323 | end |
| 322 | 324 | |
| 323 | | − it "returns nil with 'http://not.example.com/file'" do |
| 324 | | − assert_nil url.relative_path_to('http://not.example.com/file') |
| 325 | + it "returns '../PATH/to' with '/PATH/to'" do |
| 326 | + assert_equal '../PATH/to', url.relative_path_to('/PATH/to') |
| 325 | 327 | end |
| 326 | | − end |
| 327 | 328 | |
| 328 | | − context "when the URL is 'http://example.com/'" do |
| 329 | | − let :url do |
| 330 | | − URL.parse 'http://example.com/' |
| 329 | + it "returns 'to/' with '/path/to/'" do |
| 330 | + assert_equal 'to/', url.relative_path_to('/path/to/') |
| 331 | 331 | end |
| 332 | 332 | |
| 333 | | − it "returns '.' with 'http://example.com'" do |
| 334 | | − assert_equal '.', url.relative_path_to('http://example.com') |
| 333 | + it "returns 'to/file' with '/path/to/file'" do |
| 334 | + assert_equal 'to/file', url.relative_path_to('/path/to/file') |
| 335 | 335 | end |
| 336 | | − end |
| 337 | 336 | |
| 338 | | − context "when the URL is 'http://example.com/path/to'" do |
| 339 | | − let :url do |
| 340 | | − URL.parse 'http://example.com/path/to' |
| 337 | + it "returns 'to/file/' with '/path/to/file/'" do |
| 338 | + assert_equal 'to/file/', url.relative_path_to('/path/to/file/') |
| 341 | 339 | end |
| 340 | + end |
| 342 | 341 | |
| 343 | | − it "returns '../' with 'http://example.com'" do |
| 344 | | − assert_equal '../', url.relative_path_to('http://example.com') |
| 342 | + context "when the URL is '/path/to/'" do |
| 343 | + let :url do |
| 344 | + URL.parse '/path/to/' |
| 345 | 345 | end |
| 346 | 346 | |
| 347 | | − it "returns '../' with 'http://example.com/'" do |
| 348 | | − assert_equal '../', url.relative_path_to('http://example.com/') |
| 347 | + it "returns '../../' with ''" do |
| 348 | + assert_equal '../../', url.relative_path_to('') |
| 349 | 349 | end |
| 350 | 350 | |
| 351 | | − it "returns '../path' with 'http://example.com/path'" do |
| 352 | | − assert_equal '../path', url.relative_path_to('http://example.com/path') |
| 351 | + it "returns '../../' with '/'" do |
| 352 | + assert_equal '../../', url.relative_path_to('/') |
| 353 | 353 | end |
| 354 | 354 | |
| 355 | | − it "returns '.' with 'http://example.com/path/'" do |
| 356 | | − assert_equal '.', url.relative_path_to('http://example.com/path/') |
| 355 | + it "returns '../../path' with '/path'" do |
| 356 | + assert_equal '../../path', url.relative_path_to('/path') |
| 357 | 357 | end |
| 358 | 358 | |
| 359 | | − it "returns 'to' with 'http://example.com/path/to'" do |
| 360 | | − assert_equal 'to', url.relative_path_to('http://example.com/path/to') |
| 359 | + it "returns '../' with '/path/'" do |
| 360 | + assert_equal '../', url.relative_path_to('/path/') |
| 361 | 361 | end |
| 362 | 362 | |
| 363 | | − it "returns '../PATH/to' with 'http://example.com/PATH/to'" do |
| 364 | | − assert_equal '../PATH/to', url.relative_path_to('http://example.com/PATH/to') |
| 363 | + it "returns '../to' with '/path/to'" do |
| 364 | + assert_equal '../to', url.relative_path_to('/path/to') |
| 365 | 365 | end |
| 366 | 366 | |
| 367 | | − it "returns 'to/' with 'http://example.com/path/to/'" do |
| 368 | | − assert_equal 'to/', url.relative_path_to('http://example.com/path/to/') |
| 367 | + it "returns '.' with '/path/to/'" do |
| 368 | + assert_equal '.', url.relative_path_to('/path/to/') |
| 369 | 369 | end |
| 370 | 370 | |
| 371 | | − it "returns 'to/file' with 'http://example.com/path/to/file'" do |
| 372 | | − assert_equal 'to/file', url.relative_path_to('http://example.com/path/to/file') |
| 371 | + it "returns 'file' with '/path/to/file'" do |
| 372 | + assert_equal 'file', url.relative_path_to('/path/to/file') |
| 373 | 373 | end |
| 374 | 374 | |
| 375 | | − it "returns 'to/file/' with 'http://example.com/path/to/file/'" do |
| 376 | | − assert_equal 'to/file/', url.relative_path_to('http://example.com/path/to/file/') |
| 375 | + it "returns 'file/' with '/path/to/file/'" do |
| 376 | + assert_equal 'file/', url.relative_path_to('/path/to/file/') |
| 377 | 377 | end |
| 378 | 378 | end |
| 379 | 379 | |
| 380 | | − context "when the URL is 'http://example.com/path/to/'" do |
| 380 | + context "when the URL is 'http://example.com'" do |
| 381 | 381 | let :url do |
| 382 | | − URL.parse 'http://example.com/path/to/' |
| 382 | + URL.parse 'http://example.com' |
| 383 | + end |
| 384 | + |
| 385 | + it "returns '.' with 'http://example.com'" do |
| 386 | + assert_equal '.', url.relative_path_to('http://example.com') |
| 383 | 387 | end |
| 384 | 388 | |
| 385 | | − it "returns '../../' with 'http://example.com'" do |
| 386 | | − assert_equal '../../', url.relative_path_to('http://example.com') |
| 389 | + it "returns '.' with 'http://example.com/'" do |
| 390 | + assert_equal '.', url.relative_path_to('http://example.com/') |
| 387 | 391 | end |
| 388 | 392 | |
| 389 | | − it "returns '../../' with 'http://example.com/'" do |
| 390 | | − assert_equal '../../', url.relative_path_to('http://example.com/') |
| 393 | + it "returns 'file' with 'http://example.com/file?query#frag'" do |
| 394 | + assert_equal 'file', url.relative_path_to('http://example.com/file?query#frag') |
| 391 | 395 | end |
| 392 | 396 | |
| 393 | | − it "returns '../../path' with 'http://example.com/path'" do |
| 394 | | − assert_equal '../../path', url.relative_path_to('http://example.com/path') |
| 397 | + it "returns nil with '/file'" do |
| 398 | + assert_nil url.relative_path_to('/file') |
| 395 | 399 | end |
| 396 | 400 | |
| 397 | | − it "returns '../' with 'http://example.com/path/'" do |
| 398 | | − assert_equal '../', url.relative_path_to('http://example.com/path/') |
| 401 | + it "returns nil with 'file'" do |
| 402 | + assert_nil url.relative_path_to('file') |
| 399 | 403 | end |
| 400 | 404 | |
| 401 | | − it "returns '../to' with 'http://example.com/path/to'" do |
| 402 | | − assert_equal '../to', url.relative_path_to('http://example.com/path/to') |
| 405 | + it "returns nil with 'https://example.com'" do |
| 406 | + assert_nil url.relative_path_to('https://example.com') |
| 403 | 407 | end |
| 404 | 408 | |
| 405 | | − it "returns '.' with 'http://example.com/path/to/'" do |
| 406 | | − assert_equal '.', url.relative_path_to('http://example.com/path/to/') |
| 409 | + it "returns nil with 'http://not.example.com/file'" do |
| 410 | + assert_nil url.relative_path_to('http://not.example.com/file') |
| 407 | 411 | end |
| 412 | + end |
| 408 | 413 | |
| 409 | | − it "returns 'file' with 'http://example.com/path/to/file'" do |
| 410 | | − assert_equal 'file', url.relative_path_to('http://example.com/path/to/file') |
| 414 | + context "when the URL is 'http://example.com/'" do |
| 415 | + let :url do |
| 416 | + URL.parse 'http://example.com/' |
| 411 | 417 | end |
| 412 | 418 | |
| 413 | | − it "returns 'file/' with 'http://example.com/path/to/file/'" do |
| 414 | | − assert_equal 'file/', url.relative_path_to('http://example.com/path/to/file/') |
| 419 | + it "returns '.' with 'http://example.com'" do |
| 420 | + assert_equal '.', url.relative_path_to('http://example.com') |
| 415 | 421 | end |
| 416 | 422 | end |
| 417 | 423 | end |
| 418 | 424 | |
| 419 | 425 | describe "#relative_path_from" do |
| 420 | | − context "when the URL is 'http://example.com/path/file'" do |
| 421 | | − let :url do |
| 422 | | − URL.parse 'http://example.com/path/file' |
| 423 | | − end |
| 426 | + let :url do |
| 427 | + URL.new |
| 428 | + end |
| 424 | 429 | |
| 425 | | − it "returns 'path/file' with 'http://example.com/path'" do |
| 426 | | − assert_equal 'path/file', url.relative_path_from('http://example.com/path') |
| 430 | + it "returns the given url's #relative_path_to to self" do |
| 431 | + any_instance_of URL do |instance| |
| 432 | + stub(instance).relative_path_to(url) { 'path' } |
| 427 | 433 | end |
| 434 | + assert_equal 'path', url.relative_path_from('url') |
| 428 | 435 | end |
| 429 | 436 | end |
| 430 | 437 | end |