http_stub 0.27.0 → 0.28.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub/client.rb +18 -0
  3. data/lib/http_stub/client/client.rb +28 -0
  4. data/lib/http_stub/client/request.rb +38 -0
  5. data/lib/http_stub/client/server.rb +20 -0
  6. data/lib/http_stub/client/session.rb +43 -0
  7. data/lib/http_stub/configurator.rb +61 -0
  8. data/lib/http_stub/configurator/endpoint_template.rb +24 -0
  9. data/lib/http_stub/configurator/part.rb +23 -0
  10. data/lib/http_stub/configurator/scenario.rb +42 -0
  11. data/lib/http_stub/configurator/server.rb +53 -0
  12. data/lib/http_stub/configurator/state.rb +41 -0
  13. data/lib/http_stub/configurator/stub.rb +13 -0
  14. data/lib/http_stub/configurator/stub/stub.rb +75 -0
  15. data/lib/http_stub/{configurer/dsl/stub_builder_template.rb → configurator/stub/template.rb} +5 -5
  16. data/lib/http_stub/extensions/core/object.rb +17 -0
  17. data/lib/http_stub/rake/server_tasks.rb +2 -14
  18. data/lib/http_stub/rake/task_generators.rb +3 -3
  19. data/lib/http_stub/server.rb +110 -0
  20. data/lib/http_stub/server/application/application.rb +10 -6
  21. data/lib/http_stub/server/application/request_support.rb +2 -2
  22. data/lib/http_stub/server/application/routes/memory.rb +1 -6
  23. data/lib/http_stub/server/application/routes/scenario.rb +1 -11
  24. data/lib/http_stub/server/application/routes/session.rb +1 -1
  25. data/lib/http_stub/server/application/routes/status.rb +0 -10
  26. data/lib/http_stub/server/application/routes/stub.rb +2 -12
  27. data/lib/http_stub/server/daemon.rb +1 -10
  28. data/lib/http_stub/server/memory/controller.rb +2 -8
  29. data/lib/http_stub/server/memory/initial_state.rb +27 -0
  30. data/lib/http_stub/server/memory/memory.rb +6 -27
  31. data/lib/http_stub/server/registry.rb +3 -1
  32. data/lib/http_stub/server/request/factory.rb +3 -3
  33. data/lib/http_stub/server/response.rb +12 -6
  34. data/lib/http_stub/server/scenario.rb +2 -2
  35. data/lib/http_stub/server/scenario/controller.rb +3 -13
  36. data/lib/http_stub/server/scenario/registry.rb +25 -0
  37. data/lib/http_stub/server/scenario/scenario.rb +13 -8
  38. data/lib/http_stub/server/session.rb +0 -1
  39. data/lib/http_stub/server/session/controller.rb +7 -8
  40. data/lib/http_stub/server/session/identifier_strategy.rb +9 -2
  41. data/lib/http_stub/server/session/registry.rb +7 -13
  42. data/lib/http_stub/server/session/session.rb +4 -8
  43. data/lib/http_stub/server/stdout_logger.rb +13 -0
  44. data/lib/http_stub/server/stub.rb +3 -2
  45. data/lib/http_stub/server/stub/controller.rb +0 -10
  46. data/lib/http_stub/server/stub/empty.rb +2 -1
  47. data/lib/http_stub/server/stub/match/controller.rb +1 -1
  48. data/lib/http_stub/server/stub/match/exact_value_matcher.rb +2 -1
  49. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -1
  50. data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +1 -2
  51. data/lib/http_stub/server/stub/match/rule/body.rb +7 -29
  52. data/lib/http_stub/server/stub/match/rule/{json_body.rb → json_schema_body.rb} +1 -1
  53. data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
  54. data/lib/http_stub/server/stub/match/rule/schema_body.rb +39 -0
  55. data/lib/http_stub/server/stub/match/rules.rb +6 -6
  56. data/lib/http_stub/server/stub/match/string_value_matcher.rb +1 -2
  57. data/lib/http_stub/server/stub/registry.rb +4 -4
  58. data/lib/http_stub/server/stub/response.rb +2 -6
  59. data/lib/http_stub/server/stub/response/blocks.rb +33 -0
  60. data/lib/http_stub/server/stub/response/body.rb +21 -0
  61. data/lib/http_stub/server/stub/response/file_body.rb +46 -0
  62. data/lib/http_stub/server/stub/response/headers.rb +24 -0
  63. data/lib/http_stub/server/stub/response/response.rb +52 -0
  64. data/lib/http_stub/server/stub/response/text_body.rb +32 -0
  65. data/lib/http_stub/server/stub/stub.rb +17 -11
  66. data/lib/http_stub/server/stub/triggers.rb +16 -5
  67. data/lib/http_stub/server/views/_file_body_response.haml +1 -0
  68. data/lib/http_stub/server/views/_response.haml +6 -1
  69. data/lib/http_stub/server/views/_text_body_response.haml +1 -0
  70. data/lib/http_stub/server/views/application.sass +31 -31
  71. data/lib/http_stub/version.rb +1 -1
  72. data/spec/acceptance/{configurer_part_spec.rb → configurator_part_spec.rb} +8 -8
  73. data/spec/acceptance/cross_origin_support_spec.rb +9 -11
  74. data/spec/acceptance/endpoint_template_spec.rb +5 -5
  75. data/spec/acceptance/scenario_spec.rb +8 -8
  76. data/spec/acceptance/server_defaults_spec.rb +3 -3
  77. data/spec/acceptance/server_memory_spec.rb +13 -5
  78. data/spec/acceptance/server_status_spec.rb +4 -21
  79. data/spec/acceptance/session_spec.rb +8 -11
  80. data/spec/acceptance/stub_body_request_matching_spec.rb +9 -9
  81. data/spec/acceptance/stub_control_values_spec.rb +74 -82
  82. data/spec/acceptance/stub_match_last_spec.rb +60 -80
  83. data/spec/acceptance/stub_match_list_spec.rb +30 -66
  84. data/spec/acceptance/stub_miss_list_spec.rb +19 -27
  85. data/spec/acceptance/stub_response_block_spec.rb +66 -0
  86. data/spec/acceptance/stub_spec.rb +109 -185
  87. data/spec/acceptance/stub_trigger_spec.rb +12 -89
  88. data/spec/helper.rb +32 -10
  89. data/spec/lib/http_stub/client/client_spec.rb +109 -0
  90. data/spec/lib/http_stub/client/request_integration_spec.rb +74 -0
  91. data/spec/lib/http_stub/client/request_spec.rb +32 -0
  92. data/spec/lib/http_stub/client/server_spec.rb +75 -0
  93. data/spec/lib/http_stub/client/session_spec.rb +117 -0
  94. data/spec/lib/http_stub/client_spec.rb +15 -0
  95. data/spec/lib/http_stub/{configurer/dsl/server_endpoint_template_spec.rb → configurator/endpoint_template_spec.rb} +49 -38
  96. data/spec/lib/http_stub/configurator/part_spec.rb +103 -0
  97. data/spec/lib/http_stub/configurator/scenario_spec.rb +162 -0
  98. data/spec/lib/http_stub/configurator/server_spec.rb +344 -0
  99. data/spec/lib/http_stub/configurator/state_spec.rb +113 -0
  100. data/spec/lib/http_stub/configurator/stub/stub_spec.rb +867 -0
  101. data/spec/lib/http_stub/{configurer/dsl/stub_builder_template_spec.rb → configurator/stub/template_spec.rb} +46 -44
  102. data/spec/lib/http_stub/configurator/stub_spec.rb +27 -0
  103. data/spec/lib/http_stub/configurator_spec.rb +113 -0
  104. data/spec/lib/http_stub/extensions/core/hash_spec.rb +3 -3
  105. data/spec/lib/http_stub/extensions/core/object_spec.rb +29 -0
  106. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +14 -9
  107. data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +25 -53
  108. data/spec/lib/http_stub/rake/server_tasks_spec.rb +12 -55
  109. data/spec/lib/http_stub/server/application/application_spec.rb +4 -49
  110. data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +2 -5
  111. data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +4 -4
  112. data/spec/lib/http_stub/server/application/request_support_spec.rb +16 -11
  113. data/spec/lib/http_stub/server/application/routes/memory_spec.rb +1 -21
  114. data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +4 -56
  115. data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +1 -1
  116. data/spec/lib/http_stub/server/application/routes/status_spec.rb +2 -36
  117. data/spec/lib/http_stub/server/application/routes/stub_integration_spec.rb +3 -34
  118. data/spec/lib/http_stub/server/application/routes/stub_spec.rb +6 -55
  119. data/spec/lib/http_stub/server/daemon_integration_spec.rb +5 -1
  120. data/spec/lib/http_stub/server/daemon_spec.rb +8 -77
  121. data/spec/lib/http_stub/server/memory/controller_spec.rb +2 -28
  122. data/spec/lib/http_stub/server/memory/initial_state_spec.rb +57 -0
  123. data/spec/lib/http_stub/server/memory/memory_spec.rb +28 -116
  124. data/spec/lib/http_stub/server/registry_spec.rb +57 -2
  125. data/spec/lib/http_stub/server/request/factory_spec.rb +8 -6
  126. data/spec/lib/http_stub/server/response_spec.rb +32 -10
  127. data/spec/lib/http_stub/server/scenario/controller_spec.rb +14 -53
  128. data/spec/lib/http_stub/server/scenario/registry_spec.rb +147 -0
  129. data/spec/lib/http_stub/server/scenario/scenario_spec.rb +8 -10
  130. data/spec/lib/http_stub/server/scenario_spec.rb +1 -1
  131. data/spec/lib/http_stub/server/session/controller_spec.rb +4 -5
  132. data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +15 -48
  133. data/spec/lib/http_stub/server/session/registry_spec.rb +15 -28
  134. data/spec/lib/http_stub/server/session/session_spec.rb +13 -71
  135. data/spec/lib/http_stub/server/stdout_logger_spec.rb +17 -0
  136. data/spec/lib/http_stub/server/stub/controller_spec.rb +7 -65
  137. data/spec/lib/http_stub/server/stub/empty_spec.rb +8 -0
  138. data/spec/lib/http_stub/server/stub/match/controller_spec.rb +2 -2
  139. data/spec/lib/http_stub/server/stub/match/exact_value_matcher_spec.rb +49 -11
  140. data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +4 -4
  141. data/spec/lib/http_stub/server/stub/match/match_spec.rb +4 -4
  142. data/spec/lib/http_stub/server/stub/match/miss_spec.rb +2 -2
  143. data/spec/lib/http_stub/server/stub/match/omitted_value_matcher_spec.rb +31 -12
  144. data/spec/lib/http_stub/server/stub/match/regexp_value_matcher_spec.rb +20 -11
  145. data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +3 -3
  146. data/spec/lib/http_stub/server/stub/match/rule/{json_body_spec.rb → json_schema_body_spec.rb} +5 -5
  147. data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +42 -8
  148. data/spec/lib/http_stub/server/stub/match/rule/schema_body_spec.rb +64 -0
  149. data/spec/lib/http_stub/server/stub/match/rules_spec.rb +18 -18
  150. data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +10 -63
  151. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +11 -28
  152. data/spec/lib/http_stub/server/stub/registry_spec.rb +6 -13
  153. data/spec/lib/http_stub/server/stub/response/blocks_spec.rb +64 -0
  154. data/spec/lib/http_stub/server/stub/response/body_spec.rb +52 -0
  155. data/spec/lib/http_stub/server/stub/response/file_body_spec.rb +117 -0
  156. data/spec/lib/http_stub/server/stub/response/headers_spec.rb +89 -0
  157. data/spec/lib/http_stub/server/stub/response/response_spec.rb +342 -0
  158. data/spec/lib/http_stub/server/stub/response/text_body_spec.rb +138 -0
  159. data/spec/lib/http_stub/server/stub/response_spec.rb +23 -32
  160. data/spec/lib/http_stub/server/stub/stub_spec.rb +33 -39
  161. data/spec/lib/http_stub/server/stub/triggers_spec.rb +47 -12
  162. data/spec/lib/http_stub/server/stub_spec.rb +1 -1
  163. data/spec/support/extensions/core/random.rb +23 -0
  164. data/spec/support/http_stub/configurator/scenario_builder.rb +35 -0
  165. data/spec/support/http_stub/configurator/scenario_fixture.rb +39 -0
  166. data/spec/support/http_stub/configurator/stub_builder.rb +112 -0
  167. data/spec/support/http_stub/configurator/stub_fixture.rb +58 -0
  168. data/spec/support/http_stub/configurator_fixture.rb +13 -0
  169. data/spec/support/http_stub/configurator_with_stub_builder_and_requester.rb +14 -0
  170. data/spec/support/http_stub/headers_fixture.rb +11 -0
  171. data/spec/support/http_stub/{html_view_excluding_request_details.rb → html_view_excluding_a_stub_request.rb} +2 -2
  172. data/spec/support/http_stub/{html_view_including_request_details.rb → html_view_including_a_stub_request.rb} +20 -12
  173. data/spec/support/http_stub/port.rb +12 -0
  174. data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +2 -3
  175. data/spec/support/http_stub/server/driver.rb +20 -15
  176. data/spec/support/http_stub/server/memory_fixture.rb +2 -2
  177. data/spec/support/http_stub/server/request/sinatra_request_fixture.rb +16 -0
  178. data/spec/support/http_stub/server/request_fixture.rb +11 -6
  179. data/spec/support/http_stub/server/scenario_fixture.rb +14 -2
  180. data/spec/support/http_stub/server/session_fixture.rb +2 -16
  181. data/spec/support/http_stub/server/silent_logger.rb +7 -0
  182. data/spec/support/http_stub/server/simple_request.rb +17 -0
  183. data/spec/support/http_stub/server/stub/match/match_fixture.rb +1 -1
  184. data/spec/support/http_stub/server/stub/response/blocks_fixture.rb +54 -0
  185. data/spec/support/http_stub/server/stub/response/file_body_fixture.rb +25 -0
  186. data/spec/support/http_stub/server/stub/response/text_body_fixture.rb +33 -0
  187. data/spec/support/http_stub/server/stub/response_builder.rb +24 -0
  188. data/spec/support/http_stub/server/stub/response_fixture.rb +15 -0
  189. data/spec/support/http_stub/server/stub_fixture.rb +21 -0
  190. data/spec/support/http_stub/server_integration.rb +9 -6
  191. data/spec/support/http_stub/stub_requester.rb +37 -0
  192. data/spec/support/object_convertable_to_json.rb +11 -0
  193. data/spec/support/rack/rack_application_test.rb +1 -1
  194. data/spec/support/rack/request_fixture.rb +22 -4
  195. metadata +166 -207
  196. data/lib/http_stub.rb +0 -131
  197. data/lib/http_stub/configurer.rb +0 -42
  198. data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +0 -19
  199. data/lib/http_stub/configurer/dsl/request_referencer.rb +0 -24
  200. data/lib/http_stub/configurer/dsl/scenario_builder.rb +0 -39
  201. data/lib/http_stub/configurer/dsl/server.rb +0 -80
  202. data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +0 -23
  203. data/lib/http_stub/configurer/dsl/session.rb +0 -51
  204. data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +0 -22
  205. data/lib/http_stub/configurer/dsl/session_factory.rb +0 -34
  206. data/lib/http_stub/configurer/dsl/stub_builder.rb +0 -65
  207. data/lib/http_stub/configurer/part.rb +0 -23
  208. data/lib/http_stub/configurer/request/controllable_value.rb +0 -19
  209. data/lib/http_stub/configurer/request/http/basic.rb +0 -27
  210. data/lib/http_stub/configurer/request/http/factory.rb +0 -33
  211. data/lib/http_stub/configurer/request/http/multipart.rb +0 -34
  212. data/lib/http_stub/configurer/request/omittable.rb +0 -26
  213. data/lib/http_stub/configurer/request/regexpable.rb +0 -33
  214. data/lib/http_stub/configurer/request/scenario.rb +0 -29
  215. data/lib/http_stub/configurer/request/stub.rb +0 -39
  216. data/lib/http_stub/configurer/request/stub_response.rb +0 -38
  217. data/lib/http_stub/configurer/request/stub_response_file.rb +0 -20
  218. data/lib/http_stub/configurer/request/triggers.rb +0 -25
  219. data/lib/http_stub/configurer/server/buffered_command_processor.rb +0 -24
  220. data/lib/http_stub/configurer/server/command.rb +0 -22
  221. data/lib/http_stub/configurer/server/command_processor.rb +0 -35
  222. data/lib/http_stub/configurer/server/configuration.rb +0 -33
  223. data/lib/http_stub/configurer/server/facade.rb +0 -61
  224. data/lib/http_stub/configurer/server/request_processor.rb +0 -30
  225. data/lib/http_stub/configurer/server/session_facade.rb +0 -57
  226. data/lib/http_stub/server/application/configuration.rb +0 -38
  227. data/lib/http_stub/server/application/response_pipeline.rb +0 -20
  228. data/lib/http_stub/server/application/response_support.rb +0 -19
  229. data/lib/http_stub/server/scenario/parser.rb +0 -17
  230. data/lib/http_stub/server/session/configuration.rb +0 -32
  231. data/lib/http_stub/server/status/controller.rb +0 -25
  232. data/lib/http_stub/server/stub/parser.rb +0 -17
  233. data/lib/http_stub/server/stub/payload.rb +0 -20
  234. data/lib/http_stub/server/stub/payload/base_uri_modifier.rb +0 -17
  235. data/lib/http_stub/server/stub/payload/response_body_modifier.rb +0 -21
  236. data/lib/http_stub/server/stub/response/attribute/body.rb +0 -32
  237. data/lib/http_stub/server/stub/response/attribute/headers.rb +0 -32
  238. data/lib/http_stub/server/stub/response/attribute/interpolator.rb +0 -26
  239. data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +0 -27
  240. data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +0 -27
  241. data/lib/http_stub/server/stub/response/base.rb +0 -61
  242. data/lib/http_stub/server/stub/response/file.rb +0 -45
  243. data/lib/http_stub/server/stub/response/text.rb +0 -35
  244. data/lib/http_stub/server/views/_file_response.haml +0 -1
  245. data/lib/http_stub/server/views/_text_response.haml +0 -1
  246. data/spec/acceptance/configurer_initialization_spec.rb +0 -157
  247. data/spec/acceptance/request_reference_spec.rb +0 -42
  248. data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +0 -37
  249. data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +0 -37
  250. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +0 -201
  251. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +0 -575
  252. data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +0 -150
  253. data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +0 -97
  254. data/spec/lib/http_stub/configurer/dsl/session_spec.rb +0 -210
  255. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +0 -747
  256. data/spec/lib/http_stub/configurer/part_spec.rb +0 -103
  257. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +0 -34
  258. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +0 -91
  259. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +0 -222
  260. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +0 -118
  261. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +0 -70
  262. data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +0 -77
  263. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +0 -69
  264. data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +0 -195
  265. data/spec/lib/http_stub/configurer/request/stub_spec.rb +0 -231
  266. data/spec/lib/http_stub/configurer/request/triggers_spec.rb +0 -101
  267. data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +0 -35
  268. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +0 -75
  269. data/spec/lib/http_stub/configurer/server/command_spec.rb +0 -26
  270. data/spec/lib/http_stub/configurer/server/configuration_spec.rb +0 -139
  271. data/spec/lib/http_stub/configurer/server/facade_spec.rb +0 -235
  272. data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +0 -100
  273. data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +0 -285
  274. data/spec/lib/http_stub/configurer_spec.rb +0 -105
  275. data/spec/lib/http_stub/server/application/configuration_spec.rb +0 -59
  276. data/spec/lib/http_stub/server/application/response_pipeline_spec.rb +0 -29
  277. data/spec/lib/http_stub/server/application/response_support_spec.rb +0 -30
  278. data/spec/lib/http_stub/server/scenario/parser_spec.rb +0 -64
  279. data/spec/lib/http_stub/server/session/configuration_spec.rb +0 -94
  280. data/spec/lib/http_stub/server/status/controller_spec.rb +0 -47
  281. data/spec/lib/http_stub/server/stub/parser_spec.rb +0 -56
  282. data/spec/lib/http_stub/server/stub/payload/base_uri_modifier_spec.rb +0 -23
  283. data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +0 -84
  284. data/spec/lib/http_stub/server/stub/payload_spec.rb +0 -33
  285. data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +0 -98
  286. data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +0 -73
  287. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +0 -53
  288. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +0 -53
  289. data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +0 -41
  290. data/spec/lib/http_stub/server/stub/response/base_spec.rb +0 -217
  291. data/spec/lib/http_stub/server/stub/response/file_spec.rb +0 -197
  292. data/spec/lib/http_stub/server/stub/response/text_spec.rb +0 -182
  293. data/spec/resources/sample.pdf +0 -0
  294. data/spec/resources/sample.txt +0 -1
  295. data/spec/support/http_stub/configurer_integration.rb +0 -24
  296. data/spec/support/http_stub/empty_configurer.rb +0 -7
  297. data/spec/support/http_stub/scenario_fixture.rb +0 -33
  298. data/spec/support/http_stub/stub_fixture.rb +0 -125
  299. data/spec/support/http_stub/stub_registrator.rb +0 -83
@@ -43,13 +43,13 @@ describe HttpStub::Server::Stub::Match::Controller do
43
43
  before(:example) { allow(session).to receive(:last_match).and_return(match) }
44
44
 
45
45
  it "creates an ok response containing the JSON representation of the match" do
46
- expect(HttpStub::Server::Response).to receive(:ok).with("body" => match_json)
46
+ expect(HttpStub::Server::Response).to receive(:ok).with(body: match_json)
47
47
 
48
48
  subject
49
49
  end
50
50
 
51
51
  it "returns the response" do
52
- response = instance_double(HttpStub::Server::Stub::Response::Text)
52
+ response = HttpStub::Server::Stub::ResponseFixture.create
53
53
  allow(HttpStub::Server::Response).to receive(:ok).and_return(response)
54
54
 
55
55
  expect(subject).to eql(response)
@@ -2,30 +2,68 @@ describe HttpStub::Server::Stub::Match::ExactValueMatcher do
2
2
 
3
3
  describe "::match?" do
4
4
 
5
- let(:stub_value) { "some stub value" }
5
+ let(:actual_value) { "some actual value" }
6
6
 
7
- describe "when the stub value is equal to the actual value" do
7
+ subject { described_class.match?(stub_value, actual_value) }
8
8
 
9
- let(:actual_value) { stub_value }
9
+ context "when the stub value is a string" do
10
+
11
+ context "and the stub value is equal to the actual value" do
12
+
13
+ let(:stub_value) { actual_value }
14
+
15
+ it "returns true" do
16
+ expect(subject).to be(true)
17
+ end
18
+
19
+ end
20
+
21
+ context "and the stub value is not equal to the actual value" do
22
+
23
+ let(:stub_value) { "some other value" }
24
+
25
+ it "returns false" do
26
+ expect(subject).to be(false)
27
+ end
10
28
 
11
- it "returns true" do
12
- expect(perform_match).to be_truthy
13
29
  end
14
30
 
15
31
  end
16
32
 
17
- describe "when the stub value is not equal to the actual value" do
33
+ context "when the stub value is an integer" do
18
34
 
19
- let(:actual_value) { "not equal to stub value" }
35
+ let(:stub_value) { 88 }
36
+
37
+ context "whose string representation is equal to the actual value" do
38
+
39
+ let(:actual_value) { "88" }
40
+
41
+ it "returns true" do
42
+ expect(subject).to be(true)
43
+ end
44
+
45
+ end
46
+
47
+ context "whose string representation is not equal to the actual value" do
48
+
49
+ let(:actual_value) { "89" }
50
+
51
+ it "returns false" do
52
+ expect(subject).to be(false)
53
+ end
20
54
 
21
- it "returns false" do
22
- expect(perform_match).to be_falsey
23
55
  end
24
56
 
25
57
  end
26
58
 
27
- def perform_match
28
- HttpStub::Server::Stub::Match::ExactValueMatcher.match?(stub_value, actual_value)
59
+ context "when the stub value is another type" do
60
+
61
+ let(:stub_value) { actual_value.to_sym }
62
+
63
+ it "returns false" do
64
+ expect(subject).to be(false)
65
+ end
66
+
29
67
  end
30
68
 
31
69
  end
@@ -11,7 +11,7 @@ describe HttpStub::Server::Stub::Match::HashMatcher do
11
11
  let(:actual_hash) { {} }
12
12
 
13
13
  subject { described_class.match?(stub_hash, actual_hash) }
14
-
14
+
15
15
  context "when the stub hash contains multiple entries" do
16
16
 
17
17
  it "returns the result of evaluating a match for each stub value" do
@@ -114,9 +114,9 @@ describe HttpStub::Server::Stub::Match::HashMatcher do
114
114
  end
115
115
 
116
116
  end
117
-
117
+
118
118
  end
119
-
119
+
120
120
  end
121
-
121
+
122
122
  end
@@ -1,10 +1,10 @@
1
1
  describe HttpStub::Server::Stub::Match::Match do
2
2
 
3
- let(:request) { instance_double(HttpStub::Server::Request::Request) }
4
- let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
5
- let(:stub) { instance_double(HttpStub::Server::Stub::Stub) }
3
+ let(:request) { HttpStub::Server::RequestFixture.create }
4
+ let(:response) { HttpStub::Server::Stub::ResponseFixture.create }
5
+ let(:stub) { HttpStub::Server::StubFixture.create }
6
6
 
7
- let(:match) { HttpStub::Server::Stub::Match::Match.new(request, response, stub) }
7
+ let(:match) { described_class.new(request, response, stub) }
8
8
 
9
9
  describe "#request" do
10
10
 
@@ -1,8 +1,8 @@
1
1
  describe HttpStub::Server::Stub::Match::Miss do
2
2
 
3
- let(:request) { instance_double(HttpStub::Server::Request::Request) }
3
+ let(:request) { HttpStub::Server::RequestFixture.create }
4
4
 
5
- let(:miss) { HttpStub::Server::Stub::Match::Miss.new(request) }
5
+ let(:miss) { described_class.new(request) }
6
6
 
7
7
  describe "#request" do
8
8
 
@@ -2,26 +2,30 @@ describe HttpStub::Server::Stub::Match::OmittedValueMatcher do
2
2
 
3
3
  describe "::match?" do
4
4
 
5
- context "when the stubbed value is 'control:omitted'" do
5
+ let(:actual_value) { nil }
6
6
 
7
- let(:stub_value) { "control:omitted" }
7
+ subject { described_class.match?(stub_value, actual_value) }
8
+
9
+ context "when the stub value is the symbol :omitted" do
10
+
11
+ let(:stub_value) { :omitted }
8
12
 
9
13
  context "and the actual value is nil" do
10
14
 
11
15
  let(:actual_value) { nil }
12
16
 
13
17
  it "returns true" do
14
- expect(perform_match).to be_truthy
18
+ expect(subject).to be(true)
15
19
  end
16
20
 
17
21
  end
18
22
 
19
- context "and the actual value is non-empty string" do
23
+ context "and the actual value is a non-empty string" do
20
24
 
21
25
  let(:actual_value) { "some non-empty string" }
22
26
 
23
27
  it "returns false" do
24
- expect(perform_match).to be_falsey
28
+ expect(subject).to be(false)
25
29
  end
26
30
 
27
31
  end
@@ -31,26 +35,41 @@ describe HttpStub::Server::Stub::Match::OmittedValueMatcher do
31
35
  let(:actual_value) { "" }
32
36
 
33
37
  it "returns false" do
34
- expect(perform_match).to be_falsey
38
+ expect(subject).to be(false)
35
39
  end
36
40
 
37
41
  end
38
42
 
39
43
  end
40
44
 
41
- context "when the stub value is not 'control:omitted'" do
45
+ context "when the stub value is another symbol" do
46
+
47
+ let(:stub_value) { :some_other_symbol }
48
+
49
+ it "returns false" do
50
+ expect(subject).to be(false)
51
+ end
52
+
53
+ end
54
+
55
+ context "when the stub value is a string" do
42
56
 
43
- let(:stub_value) { "some other stub value" }
44
- let(:actual_value) { nil }
57
+ let(:stub_value) { "some string" }
45
58
 
46
59
  it "returns false" do
47
- expect(perform_match).to be_falsey
60
+ expect(subject).to be(false)
48
61
  end
49
62
 
50
63
  end
51
64
 
52
- def perform_match
53
- HttpStub::Server::Stub::Match::OmittedValueMatcher.match?(stub_value, actual_value)
65
+ context "when the stub value is a regular expression" do
66
+
67
+ let(:stub_value) { /some regular expression/ }
68
+
69
+ it "returns false" do
70
+ expect(subject).to be(false)
71
+ end
72
+
54
73
  end
55
74
 
56
75
  end
@@ -2,16 +2,18 @@ describe HttpStub::Server::Stub::Match::RegexpValueMatcher do
2
2
 
3
3
  describe "::match?" do
4
4
 
5
- context "when the stub value is a string prefixed with 'regexp:'" do
5
+ subject { described_class.match?(stub_value, actual_value) }
6
6
 
7
- let(:stub_value) { "regexp:^a[0-9]*\\$z$" }
7
+ context "when the stub value is a regular expression" do
8
+
9
+ let(:stub_value) { /^a[0-9]*\$z$/ }
8
10
 
9
11
  context "and the actual value matches the regular expression" do
10
12
 
11
13
  let(:actual_value) { "a789$z" }
12
14
 
13
15
  it "returns true" do
14
- expect(perform_match).to be_truthy
16
+ expect(subject).to be(true)
15
17
  end
16
18
 
17
19
  end
@@ -21,26 +23,33 @@ describe HttpStub::Server::Stub::Match::RegexpValueMatcher do
21
23
  let(:actual_value) { "a789" }
22
24
 
23
25
  it "returns false" do
24
- expect(perform_match).to be_falsey
26
+ expect(subject).to be(false)
25
27
  end
26
28
 
27
29
  end
28
30
 
29
31
  end
30
32
 
31
- context "when the provided value is not a string prefixed with 'regexp'" do
33
+ context "when the stub value is a string" do
32
34
 
33
- let(:stub_value) { "does not start with regexp:" }
34
- let(:actual_value) { "some actual value" }
35
+ let(:stub_value) { "some string" }
36
+ let(:actual_value) { stub_value }
35
37
 
36
38
  it "returns false" do
37
- expect(perform_match).to be_falsey
39
+ expect(subject).to be(false)
38
40
  end
39
41
 
40
42
  end
41
-
42
- def perform_match
43
- HttpStub::Server::Stub::Match::RegexpValueMatcher.match?(stub_value, actual_value)
43
+
44
+ context "when the stub value is a symbol" do
45
+
46
+ let(:stub_value) { :some_symbol }
47
+ let(:actual_value) { stub_value }
48
+
49
+ it "returns false" do
50
+ expect(subject).to be(false)
51
+ end
52
+
44
53
  end
45
54
 
46
55
  end
@@ -31,14 +31,14 @@ describe HttpStub::Server::Stub::Match::Rule::Body do
31
31
  let(:raw_schema) { { "type" => "json", "definition" => json_schema } }
32
32
 
33
33
  it "creates a JSON request body with the schema" do
34
- expect(HttpStub::Server::Stub::Match::Rule::JsonBody).to receive(:new).with(json_schema)
34
+ expect(HttpStub::Server::Stub::Match::Rule::JsonSchemaBody).to receive(:new).with(json_schema)
35
35
 
36
36
  subject
37
37
  end
38
38
 
39
39
  it "returns the created request body" do
40
- json_body = instance_double(HttpStub::Server::Stub::Match::Rule::JsonBody)
41
- allow(HttpStub::Server::Stub::Match::Rule::JsonBody).to receive(:new).and_return(json_body)
40
+ json_body = instance_double(HttpStub::Server::Stub::Match::Rule::JsonSchemaBody)
41
+ allow(HttpStub::Server::Stub::Match::Rule::JsonSchemaBody).to receive(:new).and_return(json_body)
42
42
 
43
43
  expect(subject).to eql(json_body)
44
44
  end
@@ -1,18 +1,18 @@
1
- describe HttpStub::Server::Stub::Match::Rule::JsonBody do
1
+ describe HttpStub::Server::Stub::Match::Rule::JsonSchemaBody do
2
2
 
3
3
  let(:stub_schema_definition) { { "type" => "object", "properties" => { "some_property" => "some_type" } } }
4
4
 
5
- let(:json_body) { described_class.new(stub_schema_definition) }
5
+ let(:json_schema_body) { described_class.new(stub_schema_definition) }
6
6
 
7
7
  describe "#matches?" do
8
8
 
9
9
  let(:request_body) { { "some_json_property" => "some_json_value" }.to_json }
10
- let(:request) { instance_double(HttpStub::Server::Request::Request, body: request_body) }
10
+ let(:request) { HttpStub::Server::RequestFixture.create(body: request_body) }
11
11
  let(:logger) { instance_double(Logger, info: nil) }
12
12
 
13
13
  let(:validation_errors) { [] }
14
14
 
15
- subject { json_body.matches?(request, logger) }
15
+ subject { json_schema_body.matches?(request, logger) }
16
16
 
17
17
  before(:example) { allow(JSON::Validator).to receive(:fully_validate).and_return(validation_errors) }
18
18
 
@@ -90,7 +90,7 @@ describe HttpStub::Server::Stub::Match::Rule::JsonBody do
90
90
 
91
91
  describe "#to_s" do
92
92
 
93
- subject { json_body.to_s }
93
+ subject { json_schema_body.to_s }
94
94
 
95
95
  it "returns the JSON representation of the schema definition" do
96
96
  expect(subject).to eql(stub_schema_definition.to_json)
@@ -1,20 +1,20 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::Method do
2
2
 
3
- let(:stub_method) { "put" }
3
+ let(:stub_method) { :put }
4
4
 
5
5
  let(:the_method) { described_class.new(stub_method) }
6
6
 
7
7
  describe "#matches?" do
8
8
 
9
9
  let(:request_method) { "get" }
10
- let(:request) { instance_double(HttpStub::Server::Request::Request, method: request_method) }
10
+ let(:request) { HttpStub::Server::RequestFixture.create(method: request_method) }
11
11
  let(:logger) { instance_double(Logger) }
12
12
 
13
13
  subject { the_method.matches?(request, logger) }
14
14
 
15
- context "when the request method is identical to the stub method" do
15
+ context "when the stub method is identical to the request method" do
16
16
 
17
- let(:request_method) { stub_method }
17
+ let(:stub_method) { request_method }
18
18
 
19
19
  it "returns true" do
20
20
  expect(subject).to be(true)
@@ -22,7 +22,7 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
22
22
 
23
23
  end
24
24
 
25
- context "when the stub method and request method are the the same value but have different casing" do
25
+ context "when the stub and request methods are the same value but have different casing" do
26
26
 
27
27
  let(:stub_method) { "GET" }
28
28
 
@@ -32,6 +32,26 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
32
32
 
33
33
  end
34
34
 
35
+ context "when the stub and request methods are the same value but the stub method is symbolised" do
36
+
37
+ let(:stub_method) { :get }
38
+
39
+ it "returns true" do
40
+ expect(subject).to be(true)
41
+ end
42
+
43
+ end
44
+
45
+ context "when the stub and request methods are the same but the stub method is symbolised with different casing" do
46
+
47
+ let(:stub_method) { :GET }
48
+
49
+ it "returns true" do
50
+ expect(subject).to be(true)
51
+ end
52
+
53
+ end
54
+
35
55
  context "when the stub method is omitted" do
36
56
 
37
57
  context "with a nil value" do
@@ -75,10 +95,24 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
75
95
 
76
96
  context "when the stub method is not nil" do
77
97
 
78
- let(:stub_method) { "present" }
98
+ context "and is a string" do
99
+
100
+ let(:stub_method) { "present" }
101
+
102
+ it "returns the capitalised stub method" do
103
+ expect(subject).to eql("PRESENT")
104
+ end
105
+
106
+ end
107
+
108
+ context "and is a symbol" do
109
+
110
+ let(:stub_method) { :present }
111
+
112
+ it "returns the method as a capitalised string" do
113
+ expect(subject).to eql("PRESENT")
114
+ end
79
115
 
80
- it "returns the stub method" do
81
- expect(subject).to eql(stub_method)
82
116
  end
83
117
 
84
118
  end
@@ -0,0 +1,64 @@
1
+ describe HttpStub::Server::Stub::Match::Rule::SchemaBody do
2
+
3
+ class HttpStub::Server::Stub::Match::Rule::TestSchemaBody
4
+
5
+ attr_reader :definition
6
+
7
+ def initialize(definition)
8
+ @definition = definition
9
+ end
10
+
11
+ end
12
+
13
+ describe "::create" do
14
+
15
+ subject { described_class.create(args) }
16
+
17
+ context "when a supported type is specified" do
18
+
19
+ let(:definition) { "some definition" }
20
+ let(:args) { { type: :test, definition: "some definition" } }
21
+
22
+ it "creates a schema body of the specified type" do
23
+ expect(subject).to be_an_instance_of(HttpStub::Server::Stub::Match::Rule::TestSchemaBody)
24
+ end
25
+
26
+ it "creates a body with the specified definition" do
27
+ expect(subject.definition).to eql(definition)
28
+ end
29
+
30
+ end
31
+
32
+ context "when an unsupported type is specified" do
33
+
34
+ let(:args) { { type: :not_supported, definition: "some definition" } }
35
+
36
+ it "raises an error indicating the schema type is not supported" do
37
+ expect { subject }.to raise_error(/not_supported schema is not supported/)
38
+ end
39
+
40
+ end
41
+
42
+ context "when the schema type is not specified" do
43
+
44
+ let(:args) { { definition: "some definition" } }
45
+
46
+ it "raises an error indicating the type is mandatory" do
47
+ expect { subject }.to raise_error(/type expected/)
48
+ end
49
+
50
+ end
51
+
52
+ context "when the schema definition is not specified" do
53
+
54
+ let(:args) { { type: :test } }
55
+
56
+ it "raises an error indicating the type is mandatory" do
57
+ expect { subject }.to raise_error(/definition expected/)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end