logstash-output-scalyr 0.1.10.beta → 0.1.11.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (317) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +4 -0
  4. data/README.md +2 -2
  5. data/lib/logstash/outputs/scalyr.rb +94 -73
  6. data/lib/scalyr/common/client.rb +3 -1
  7. data/lib/scalyr/constants.rb +2 -0
  8. data/logstash-output-scalyr.gemspec +1 -1
  9. data/spec/logstash/outputs/scalyr_integration_spec.rb +119 -8
  10. data/spec/logstash/outputs/scalyr_spec.rb +9 -6
  11. data/vendor/bundle/jruby/2.5.0/cache/addressable-2.7.0.gem +0 -0
  12. data/vendor/bundle/jruby/2.5.0/cache/crack-0.4.5.gem +0 -0
  13. data/vendor/bundle/jruby/2.5.0/cache/hashdiff-1.0.1.gem +0 -0
  14. data/vendor/bundle/jruby/2.5.0/cache/public_suffix-4.0.6.gem +0 -0
  15. data/vendor/bundle/jruby/2.5.0/cache/rexml-3.2.5.gem +0 -0
  16. data/vendor/bundle/jruby/2.5.0/cache/webmock-3.13.0.gem +0 -0
  17. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/CHANGELOG.md +235 -0
  18. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/Gemfile +32 -0
  19. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/LICENSE.txt +202 -0
  20. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/README.md +121 -0
  21. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/Rakefile +34 -0
  22. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/data/unicode.data +0 -0
  23. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable.rb +4 -0
  24. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/idna.rb +27 -0
  25. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/idna/native.rb +61 -0
  26. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/idna/pure.rb +676 -0
  27. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/template.rb +1045 -0
  28. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/uri.rb +2529 -0
  29. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/lib/addressable/version.rb +32 -0
  30. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/idna_spec.rb +300 -0
  31. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/net_http_compat_spec.rb +30 -0
  32. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/rack_mount_compat_spec.rb +106 -0
  33. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/security_spec.rb +59 -0
  34. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/template_spec.rb +1451 -0
  35. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/addressable/uri_spec.rb +6603 -0
  36. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/spec/spec_helper.rb +24 -0
  37. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/clobber.rake +4 -0
  38. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/gem.rake +93 -0
  39. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/git.rake +47 -0
  40. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/metrics.rake +24 -0
  41. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/rspec.rake +23 -0
  42. data/vendor/bundle/jruby/2.5.0/gems/addressable-2.7.0/tasks/yard.rake +29 -0
  43. data/vendor/bundle/jruby/2.5.0/gems/crack-0.4.5/lib/crack.rb +7 -0
  44. data/vendor/bundle/jruby/2.5.0/gems/crack-0.4.5/lib/crack/json.rb +98 -0
  45. data/vendor/bundle/jruby/2.5.0/gems/crack-0.4.5/lib/crack/util.rb +17 -0
  46. data/vendor/bundle/jruby/2.5.0/gems/crack-0.4.5/lib/crack/version.rb +3 -0
  47. data/vendor/bundle/jruby/2.5.0/gems/crack-0.4.5/lib/crack/xml.rb +238 -0
  48. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/Gemfile +8 -0
  49. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/LICENSE +19 -0
  50. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/README.md +276 -0
  51. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/Rakefile +18 -0
  52. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/changelog.md +100 -0
  53. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/hashdiff.gemspec +39 -0
  54. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff.rb +10 -0
  55. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/compare_hashes.rb +69 -0
  56. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/diff.rb +177 -0
  57. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/lcs.rb +66 -0
  58. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/lcs_compare_arrays.rb +32 -0
  59. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/linear_compare_array.rb +159 -0
  60. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/patch.rb +88 -0
  61. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/util.rb +155 -0
  62. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/lib/hashdiff/version.rb +5 -0
  63. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/best_diff_spec.rb +75 -0
  64. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb +60 -0
  65. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_spec.rb +360 -0
  66. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb +76 -0
  67. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/linear_compare_array_spec.rb +50 -0
  68. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/patch_spec.rb +185 -0
  69. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/readme_spec.rb +15 -0
  70. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/util_spec.rb +116 -0
  71. data/vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/spec_helper.rb +15 -0
  72. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/2.0-Upgrade.md +52 -0
  73. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/CHANGELOG.md +406 -0
  74. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/Gemfile +15 -0
  75. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/LICENSE.txt +22 -0
  76. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/README.md +207 -0
  77. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/Rakefile +51 -0
  78. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/SECURITY.md +104 -0
  79. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/bin/console +15 -0
  80. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/codecov.yml +12 -0
  81. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/data/list.txt +13380 -0
  82. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix.rb +179 -0
  83. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix/domain.rb +235 -0
  84. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix/errors.rb +41 -0
  85. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix/list.rb +247 -0
  86. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix/rule.rb +350 -0
  87. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/lib/public_suffix/version.rb +13 -0
  88. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/public_suffix.gemspec +29 -0
  89. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/acceptance_test.rb +131 -0
  90. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_find.rb +66 -0
  91. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_find_all.rb +102 -0
  92. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_names.rb +91 -0
  93. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_select.rb +26 -0
  94. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_select_incremental.rb +25 -0
  95. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/benchmarks/bm_valid.rb +101 -0
  96. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/domain_profiler.rb +12 -0
  97. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/find_profiler.rb +12 -0
  98. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/find_profiler_jp.rb +12 -0
  99. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/initialization_profiler.rb +11 -0
  100. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/list_profsize.rb +11 -0
  101. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/profilers/object_binsize.rb +57 -0
  102. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/psl_test.rb +52 -0
  103. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/test_helper.rb +18 -0
  104. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/tests.txt +98 -0
  105. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/unit/domain_test.rb +106 -0
  106. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/unit/errors_test.rb +25 -0
  107. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/unit/list_test.rb +241 -0
  108. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/unit/public_suffix_test.rb +188 -0
  109. data/vendor/bundle/jruby/2.5.0/gems/public_suffix-4.0.6/test/unit/rule_test.rb +222 -0
  110. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/LICENSE.txt +22 -0
  111. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/NEWS.md +178 -0
  112. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/README.md +48 -0
  113. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/context.rdoc +143 -0
  114. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/rdoc/child.rdoc +87 -0
  115. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/rdoc/document.rdoc +276 -0
  116. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/rdoc/element.rdoc +602 -0
  117. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/rdoc/node.rdoc +97 -0
  118. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/rdoc/parent.rdoc +267 -0
  119. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/child_toc.rdoc +12 -0
  120. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/document_toc.rdoc +30 -0
  121. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/element_toc.rdoc +55 -0
  122. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/master_toc.rdoc +135 -0
  123. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/node_toc.rdoc +16 -0
  124. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/doc/rexml/tasks/tocs/parent_toc.rdoc +25 -0
  125. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml.rb +3 -0
  126. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb +63 -0
  127. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/attribute.rb +205 -0
  128. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/cdata.rb +68 -0
  129. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/child.rb +97 -0
  130. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/comment.rb +80 -0
  131. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/doctype.rb +311 -0
  132. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/document.rb +451 -0
  133. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/dtd/attlistdecl.rb +11 -0
  134. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/dtd/dtd.rb +47 -0
  135. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/dtd/elementdecl.rb +18 -0
  136. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/dtd/entitydecl.rb +57 -0
  137. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/dtd/notationdecl.rb +40 -0
  138. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/element.rb +2599 -0
  139. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/encoding.rb +51 -0
  140. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/entity.rb +171 -0
  141. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb +116 -0
  142. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/formatters/pretty.rb +142 -0
  143. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/formatters/transitive.rb +58 -0
  144. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/functions.rb +447 -0
  145. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/instruction.rb +79 -0
  146. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/light/node.rb +188 -0
  147. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/namespace.rb +59 -0
  148. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/node.rb +76 -0
  149. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/output.rb +30 -0
  150. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parent.rb +166 -0
  151. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parseexception.rb +52 -0
  152. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb +694 -0
  153. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/lightparser.rb +59 -0
  154. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb +197 -0
  155. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb +273 -0
  156. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb +61 -0
  157. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/treeparser.rb +101 -0
  158. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/ultralightparser.rb +57 -0
  159. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/parsers/xpathparser.rb +689 -0
  160. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/quickpath.rb +266 -0
  161. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/rexml.rb +37 -0
  162. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/sax2listener.rb +98 -0
  163. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/security.rb +28 -0
  164. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/source.rb +298 -0
  165. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/streamlistener.rb +93 -0
  166. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/text.rb +424 -0
  167. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/undefinednamespaceexception.rb +9 -0
  168. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/validation/relaxng.rb +539 -0
  169. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/validation/validation.rb +144 -0
  170. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/validation/validationexception.rb +10 -0
  171. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/xmldecl.rb +130 -0
  172. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/xmltokens.rb +85 -0
  173. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/xpath.rb +81 -0
  174. data/vendor/bundle/jruby/2.5.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb +974 -0
  175. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/CHANGELOG.md +1894 -0
  176. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/Gemfile +9 -0
  177. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/LICENSE +20 -0
  178. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/README.md +1176 -0
  179. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/Rakefile +38 -0
  180. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock.rb +59 -0
  181. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/api.rb +109 -0
  182. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/assertion_failure.rb +11 -0
  183. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/callback_registry.rb +35 -0
  184. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/config.rb +18 -0
  185. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/cucumber.rb +10 -0
  186. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/deprecation.rb +9 -0
  187. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/errors.rb +17 -0
  188. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +216 -0
  189. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/curb_adapter.rb +351 -0
  190. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +231 -0
  191. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/excon_adapter.rb +165 -0
  192. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_lib_adapter.rb +7 -0
  193. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +19 -0
  194. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
  195. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb/request.rb +16 -0
  196. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb/response.rb +64 -0
  197. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb/streamer.rb +29 -0
  198. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb/webmock.rb +68 -0
  199. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/http_rb_adapter.rb +37 -0
  200. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/httpclient_adapter.rb +259 -0
  201. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/manticore_adapter.rb +145 -0
  202. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/net_http.rb +385 -0
  203. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/net_http_response.rb +34 -0
  204. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/patron_adapter.rb +130 -0
  205. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +174 -0
  206. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/matchers/any_arg_matcher.rb +13 -0
  207. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/matchers/hash_argument_matcher.rb +21 -0
  208. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/matchers/hash_excluding_matcher.rb +15 -0
  209. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/matchers/hash_including_matcher.rb +17 -0
  210. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/minitest.rb +41 -0
  211. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/rack_response.rb +69 -0
  212. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_body_diff.rb +64 -0
  213. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_execution_verifier.rb +77 -0
  214. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_pattern.rb +405 -0
  215. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_registry.rb +35 -0
  216. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_signature.rb +54 -0
  217. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_signature_snippet.rb +61 -0
  218. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/request_stub.rb +100 -0
  219. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/response.rb +159 -0
  220. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/responses_sequence.rb +40 -0
  221. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/rspec.rb +42 -0
  222. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/rspec/matchers.rb +27 -0
  223. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/rspec/matchers/request_pattern_matcher.rb +78 -0
  224. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/rspec/matchers/webmock_matcher.rb +67 -0
  225. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_registry.rb +82 -0
  226. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb +38 -0
  227. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/test_unit.rb +20 -0
  228. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb +39 -0
  229. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_keys_stringifier.rb +25 -0
  230. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_validator.rb +17 -0
  231. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/headers.rb +64 -0
  232. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/json.rb +67 -0
  233. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/query_mapper.rb +281 -0
  234. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/uri.rb +111 -0
  235. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/values_stringifier.rb +20 -0
  236. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/version_checker.rb +111 -0
  237. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/version.rb +3 -0
  238. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/webmock.rb +163 -0
  239. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/minitest/test_helper.rb +34 -0
  240. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/minitest/test_webmock.rb +9 -0
  241. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/minitest/webmock_spec.rb +60 -0
  242. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/async_http_client/async_http_client_spec.rb +375 -0
  243. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
  244. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/curb/curb_spec.rb +499 -0
  245. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/curb/curb_spec_helper.rb +147 -0
  246. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/em_http_request/em_http_request_spec.rb +462 -0
  247. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +77 -0
  248. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec.rb +77 -0
  249. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb +52 -0
  250. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/http_rb/http_rb_spec.rb +93 -0
  251. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/http_rb/http_rb_spec_helper.rb +54 -0
  252. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec.rb +217 -0
  253. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb +57 -0
  254. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/manticore/manticore_spec.rb +107 -0
  255. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/manticore/manticore_spec_helper.rb +35 -0
  256. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/net_http/net_http_shared.rb +153 -0
  257. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/net_http/net_http_spec.rb +369 -0
  258. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/net_http/net_http_spec_helper.rb +64 -0
  259. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/net_http/real_net_http_spec.rb +20 -0
  260. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/patron/patron_spec.rb +125 -0
  261. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/patron/patron_spec_helper.rb +54 -0
  262. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +313 -0
  263. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/callbacks.rb +148 -0
  264. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/complex_cross_concern_behaviors.rb +36 -0
  265. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/enabling_and_disabling_webmock.rb +95 -0
  266. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/precedence_of_stubs.rb +15 -0
  267. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/request_expectations.rb +930 -0
  268. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/returning_declared_responses.rb +409 -0
  269. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/shared/stubbing_requests.rb +678 -0
  270. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +135 -0
  271. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +60 -0
  272. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/webmock_shared.rb +41 -0
  273. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/fixtures/test.txt +1 -0
  274. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/quality_spec.rb +84 -0
  275. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/spec_helper.rb +48 -0
  276. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/support/example_curl_output.txt +22 -0
  277. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/support/failures.rb +9 -0
  278. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/support/my_rack_app.rb +53 -0
  279. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/support/network_connection.rb +19 -0
  280. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/support/webmock_server.rb +70 -0
  281. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/api_spec.rb +175 -0
  282. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/errors_spec.rb +129 -0
  283. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +17 -0
  284. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +12 -0
  285. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb +61 -0
  286. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_including_matcher_spec.rb +87 -0
  287. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/rack_response_spec.rb +112 -0
  288. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_body_diff_spec.rb +90 -0
  289. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_execution_verifier_spec.rb +208 -0
  290. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_pattern_spec.rb +736 -0
  291. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_registry_spec.rb +95 -0
  292. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_signature_snippet_spec.rb +89 -0
  293. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_signature_spec.rb +155 -0
  294. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/request_stub_spec.rb +199 -0
  295. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/response_spec.rb +286 -0
  296. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/stub_registry_spec.rb +103 -0
  297. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/stub_request_snippet_spec.rb +115 -0
  298. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/hash_counter_spec.rb +39 -0
  299. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/hash_keys_stringifier_spec.rb +27 -0
  300. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/headers_spec.rb +28 -0
  301. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/json_spec.rb +33 -0
  302. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/query_mapper_spec.rb +157 -0
  303. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/uri_spec.rb +371 -0
  304. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/util/version_checker_spec.rb +65 -0
  305. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/webmock_spec.rb +60 -0
  306. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/test/http_request.rb +24 -0
  307. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/test/shared_test.rb +108 -0
  308. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/test/test_helper.rb +23 -0
  309. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/test/test_webmock.rb +12 -0
  310. data/vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/webmock.gemspec +54 -0
  311. data/vendor/bundle/jruby/2.5.0/specifications/addressable-2.7.0.gemspec +39 -0
  312. data/vendor/bundle/jruby/2.5.0/specifications/crack-0.4.5.gemspec +32 -0
  313. data/vendor/bundle/jruby/2.5.0/specifications/hashdiff-1.0.1.gemspec +46 -0
  314. data/vendor/bundle/jruby/2.5.0/specifications/public_suffix-4.0.6.gemspec +24 -0
  315. data/vendor/bundle/jruby/2.5.0/specifications/rexml-3.2.5.gemspec +42 -0
  316. data/vendor/bundle/jruby/2.5.0/specifications/webmock-3.13.0.gemspec +85 -0
  317. metadata +309 -2
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # coding: utf-8
4
+ # Copyright (C) Bob Aman
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+
19
+ require "spec_helper"
20
+
21
+ require "addressable/uri"
22
+
23
+ describe Addressable::URI, "when created with a URI known to cause crashes " +
24
+ "in certain browsers" do
25
+ it "should parse correctly" do
26
+ uri = Addressable::URI.parse('%%30%30')
27
+ expect(uri.path).to eq('%%30%30')
28
+ expect(uri.normalize.path).to eq('%2500')
29
+ end
30
+
31
+ it "should parse correctly as a full URI" do
32
+ uri = Addressable::URI.parse('http://www.example.com/%%30%30')
33
+ expect(uri.path).to eq('/%%30%30')
34
+ expect(uri.normalize.path).to eq('/%2500')
35
+ end
36
+ end
37
+
38
+ describe Addressable::URI, "when created with a URI known to cause crashes " +
39
+ "in certain browsers" do
40
+ it "should parse correctly" do
41
+ uri = Addressable::URI.parse('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
42
+ expect(uri.path).to eq('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
43
+ expect(uri.normalize.path).to eq(
44
+ '%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
45
+ '%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
46
+ '%A3%20%E0%A5%A3%20%E5%86%97'
47
+ )
48
+ end
49
+
50
+ it "should parse correctly as a full URI" do
51
+ uri = Addressable::URI.parse('http://www.example.com/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
52
+ expect(uri.path).to eq('/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
53
+ expect(uri.normalize.path).to eq(
54
+ '/%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
55
+ '%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
56
+ '%A3%20%E0%A5%A3%20%E5%86%97'
57
+ )
58
+ end
59
+ end
@@ -0,0 +1,1451 @@
1
+ # frozen_string_literal: true
2
+
3
+ # coding: utf-8
4
+ # Copyright (C) Bob Aman
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+
19
+ require "spec_helper"
20
+
21
+ require "bigdecimal"
22
+ require "addressable/template"
23
+
24
+ shared_examples_for 'expands' do |tests|
25
+ tests.each do |template, expansion|
26
+ exp = expansion.is_a?(Array) ? expansion.first : expansion
27
+ it "#{template} to #{exp}" do
28
+ tmpl = Addressable::Template.new(template).expand(subject)
29
+ if expansion.is_a?(Array)
30
+ expect(expansion.any?{|i| i == tmpl.to_str}).to be true
31
+ else
32
+ expect(tmpl.to_str).to eq(expansion)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "eql?" do
39
+ let(:template) { Addressable::Template.new('https://www.example.com/{foo}') }
40
+ it 'is equal when the pattern matches' do
41
+ other_template = Addressable::Template.new('https://www.example.com/{foo}')
42
+ expect(template).to be_eql(other_template)
43
+ expect(other_template).to be_eql(template)
44
+ end
45
+ it 'is not equal when the pattern differs' do
46
+ other_template = Addressable::Template.new('https://www.example.com/{bar}')
47
+ expect(template).to_not be_eql(other_template)
48
+ expect(other_template).to_not be_eql(template)
49
+ end
50
+ it 'is not equal to non-templates' do
51
+ uri = 'https://www.example.com/foo/bar'
52
+ addressable_template = Addressable::Template.new uri
53
+ addressable_uri = Addressable::URI.parse uri
54
+ expect(addressable_template).to_not be_eql(addressable_uri)
55
+ expect(addressable_uri).to_not be_eql(addressable_template)
56
+ end
57
+ end
58
+
59
+ describe "==" do
60
+ let(:template) { Addressable::Template.new('https://www.example.com/{foo}') }
61
+ it 'is equal when the pattern matches' do
62
+ other_template = Addressable::Template.new('https://www.example.com/{foo}')
63
+ expect(template).to eq other_template
64
+ expect(other_template).to eq template
65
+ end
66
+ it 'is not equal when the pattern differs' do
67
+ other_template = Addressable::Template.new('https://www.example.com/{bar}')
68
+ expect(template).not_to eq other_template
69
+ expect(other_template).not_to eq template
70
+ end
71
+ it 'is not equal to non-templates' do
72
+ uri = 'https://www.example.com/foo/bar'
73
+ addressable_template = Addressable::Template.new uri
74
+ addressable_uri = Addressable::URI.parse uri
75
+ expect(addressable_template).not_to eq addressable_uri
76
+ expect(addressable_uri).not_to eq addressable_template
77
+ end
78
+ end
79
+
80
+ describe "Type conversion" do
81
+ subject {
82
+ {
83
+ :var => true,
84
+ :hello => 1234,
85
+ :nothing => nil,
86
+ :sym => :symbolic,
87
+ :decimal => BigDecimal('1')
88
+ }
89
+ }
90
+
91
+ it_behaves_like 'expands', {
92
+ '{var}' => 'true',
93
+ '{hello}' => '1234',
94
+ '{nothing}' => '',
95
+ '{sym}' => 'symbolic',
96
+ '{decimal}' => RUBY_VERSION < '2.4.0' ? '0.1E1' : '0.1e1'
97
+ }
98
+ end
99
+
100
+ describe "Level 1:" do
101
+ subject {
102
+ {:var => "value", :hello => "Hello World!"}
103
+ }
104
+ it_behaves_like 'expands', {
105
+ '{var}' => 'value',
106
+ '{hello}' => 'Hello%20World%21'
107
+ }
108
+ end
109
+
110
+ describe "Level 2" do
111
+ subject {
112
+ {
113
+ :var => "value",
114
+ :hello => "Hello World!",
115
+ :path => "/foo/bar"
116
+ }
117
+ }
118
+ context "Operator +:" do
119
+ it_behaves_like 'expands', {
120
+ '{+var}' => 'value',
121
+ '{+hello}' => 'Hello%20World!',
122
+ '{+path}/here' => '/foo/bar/here',
123
+ 'here?ref={+path}' => 'here?ref=/foo/bar'
124
+ }
125
+ end
126
+ context "Operator #:" do
127
+ it_behaves_like 'expands', {
128
+ 'X{#var}' => 'X#value',
129
+ 'X{#hello}' => 'X#Hello%20World!'
130
+ }
131
+ end
132
+ end
133
+
134
+ describe "Level 3" do
135
+ subject {
136
+ {
137
+ :var => "value",
138
+ :hello => "Hello World!",
139
+ :empty => "",
140
+ :path => "/foo/bar",
141
+ :x => "1024",
142
+ :y => "768"
143
+ }
144
+ }
145
+ context "Operator nil (multiple vars):" do
146
+ it_behaves_like 'expands', {
147
+ 'map?{x,y}' => 'map?1024,768',
148
+ '{x,hello,y}' => '1024,Hello%20World%21,768'
149
+ }
150
+ end
151
+ context "Operator + (multiple vars):" do
152
+ it_behaves_like 'expands', {
153
+ '{+x,hello,y}' => '1024,Hello%20World!,768',
154
+ '{+path,x}/here' => '/foo/bar,1024/here'
155
+ }
156
+ end
157
+ context "Operator # (multiple vars):" do
158
+ it_behaves_like 'expands', {
159
+ '{#x,hello,y}' => '#1024,Hello%20World!,768',
160
+ '{#path,x}/here' => '#/foo/bar,1024/here'
161
+ }
162
+ end
163
+ context "Operator ." do
164
+ it_behaves_like 'expands', {
165
+ 'X{.var}' => 'X.value',
166
+ 'X{.x,y}' => 'X.1024.768'
167
+ }
168
+ end
169
+ context "Operator /" do
170
+ it_behaves_like 'expands', {
171
+ '{/var}' => '/value',
172
+ '{/var,x}/here' => '/value/1024/here'
173
+ }
174
+ end
175
+ context "Operator ;" do
176
+ it_behaves_like 'expands', {
177
+ '{;x,y}' => ';x=1024;y=768',
178
+ '{;x,y,empty}' => ';x=1024;y=768;empty'
179
+ }
180
+ end
181
+ context "Operator ?" do
182
+ it_behaves_like 'expands', {
183
+ '{?x,y}' => '?x=1024&y=768',
184
+ '{?x,y,empty}' => '?x=1024&y=768&empty='
185
+ }
186
+ end
187
+ context "Operator &" do
188
+ it_behaves_like 'expands', {
189
+ '?fixed=yes{&x}' => '?fixed=yes&x=1024',
190
+ '{&x,y,empty}' => '&x=1024&y=768&empty='
191
+ }
192
+ end
193
+ end
194
+
195
+ describe "Level 4" do
196
+ subject {
197
+ {
198
+ :var => "value",
199
+ :hello => "Hello World!",
200
+ :path => "/foo/bar",
201
+ :semi => ";",
202
+ :list => %w(red green blue),
203
+ :keys => {"semi" => ';', "dot" => '.', "comma" => ','}
204
+ }
205
+ }
206
+ context "Expansion with value modifiers" do
207
+ it_behaves_like 'expands', {
208
+ '{var:3}' => 'val',
209
+ '{var:30}' => 'value',
210
+ '{list}' => 'red,green,blue',
211
+ '{list*}' => 'red,green,blue',
212
+ '{keys}' => [
213
+ 'semi,%3B,dot,.,comma,%2C',
214
+ 'dot,.,semi,%3B,comma,%2C',
215
+ 'comma,%2C,semi,%3B,dot,.',
216
+ 'semi,%3B,comma,%2C,dot,.',
217
+ 'dot,.,comma,%2C,semi,%3B',
218
+ 'comma,%2C,dot,.,semi,%3B'
219
+ ],
220
+ '{keys*}' => [
221
+ 'semi=%3B,dot=.,comma=%2C',
222
+ 'dot=.,semi=%3B,comma=%2C',
223
+ 'comma=%2C,semi=%3B,dot=.',
224
+ 'semi=%3B,comma=%2C,dot=.',
225
+ 'dot=.,comma=%2C,semi=%3B',
226
+ 'comma=%2C,dot=.,semi=%3B'
227
+ ]
228
+ }
229
+ end
230
+ context "Operator + with value modifiers" do
231
+ it_behaves_like 'expands', {
232
+ '{+path:6}/here' => '/foo/b/here',
233
+ '{+list}' => 'red,green,blue',
234
+ '{+list*}' => 'red,green,blue',
235
+ '{+keys}' => [
236
+ 'semi,;,dot,.,comma,,',
237
+ 'dot,.,semi,;,comma,,',
238
+ 'comma,,,semi,;,dot,.',
239
+ 'semi,;,comma,,,dot,.',
240
+ 'dot,.,comma,,,semi,;',
241
+ 'comma,,,dot,.,semi,;'
242
+ ],
243
+ '{+keys*}' => [
244
+ 'semi=;,dot=.,comma=,',
245
+ 'dot=.,semi=;,comma=,',
246
+ 'comma=,,semi=;,dot=.',
247
+ 'semi=;,comma=,,dot=.',
248
+ 'dot=.,comma=,,semi=;',
249
+ 'comma=,,dot=.,semi=;'
250
+ ]
251
+ }
252
+ end
253
+ context "Operator # with value modifiers" do
254
+ it_behaves_like 'expands', {
255
+ '{#path:6}/here' => '#/foo/b/here',
256
+ '{#list}' => '#red,green,blue',
257
+ '{#list*}' => '#red,green,blue',
258
+ '{#keys}' => [
259
+ '#semi,;,dot,.,comma,,',
260
+ '#dot,.,semi,;,comma,,',
261
+ '#comma,,,semi,;,dot,.',
262
+ '#semi,;,comma,,,dot,.',
263
+ '#dot,.,comma,,,semi,;',
264
+ '#comma,,,dot,.,semi,;'
265
+ ],
266
+ '{#keys*}' => [
267
+ '#semi=;,dot=.,comma=,',
268
+ '#dot=.,semi=;,comma=,',
269
+ '#comma=,,semi=;,dot=.',
270
+ '#semi=;,comma=,,dot=.',
271
+ '#dot=.,comma=,,semi=;',
272
+ '#comma=,,dot=.,semi=;'
273
+ ]
274
+ }
275
+ end
276
+ context "Operator . with value modifiers" do
277
+ it_behaves_like 'expands', {
278
+ 'X{.var:3}' => 'X.val',
279
+ 'X{.list}' => 'X.red,green,blue',
280
+ 'X{.list*}' => 'X.red.green.blue',
281
+ 'X{.keys}' => [
282
+ 'X.semi,%3B,dot,.,comma,%2C',
283
+ 'X.dot,.,semi,%3B,comma,%2C',
284
+ 'X.comma,%2C,semi,%3B,dot,.',
285
+ 'X.semi,%3B,comma,%2C,dot,.',
286
+ 'X.dot,.,comma,%2C,semi,%3B',
287
+ 'X.comma,%2C,dot,.,semi,%3B'
288
+ ],
289
+ 'X{.keys*}' => [
290
+ 'X.semi=%3B.dot=..comma=%2C',
291
+ 'X.dot=..semi=%3B.comma=%2C',
292
+ 'X.comma=%2C.semi=%3B.dot=.',
293
+ 'X.semi=%3B.comma=%2C.dot=.',
294
+ 'X.dot=..comma=%2C.semi=%3B',
295
+ 'X.comma=%2C.dot=..semi=%3B'
296
+ ]
297
+ }
298
+ end
299
+ context "Operator / with value modifiers" do
300
+ it_behaves_like 'expands', {
301
+ '{/var:1,var}' => '/v/value',
302
+ '{/list}' => '/red,green,blue',
303
+ '{/list*}' => '/red/green/blue',
304
+ '{/list*,path:4}' => '/red/green/blue/%2Ffoo',
305
+ '{/keys}' => [
306
+ '/semi,%3B,dot,.,comma,%2C',
307
+ '/dot,.,semi,%3B,comma,%2C',
308
+ '/comma,%2C,semi,%3B,dot,.',
309
+ '/semi,%3B,comma,%2C,dot,.',
310
+ '/dot,.,comma,%2C,semi,%3B',
311
+ '/comma,%2C,dot,.,semi,%3B'
312
+ ],
313
+ '{/keys*}' => [
314
+ '/semi=%3B/dot=./comma=%2C',
315
+ '/dot=./semi=%3B/comma=%2C',
316
+ '/comma=%2C/semi=%3B/dot=.',
317
+ '/semi=%3B/comma=%2C/dot=.',
318
+ '/dot=./comma=%2C/semi=%3B',
319
+ '/comma=%2C/dot=./semi=%3B'
320
+ ]
321
+ }
322
+ end
323
+ context "Operator ; with value modifiers" do
324
+ it_behaves_like 'expands', {
325
+ '{;hello:5}' => ';hello=Hello',
326
+ '{;list}' => ';list=red,green,blue',
327
+ '{;list*}' => ';list=red;list=green;list=blue',
328
+ '{;keys}' => [
329
+ ';keys=semi,%3B,dot,.,comma,%2C',
330
+ ';keys=dot,.,semi,%3B,comma,%2C',
331
+ ';keys=comma,%2C,semi,%3B,dot,.',
332
+ ';keys=semi,%3B,comma,%2C,dot,.',
333
+ ';keys=dot,.,comma,%2C,semi,%3B',
334
+ ';keys=comma,%2C,dot,.,semi,%3B'
335
+ ],
336
+ '{;keys*}' => [
337
+ ';semi=%3B;dot=.;comma=%2C',
338
+ ';dot=.;semi=%3B;comma=%2C',
339
+ ';comma=%2C;semi=%3B;dot=.',
340
+ ';semi=%3B;comma=%2C;dot=.',
341
+ ';dot=.;comma=%2C;semi=%3B',
342
+ ';comma=%2C;dot=.;semi=%3B'
343
+ ]
344
+ }
345
+ end
346
+ context "Operator ? with value modifiers" do
347
+ it_behaves_like 'expands', {
348
+ '{?var:3}' => '?var=val',
349
+ '{?list}' => '?list=red,green,blue',
350
+ '{?list*}' => '?list=red&list=green&list=blue',
351
+ '{?keys}' => [
352
+ '?keys=semi,%3B,dot,.,comma,%2C',
353
+ '?keys=dot,.,semi,%3B,comma,%2C',
354
+ '?keys=comma,%2C,semi,%3B,dot,.',
355
+ '?keys=semi,%3B,comma,%2C,dot,.',
356
+ '?keys=dot,.,comma,%2C,semi,%3B',
357
+ '?keys=comma,%2C,dot,.,semi,%3B'
358
+ ],
359
+ '{?keys*}' => [
360
+ '?semi=%3B&dot=.&comma=%2C',
361
+ '?dot=.&semi=%3B&comma=%2C',
362
+ '?comma=%2C&semi=%3B&dot=.',
363
+ '?semi=%3B&comma=%2C&dot=.',
364
+ '?dot=.&comma=%2C&semi=%3B',
365
+ '?comma=%2C&dot=.&semi=%3B'
366
+ ]
367
+ }
368
+ end
369
+ context "Operator & with value modifiers" do
370
+ it_behaves_like 'expands', {
371
+ '{&var:3}' => '&var=val',
372
+ '{&list}' => '&list=red,green,blue',
373
+ '{&list*}' => '&list=red&list=green&list=blue',
374
+ '{&keys}' => [
375
+ '&keys=semi,%3B,dot,.,comma,%2C',
376
+ '&keys=dot,.,semi,%3B,comma,%2C',
377
+ '&keys=comma,%2C,semi,%3B,dot,.',
378
+ '&keys=semi,%3B,comma,%2C,dot,.',
379
+ '&keys=dot,.,comma,%2C,semi,%3B',
380
+ '&keys=comma,%2C,dot,.,semi,%3B'
381
+ ],
382
+ '{&keys*}' => [
383
+ '&semi=%3B&dot=.&comma=%2C',
384
+ '&dot=.&semi=%3B&comma=%2C',
385
+ '&comma=%2C&semi=%3B&dot=.',
386
+ '&semi=%3B&comma=%2C&dot=.',
387
+ '&dot=.&comma=%2C&semi=%3B',
388
+ '&comma=%2C&dot=.&semi=%3B'
389
+ ]
390
+ }
391
+ end
392
+ end
393
+ describe "Modifiers" do
394
+ subject {
395
+ {
396
+ :var => "value",
397
+ :semi => ";",
398
+ :year => %w(1965 2000 2012),
399
+ :dom => %w(example com)
400
+ }
401
+ }
402
+ context "length" do
403
+ it_behaves_like 'expands', {
404
+ '{var:3}' => 'val',
405
+ '{var:30}' => 'value',
406
+ '{var}' => 'value',
407
+ '{semi}' => '%3B',
408
+ '{semi:2}' => '%3B'
409
+ }
410
+ end
411
+ context "explode" do
412
+ it_behaves_like 'expands', {
413
+ 'find{?year*}' => 'find?year=1965&year=2000&year=2012',
414
+ 'www{.dom*}' => 'www.example.com',
415
+ }
416
+ end
417
+ end
418
+ describe "Expansion" do
419
+ subject {
420
+ {
421
+ :count => ["one", "two", "three"],
422
+ :dom => ["example", "com"],
423
+ :dub => "me/too",
424
+ :hello => "Hello World!",
425
+ :half => "50%",
426
+ :var => "value",
427
+ :who => "fred",
428
+ :base => "http://example.com/home/",
429
+ :path => "/foo/bar",
430
+ :list => ["red", "green", "blue"],
431
+ :keys => {"semi" => ";","dot" => ".","comma" => ","},
432
+ :v => "6",
433
+ :x => "1024",
434
+ :y => "768",
435
+ :empty => "",
436
+ :empty_keys => {},
437
+ :undef => nil
438
+ }
439
+ }
440
+ context "concatenation" do
441
+ it_behaves_like 'expands', {
442
+ '{count}' => 'one,two,three',
443
+ '{count*}' => 'one,two,three',
444
+ '{/count}' => '/one,two,three',
445
+ '{/count*}' => '/one/two/three',
446
+ '{;count}' => ';count=one,two,three',
447
+ '{;count*}' => ';count=one;count=two;count=three',
448
+ '{?count}' => '?count=one,two,three',
449
+ '{?count*}' => '?count=one&count=two&count=three',
450
+ '{&count*}' => '&count=one&count=two&count=three'
451
+ }
452
+ end
453
+ context "simple expansion" do
454
+ it_behaves_like 'expands', {
455
+ '{var}' => 'value',
456
+ '{hello}' => 'Hello%20World%21',
457
+ '{half}' => '50%25',
458
+ 'O{empty}X' => 'OX',
459
+ 'O{undef}X' => 'OX',
460
+ '{x,y}' => '1024,768',
461
+ '{x,hello,y}' => '1024,Hello%20World%21,768',
462
+ '?{x,empty}' => '?1024,',
463
+ '?{x,undef}' => '?1024',
464
+ '?{undef,y}' => '?768',
465
+ '{var:3}' => 'val',
466
+ '{var:30}' => 'value',
467
+ '{list}' => 'red,green,blue',
468
+ '{list*}' => 'red,green,blue',
469
+ '{keys}' => [
470
+ 'semi,%3B,dot,.,comma,%2C',
471
+ 'dot,.,semi,%3B,comma,%2C',
472
+ 'comma,%2C,semi,%3B,dot,.',
473
+ 'semi,%3B,comma,%2C,dot,.',
474
+ 'dot,.,comma,%2C,semi,%3B',
475
+ 'comma,%2C,dot,.,semi,%3B'
476
+ ],
477
+ '{keys*}' => [
478
+ 'semi=%3B,dot=.,comma=%2C',
479
+ 'dot=.,semi=%3B,comma=%2C',
480
+ 'comma=%2C,semi=%3B,dot=.',
481
+ 'semi=%3B,comma=%2C,dot=.',
482
+ 'dot=.,comma=%2C,semi=%3B',
483
+ 'comma=%2C,dot=.,semi=%3B'
484
+ ]
485
+ }
486
+ end
487
+ context "reserved expansion (+)" do
488
+ it_behaves_like 'expands', {
489
+ '{+var}' => 'value',
490
+ '{+hello}' => 'Hello%20World!',
491
+ '{+half}' => '50%25',
492
+ '{base}index' => 'http%3A%2F%2Fexample.com%2Fhome%2Findex',
493
+ '{+base}index' => 'http://example.com/home/index',
494
+ 'O{+empty}X' => 'OX',
495
+ 'O{+undef}X' => 'OX',
496
+ '{+path}/here' => '/foo/bar/here',
497
+ 'here?ref={+path}' => 'here?ref=/foo/bar',
498
+ 'up{+path}{var}/here' => 'up/foo/barvalue/here',
499
+ '{+x,hello,y}' => '1024,Hello%20World!,768',
500
+ '{+path,x}/here' => '/foo/bar,1024/here',
501
+ '{+path:6}/here' => '/foo/b/here',
502
+ '{+list}' => 'red,green,blue',
503
+ '{+list*}' => 'red,green,blue',
504
+ '{+keys}' => [
505
+ 'semi,;,dot,.,comma,,',
506
+ 'dot,.,semi,;,comma,,',
507
+ 'comma,,,semi,;,dot,.',
508
+ 'semi,;,comma,,,dot,.',
509
+ 'dot,.,comma,,,semi,;',
510
+ 'comma,,,dot,.,semi,;'
511
+ ],
512
+ '{+keys*}' => [
513
+ 'semi=;,dot=.,comma=,',
514
+ 'dot=.,semi=;,comma=,',
515
+ 'comma=,,semi=;,dot=.',
516
+ 'semi=;,comma=,,dot=.',
517
+ 'dot=.,comma=,,semi=;',
518
+ 'comma=,,dot=.,semi=;'
519
+ ]
520
+ }
521
+ end
522
+ context "fragment expansion (#)" do
523
+ it_behaves_like 'expands', {
524
+ '{#var}' => '#value',
525
+ '{#hello}' => '#Hello%20World!',
526
+ '{#half}' => '#50%25',
527
+ 'foo{#empty}' => 'foo#',
528
+ 'foo{#undef}' => 'foo',
529
+ '{#x,hello,y}' => '#1024,Hello%20World!,768',
530
+ '{#path,x}/here' => '#/foo/bar,1024/here',
531
+ '{#path:6}/here' => '#/foo/b/here',
532
+ '{#list}' => '#red,green,blue',
533
+ '{#list*}' => '#red,green,blue',
534
+ '{#keys}' => [
535
+ '#semi,;,dot,.,comma,,',
536
+ '#dot,.,semi,;,comma,,',
537
+ '#comma,,,semi,;,dot,.',
538
+ '#semi,;,comma,,,dot,.',
539
+ '#dot,.,comma,,,semi,;',
540
+ '#comma,,,dot,.,semi,;'
541
+ ],
542
+ '{#keys*}' => [
543
+ '#semi=;,dot=.,comma=,',
544
+ '#dot=.,semi=;,comma=,',
545
+ '#comma=,,semi=;,dot=.',
546
+ '#semi=;,comma=,,dot=.',
547
+ '#dot=.,comma=,,semi=;',
548
+ '#comma=,,dot=.,semi=;'
549
+ ]
550
+ }
551
+ end
552
+ context "label expansion (.)" do
553
+ it_behaves_like 'expands', {
554
+ '{.who}' => '.fred',
555
+ '{.who,who}' => '.fred.fred',
556
+ '{.half,who}' => '.50%25.fred',
557
+ 'www{.dom*}' => 'www.example.com',
558
+ 'X{.var}' => 'X.value',
559
+ 'X{.empty}' => 'X.',
560
+ 'X{.undef}' => 'X',
561
+ 'X{.var:3}' => 'X.val',
562
+ 'X{.list}' => 'X.red,green,blue',
563
+ 'X{.list*}' => 'X.red.green.blue',
564
+ 'X{.keys}' => [
565
+ 'X.semi,%3B,dot,.,comma,%2C',
566
+ 'X.dot,.,semi,%3B,comma,%2C',
567
+ 'X.comma,%2C,semi,%3B,dot,.',
568
+ 'X.semi,%3B,comma,%2C,dot,.',
569
+ 'X.dot,.,comma,%2C,semi,%3B',
570
+ 'X.comma,%2C,dot,.,semi,%3B'
571
+ ],
572
+ 'X{.keys*}' => [
573
+ 'X.semi=%3B.dot=..comma=%2C',
574
+ 'X.dot=..semi=%3B.comma=%2C',
575
+ 'X.comma=%2C.semi=%3B.dot=.',
576
+ 'X.semi=%3B.comma=%2C.dot=.',
577
+ 'X.dot=..comma=%2C.semi=%3B',
578
+ 'X.comma=%2C.dot=..semi=%3B'
579
+ ],
580
+ 'X{.empty_keys}' => 'X',
581
+ 'X{.empty_keys*}' => 'X'
582
+ }
583
+ end
584
+ context "path expansion (/)" do
585
+ it_behaves_like 'expands', {
586
+ '{/who}' => '/fred',
587
+ '{/who,who}' => '/fred/fred',
588
+ '{/half,who}' => '/50%25/fred',
589
+ '{/who,dub}' => '/fred/me%2Ftoo',
590
+ '{/var}' => '/value',
591
+ '{/var,empty}' => '/value/',
592
+ '{/var,undef}' => '/value',
593
+ '{/var,x}/here' => '/value/1024/here',
594
+ '{/var:1,var}' => '/v/value',
595
+ '{/list}' => '/red,green,blue',
596
+ '{/list*}' => '/red/green/blue',
597
+ '{/list*,path:4}' => '/red/green/blue/%2Ffoo',
598
+ '{/keys}' => [
599
+ '/semi,%3B,dot,.,comma,%2C',
600
+ '/dot,.,semi,%3B,comma,%2C',
601
+ '/comma,%2C,semi,%3B,dot,.',
602
+ '/semi,%3B,comma,%2C,dot,.',
603
+ '/dot,.,comma,%2C,semi,%3B',
604
+ '/comma,%2C,dot,.,semi,%3B'
605
+ ],
606
+ '{/keys*}' => [
607
+ '/semi=%3B/dot=./comma=%2C',
608
+ '/dot=./semi=%3B/comma=%2C',
609
+ '/comma=%2C/semi=%3B/dot=.',
610
+ '/semi=%3B/comma=%2C/dot=.',
611
+ '/dot=./comma=%2C/semi=%3B',
612
+ '/comma=%2C/dot=./semi=%3B'
613
+ ]
614
+ }
615
+ end
616
+ context "path-style expansion (;)" do
617
+ it_behaves_like 'expands', {
618
+ '{;who}' => ';who=fred',
619
+ '{;half}' => ';half=50%25',
620
+ '{;empty}' => ';empty',
621
+ '{;v,empty,who}' => ';v=6;empty;who=fred',
622
+ '{;v,bar,who}' => ';v=6;who=fred',
623
+ '{;x,y}' => ';x=1024;y=768',
624
+ '{;x,y,empty}' => ';x=1024;y=768;empty',
625
+ '{;x,y,undef}' => ';x=1024;y=768',
626
+ '{;hello:5}' => ';hello=Hello',
627
+ '{;list}' => ';list=red,green,blue',
628
+ '{;list*}' => ';list=red;list=green;list=blue',
629
+ '{;keys}' => [
630
+ ';keys=semi,%3B,dot,.,comma,%2C',
631
+ ';keys=dot,.,semi,%3B,comma,%2C',
632
+ ';keys=comma,%2C,semi,%3B,dot,.',
633
+ ';keys=semi,%3B,comma,%2C,dot,.',
634
+ ';keys=dot,.,comma,%2C,semi,%3B',
635
+ ';keys=comma,%2C,dot,.,semi,%3B'
636
+ ],
637
+ '{;keys*}' => [
638
+ ';semi=%3B;dot=.;comma=%2C',
639
+ ';dot=.;semi=%3B;comma=%2C',
640
+ ';comma=%2C;semi=%3B;dot=.',
641
+ ';semi=%3B;comma=%2C;dot=.',
642
+ ';dot=.;comma=%2C;semi=%3B',
643
+ ';comma=%2C;dot=.;semi=%3B'
644
+ ]
645
+ }
646
+ end
647
+ context "form query expansion (?)" do
648
+ it_behaves_like 'expands', {
649
+ '{?who}' => '?who=fred',
650
+ '{?half}' => '?half=50%25',
651
+ '{?x,y}' => '?x=1024&y=768',
652
+ '{?x,y,empty}' => '?x=1024&y=768&empty=',
653
+ '{?x,y,undef}' => '?x=1024&y=768',
654
+ '{?var:3}' => '?var=val',
655
+ '{?list}' => '?list=red,green,blue',
656
+ '{?list*}' => '?list=red&list=green&list=blue',
657
+ '{?keys}' => [
658
+ '?keys=semi,%3B,dot,.,comma,%2C',
659
+ '?keys=dot,.,semi,%3B,comma,%2C',
660
+ '?keys=comma,%2C,semi,%3B,dot,.',
661
+ '?keys=semi,%3B,comma,%2C,dot,.',
662
+ '?keys=dot,.,comma,%2C,semi,%3B',
663
+ '?keys=comma,%2C,dot,.,semi,%3B'
664
+ ],
665
+ '{?keys*}' => [
666
+ '?semi=%3B&dot=.&comma=%2C',
667
+ '?dot=.&semi=%3B&comma=%2C',
668
+ '?comma=%2C&semi=%3B&dot=.',
669
+ '?semi=%3B&comma=%2C&dot=.',
670
+ '?dot=.&comma=%2C&semi=%3B',
671
+ '?comma=%2C&dot=.&semi=%3B'
672
+ ]
673
+ }
674
+ end
675
+ context "form query expansion (&)" do
676
+ it_behaves_like 'expands', {
677
+ '{&who}' => '&who=fred',
678
+ '{&half}' => '&half=50%25',
679
+ '?fixed=yes{&x}' => '?fixed=yes&x=1024',
680
+ '{&x,y,empty}' => '&x=1024&y=768&empty=',
681
+ '{&x,y,undef}' => '&x=1024&y=768',
682
+ '{&var:3}' => '&var=val',
683
+ '{&list}' => '&list=red,green,blue',
684
+ '{&list*}' => '&list=red&list=green&list=blue',
685
+ '{&keys}' => [
686
+ '&keys=semi,%3B,dot,.,comma,%2C',
687
+ '&keys=dot,.,semi,%3B,comma,%2C',
688
+ '&keys=comma,%2C,semi,%3B,dot,.',
689
+ '&keys=semi,%3B,comma,%2C,dot,.',
690
+ '&keys=dot,.,comma,%2C,semi,%3B',
691
+ '&keys=comma,%2C,dot,.,semi,%3B'
692
+ ],
693
+ '{&keys*}' => [
694
+ '&semi=%3B&dot=.&comma=%2C',
695
+ '&dot=.&semi=%3B&comma=%2C',
696
+ '&comma=%2C&semi=%3B&dot=.',
697
+ '&semi=%3B&comma=%2C&dot=.',
698
+ '&dot=.&comma=%2C&semi=%3B',
699
+ '&comma=%2C&dot=.&semi=%3B'
700
+ ]
701
+ }
702
+ end
703
+ context "non-string key in match data" do
704
+ subject {Addressable::Template.new("http://example.com/{one}")}
705
+
706
+ it "raises TypeError" do
707
+ expect { subject.expand(Object.new => "1") }.to raise_error TypeError
708
+ end
709
+ end
710
+ end
711
+
712
+ class ExampleTwoProcessor
713
+ def self.restore(name, value)
714
+ return value.gsub(/-/, " ") if name == "query"
715
+ return value
716
+ end
717
+
718
+ def self.match(name)
719
+ return ".*?" if name == "first"
720
+ return ".*"
721
+ end
722
+ def self.validate(name, value)
723
+ return !!(value =~ /^[\w ]+$/) if name == "query"
724
+ return true
725
+ end
726
+
727
+ def self.transform(name, value)
728
+ return value.gsub(/ /, "+") if name == "query"
729
+ return value
730
+ end
731
+ end
732
+
733
+ class DumbProcessor
734
+ def self.match(name)
735
+ return ".*?" if name == "first"
736
+ end
737
+ end
738
+
739
+ describe Addressable::Template do
740
+ describe 'initialize' do
741
+ context 'with a non-string' do
742
+ it 'raises a TypeError' do
743
+ expect { Addressable::Template.new(nil) }.to raise_error(TypeError)
744
+ end
745
+ end
746
+ end
747
+
748
+ describe 'freeze' do
749
+ subject { Addressable::Template.new("http://example.com/{first}/{+second}/") }
750
+ it 'freezes the template' do
751
+ expect(subject.freeze).to be_frozen
752
+ end
753
+ end
754
+
755
+ describe "Matching" do
756
+ let(:uri){
757
+ Addressable::URI.parse(
758
+ "http://example.com/search/an-example-search-query/"
759
+ )
760
+ }
761
+ let(:uri2){
762
+ Addressable::URI.parse("http://example.com/a/b/c/")
763
+ }
764
+ let(:uri3){
765
+ Addressable::URI.parse("http://example.com/;a=1;b=2;c=3;first=foo")
766
+ }
767
+ let(:uri4){
768
+ Addressable::URI.parse("http://example.com/?a=1&b=2&c=3&first=foo")
769
+ }
770
+ let(:uri5){
771
+ "http://example.com/foo"
772
+ }
773
+ context "first uri with ExampleTwoProcessor" do
774
+ subject {
775
+ Addressable::Template.new(
776
+ "http://example.com/search/{query}/"
777
+ ).match(uri, ExampleTwoProcessor)
778
+ }
779
+ its(:variables){ should == ["query"] }
780
+ its(:captures){ should == ["an example search query"] }
781
+ end
782
+
783
+ context "second uri with ExampleTwoProcessor" do
784
+ subject {
785
+ Addressable::Template.new(
786
+ "http://example.com/{first}/{+second}/"
787
+ ).match(uri2, ExampleTwoProcessor)
788
+ }
789
+ its(:variables){ should == ["first", "second"] }
790
+ its(:captures){ should == ["a", "b/c"] }
791
+ end
792
+
793
+ context "second uri with DumbProcessor" do
794
+ subject {
795
+ Addressable::Template.new(
796
+ "http://example.com/{first}/{+second}/"
797
+ ).match(uri2, DumbProcessor)
798
+ }
799
+ its(:variables){ should == ["first", "second"] }
800
+ its(:captures){ should == ["a", "b/c"] }
801
+ end
802
+
803
+ context "second uri" do
804
+ subject {
805
+ Addressable::Template.new(
806
+ "http://example.com/{first}{/second*}/"
807
+ ).match(uri2)
808
+ }
809
+ its(:variables){ should == ["first", "second"] }
810
+ its(:captures){ should == ["a", ["b","c"]] }
811
+ end
812
+ context "third uri" do
813
+ subject {
814
+ Addressable::Template.new(
815
+ "http://example.com/{;hash*,first}"
816
+ ).match(uri3)
817
+ }
818
+ its(:variables){ should == ["hash", "first"] }
819
+ its(:captures){ should == [
820
+ {"a" => "1", "b" => "2", "c" => "3", "first" => "foo"}, nil] }
821
+ end
822
+ # Note that this expansion is impossible to revert deterministically - the
823
+ # * operator means first could have been a key of hash or a separate key.
824
+ # Semantically, a separate key is more likely, but both are possible.
825
+ context "fourth uri" do
826
+ subject {
827
+ Addressable::Template.new(
828
+ "http://example.com/{?hash*,first}"
829
+ ).match(uri4)
830
+ }
831
+ its(:variables){ should == ["hash", "first"] }
832
+ its(:captures){ should == [
833
+ {"a" => "1", "b" => "2", "c" => "3", "first"=> "foo"}, nil] }
834
+ end
835
+ context "fifth uri" do
836
+ subject {
837
+ Addressable::Template.new(
838
+ "http://example.com/{path}{?hash*,first}"
839
+ ).match(uri5)
840
+ }
841
+ its(:variables){ should == ["path", "hash", "first"] }
842
+ its(:captures){ should == ["foo", nil, nil] }
843
+ end
844
+ end
845
+
846
+ describe 'match' do
847
+ subject { Addressable::Template.new('http://example.com/first/second/') }
848
+ context 'when the URI is the same as the template' do
849
+ it 'returns the match data itself with an empty mapping' do
850
+ uri = Addressable::URI.parse('http://example.com/first/second/')
851
+ match_data = subject.match(uri)
852
+ expect(match_data).to be_an Addressable::Template::MatchData
853
+ expect(match_data.uri).to eq(uri)
854
+ expect(match_data.template).to eq(subject)
855
+ expect(match_data.mapping).to be_empty
856
+ expect(match_data.inspect).to be_an String
857
+ end
858
+ end
859
+ end
860
+
861
+ describe "extract" do
862
+ let(:template) {
863
+ Addressable::Template.new(
864
+ "http://{host}{/segments*}/{?one,two,bogus}{#fragment}"
865
+ )
866
+ }
867
+ let(:uri){ "http://example.com/a/b/c/?one=1&two=2#foo" }
868
+ let(:uri2){ "http://example.com/a/b/c/#foo" }
869
+ it "should be able to extract with queries" do
870
+ expect(template.extract(uri)).to eq({
871
+ "host" => "example.com",
872
+ "segments" => %w(a b c),
873
+ "one" => "1",
874
+ "bogus" => nil,
875
+ "two" => "2",
876
+ "fragment" => "foo"
877
+ })
878
+ end
879
+ it "should be able to extract without queries" do
880
+ expect(template.extract(uri2)).to eq({
881
+ "host" => "example.com",
882
+ "segments" => %w(a b c),
883
+ "one" => nil,
884
+ "bogus" => nil,
885
+ "two" => nil,
886
+ "fragment" => "foo"
887
+ })
888
+ end
889
+
890
+ context "issue #137" do
891
+ subject { Addressable::Template.new('/path{?page,per_page}') }
892
+
893
+ it "can match empty" do
894
+ data = subject.extract("/path")
895
+ expect(data["page"]).to eq(nil)
896
+ expect(data["per_page"]).to eq(nil)
897
+ expect(data.keys.sort).to eq(['page', 'per_page'])
898
+ end
899
+
900
+ it "can match first var" do
901
+ data = subject.extract("/path?page=1")
902
+ expect(data["page"]).to eq("1")
903
+ expect(data["per_page"]).to eq(nil)
904
+ expect(data.keys.sort).to eq(['page', 'per_page'])
905
+ end
906
+
907
+ it "can match second var" do
908
+ data = subject.extract("/path?per_page=1")
909
+ expect(data["page"]).to eq(nil)
910
+ expect(data["per_page"]).to eq("1")
911
+ expect(data.keys.sort).to eq(['page', 'per_page'])
912
+ end
913
+
914
+ it "can match both vars" do
915
+ data = subject.extract("/path?page=2&per_page=1")
916
+ expect(data["page"]).to eq("2")
917
+ expect(data["per_page"]).to eq("1")
918
+ expect(data.keys.sort).to eq(['page', 'per_page'])
919
+ end
920
+ end
921
+ end
922
+
923
+ describe "Partial expand with symbols" do
924
+ context "partial_expand with two simple values" do
925
+ subject {
926
+ Addressable::Template.new("http://example.com/{one}/{two}/")
927
+ }
928
+ it "builds a new pattern" do
929
+ expect(subject.partial_expand(:one => "1").pattern).to eq(
930
+ "http://example.com/1/{two}/"
931
+ )
932
+ end
933
+ end
934
+ context "partial_expand query with missing param in middle" do
935
+ subject {
936
+ Addressable::Template.new("http://example.com/{?one,two,three}/")
937
+ }
938
+ it "builds a new pattern" do
939
+ expect(subject.partial_expand(:one => "1", :three => "3").pattern).to eq(
940
+ "http://example.com/?one=1{&two}&three=3/"
941
+ )
942
+ end
943
+ end
944
+ context "partial_expand form style query with missing param at beginning" do
945
+ subject {
946
+ Addressable::Template.new("http://example.com/{?one,two}/")
947
+ }
948
+ it "builds a new pattern" do
949
+ expect(subject.partial_expand(:two => "2").pattern).to eq(
950
+ "http://example.com/?two=2{&one}/"
951
+ )
952
+ end
953
+ end
954
+ context "issue #307 - partial_expand form query with nil params" do
955
+ subject do
956
+ Addressable::Template.new("http://example.com/{?one,two,three}/")
957
+ end
958
+ it "builds a new pattern with two=nil" do
959
+ expect(subject.partial_expand(two: nil).pattern).to eq(
960
+ "http://example.com/{?one}{&three}/"
961
+ )
962
+ end
963
+ it "builds a new pattern with one=nil and two=nil" do
964
+ expect(subject.partial_expand(one: nil, two: nil).pattern).to eq(
965
+ "http://example.com/{?three}/"
966
+ )
967
+ end
968
+ it "builds a new pattern with one=1 and two=nil" do
969
+ expect(subject.partial_expand(one: 1, two: nil).pattern).to eq(
970
+ "http://example.com/?one=1{&three}/"
971
+ )
972
+ end
973
+ it "builds a new pattern with one=nil and two=2" do
974
+ expect(subject.partial_expand(one: nil, two: 2).pattern).to eq(
975
+ "http://example.com/?two=2{&three}/"
976
+ )
977
+ end
978
+ it "builds a new pattern with one=nil" do
979
+ expect(subject.partial_expand(one: nil).pattern).to eq(
980
+ "http://example.com/{?two}{&three}/"
981
+ )
982
+ end
983
+ end
984
+ context "partial_expand with query string" do
985
+ subject {
986
+ Addressable::Template.new("http://example.com/{?two,one}/")
987
+ }
988
+ it "builds a new pattern" do
989
+ expect(subject.partial_expand(:one => "1").pattern).to eq(
990
+ "http://example.com/?one=1{&two}/"
991
+ )
992
+ end
993
+ end
994
+ context "partial_expand with path operator" do
995
+ subject {
996
+ Addressable::Template.new("http://example.com{/one,two}/")
997
+ }
998
+ it "builds a new pattern" do
999
+ expect(subject.partial_expand(:one => "1").pattern).to eq(
1000
+ "http://example.com/1{/two}/"
1001
+ )
1002
+ end
1003
+ end
1004
+ context "partial expand with unicode values" do
1005
+ subject do
1006
+ Addressable::Template.new("http://example.com/{resource}/{query}/")
1007
+ end
1008
+ it "normalizes unicode by default" do
1009
+ template = subject.partial_expand("query" => "Cafe\u0301")
1010
+ expect(template.pattern).to eq(
1011
+ "http://example.com/{resource}/Caf%C3%A9/"
1012
+ )
1013
+ end
1014
+
1015
+ it "does not normalize unicode when byte semantics requested" do
1016
+ template = subject.partial_expand({"query" => "Cafe\u0301"}, nil, false)
1017
+ expect(template.pattern).to eq(
1018
+ "http://example.com/{resource}/Cafe%CC%81/"
1019
+ )
1020
+ end
1021
+ end
1022
+ end
1023
+ describe "Partial expand with strings" do
1024
+ context "partial_expand with two simple values" do
1025
+ subject {
1026
+ Addressable::Template.new("http://example.com/{one}/{two}/")
1027
+ }
1028
+ it "builds a new pattern" do
1029
+ expect(subject.partial_expand("one" => "1").pattern).to eq(
1030
+ "http://example.com/1/{two}/"
1031
+ )
1032
+ end
1033
+ end
1034
+ context "partial_expand query with missing param in middle" do
1035
+ subject {
1036
+ Addressable::Template.new("http://example.com/{?one,two,three}/")
1037
+ }
1038
+ it "builds a new pattern" do
1039
+ expect(subject.partial_expand("one" => "1", "three" => "3").pattern).to eq(
1040
+ "http://example.com/?one=1{&two}&three=3/"
1041
+ )
1042
+ end
1043
+ end
1044
+ context "partial_expand with query string" do
1045
+ subject {
1046
+ Addressable::Template.new("http://example.com/{?two,one}/")
1047
+ }
1048
+ it "builds a new pattern" do
1049
+ expect(subject.partial_expand("one" => "1").pattern).to eq(
1050
+ "http://example.com/?one=1{&two}/"
1051
+ )
1052
+ end
1053
+ end
1054
+ context "partial_expand with path operator" do
1055
+ subject {
1056
+ Addressable::Template.new("http://example.com{/one,two}/")
1057
+ }
1058
+ it "builds a new pattern" do
1059
+ expect(subject.partial_expand("one" => "1").pattern).to eq(
1060
+ "http://example.com/1{/two}/"
1061
+ )
1062
+ end
1063
+ end
1064
+ end
1065
+ describe "Expand" do
1066
+ context "expand with unicode values" do
1067
+ subject do
1068
+ Addressable::Template.new("http://example.com/search/{query}/")
1069
+ end
1070
+ it "normalizes unicode by default" do
1071
+ uri = subject.expand("query" => "Cafe\u0301").to_str
1072
+ expect(uri).to eq("http://example.com/search/Caf%C3%A9/")
1073
+ end
1074
+
1075
+ it "does not normalize unicode when byte semantics requested" do
1076
+ uri = subject.expand({ "query" => "Cafe\u0301" }, nil, false).to_str
1077
+ expect(uri).to eq("http://example.com/search/Cafe%CC%81/")
1078
+ end
1079
+ end
1080
+ context "expand with a processor" do
1081
+ subject {
1082
+ Addressable::Template.new("http://example.com/search/{query}/")
1083
+ }
1084
+ it "processes spaces" do
1085
+ expect(subject.expand({"query" => "an example search query"},
1086
+ ExampleTwoProcessor).to_str).to eq(
1087
+ "http://example.com/search/an+example+search+query/"
1088
+ )
1089
+ end
1090
+ it "validates" do
1091
+ expect{
1092
+ subject.expand({"query" => "Bogus!"},
1093
+ ExampleTwoProcessor).to_str
1094
+ }.to raise_error(Addressable::Template::InvalidTemplateValueError)
1095
+ end
1096
+ end
1097
+ context "partial_expand query with missing param in middle" do
1098
+ subject {
1099
+ Addressable::Template.new("http://example.com/{?one,two,three}/")
1100
+ }
1101
+ it "builds a new pattern" do
1102
+ expect(subject.partial_expand("one" => "1", "three" => "3").pattern).to eq(
1103
+ "http://example.com/?one=1{&two}&three=3/"
1104
+ )
1105
+ end
1106
+ end
1107
+ context "partial_expand with query string" do
1108
+ subject {
1109
+ Addressable::Template.new("http://example.com/{?two,one}/")
1110
+ }
1111
+ it "builds a new pattern" do
1112
+ expect(subject.partial_expand("one" => "1").pattern).to eq(
1113
+ "http://example.com/?one=1{&two}/"
1114
+ )
1115
+ end
1116
+ end
1117
+ context "partial_expand with path operator" do
1118
+ subject {
1119
+ Addressable::Template.new("http://example.com{/one,two}/")
1120
+ }
1121
+ it "builds a new pattern" do
1122
+ expect(subject.partial_expand("one" => "1").pattern).to eq(
1123
+ "http://example.com/1{/two}/"
1124
+ )
1125
+ end
1126
+ end
1127
+ end
1128
+ context "Matching with operators" do
1129
+ describe "Level 1:" do
1130
+ subject { Addressable::Template.new("foo{foo}/{bar}baz") }
1131
+ it "can match" do
1132
+ data = subject.match("foofoo/bananabaz")
1133
+ expect(data.mapping["foo"]).to eq("foo")
1134
+ expect(data.mapping["bar"]).to eq("banana")
1135
+ end
1136
+ it "can fail" do
1137
+ expect(subject.match("bar/foo")).to be_nil
1138
+ expect(subject.match("foobaz")).to be_nil
1139
+ end
1140
+ it "can match empty" do
1141
+ data = subject.match("foo/baz")
1142
+ expect(data.mapping["foo"]).to eq(nil)
1143
+ expect(data.mapping["bar"]).to eq(nil)
1144
+ end
1145
+ it "lists vars" do
1146
+ expect(subject.variables).to eq(["foo", "bar"])
1147
+ end
1148
+ end
1149
+
1150
+ describe "Level 2:" do
1151
+ subject { Addressable::Template.new("foo{+foo}{#bar}baz") }
1152
+ it "can match" do
1153
+ data = subject.match("foo/test/banana#bazbaz")
1154
+ expect(data.mapping["foo"]).to eq("/test/banana")
1155
+ expect(data.mapping["bar"]).to eq("baz")
1156
+ end
1157
+ it "can match empty level 2 #" do
1158
+ data = subject.match("foo/test/bananabaz")
1159
+ expect(data.mapping["foo"]).to eq("/test/banana")
1160
+ expect(data.mapping["bar"]).to eq(nil)
1161
+ data = subject.match("foo/test/banana#baz")
1162
+ expect(data.mapping["foo"]).to eq("/test/banana")
1163
+ expect(data.mapping["bar"]).to eq("")
1164
+ end
1165
+ it "can match empty level 2 +" do
1166
+ data = subject.match("foobaz")
1167
+ expect(data.mapping["foo"]).to eq(nil)
1168
+ expect(data.mapping["bar"]).to eq(nil)
1169
+ data = subject.match("foo#barbaz")
1170
+ expect(data.mapping["foo"]).to eq(nil)
1171
+ expect(data.mapping["bar"]).to eq("bar")
1172
+ end
1173
+ it "lists vars" do
1174
+ expect(subject.variables).to eq(["foo", "bar"])
1175
+ end
1176
+ end
1177
+
1178
+ describe "Level 3:" do
1179
+ context "no operator" do
1180
+ subject { Addressable::Template.new("foo{foo,bar}baz") }
1181
+ it "can match" do
1182
+ data = subject.match("foofoo,barbaz")
1183
+ expect(data.mapping["foo"]).to eq("foo")
1184
+ expect(data.mapping["bar"]).to eq("bar")
1185
+ end
1186
+ it "lists vars" do
1187
+ expect(subject.variables).to eq(["foo", "bar"])
1188
+ end
1189
+ end
1190
+ context "+ operator" do
1191
+ subject { Addressable::Template.new("foo{+foo,bar}baz") }
1192
+ it "can match" do
1193
+ data = subject.match("foofoo/bar,barbaz")
1194
+ expect(data.mapping["bar"]).to eq("foo/bar,bar")
1195
+ expect(data.mapping["foo"]).to eq("")
1196
+ end
1197
+ it "lists vars" do
1198
+ expect(subject.variables).to eq(["foo", "bar"])
1199
+ end
1200
+ end
1201
+ context ". operator" do
1202
+ subject { Addressable::Template.new("foo{.foo,bar}baz") }
1203
+ it "can match" do
1204
+ data = subject.match("foo.foo.barbaz")
1205
+ expect(data.mapping["foo"]).to eq("foo")
1206
+ expect(data.mapping["bar"]).to eq("bar")
1207
+ end
1208
+ it "lists vars" do
1209
+ expect(subject.variables).to eq(["foo", "bar"])
1210
+ end
1211
+ end
1212
+ context "/ operator" do
1213
+ subject { Addressable::Template.new("foo{/foo,bar}baz") }
1214
+ it "can match" do
1215
+ data = subject.match("foo/foo/barbaz")
1216
+ expect(data.mapping["foo"]).to eq("foo")
1217
+ expect(data.mapping["bar"]).to eq("bar")
1218
+ end
1219
+ it "lists vars" do
1220
+ expect(subject.variables).to eq(["foo", "bar"])
1221
+ end
1222
+ end
1223
+ context "; operator" do
1224
+ subject { Addressable::Template.new("foo{;foo,bar,baz}baz") }
1225
+ it "can match" do
1226
+ data = subject.match("foo;foo=bar%20baz;bar=foo;bazbaz")
1227
+ expect(data.mapping["foo"]).to eq("bar baz")
1228
+ expect(data.mapping["bar"]).to eq("foo")
1229
+ expect(data.mapping["baz"]).to eq("")
1230
+ end
1231
+ it "lists vars" do
1232
+ expect(subject.variables).to eq(%w(foo bar baz))
1233
+ end
1234
+ end
1235
+ context "? operator" do
1236
+ context "test" do
1237
+ subject { Addressable::Template.new("foo{?foo,bar}baz") }
1238
+ it "can match" do
1239
+ data = subject.match("foo?foo=bar%20baz&bar=foobaz")
1240
+ expect(data.mapping["foo"]).to eq("bar baz")
1241
+ expect(data.mapping["bar"]).to eq("foo")
1242
+ end
1243
+ it "lists vars" do
1244
+ expect(subject.variables).to eq(%w(foo bar))
1245
+ end
1246
+ end
1247
+
1248
+ context "issue #137" do
1249
+ subject { Addressable::Template.new('/path{?page,per_page}') }
1250
+
1251
+ it "can match empty" do
1252
+ data = subject.match("/path")
1253
+ expect(data.mapping["page"]).to eq(nil)
1254
+ expect(data.mapping["per_page"]).to eq(nil)
1255
+ expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
1256
+ end
1257
+
1258
+ it "can match first var" do
1259
+ data = subject.match("/path?page=1")
1260
+ expect(data.mapping["page"]).to eq("1")
1261
+ expect(data.mapping["per_page"]).to eq(nil)
1262
+ expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
1263
+ end
1264
+
1265
+ it "can match second var" do
1266
+ data = subject.match("/path?per_page=1")
1267
+ expect(data.mapping["page"]).to eq(nil)
1268
+ expect(data.mapping["per_page"]).to eq("1")
1269
+ expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
1270
+ end
1271
+
1272
+ it "can match both vars" do
1273
+ data = subject.match("/path?page=2&per_page=1")
1274
+ expect(data.mapping["page"]).to eq("2")
1275
+ expect(data.mapping["per_page"]).to eq("1")
1276
+ expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
1277
+ end
1278
+ end
1279
+
1280
+ context "issue #71" do
1281
+ subject { Addressable::Template.new("http://cyberscore.dev/api/users{?username}") }
1282
+ it "can match" do
1283
+ data = subject.match("http://cyberscore.dev/api/users?username=foobaz")
1284
+ expect(data.mapping["username"]).to eq("foobaz")
1285
+ end
1286
+ it "lists vars" do
1287
+ expect(subject.variables).to eq(%w(username))
1288
+ expect(subject.keys).to eq(%w(username))
1289
+ end
1290
+ end
1291
+ end
1292
+ context "& operator" do
1293
+ subject { Addressable::Template.new("foo{&foo,bar}baz") }
1294
+ it "can match" do
1295
+ data = subject.match("foo&foo=bar%20baz&bar=foobaz")
1296
+ expect(data.mapping["foo"]).to eq("bar baz")
1297
+ expect(data.mapping["bar"]).to eq("foo")
1298
+ end
1299
+ it "lists vars" do
1300
+ expect(subject.variables).to eq(%w(foo bar))
1301
+ end
1302
+ end
1303
+ end
1304
+ end
1305
+
1306
+ context "support regexes:" do
1307
+ context "EXPRESSION" do
1308
+ subject { Addressable::Template::EXPRESSION }
1309
+ it "should be able to match an expression" do
1310
+ expect(subject).to match("{foo}")
1311
+ expect(subject).to match("{foo,9}")
1312
+ expect(subject).to match("{foo.bar,baz}")
1313
+ expect(subject).to match("{+foo.bar,baz}")
1314
+ expect(subject).to match("{foo,foo%20bar}")
1315
+ expect(subject).to match("{#foo:20,baz*}")
1316
+ expect(subject).to match("stuff{#foo:20,baz*}things")
1317
+ end
1318
+ it "should fail on non vars" do
1319
+ expect(subject).not_to match("!{foo")
1320
+ expect(subject).not_to match("{foo.bar.}")
1321
+ expect(subject).not_to match("!{}")
1322
+ end
1323
+ end
1324
+ context "VARNAME" do
1325
+ subject { Addressable::Template::VARNAME }
1326
+ it "should be able to match a variable" do
1327
+ expect(subject).to match("foo")
1328
+ expect(subject).to match("9")
1329
+ expect(subject).to match("foo.bar")
1330
+ expect(subject).to match("foo_bar")
1331
+ expect(subject).to match("foo_bar.baz")
1332
+ expect(subject).to match("foo%20bar")
1333
+ expect(subject).to match("foo%20bar.baz")
1334
+ end
1335
+ it "should fail on non vars" do
1336
+ expect(subject).not_to match("!foo")
1337
+ expect(subject).not_to match("foo.bar.")
1338
+ expect(subject).not_to match("foo%2%00bar")
1339
+ expect(subject).not_to match("foo_ba%r")
1340
+ expect(subject).not_to match("foo_bar*")
1341
+ expect(subject).not_to match("foo_bar:20")
1342
+ end
1343
+ end
1344
+ context "VARIABLE_LIST" do
1345
+ subject { Addressable::Template::VARIABLE_LIST }
1346
+ it "should be able to match a variable list" do
1347
+ expect(subject).to match("foo,bar")
1348
+ expect(subject).to match("foo")
1349
+ expect(subject).to match("foo,bar*,baz")
1350
+ expect(subject).to match("foo.bar,bar_baz*,baz:12")
1351
+ end
1352
+ it "should fail on non vars" do
1353
+ expect(subject).not_to match(",foo,bar*,baz")
1354
+ expect(subject).not_to match("foo,*bar,baz")
1355
+ expect(subject).not_to match("foo,,bar*,baz")
1356
+ end
1357
+ end
1358
+ context "VARSPEC" do
1359
+ subject { Addressable::Template::VARSPEC }
1360
+ it "should be able to match a variable with modifier" do
1361
+ expect(subject).to match("9:8")
1362
+ expect(subject).to match("foo.bar*")
1363
+ expect(subject).to match("foo_bar:12")
1364
+ expect(subject).to match("foo_bar.baz*")
1365
+ expect(subject).to match("foo%20bar:12")
1366
+ expect(subject).to match("foo%20bar.baz*")
1367
+ end
1368
+ it "should fail on non vars" do
1369
+ expect(subject).not_to match("!foo")
1370
+ expect(subject).not_to match("*foo")
1371
+ expect(subject).not_to match("fo*o")
1372
+ expect(subject).not_to match("fo:o")
1373
+ expect(subject).not_to match("foo:")
1374
+ end
1375
+ end
1376
+ end
1377
+ end
1378
+
1379
+ describe Addressable::Template::MatchData do
1380
+ let(:template) { Addressable::Template.new('{foo}/{bar}') }
1381
+ subject(:its) { template.match('ab/cd') }
1382
+ its(:uri) { should == Addressable::URI.parse('ab/cd') }
1383
+ its(:template) { should == template }
1384
+ its(:mapping) { should == { 'foo' => 'ab', 'bar' => 'cd' } }
1385
+ its(:variables) { should == ['foo', 'bar'] }
1386
+ its(:keys) { should == ['foo', 'bar'] }
1387
+ its(:names) { should == ['foo', 'bar'] }
1388
+ its(:values) { should == ['ab', 'cd'] }
1389
+ its(:captures) { should == ['ab', 'cd'] }
1390
+ its(:to_a) { should == ['ab/cd', 'ab', 'cd'] }
1391
+ its(:to_s) { should == 'ab/cd' }
1392
+ its(:string) { should == its.to_s }
1393
+ its(:pre_match) { should == "" }
1394
+ its(:post_match) { should == "" }
1395
+
1396
+ describe 'values_at' do
1397
+ it 'returns an array with the values' do
1398
+ expect(its.values_at(0, 2)).to eq(['ab/cd', 'cd'])
1399
+ end
1400
+ it 'allows mixing integer an string keys' do
1401
+ expect(its.values_at('foo', 1)).to eq(['ab', 'ab'])
1402
+ end
1403
+ it 'accepts unknown keys' do
1404
+ expect(its.values_at('baz', 'foo')).to eq([nil, 'ab'])
1405
+ end
1406
+ end
1407
+
1408
+ describe '[]' do
1409
+ context 'string key' do
1410
+ it 'returns the corresponding capture' do
1411
+ expect(its['foo']).to eq('ab')
1412
+ expect(its['bar']).to eq('cd')
1413
+ end
1414
+ it 'returns nil for unknown keys' do
1415
+ expect(its['baz']).to be_nil
1416
+ end
1417
+ end
1418
+ context 'symbol key' do
1419
+ it 'returns the corresponding capture' do
1420
+ expect(its[:foo]).to eq('ab')
1421
+ expect(its[:bar]).to eq('cd')
1422
+ end
1423
+ it 'returns nil for unknown keys' do
1424
+ expect(its[:baz]).to be_nil
1425
+ end
1426
+ end
1427
+ context 'integer key' do
1428
+ it 'returns the full URI for index 0' do
1429
+ expect(its[0]).to eq('ab/cd')
1430
+ end
1431
+ it 'returns the corresponding capture' do
1432
+ expect(its[1]).to eq('ab')
1433
+ expect(its[2]).to eq('cd')
1434
+ end
1435
+ it 'returns nil for unknown keys' do
1436
+ expect(its[3]).to be_nil
1437
+ end
1438
+ end
1439
+ context 'other key' do
1440
+ it 'raises an exception' do
1441
+ expect { its[Object.new] }.to raise_error(TypeError)
1442
+ end
1443
+ end
1444
+ context 'with length' do
1445
+ it 'returns an array starting at index with given length' do
1446
+ expect(its[0, 2]).to eq(['ab/cd', 'ab'])
1447
+ expect(its[2, 1]).to eq(['cd'])
1448
+ end
1449
+ end
1450
+ end
1451
+ end