simple-client 0.0.2

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