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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9130ae13d037581af8407734972808552052ad35
4
- data.tar.gz: b185025a934c899e37e257647f444d80376ab307
3
+ metadata.gz: e93b34750d08ac6ef4488d2fea5a9c9084776cc4
4
+ data.tar.gz: 31b000bf7e1a75cd549ab63c3d9cbbd935d8abd2
5
5
  SHA512:
6
- metadata.gz: 359a8710eb2c61f341c78dc5dc1a58bc70af70a179f6d648cd6301e8b0aec1d591db3d3cc32ec24c6c8a4b7cc089fd944fe99b9c1d338271ab6fac8e9c975c11
7
- data.tar.gz: 4ec1a47dd1ac04109f73de519751b6b1eb9be35c6cadd05db1f208ccd33da5ad4166ac36545b1cfb5d60303baf8b33aab93e048ff1d4368733300800022ca199
6
+ metadata.gz: 820dcaac517a6972ce83a01f58640120f723cc6b6d23ef81e1719ec6a141eb341611356282fe9414d592ce825dad0c00816abf15678f103ef241a7bc660bb3e0
7
+ data.tar.gz: 383722facf4da0cb57491d2e571b20a23227f1b3abaabb6df626235df97927d5b12a98cb6720efdf9ef2c458e6b1c4db5cc1e76caf62f2426048db9f34d96a93
@@ -0,0 +1,18 @@
1
+ require 'net/http'
2
+
3
+ require_relative 'client/request'
4
+ require_relative 'client/server'
5
+ require_relative 'client/session'
6
+ require_relative 'client/client'
7
+
8
+ module HttpStub
9
+
10
+ module Client
11
+
12
+ def self.create(server_uri)
13
+ HttpStub::Client::Client.new(server_uri)
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ module HttpStub
2
+ module Client
3
+
4
+ class Client
5
+
6
+ TRANSACTIONAL_SESSION_ID = "http_stub_transactional".freeze
7
+
8
+ private_constant :TRANSACTIONAL_SESSION_ID
9
+
10
+ delegate :activate!, to: :@default_session
11
+
12
+ def initialize(server_uri)
13
+ @server = HttpStub::Client::Server.new(server_uri)
14
+ @default_session = HttpStub::Client::Session.new(TRANSACTIONAL_SESSION_ID, @server)
15
+ end
16
+
17
+ def session(id)
18
+ HttpStub::Client::Session.new(id, @server)
19
+ end
20
+
21
+ def reset!
22
+ @server.submit!(method: :delete, path: "sessions", intent: "reset server")
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ module HttpStub
2
+ module Client
3
+
4
+ class Request
5
+
6
+ def initialize(args)
7
+ @base_uri = URI(args[:base_uri])
8
+ @path = args[:path]
9
+ @method = args[:method]
10
+ @headers = args[:headers] || {}
11
+ @parameters = args[:parameters]
12
+ @http_options = args[:http_options] || {}
13
+ @intent = args[:intent]
14
+ end
15
+
16
+ def submit
17
+ Net::HTTP.start(@base_uri.host, @base_uri.port, @http_options) { |http| http.request(http_request) }
18
+ rescue StandardError => error
19
+ raise "#{error_message_prefix} #{error}"
20
+ end
21
+
22
+ def error_message_prefix
23
+ "Error occurred issuing request to #{@base_uri} - intent: #{@intent}, cause: "
24
+ end
25
+
26
+ private
27
+
28
+ def http_request
29
+ http_request_class = Net::HTTP.const_get(@method.to_s.capitalize)
30
+ http_request_class.new("/http_stub/#{@path}", @headers.stringify_keys).tap do |request|
31
+ request.set_form_data(@parameters) if @parameters
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module HttpStub
2
+ module Client
3
+
4
+ class Server
5
+
6
+ def initialize(base_uri)
7
+ @base_uri = base_uri
8
+ end
9
+
10
+ def submit!(args)
11
+ request = HttpStub::Client::Request.new(args.merge(base_uri: @base_uri))
12
+ response = request.submit
13
+ raise "#{request.error_message_prefix} #{response.code} #{response.message}" unless response.code == "200"
14
+ response
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ module HttpStub
2
+ module Client
3
+
4
+ class Session
5
+
6
+ def initialize(id, server)
7
+ @session_id = id
8
+ @server = server
9
+ @description = "session '#{@session_id}'"
10
+ end
11
+
12
+ def activate!(*scenario_names)
13
+ parameters = { http_stub_session_id: @session_id, "names[]" => scenario_names }
14
+ @server.submit!(
15
+ method: :post,
16
+ path: "scenarios/activate",
17
+ parameters: parameters,
18
+ intent: "activate scenarios #{scenario_names.map { |name| "'#{name}'" }.join(", ")} in #{@description}"
19
+ )
20
+ end
21
+
22
+ def reset!
23
+ @server.submit!(
24
+ method: :post,
25
+ path: "stubs/reset",
26
+ parameters: { http_stub_session_id: @session_id },
27
+ intent: "reset stubs in #{@description}"
28
+ )
29
+ end
30
+
31
+ def delete!
32
+ @server.submit!(
33
+ method: :delete,
34
+ path: "sessions",
35
+ parameters: { http_stub_session_id: @session_id },
36
+ intent: "delete #{@description}"
37
+ )
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,61 @@
1
+ require 'active_support/core_ext/object/try'
2
+ require 'active_support/core_ext/module/delegation'
3
+ require 'active_support/core_ext/hash/deep_merge'
4
+ require 'active_support/core_ext/hash/indifferent_access'
5
+
6
+ require_relative 'extensions/core/hash/indifferent_and_insensitive_access'
7
+ require_relative 'extensions/core/hash/with_indifferent_and_insensitive_access'
8
+
9
+ require_relative 'configurator/stub/stub'
10
+ require_relative 'configurator/stub/template'
11
+ require_relative 'configurator/stub'
12
+ require_relative 'configurator/scenario'
13
+ require_relative 'configurator/endpoint_template'
14
+ require_relative 'configurator/state'
15
+ require_relative 'configurator/server'
16
+ require_relative 'configurator/part'
17
+
18
+ module HttpStub
19
+
20
+ module Configurator
21
+
22
+ def self.included(mod)
23
+ mod.extend(HttpStub::Configurator::ClassMethods)
24
+ mod.send(:include, HttpStub::Configurator::InstanceMethods)
25
+ end
26
+
27
+ module ClassMethods
28
+
29
+ def state
30
+ @state ||= HttpStub::Configurator::State.new
31
+ end
32
+
33
+ def stub_server
34
+ @stub_server ||= HttpStub::Configurator::Server.new(state)
35
+ end
36
+
37
+ def parts=(parts)
38
+ parts.each do |name, part|
39
+ part.apply_to(self)
40
+ self.define_singleton_method(name) { part }
41
+ self.send(:define_method, name) { part }
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ module InstanceMethods
48
+
49
+ def state
50
+ self.class.state
51
+ end
52
+
53
+ def stub_server
54
+ self.class.stub_server
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,24 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ class EndpointTemplate
5
+
6
+ delegate :match_requests, :schema, :respond_with, :trigger, :invoke, :build_stub, to: :@stub_template
7
+
8
+ def initialize(server, default_stub_template, &block)
9
+ @server = server
10
+ @stub_template = HttpStub::Configurator::Stub::Template.new(default_stub_template, &block)
11
+ end
12
+
13
+ def add_scenario!(name, response_overrides={}, &block)
14
+ @server.add_scenario_with_one_stub!(name, self.build_stub(response_overrides, &block))
15
+ end
16
+
17
+ def add_stub!(response_overrides={}, &block)
18
+ @server.add_stub!(self.build_stub(response_overrides, &block))
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ module Part
5
+
6
+ def apply_to(configurator)
7
+ @configurator = configurator
8
+ configuration_methods = self.methods.find_all { |method| method.to_s =~ /^configure_.+_(stub|scenario)s?$/ }
9
+ configuration_methods.each { |configuration_method| self.send(configuration_method) }
10
+ end
11
+
12
+ def method_missing(name, *args, &block)
13
+ @configurator.respond_to?(name, true) ? @configurator.send(name, *args, &block) : super
14
+ end
15
+
16
+ def respond_to_missing?(name, include_private = false)
17
+ @configurator.respond_to?(name, include_private)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ class Scenario
5
+
6
+ delegate :build_stub, to: :@default_stub_template
7
+
8
+ def initialize(name, default_stub_template)
9
+ @default_stub_template = default_stub_template
10
+ @hash = {
11
+ name: name,
12
+ activated: false,
13
+ stubs: [],
14
+ triggered_scenario_names: []
15
+ }.with_indifferent_access
16
+ end
17
+
18
+ def add_stub!(stub=nil, &block)
19
+ resolved_stub = stub || build_stub(&block)
20
+ @hash[:stubs] << resolved_stub.to_hash
21
+ end
22
+
23
+ def add_stubs!(stubs)
24
+ stubs.each { |stub| add_stub!(stub) }
25
+ end
26
+
27
+ def activate_scenarios!(*names)
28
+ @hash[:triggered_scenario_names].concat(names.flatten)
29
+ end
30
+
31
+ def activate!
32
+ @hash[:activated] = true
33
+ end
34
+
35
+ def to_hash
36
+ @hash
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ class Server
5
+
6
+ delegate :port=, :external_base_uri, to: :@state
7
+ delegate :session_identifier=, to: :@state
8
+ delegate :enable, to: :@state
9
+
10
+ delegate :build_stub, to: :@server_stub_template
11
+
12
+ def initialize(state)
13
+ @state = state
14
+ @server_stub_template = HttpStub::Configurator::Stub::Template.new
15
+ end
16
+
17
+ def request_defaults=(args)
18
+ @server_stub_template.match_requests(args)
19
+ end
20
+
21
+ def response_defaults=(args)
22
+ @server_stub_template.respond_with(args)
23
+ end
24
+
25
+ def endpoint_template(&block)
26
+ HttpStub::Configurator::EndpointTemplate.new(self, @server_stub_template, &block)
27
+ end
28
+
29
+ def add_scenario!(name, &_block)
30
+ scenario = HttpStub::Configurator::Scenario.new(name, @server_stub_template)
31
+ yield scenario
32
+ @state.add_scenario(scenario)
33
+ end
34
+
35
+ def add_scenario_with_one_stub!(name, stub=nil, &block)
36
+ add_scenario!(name) do |scenario|
37
+ scenario.add_stub!(stub) { |added_stub| added_stub.invoke(block.arity == 2 ? scenario : nil, &block) }
38
+ end
39
+ end
40
+
41
+ def add_stub!(stub=nil, &block)
42
+ resolved_stub = stub || self.build_stub(&block)
43
+ @state.add_stub(resolved_stub)
44
+ end
45
+
46
+ def add_stubs!(stubs)
47
+ stubs.each { |stub| add_stub!(stub) }
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ class State
5
+
6
+ attr_accessor :port
7
+
8
+ attr_writer :session_identifier
9
+
10
+ attr_reader :scenario_hashes, :stub_hashes
11
+
12
+ def initialize
13
+ @scenario_hashes = []
14
+ @stub_hashes = []
15
+ @cross_origin_support_flag = false
16
+ end
17
+
18
+ def external_base_uri
19
+ ENV["STUB_EXTERNAL_BASE_URI"] || "http://localhost:#{@port}"
20
+ end
21
+
22
+ def enable(feature)
23
+ @cross_origin_support_flag = true if feature == :cross_origin_support
24
+ end
25
+
26
+ def add_scenario(scenario)
27
+ @scenario_hashes << scenario.to_hash
28
+ end
29
+
30
+ def add_stub(stub)
31
+ @stub_hashes << stub.to_hash
32
+ end
33
+
34
+ def application_settings
35
+ { port: @port, session_identifier: @session_identifier, cross_origin_support: @cross_origin_support_flag }
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ module HttpStub
2
+ module Configurator
3
+
4
+ module Stub
5
+
6
+ def self.create(parent=nil, &block)
7
+ HttpStub::Configurator::Stub::Stub.new(parent, &block)
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,75 @@
1
+ module HttpStub
2
+ module Configurator
3
+ module Stub
4
+
5
+ class Stub
6
+
7
+ def initialize(parent=nil, &block)
8
+ @hash = {
9
+ match_rules: {},
10
+ response: { blocks: [] },
11
+ triggers: { scenario_names: [], stubs: [] }
12
+ }.with_indifferent_access
13
+ self.merge!(parent) if parent
14
+ self.invoke(&block) if block_given?
15
+ end
16
+
17
+ def match_requests(args)
18
+ self.tap { @hash[:match_rules].deep_merge!(args) }
19
+ end
20
+
21
+ def schema(type, definition)
22
+ { schema: { type: type, definition: definition } }
23
+ end
24
+
25
+ def respond_with(args={}, &block)
26
+ remaining_args = args.clone
27
+ response_args = @hash[:response]
28
+ response_args[:blocks].concat(remaining_args.delete(:blocks) || [])
29
+ response_args[:blocks] << block if block_given?
30
+ self.tap { response_args.deep_merge!(remaining_args) }
31
+ end
32
+
33
+ def trigger(args)
34
+ resolved_args = to_triggers(args)
35
+ triggers_args = @hash[:triggers]
36
+ triggers_args[:scenario_names].concat(resolved_args[:scenario_names])
37
+ triggers_args[:stubs].concat(resolved_args[:stubs])
38
+ self
39
+ end
40
+
41
+ def invoke(additional_arg=nil, &block)
42
+ block.arity.zero? ? self.instance_eval(&block) : yield(*[ self, additional_arg ].compact)
43
+ end
44
+
45
+ def merge!(stub)
46
+ stub_hash = stub.to_hash
47
+ self.match_requests(stub_hash[:match_rules])
48
+ self.respond_with(stub_hash[:response])
49
+ self.trigger(scenarios: stub_hash[:triggers][:scenario_names], stubs: stub_hash[:triggers][:stubs])
50
+ end
51
+
52
+ def id
53
+ basic_response = @hash[:response].clone.tap { |hash| hash[:blocks] = hash[:blocks].map(&:source_location) }
54
+ Digest::MD5.hexdigest([ @hash[:match_rules], basic_response, @hash[:triggers] ].to_s)
55
+ end
56
+
57
+ def to_hash
58
+ @hash.merge(id: id)
59
+ end
60
+
61
+ private
62
+
63
+ def to_triggers(args)
64
+ {}.tap do |resolved_args|
65
+ resolved_args[:scenario_names] = args[:scenario] ? [ args[:scenario] ] : args[:scenarios] || []
66
+ stubs = args[:stub] ? [ args[:stub] ] : args[:stubs] || []
67
+ resolved_args[:stubs] = stubs.map(&:to_hash)
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
75
+ end