PageRenderTime 35ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/spec/addressable/uri_spec.rb

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