vagrant-unbundled 2.0.0.1 → 2.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +34 -0
  4. data/Gemfile.lock +10 -10
  5. data/README.md +2 -2
  6. data/contrib/sudoers/linux-suse +6 -7
  7. data/lib/vagrant/plugin/v2/command.rb +3 -0
  8. data/lib/vagrant/plugin/v2/communicator.rb +1 -1
  9. data/lib/vagrant/registry.rb +1 -1
  10. data/lib/vagrant/util/downloader.rb +1 -2
  11. data/lib/vagrant/util/is_port_open.rb +2 -1
  12. data/lib/vagrant/util/keypair.rb +1 -1
  13. data/lib/vagrant/util/platform.rb +39 -23
  14. data/plugins/commands/destroy/command.rb +31 -10
  15. data/plugins/communicators/ssh/communicator.rb +1 -0
  16. data/plugins/communicators/winrm/helper.rb +6 -1
  17. data/plugins/guests/solaris11/cap/change_host_name.rb +0 -2
  18. data/plugins/guests/solaris11/cap/configure_networks.rb +1 -7
  19. data/plugins/guests/solaris11/plugin.rb +5 -35
  20. data/plugins/guests/windows/cap/public_key.rb +2 -0
  21. data/plugins/guests/windows/guest_network.rb +3 -3
  22. data/plugins/guests/windows/scripts/reboot_detect.ps1 +5 -0
  23. data/plugins/providers/docker/driver.rb +1 -1
  24. data/plugins/providers/docker/executor/local.rb +4 -0
  25. data/plugins/providers/docker/executor/vagrant.rb +4 -0
  26. data/plugins/providers/hyperv/scripts/import_vm_vmcx.ps1 +1 -1
  27. data/plugins/providers/virtualbox/driver/meta.rb +1 -0
  28. data/plugins/providers/virtualbox/driver/version_5_2.rb +16 -0
  29. data/plugins/providers/virtualbox/plugin.rb +1 -0
  30. data/plugins/providers/virtualbox/synced_folder.rb +1 -1
  31. data/plugins/provisioners/chef/provisioner/chef_client.rb +30 -23
  32. data/plugins/provisioners/chef/provisioner/chef_solo.rb +26 -19
  33. data/plugins/provisioners/chef/provisioner/chef_zero.rb +29 -22
  34. data/plugins/provisioners/puppet/provisioner/puppet.rb +23 -4
  35. data/plugins/provisioners/salt/bootstrap-salt.ps1 +15 -3
  36. data/plugins/provisioners/salt/bootstrap-salt.sh +2 -0
  37. data/plugins/provisioners/salt/config.rb +11 -0
  38. data/plugins/provisioners/salt/provisioner.rb +10 -7
  39. data/plugins/provisioners/shell/provisioner.rb +1 -1
  40. data/templates/locales/en.yml +5 -0
  41. data/test/unit/base.rb +2 -0
  42. data/test/unit/plugins/commands/destroy/command_test.rb +155 -0
  43. data/test/unit/plugins/communicators/winrm/helper_test.rb +33 -0
  44. data/test/unit/plugins/guests/solaris11/cap/change_host_name_test.rb +36 -0
  45. data/test/unit/plugins/guests/solaris11/cap/configure_networks_test.rb +56 -0
  46. data/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +26 -0
  47. data/test/unit/plugins/provisioners/salt/config_test.rb +42 -0
  48. data/test/unit/plugins/provisioners/salt/provisioner_test.rb +16 -1
  49. data/test/unit/plugins/provisioners/shell/config_test.rb +3 -3
  50. data/test/unit/plugins/pushes/local-exec/config_test.rb +2 -2
  51. data/test/unit/vagrant/util/downloader_test.rb +28 -0
  52. data/test/unit/vagrant/util/platform_test.rb +58 -0
  53. data/vagrant.gemspec +1 -1
  54. data/vendor/bundle/ruby/2.4.0/bin/rwinrmcp +5 -0
  55. data/vendor/bundle/ruby/2.4.0/bin/vagrant +5 -0
  56. data/vendor/bundle/ruby/2.4.0/bin/vagrant-spec +5 -0
  57. data/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-spec-af86757912f7/vagrant-spec.gemspec +3 -3
  58. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/CHANGELOG.md +216 -0
  59. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/Gemfile +32 -0
  60. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/LICENSE.txt +202 -0
  61. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/README.md +121 -0
  62. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/Rakefile +32 -0
  63. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/data/unicode.data +0 -0
  64. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/idna/native.rb +59 -0
  65. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/idna/pure.rb +677 -0
  66. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/idna.rb +25 -0
  67. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/template.rb +1065 -0
  68. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb +2492 -0
  69. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable/version.rb +30 -0
  70. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/lib/addressable.rb +2 -0
  71. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/idna_spec.rb +298 -0
  72. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/net_http_compat_spec.rb +28 -0
  73. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/rack_mount_compat_spec.rb +104 -0
  74. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/security_spec.rb +57 -0
  75. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/template_spec.rb +1419 -0
  76. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/addressable/uri_spec.rb +6468 -0
  77. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/spec/spec_helper.rb +21 -0
  78. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/clobber.rake +2 -0
  79. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/gem.rake +91 -0
  80. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/git.rake +45 -0
  81. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/metrics.rake +22 -0
  82. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/rspec.rake +21 -0
  83. data/vendor/bundle/ruby/2.4.0/gems/addressable-2.5.2/tasks/yard.rake +27 -0
  84. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/.gitignore +15 -0
  85. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/.rspec +1 -0
  86. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/.travis.yml +13 -0
  87. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/.yardopts +1 -0
  88. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/Gemfile +6 -0
  89. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/LICENSE +19 -0
  90. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/README.md +265 -0
  91. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/Rakefile +13 -0
  92. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/changelog.md +72 -0
  93. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/hashdiff.gemspec +25 -0
  94. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/diff.rb +232 -0
  95. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/lcs.rb +69 -0
  96. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/linear_compare_array.rb +155 -0
  97. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/patch.rb +88 -0
  98. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/util.rb +146 -0
  99. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff/version.rb +3 -0
  100. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/lib/hashdiff.rb +6 -0
  101. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/best_diff_spec.rb +74 -0
  102. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/diff_array_spec.rb +60 -0
  103. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/diff_spec.rb +339 -0
  104. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb +75 -0
  105. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb +48 -0
  106. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/patch_spec.rb +183 -0
  107. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/util_spec.rb +78 -0
  108. data/vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/spec_helper.rb +13 -0
  109. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/CHANGELOG.md +250 -0
  110. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/CONTRIBUTING.md +46 -0
  111. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/LICENSE.md +20 -0
  112. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/README.md +122 -0
  113. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapter.rb +49 -0
  114. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapter_error.rb +15 -0
  115. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/gson.rb +20 -0
  116. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/jr_jackson.rb +25 -0
  117. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/json_common.rb +23 -0
  118. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/json_gem.rb +11 -0
  119. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/json_pure.rb +11 -0
  120. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/nsjsonserialization.rb +32 -0
  121. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/oj.rb +25 -0
  122. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/ok_json.rb +23 -0
  123. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/adapters/yajl.rb +19 -0
  124. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/convertible_hash_keys.rb +43 -0
  125. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/options.rb +39 -0
  126. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/options_cache.rb +29 -0
  127. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/parse_error.rb +17 -0
  128. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/vendor/okjson.rb +606 -0
  129. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json/version.rb +17 -0
  130. data/vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.2/lib/multi_json.rb +161 -0
  131. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/.gitignore +11 -0
  132. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/.rubocop.yml +32 -0
  133. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/.rubocop_defaults.yml +177 -0
  134. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/.travis.yml +24 -0
  135. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/.yardopts +1 -0
  136. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/2.0-Upgrade.md +52 -0
  137. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/CHANGELOG.md +330 -0
  138. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/Gemfile +10 -0
  139. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/LICENSE.txt +22 -0
  140. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/README.md +202 -0
  141. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/Rakefile +49 -0
  142. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/bin/console +14 -0
  143. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/data/list.txt +12288 -0
  144. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix/domain.rb +235 -0
  145. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix/errors.rb +39 -0
  146. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix/list.rb +243 -0
  147. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix/rule.rb +348 -0
  148. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix/version.rb +10 -0
  149. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/lib/public_suffix.rb +175 -0
  150. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/public_suffix.gemspec +25 -0
  151. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/.empty +2 -0
  152. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/acceptance_test.rb +127 -0
  153. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_find.rb +66 -0
  154. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_find_all.rb +102 -0
  155. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_names.rb +91 -0
  156. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_select.rb +26 -0
  157. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_select_incremental.rb +25 -0
  158. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/benchmarks/bm_valid.rb +101 -0
  159. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/domain_profiler.rb +12 -0
  160. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/find_profiler.rb +12 -0
  161. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/find_profiler_jp.rb +12 -0
  162. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/initialization_profiler.rb +11 -0
  163. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/list_profsize.rb +11 -0
  164. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/profilers/object_binsize.rb +57 -0
  165. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/psl_test.rb +49 -0
  166. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/test_helper.rb +13 -0
  167. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/tests.txt +98 -0
  168. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/unit/domain_test.rb +104 -0
  169. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/unit/errors_test.rb +23 -0
  170. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/unit/list_test.rb +239 -0
  171. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/unit/public_suffix_test.rb +186 -0
  172. data/vendor/bundle/ruby/2.4.0/gems/public_suffix-3.0.1/test/unit/rule_test.rb +220 -0
  173. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/.gemtest +0 -0
  174. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/.gitignore +34 -0
  175. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/.rspec-tm +2 -0
  176. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/.travis.yml +24 -0
  177. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/CHANGELOG.md +1460 -0
  178. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/Gemfile +9 -0
  179. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/LICENSE +20 -0
  180. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/README.md +1045 -0
  181. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/Rakefile +30 -0
  182. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/api.rb +97 -0
  183. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/assertion_failure.rb +11 -0
  184. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/callback_registry.rb +35 -0
  185. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/config.rb +18 -0
  186. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/cucumber.rb +10 -0
  187. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/deprecation.rb +9 -0
  188. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/errors.rb +17 -0
  189. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/curb_adapter.rb +337 -0
  190. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +228 -0
  191. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/excon_adapter.rb +162 -0
  192. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_lib_adapter.rb +7 -0
  193. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +19 -0
  194. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/client.rb +14 -0
  195. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/request.rb +10 -0
  196. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb +43 -0
  197. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/streamer.rb +25 -0
  198. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/webmock.rb +68 -0
  199. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb_adapter.rb +37 -0
  200. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/httpclient_adapter.rb +240 -0
  201. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/manticore_adapter.rb +127 -0
  202. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb +362 -0
  203. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http_response.rb +34 -0
  204. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/patron_adapter.rb +130 -0
  205. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +174 -0
  206. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/matchers/hash_including_matcher.rb +36 -0
  207. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/minitest.rb +41 -0
  208. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/rack_response.rb +69 -0
  209. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_body_diff.rb +64 -0
  210. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_execution_verifier.rb +78 -0
  211. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_pattern.rb +343 -0
  212. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_registry.rb +35 -0
  213. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_signature.rb +54 -0
  214. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_signature_snippet.rb +61 -0
  215. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/request_stub.rb +100 -0
  216. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/response.rb +153 -0
  217. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/responses_sequence.rb +40 -0
  218. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/rspec/matchers/request_pattern_matcher.rb +78 -0
  219. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/rspec/matchers/webmock_matcher.rb +52 -0
  220. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/rspec/matchers.rb +27 -0
  221. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/rspec.rb +35 -0
  222. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/stub_registry.rb +67 -0
  223. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/stub_request_snippet.rb +34 -0
  224. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/test_unit.rb +22 -0
  225. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/hash_counter.rb +32 -0
  226. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/hash_keys_stringifier.rb +25 -0
  227. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/hash_validator.rb +17 -0
  228. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/headers.rb +49 -0
  229. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/json.rb +78 -0
  230. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/query_mapper.rb +279 -0
  231. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/uri.rb +111 -0
  232. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/util/version_checker.rb +111 -0
  233. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/version.rb +3 -0
  234. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock/webmock.rb +156 -0
  235. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/lib/webmock.rb +54 -0
  236. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/minitest/test_helper.rb +34 -0
  237. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/minitest/test_webmock.rb +9 -0
  238. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/minitest/webmock_spec.rb +60 -0
  239. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/curb/curb_spec.rb +466 -0
  240. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/curb/curb_spec_helper.rb +147 -0
  241. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/em_http_request/em_http_request_spec.rb +406 -0
  242. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +77 -0
  243. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec.rb +75 -0
  244. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb +50 -0
  245. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/http_rb/http_rb_spec.rb +73 -0
  246. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/http_rb/http_rb_spec_helper.rb +51 -0
  247. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/httpclient/httpclient_spec.rb +209 -0
  248. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/httpclient/httpclient_spec_helper.rb +57 -0
  249. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/manticore/manticore_spec.rb +56 -0
  250. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/manticore/manticore_spec_helper.rb +35 -0
  251. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/net_http/net_http_shared.rb +142 -0
  252. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/net_http/net_http_spec.rb +317 -0
  253. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/net_http/net_http_spec_helper.rb +64 -0
  254. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/net_http/real_net_http_spec.rb +20 -0
  255. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/patron/patron_spec.rb +118 -0
  256. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/patron/patron_spec_helper.rb +54 -0
  257. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +313 -0
  258. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/callbacks.rb +147 -0
  259. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/complex_cross_concern_behaviors.rb +36 -0
  260. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/enabling_and_disabling_webmock.rb +95 -0
  261. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/precedence_of_stubs.rb +15 -0
  262. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/request_expectations.rb +916 -0
  263. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/returning_declared_responses.rb +388 -0
  264. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/shared/stubbing_requests.rb +583 -0
  265. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +135 -0
  266. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +60 -0
  267. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/acceptance/webmock_shared.rb +41 -0
  268. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/fixtures/test.txt +1 -0
  269. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/quality_spec.rb +84 -0
  270. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/spec_helper.rb +48 -0
  271. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/support/example_curl_output.txt +22 -0
  272. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/support/failures.rb +9 -0
  273. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/support/my_rack_app.rb +53 -0
  274. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/support/network_connection.rb +19 -0
  275. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/support/webmock_server.rb +69 -0
  276. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/api_spec.rb +75 -0
  277. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/errors_spec.rb +129 -0
  278. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +17 -0
  279. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +12 -0
  280. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/matchers/hash_including_matcher_spec.rb +87 -0
  281. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/rack_response_spec.rb +112 -0
  282. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_body_diff_spec.rb +90 -0
  283. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_execution_verifier_spec.rb +208 -0
  284. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_pattern_spec.rb +590 -0
  285. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_registry_spec.rb +76 -0
  286. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_signature_snippet_spec.rb +89 -0
  287. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_signature_spec.rb +155 -0
  288. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/request_stub_spec.rb +199 -0
  289. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/response_spec.rb +282 -0
  290. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/stub_registry_spec.rb +103 -0
  291. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/stub_request_snippet_spec.rb +95 -0
  292. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/hash_counter_spec.rb +39 -0
  293. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/hash_keys_stringifier_spec.rb +27 -0
  294. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/headers_spec.rb +28 -0
  295. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/json_spec.rb +33 -0
  296. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/query_mapper_spec.rb +138 -0
  297. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/uri_spec.rb +299 -0
  298. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/util/version_checker_spec.rb +65 -0
  299. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/spec/unit/webmock_spec.rb +11 -0
  300. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/test/http_request.rb +24 -0
  301. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/test/shared_test.rb +95 -0
  302. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/test/test_helper.rb +23 -0
  303. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/test/test_webmock.rb +6 -0
  304. data/vendor/bundle/ruby/2.4.0/gems/webmock-2.3.2/webmock.gemspec +46 -0
  305. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/.gitignore +11 -0
  306. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/.rspec +3 -0
  307. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/.rubocop.yml +9 -0
  308. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/.travis.yml +9 -0
  309. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/Gemfile +5 -0
  310. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/LICENSE +202 -0
  311. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/README.md +79 -0
  312. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/Rakefile +28 -0
  313. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/VERSION +1 -0
  314. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/Vagrantfile +9 -0
  315. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/appveyor.yml +38 -0
  316. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/bin/rwinrmcp +86 -0
  317. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/changelog.md +60 -0
  318. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/core/file_transporter.rb +527 -0
  319. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/core/tmp_zip.rb +177 -0
  320. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/exceptions.rb +28 -0
  321. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/file_manager.rb +118 -0
  322. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/check_files.ps1.erb +49 -0
  323. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/checksum.ps1.erb +13 -0
  324. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/create_dir.ps1.erb +6 -0
  325. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/delete.ps1.erb +6 -0
  326. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/download.ps1.erb +8 -0
  327. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/exists.ps1.erb +10 -0
  328. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/extract_files.ps1.erb +52 -0
  329. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs/scripts/scripts.rb +31 -0
  330. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/lib/winrm-fs.rb +28 -0
  331. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/config-example.yml +3 -0
  332. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/integration/file_manager_spec.rb +224 -0
  333. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/integration/tmp_zip_spec.rb +26 -0
  334. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/matchers.rb +58 -0
  335. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/spec_helper.rb +71 -0
  336. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/spec/unit/tmp_zip_spec.rb +79 -0
  337. data/vendor/bundle/ruby/2.4.0/gems/winrm-fs-1.1.1/winrm-fs.gemspec +37 -0
  338. data/vendor/bundle/ruby/2.4.0/specifications/addressable-2.5.2.gemspec +39 -0
  339. data/vendor/bundle/ruby/2.4.0/specifications/hashdiff-0.3.7.gemspec +39 -0
  340. data/vendor/bundle/ruby/2.4.0/specifications/multi_json-1.12.2.gemspec +33 -0
  341. data/vendor/bundle/ruby/2.4.0/specifications/public_suffix-3.0.1.gemspec +41 -0
  342. data/vendor/bundle/ruby/2.4.0/specifications/webmock-2.3.2.gemspec +79 -0
  343. data/vendor/bundle/ruby/2.4.0/specifications/winrm-fs-1.1.1.gemspec +57 -0
  344. data/version.txt +1 -1
  345. metadata +295 -11
  346. data/plugins/guests/solaris11/cap/halt.rb +0 -26
  347. data/plugins/guests/solaris11/cap/insert_public_key.rb +0 -21
  348. data/plugins/guests/solaris11/cap/mount_virtualbox_shared_folder.rb +0 -45
  349. data/plugins/guests/solaris11/cap/remove_public_key.rb +0 -21
  350. data/plugins/guests/solaris11/cap/rsync.rb +0 -29
  351. data/test/unit/plugins/guests/solaris11/cap/halt_test.rb +0 -44
@@ -0,0 +1,388 @@
1
+ class MyException < StandardError; end;
2
+
3
+ class Responder
4
+ def call(request)
5
+ {body: request.body}
6
+ end
7
+ end
8
+
9
+ shared_context "declared responses" do |*adapter_info|
10
+ describe "when request stub declares that request should raise exception" do
11
+ it "should raise exception" do
12
+ stub_request(:get, "www.example.com").to_raise(MyException)
13
+ expect {
14
+ http_request(:get, "http://www.example.com/")
15
+ }.to raise_error(MyException, "Exception from WebMock")
16
+ end
17
+
18
+ it "should raise exception if declared as and exception instance" do
19
+ stub_request(:get, "www.example.com").to_raise(MyException.new("hello world"))
20
+ expect {
21
+ http_request(:get, "http://www.example.com/")
22
+ }.to raise_error(MyException, "hello world")
23
+ end
24
+
25
+ it "should raise exception if declared as an exception instance" do
26
+ stub_request(:get, "www.example.com").to_raise("hello world")
27
+ expect {
28
+ http_request(:get, "http://www.example.com/")
29
+ }.to raise_error("hello world")
30
+ end
31
+
32
+ it "should raise exception after returning declared successful response first" do
33
+ stub_request(:get, "www.example.com").to_return(body: "abc").then.to_raise(MyException)
34
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
35
+ expect {
36
+ http_request(:get, "http://www.example.com/")
37
+ }.to raise_error(MyException, "Exception from WebMock")
38
+ end
39
+ end
40
+
41
+ describe "when request stub declares that request should timeout" do
42
+ it "should timeout" do
43
+ stub_request(:get, "www.example.com").to_timeout
44
+ expect {
45
+ http_request(:get, "http://www.example.com/")
46
+ }.to raise_error(client_timeout_exception_class)
47
+ end
48
+
49
+ it "should timeout after returning declared successful response" do
50
+ stub_request(:get, "www.example.com").to_return(body: "abc").then.to_timeout
51
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
52
+ expect {
53
+ http_request(:get, "http://www.example.com/")
54
+ }.to raise_error(client_timeout_exception_class)
55
+ end
56
+ end
57
+
58
+ describe "when request stub declares that request should return a response" do
59
+ it "should return response with declared body" do
60
+ stub_request(:get, "www.example.com").to_return(body: "abc")
61
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
62
+ end
63
+
64
+ it "should return response with declared headers" do
65
+ stub_request(:get, "www.example.com").to_return(headers: SAMPLE_HEADERS)
66
+ response = http_request(:get, "http://www.example.com/")
67
+ expect(response.headers["Content-Length"]).to eq("8888")
68
+ end
69
+
70
+ it "should return response with declared headers even if there are multiple headers with the same key" do
71
+ stub_request(:get, "www.example.com").to_return(headers: {"a" => ["b", "c"]})
72
+ response = http_request(:get, "http://www.example.com/")
73
+ expect(response.headers["A"]).to eq("b, c")
74
+ end
75
+
76
+ it "should return response with declared status code" do
77
+ stub_request(:get, "www.example.com").to_return(status: 500)
78
+ expect(http_request(:get, "http://www.example.com/").status).to eq("500")
79
+ end
80
+
81
+ it "should return response with declared status message", unless: (adapter_info.include?(:no_status_message)) do
82
+ stub_request(:get, "www.example.com").to_return(status: [500, "Internal Server Error"])
83
+ response = http_request(:get, "http://www.example.com/")
84
+ expect(response.message).to eq("Internal Server Error")
85
+ end
86
+
87
+ it "should return response with a default status code" do
88
+ stub_request(:get, "www.example.com")
89
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
90
+ end
91
+
92
+ it "should return default response with empty message if response was not declared", unless: (adapter_info.include?(:no_status_message)) do
93
+ stub_request(:get, "www.example.com")
94
+ response = http_request(:get, "http://www.example.com/")
95
+ expect(response.message).to eq("")
96
+ end
97
+
98
+ describe "when response body was declared as IO" do
99
+ it "should return response body" do
100
+ stub_request(:get, "www.example.com").to_return(body: File.new(__FILE__))
101
+ expect(http_request(:get, "http://www.example.com/").body).to eq(File.read(__FILE__))
102
+ end
103
+
104
+ it "should return response body if requested many times" do
105
+ stub_request(:get, "www.example.com").to_return(body: File.new(__FILE__))
106
+ 2.times do
107
+ expect(http_request(:get, "http://www.example.com/").body).to eq(File.read(__FILE__))
108
+ end
109
+ end
110
+
111
+ it "should close IO after request" do
112
+ stub_request(:get, "www.example.com").to_return(body: @file = File.new(__FILE__))
113
+ expect(@file).to be_closed
114
+ end
115
+ end
116
+
117
+ describe "when response parts were declared as lambdas" do
118
+ it "should return evaluated response body" do
119
+ stub_request(:post, "www.example.com").to_return(body: lambda { |request| request.body })
120
+ expect(http_request(:post, "http://www.example.com/", body: "echo").body).to eq("echo")
121
+ end
122
+
123
+ it "should return evaluated response headers" do
124
+ stub_request(:post, "www.example.com").to_return(headers: lambda { |request| request.headers })
125
+ expect(http_request(:post, "http://www.example.com/", body: "abc", headers: {'A' => 'B'}).headers['A']).to eq('B')
126
+ expect(http_request(:post, "http://www.example.com/", body: "abc", headers: {'A' => 'C'}).headers['A']).to eq('C')
127
+ end
128
+
129
+ it "should evaluate response body for each request" do
130
+ stub_request(:post, "www.example.com").to_return(body: lambda { |request| request.body })
131
+ expect(http_request(:post, "http://www.example.com/", body: "echo").body).to eq("echo")
132
+ expect(http_request(:post, "http://www.example.com/", body: "foxtrot").body).to eq("foxtrot")
133
+ end
134
+ end
135
+
136
+ describe "when response was declared as lambda" do
137
+ it "should return evaluated response body" do
138
+ stub_request(:post, "www.example.com").to_return(lambda {|request|
139
+ {body: request.body}
140
+ })
141
+ expect(http_request(:post, "http://www.example.com/", body: "echo").body).to eq("echo")
142
+ expect(http_request(:post, "http://www.example.com/", body: "foxtrot").body).to eq("foxtrot")
143
+ end
144
+
145
+ it "should return evaluated response headers" do
146
+ stub_request(:get, "www.example.com").to_return(lambda { |request|
147
+ {headers: request.headers}
148
+ })
149
+ expect(http_request(:get, "http://www.example.com/", headers: {'A' => 'B'}).headers['A']).to eq('B')
150
+ end
151
+
152
+ it "should return dynamic response declared as a block" do
153
+ stub_request(:post, "www.example.com").to_return do |request|
154
+ {body: request.body}
155
+ end
156
+ expect(http_request(:post, "http://www.example.com/", body: "echo").body).to eq("echo")
157
+ end
158
+
159
+ it "should return dynamic response declared as an object responding to call" do
160
+ stub_request(:post, "www.example.com").to_return(Responder.new)
161
+ expect(http_request(:post, "http://www.example.com/", body: "echo").body).to eq("echo")
162
+ end
163
+ end
164
+
165
+
166
+ describe "when response was declared as a file with a raw response" do
167
+ before(:each) do
168
+ @file = File.new(CURL_EXAMPLE_OUTPUT_PATH)
169
+ stub_request(:get, "www.example.com").to_return(@file)
170
+ @response = http_request(:get, "http://www.example.com/")
171
+ end
172
+
173
+ it "should return recorded headers" do
174
+ expect(@response.headers).to eq({
175
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
176
+ "Content-Type"=>"text/html; charset=UTF-8",
177
+ "Content-Length"=>"419",
178
+ "Connection"=>"Keep-Alive",
179
+ "Accept"=>"image/jpeg, image/png"
180
+ })
181
+ end
182
+
183
+ it "should return recorded body" do
184
+ expect(@response.body.size).to eq(419)
185
+ end
186
+
187
+ it "should return recorded status" do
188
+ expect(@response.status).to eq("202")
189
+ end
190
+
191
+ it "should return recorded status message", unless: (adapter_info.include?(:no_status_message)) do
192
+ expect(@response.message).to eq("OK")
193
+ end
194
+
195
+ it "should ensure file is closed" do
196
+ expect(@file).to be_closed
197
+ end
198
+ end
199
+
200
+ describe "when response was declared as a string with a raw response" do
201
+ before(:each) do
202
+ @input = File.read(CURL_EXAMPLE_OUTPUT_PATH)
203
+ stub_request(:get, "www.example.com").to_return(@input)
204
+ @response = http_request(:get, "http://www.example.com/")
205
+ end
206
+
207
+ it "should return recorded headers" do
208
+ expect(@response.headers).to eq({
209
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
210
+ "Content-Type"=>"text/html; charset=UTF-8",
211
+ "Content-Length"=>"419",
212
+ "Connection"=>"Keep-Alive",
213
+ "Accept"=>"image/jpeg, image/png"
214
+ })
215
+ end
216
+
217
+ it "should return recorded body" do
218
+ expect(@response.body.size).to eq(419)
219
+ end
220
+
221
+ it "should return recorded status" do
222
+ expect(@response.status).to eq("202")
223
+ end
224
+
225
+ it "should return recorded status message", unless: (adapter_info.include?(:no_status_message)) do
226
+ expect(@response.message).to eq("OK")
227
+ end
228
+ end
229
+
230
+ describe "when response was declared as lambda evaluating to a string with a raw response" do
231
+ before(:each) do
232
+ @files = {
233
+ "www.example.com" => File.new(CURL_EXAMPLE_OUTPUT_PATH)
234
+ }
235
+ end
236
+
237
+ it "should return response from evaluated file" do
238
+ stub_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s] })
239
+ expect(http_request(:get, "http://www.example.com/").body.size).to eq(419)
240
+ end
241
+
242
+ it "should return response from evaluated string" do
243
+ stub_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s].read })
244
+ expect(http_request(:get, "http://www.example.com/").body.size).to eq(419)
245
+ end
246
+ end
247
+
248
+ describe "when response is declared as an Rack app" do
249
+ it "should return response returned by the rack app" do
250
+ stub_request(:any, "http://www.example.com/greet").to_rack(MyRackApp)
251
+ expect(http_request(:post, 'http://www.example.com/greet', body: 'name=Jimmy').body).to eq('Good to meet you, Jimmy!')
252
+ end
253
+
254
+ it "should pass along the port number to the rack app" do
255
+ stub_request(:get, "http://www.example.com/compute").to_rack(MyRackApp)
256
+ expect(http_request(:get, "http://www.example.com/compute").status).to eq("200")
257
+ end
258
+
259
+ it "preserves content-type header when proxying to a rack app" do
260
+ stub_request(:any, //).to_rack(lambda {|req| [200, {}, ["OK"]] })
261
+
262
+ url = "https://google.com/hi/there"
263
+ headers = {
264
+ "Accept" => "application/json",
265
+ "Content-Type" => "application/json"
266
+ }
267
+
268
+ http_request(:get, url, headers: headers)
269
+ expect(WebMock).to have_requested(:get, url).with(headers: headers)
270
+ end
271
+ end
272
+
273
+ describe "when sequences of responses are declared" do
274
+ it "should return responses one by one if declared in array" do
275
+ stub_request(:get, "www.example.com").to_return([ {body: "1"}, {body: "2"}, {body: "3"} ])
276
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
277
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
278
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
279
+ end
280
+
281
+ it "should repeat returning last declared response from a sequence after all responses were returned" do
282
+ stub_request(:get, "www.example.com").to_return([ {body: "1"}, {body: "2"} ])
283
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
284
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
285
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
286
+ end
287
+
288
+ it "should return responses one by one if declared as comma separated params" do
289
+ stub_request(:get, "www.example.com").to_return({body: "1"}, {body: "2"}, {body: "3"})
290
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
291
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
292
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
293
+ end
294
+
295
+ it "should return responses one by one if declared with several to_return invokations" do
296
+ stub_request(:get, "www.example.com").
297
+ to_return({body: "1"}).
298
+ to_return({body: "2"}).
299
+ to_return({body: "3"})
300
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
301
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
302
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
303
+ end
304
+
305
+ it "should return responses one by one if declared with to_return invocations separated with then syntactic sugar" do
306
+ stub_request(:get, "www.example.com").to_return({body: "1"}).then.
307
+ to_return({body: "2"}).then.to_return({body: "3"})
308
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
309
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
310
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
311
+ end
312
+
313
+ end
314
+
315
+ describe "when responses are declared to return more than once" do
316
+ it "should repeat one response declared number of times" do
317
+ stub_request(:get, "www.example.com").
318
+ to_return({body: "1"}).times(2).
319
+ to_return({body: "2"})
320
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
321
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
322
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
323
+ end
324
+
325
+
326
+ it "should repeat sequence of response declared number of times" do
327
+ stub_request(:get, "www.example.com").
328
+ to_return({body: "1"}, {body: "2"}).times(2).
329
+ to_return({body: "3"})
330
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
331
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
332
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
333
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
334
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
335
+ end
336
+
337
+
338
+ it "should repeat infinitely last response even if number of declared times is lower" do
339
+ stub_request(:get, "www.example.com").
340
+ to_return({body: "1"}).times(2)
341
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
342
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
343
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
344
+ end
345
+
346
+ it "should give error if times is declared without specifying response" do
347
+ expect {
348
+ stub_request(:get, "www.example.com").times(3)
349
+ }.to raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
350
+ end
351
+
352
+ end
353
+
354
+ describe "when exception is declared to be raised more than once" do
355
+ it "should repeat raising exception declared number of times" do
356
+ stub_request(:get, "www.example.com").
357
+ to_raise(MyException).times(2).
358
+ to_return({body: "2"})
359
+ expect {
360
+ http_request(:get, "http://www.example.com/")
361
+ }.to raise_error(MyException, "Exception from WebMock")
362
+ expect {
363
+ http_request(:get, "http://www.example.com/")
364
+ }.to raise_error(MyException, "Exception from WebMock")
365
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
366
+ end
367
+
368
+ it "should repeat raising sequence of exceptions declared number of times" do
369
+ stub_request(:get, "www.example.com").
370
+ to_raise(MyException, ArgumentError).times(2).
371
+ to_return({body: "2"})
372
+ expect {
373
+ http_request(:get, "http://www.example.com/")
374
+ }.to raise_error(MyException, "Exception from WebMock")
375
+ expect {
376
+ http_request(:get, "http://www.example.com/")
377
+ }.to raise_error(ArgumentError)
378
+ expect {
379
+ http_request(:get, "http://www.example.com/")
380
+ }.to raise_error(MyException, "Exception from WebMock")
381
+ expect {
382
+ http_request(:get, "http://www.example.com/")
383
+ }.to raise_error(ArgumentError)
384
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
385
+ end
386
+ end
387
+ end
388
+ end
@@ -0,0 +1,583 @@
1
+ # encoding: utf-8
2
+
3
+ shared_examples_for "stubbing requests" do |*adapter_info|
4
+ describe "when requests are stubbed" do
5
+ describe "based on uri" do
6
+ it "should return stubbed response even if request have escaped parameters" do
7
+ stub_request(:get, "www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").to_return(body: "abc")
8
+ expect(http_request(:get, "http://www.example.com/hello%2B/?#{ESCAPED_PARAMS}").body).to eq("abc")
9
+ end
10
+
11
+ it "should return stubbed response even if query params have integer values" do
12
+ stub_request(:get, "www.example.com").with(query: {"a" => 1}).to_return(body: "abc")
13
+ expect(http_request(:get, "http://www.example.com/?a=1").body).to eq("abc")
14
+ end
15
+
16
+ it "should return stubbed response even if request has non escaped params" do
17
+ stub_request(:get, "www.example.com/hello%2B/?#{ESCAPED_PARAMS}").to_return(body: "abc")
18
+ expect(http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").body).to eq("abc")
19
+ end
20
+
21
+ it "should return stubbed response for url with non utf query params", "ruby>1.9" => true do
22
+ param = 'aäoöuü'.encode('iso-8859-1')
23
+ param = CGI.escape(param)
24
+ stub_request(:get, "www.example.com/?#{param}").to_return(body: "abc")
25
+ expect(http_request(:get, "http://www.example.com/?#{param}").body).to eq("abc")
26
+ end
27
+
28
+ it "should return stubbed response even if stub uri is declared as regexp and request params are escaped" do
29
+ stub_request(:get, /.*x=ab c.*/).to_return(body: "abc")
30
+ expect(http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body).to eq("abc")
31
+ end
32
+
33
+ it "should raise error specifying stubbing instructions with escaped characters in params if there is no matching stub" do
34
+ begin
35
+ http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
36
+ rescue WebMock::NetConnectNotAllowedError => e
37
+ expect(e.message).to match(/Unregistered request: GET http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m)
38
+ expect(e.message).to match(/stub_request\(:get, "http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m)
39
+ end
40
+
41
+ stub_request(:get, "http://www.example.com/hello+/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
42
+ http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
43
+ end
44
+ end
45
+
46
+ describe "based on query params" do
47
+ it "should return stubbed response when stub declares query params as a hash" do
48
+ stub_request(:get, "www.example.com").with(query: {"a" => ["b x", "c d"]}).to_return(body: "abc")
49
+ expect(http_request(:get, "http://www.example.com/?a[]=b+x&a[]=c%20d").body).to eq("abc")
50
+ end
51
+
52
+ it "should return stubbed response when stub declares query params as a hash" do
53
+ stub_request(:get, "www.example.com").with(query: "a[]=b&a[]=c").to_return(body: "abc")
54
+ expect(http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body).to eq("abc")
55
+ end
56
+
57
+ it "should return stubbed response when stub declares query params both in uri and as a hash" do
58
+ stub_request(:get, "www.example.com/?x=3").with(query: {"a" => ["b", "c"]}).to_return(body: "abc")
59
+ expect(http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c").body).to eq("abc")
60
+ end
61
+
62
+ it "should return stubbed response when stub expects only part of query params" do
63
+ stub_request(:get, "www.example.com").with(query: hash_including({"a" => ["b", "c"]})).to_return(body: "abc")
64
+ expect(http_request(:get, "http://www.example.com/?a[]=b&a[]=c&b=1").body).to eq("abc")
65
+ end
66
+ end
67
+
68
+ describe "based on method" do
69
+ it "should return stubbed response" do
70
+ stub_request(:get, "www.example.com")
71
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
72
+ end
73
+
74
+ it "should match stubbed request when http request was made with method given as string" do
75
+ stub_request(:get, "www.example.com")
76
+ expect(http_request('get', "http://www.example.com/").status).to eq("200")
77
+ end
78
+
79
+ it "should raise error if stubbed request has different method" do
80
+ stub_request(:get, "www.example.com")
81
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
82
+ expect {
83
+ http_request(:delete, "http://www.example.com/")
84
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
85
+ )
86
+ end
87
+ end
88
+
89
+ describe "based on body" do
90
+ it "should match requests if body is the same" do
91
+ stub_request(:post, "www.example.com").with(body: "abc")
92
+ expect(http_request(
93
+ :post, "http://www.example.com/",
94
+ body: "abc").status).to eq("200")
95
+ end
96
+
97
+ it "should match requests if body is not set in the stub" do
98
+ stub_request(:post, "www.example.com")
99
+ expect(http_request(
100
+ :post, "http://www.example.com/",
101
+ body: "abc").status).to eq("200")
102
+ end
103
+
104
+ it "should not match requests if body is different" do
105
+ stub_request(:post, "www.example.com").with(body: "abc")
106
+ expect {
107
+ http_request(:post, "http://www.example.com/", body: "def")
108
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
109
+ end
110
+
111
+ describe "with regular expressions" do
112
+ it "should match requests if body matches regexp" do
113
+ stub_request(:post, "www.example.com").with(body: /\d+abc$/)
114
+ expect(http_request(
115
+ :post, "http://www.example.com/",
116
+ body: "123abc").status).to eq("200")
117
+ end
118
+
119
+ it "should not match requests if body doesn't match regexp" do
120
+ stub_request(:post, "www.example.com").with(body: /^abc/)
121
+ expect {
122
+ http_request(:post, "http://www.example.com/", body: "xabc")
123
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
124
+ end
125
+ end
126
+
127
+ describe "when body is declared as a hash" do
128
+ before(:each) do
129
+ stub_request(:post, "www.example.com").
130
+ with(body: {:a => '1', :b => 'five x', 'c' => {'d' => ['e', 'f']} })
131
+ end
132
+
133
+ describe "for request with url encoded body" do
134
+ it "should match request if hash matches body" do
135
+ expect(http_request(
136
+ :post, "http://www.example.com/",
137
+ body: 'a=1&c[d][]=e&c[d][]=f&b=five+x').status).to eq("200")
138
+ end
139
+
140
+ it "should match request if hash matches body in different order of params" do
141
+ expect(http_request(
142
+ :post, "http://www.example.com/",
143
+ body: 'a=1&c[d][]=e&b=five+x&c[d][]=f').status).to eq("200")
144
+ end
145
+
146
+ it "should not match if hash doesn't match url encoded body" do
147
+ expect {
148
+ http_request(
149
+ :post, "http://www.example.com/",
150
+ body: 'c[d][]=f&a=1&c[d][]=e')
151
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'c\[d\]\[\]=f&a=1&c\[d\]\[\]=e'))
152
+ end
153
+ end
154
+
155
+
156
+ describe "for request with json body and content type is set to json" do
157
+ it "should match if hash matches body" do
158
+ expect(http_request(
159
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
160
+ body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five x\"}").status).to eq("200")
161
+ end
162
+
163
+ it "should match if hash matches body in different form" do
164
+ expect(http_request(
165
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
166
+ body: "{\"a\":\"1\",\"b\":\"five x\",\"c\":{\"d\":[\"e\",\"f\"]}}").status).to eq("200")
167
+ end
168
+
169
+ it "should match if hash contains date string" do #Crack creates date object
170
+ WebMock.reset!
171
+ stub_request(:post, "www.example.com").
172
+ with(body: {"foo" => "2010-01-01"})
173
+ expect(http_request(
174
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
175
+ body: "{\"foo\":\"2010-01-01\"}").status).to eq("200")
176
+ end
177
+
178
+ it "should match if any of the strings have spaces" do
179
+ WebMock.reset!
180
+ stub_request(:post, "www.example.com").with(body: {"foo" => "a b c"})
181
+ expect(http_request(
182
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
183
+ body: "{\"foo\":\"a b c\"}").status).to eq("200")
184
+ end
185
+ end
186
+
187
+ describe "for request with xml body and content type is set to xml" do
188
+ before(:each) do
189
+ WebMock.reset!
190
+ stub_request(:post, "www.example.com").
191
+ with(body: { "opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']} }})
192
+ end
193
+
194
+ it "should match if hash matches body" do
195
+ expect(http_request(
196
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
197
+ body: "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status).to eq("200")
198
+ end
199
+
200
+ it "should match if hash matches body in different form" do
201
+ expect(http_request(
202
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
203
+ body: "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status).to eq("200")
204
+ end
205
+
206
+ it "should match if hash contains date string" do #Crack creates date object
207
+ WebMock.reset!
208
+ stub_request(:post, "www.example.com").
209
+ with(body: {"opt" => {"foo" => "2010-01-01"}})
210
+ expect(http_request(
211
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/xml'},
212
+ body: "<opt foo=\"2010-01-01\">\n</opt>\n").status).to eq("200")
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "when body is declared as partial hash matcher" do
218
+ subject(:request) { http_request( :post, "http://www.example.com/",
219
+ body: 'a=1&c[d][]=e&c[d][]=f&b=five') }
220
+
221
+ subject(:wrong_request) { http_request(:post, "http://www.example.com/",
222
+ body: 'c[d][]=f&a=1&c[d][]=e').status }
223
+
224
+ describe "when using 'RSpec:Mocks::ArgumentMatchers#hash_including'" do
225
+ before(:each) do
226
+ stub_request(:post, "www.example.com").
227
+ with(body: hash_including(:a, c: {'d' => ['e', 'f']} ))
228
+ end
229
+
230
+ describe "for request with url encoded body" do
231
+ it "should match request if hash matches body" do
232
+ expect(request.status).to eq("200")
233
+ end
234
+
235
+ it "should not match if hash doesn't match url encoded body" do
236
+ expect { wrong_request }.to raise_error(WebMock::NetConnectNotAllowedError)
237
+ end
238
+ end
239
+
240
+ describe "for request with json body and content type is set to json" do
241
+ it "should match if hash matches body" do
242
+ expect(http_request(
243
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
244
+ body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status).to eq("200")
245
+ end
246
+ end
247
+ end
248
+
249
+ describe "when using 'WebMock::API#hash_including'" do
250
+ before(:each) do
251
+ stub_request(:post, "www.example.com").
252
+ with(body: WebMock::API.hash_including(:a, c: {'d' => ['e', 'f']} ))
253
+ end
254
+
255
+ describe "for request with url encoded body" do
256
+ it "should match request if hash matches body" do
257
+ expect(request.status).to eq("200")
258
+ end
259
+
260
+ it "should not match if hash doesn't match url encoded body" do
261
+ expect { wrong_request }.to raise_error(WebMock::NetConnectNotAllowedError)
262
+ end
263
+ end
264
+
265
+ describe "for request with json body and content type is set to json" do
266
+ it "should match if hash matches body" do
267
+ expect(http_request(
268
+ :post, "http://www.example.com/", headers: {'Content-Type' => 'application/json'},
269
+ body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status).to eq("200")
270
+ end
271
+ end
272
+ end
273
+
274
+ end
275
+ end
276
+
277
+ describe "based on headers" do
278
+ it "should match requests if headers are the same" do
279
+ stub_request(:get, "www.example.com").with(headers: SAMPLE_HEADERS )
280
+ expect(http_request(
281
+ :get, "http://www.example.com/",
282
+ headers: SAMPLE_HEADERS).status).to eq("200")
283
+ end
284
+
285
+ it "should match requests if headers are the same and declared as array" do
286
+ stub_request(:get, "www.example.com").with(headers: {"a" => ["b"]} )
287
+ expect(http_request(
288
+ :get, "http://www.example.com/",
289
+ headers: {"a" => "b"}).status).to eq("200")
290
+ end
291
+
292
+ describe "when multiple headers with the same key are used" do
293
+ it "should match requests if headers are the same" do
294
+ stub_request(:get, "www.example.com").with(headers: {"a" => ["b", "c"]} )
295
+ expect(http_request(
296
+ :get, "http://www.example.com/",
297
+ headers: {"a" => ["b", "c"]}).status).to eq("200")
298
+ end
299
+
300
+ it "should match requests if headers are the same but in different order" do
301
+ stub_request(:get, "www.example.com").with(headers: {"a" => ["b", "c"]} )
302
+ expect(http_request(
303
+ :get, "http://www.example.com/",
304
+ headers: {"a" => ["c", "b"]}).status).to eq("200")
305
+ end
306
+
307
+ it "should not match requests if headers are different" do
308
+ stub_request(:get, "www.example.com").with(headers: {"a" => ["b", "c"]})
309
+
310
+ expect {
311
+ http_request(
312
+ :get, "http://www.example.com/",
313
+ headers: {"a" => ["b", "d"]})
314
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
315
+ end
316
+ end
317
+
318
+ it "should match requests if request headers are not stubbed" do
319
+ stub_request(:get, "www.example.com")
320
+ expect(http_request(
321
+ :get, "http://www.example.com/",
322
+ headers: SAMPLE_HEADERS).status).to eq("200")
323
+ end
324
+
325
+ it "should not match requests if headers are different" do
326
+ stub_request(:get, "www.example.com").with(headers: SAMPLE_HEADERS)
327
+
328
+ expect {
329
+ http_request(
330
+ :get, "http://www.example.com/",
331
+ headers: { 'Content-Length' => '9999'})
332
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
333
+ end
334
+
335
+ it "should not match if accept header is different" do
336
+ stub_request(:get, "www.example.com").
337
+ with(headers: { 'Accept' => 'application/json'})
338
+ expect {
339
+ http_request(
340
+ :get, "http://www.example.com/",
341
+ headers: { 'Accept' => 'application/xml'})
342
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
343
+ end
344
+
345
+ describe "declared as regular expressions" do
346
+ it "should match requests if header values match regular expression" do
347
+ stub_request(:get, "www.example.com").with(headers: { some_header: /^MyAppName$/ })
348
+ expect(http_request(
349
+ :get, "http://www.example.com/",
350
+ headers: { 'some-header' => 'MyAppName' }).status).to eq("200")
351
+ end
352
+
353
+ it "should not match requests if headers values do not match regular expression" do
354
+ stub_request(:get, "www.example.com").with(headers: { some_header: /^MyAppName$/ })
355
+
356
+ expect {
357
+ http_request(
358
+ :get, "http://www.example.com/",
359
+ headers: { 'some-header' => 'xMyAppName' })
360
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
361
+ end
362
+ end
363
+ end
364
+
365
+ describe "when stubbing request with userinfo in url", unless: (adapter_info.include?(:no_url_auth)) do
366
+ it "should match if credentials are the same" do
367
+ stub_request(:get, "user:pass@www.example.com")
368
+ expect(http_request(:get, "http://user:pass@www.example.com/").status).to eq("200")
369
+ end
370
+
371
+ it "should not match if credentials are different" do
372
+ stub_request(:get, "user:pass@www.example.com")
373
+ expect {
374
+ expect(http_request(:get, "http://user:pazz@www.example.com/").status).to eq("200")
375
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
376
+ end
377
+
378
+ it "should not match if credentials are stubbed but not provided in the request" do
379
+ stub_request(:get, "user:pass@www.example.com")
380
+ expect {
381
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
382
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
383
+ end
384
+
385
+ it "should not match if credentials are not stubbed but exist in the request" do
386
+ stub_request(:get, "www.example.com")
387
+ expect {
388
+ expect(http_request(:get, "http://user:pazz@www.example.com/").status).to eq("200")
389
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
390
+ end
391
+
392
+ it "should not match if request has credentials provided in basic authentication herader" do
393
+ stub_request(:get, "user:pass@www.example.com")
394
+ expect {
395
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user', 'pass']).status).to eq("200")
396
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
397
+ end
398
+ end
399
+
400
+ describe "when stubbing request with basic authentication header" do
401
+ it "should match if credentials are the same" do
402
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
403
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user', 'pass']).status).to eq("200")
404
+ end
405
+
406
+ it "should match if credentials are the same and encode to more than one line" do
407
+ stub_request(:get, "www.example.com").with(basic_auth: ['user' * 5, 'pass' * 5])
408
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user' * 5, 'pass' * 5]).status).to eq("200")
409
+ end
410
+
411
+ it "should match if credentials are the same and were provided directly as authentication headers in request" do
412
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
413
+ expect(http_request(:get, "http://www.example.com/", headers: {'Authorization'=>'Basic dXNlcjpwYXNz'}).status).to eq("200")
414
+ end
415
+
416
+ it "should match if credentials are the same and have been declared in the stub as encoded header" do
417
+ stub_request(:get, "www.example.com").with(headers: {'Authorization'=>'Basic dXNlcjpwYXNz'})
418
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user', 'pass']).status).to eq("200")
419
+ end
420
+
421
+ it "should not match if credentials are different" do
422
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
423
+ expect {
424
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user', 'pazz']).status).to eq("200")
425
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
426
+ end
427
+
428
+ it "should not match if credentials are stubbed but not provided in the request" do
429
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
430
+ expect {
431
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
432
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
433
+ end
434
+
435
+ it "should match if credentials are not stubbed but exist in the request" do
436
+ stub_request(:get, "www.example.com")
437
+ expect(http_request(:get, "http://www.example.com/", basic_auth: ['user', 'pass']).status).to eq("200")
438
+ end
439
+
440
+ it "should not match if request has credentials provides in userinfo", unless: (adapter_info.include?(:no_url_auth)) do
441
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
442
+ expect {
443
+ expect(http_request(:get, "http://user:pass@www.example.com/").status).to eq("200")
444
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pass@www.example.com/))
445
+ end
446
+ end
447
+
448
+ describe "when stubbing request with a global hook" do
449
+ after(:each) do
450
+ WebMock::StubRegistry.instance.global_stubs.clear
451
+ end
452
+
453
+ it 'returns the response returned by the hook' do
454
+ WebMock.globally_stub_request do |request|
455
+ { body: "global stub body" }
456
+ end
457
+
458
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
459
+ end
460
+
461
+ it 'does not get cleared when a user calls WebMock.reset!' do
462
+ WebMock.globally_stub_request do |request|
463
+ { body: "global stub body" }
464
+ end
465
+ WebMock.reset!
466
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
467
+ end
468
+
469
+ it "does not stub the request if the hook does not return anything" do
470
+ WebMock.globally_stub_request { |r| }
471
+ expect {
472
+ http_request(:get, "http://www.example.com/")
473
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
474
+ end
475
+
476
+ it "passes the request to the block" do
477
+ passed_request = nil
478
+ WebMock.globally_stub_request do |request|
479
+ passed_request = request
480
+ { body: "global stub body" }
481
+ end
482
+
483
+ http_request(:get, "http://www.example.com:456/bar")
484
+ expect(passed_request.uri.to_s).to eq("http://www.example.com:456/bar")
485
+ end
486
+
487
+ it "should call the block only once per request" do
488
+ call_count = 0
489
+ WebMock.globally_stub_request do |request|
490
+ call_count += 1
491
+ { body: "global stub body" }
492
+ end
493
+ http_request(:get, "http://www.example.com/")
494
+ expect(call_count).to eq(1)
495
+ end
496
+
497
+ it 'supports multiple global stubs; the first registered one that returns a non-nil value determines the stub' do
498
+ stub_invocation_order = []
499
+ WebMock.globally_stub_request do |request|
500
+ stub_invocation_order << :nil_stub
501
+ nil
502
+ end
503
+
504
+ WebMock.globally_stub_request do |request|
505
+ stub_invocation_order << :hash_stub
506
+ { body: "global stub body" }
507
+ end
508
+
509
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
510
+ expect(stub_invocation_order).to eq([:nil_stub, :hash_stub])
511
+ end
512
+
513
+ [:before, :after].each do |before_or_after|
514
+ context "when there is also a non-global registered stub #{before_or_after} the global stub" do
515
+ def stub_non_globally
516
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
517
+ end
518
+
519
+ define_method :register_stubs do |block|
520
+ stub_non_globally if before_or_after == :before
521
+ WebMock.globally_stub_request(&block)
522
+ stub_non_globally if before_or_after == :after
523
+ end
524
+
525
+ it 'uses the response from the global stub if the block returns a non-nil value' do
526
+ register_stubs(lambda { |req| { body: 'global stub body' } })
527
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
528
+ end
529
+
530
+ it 'uses the response from the non-global stub if the block returns a nil value' do
531
+ register_stubs(lambda { |req| nil })
532
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
533
+ end
534
+ end
535
+ end
536
+ end
537
+
538
+ describe "when stubbing request with a block evaluated on request" do
539
+ it "should match if block returns true" do
540
+ stub_request(:get, "www.example.com").with { |request| true }
541
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
542
+ end
543
+
544
+ it "should not match if block returns false" do
545
+ stub_request(:get, "www.example.com").with { |request| false }
546
+ expect {
547
+ http_request(:get, "http://www.example.com/")
548
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
549
+ end
550
+
551
+ it "should pass the request to the block" do
552
+ stub_request(:post, "www.example.com").with { |request| request.body == "wadus" }
553
+ expect(http_request(
554
+ :post, "http://www.example.com/",
555
+ body: "wadus").status).to eq("200")
556
+ expect {
557
+ http_request(:post, "http://www.example.com/", body: "jander")
558
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
559
+ end
560
+
561
+ it "should call the block only once per request" do
562
+ call_count = 0
563
+ stub_request(:get, "www.example.com").with { |request| call_count += 1; true }
564
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
565
+ expect(call_count).to eq(1)
566
+ end
567
+ end
568
+ end
569
+
570
+ describe "when request stub was removed" do
571
+ it "should raise an error on request" do
572
+ stub = stub_request(:get, "www.example.com")
573
+
574
+ http_request(:get, "http://www.example.com/")
575
+
576
+ remove_request_stub(stub)
577
+
578
+ expect {
579
+ http_request(:get, "http://www.example.com/")
580
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
581
+ end
582
+ end
583
+ end