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
@@ -4,16 +4,27 @@ module HttpStub
4
4
 
5
5
  class Triggers
6
6
 
7
- attr_reader :scenario_names
8
- attr_reader :stubs
7
+ DEFAULT_ARGS = { scenario_names: [], stubs: [] }.with_indifferent_access.freeze
8
+
9
+ private_constant :DEFAULT_ARGS
10
+
11
+ attr_reader :scenario_names, :stubs
9
12
 
10
13
  def initialize(args={})
11
- resolved_args = { "scenario_names" => [], "stubs" => [] }.merge(args || {})
12
- @scenario_names = resolved_args["scenario_names"]
13
- @stubs = resolved_args["stubs"].map { |stub_args| HttpStub::Server::Stub.create(stub_args) }
14
+ resolved_args = DEFAULT_ARGS.merge(args || {})
15
+ @scenario_names = resolved_args[:scenario_names]
16
+ @stubs = create_stubs(resolved_args[:stubs])
14
17
  @description = resolved_args.to_s
15
18
  end
16
19
 
20
+ private
21
+
22
+ def create_stubs(stub_hashes)
23
+ stub_hashes.map { |hash| HttpStub::Server::Stub.create(hash) }
24
+ end
25
+
26
+ public
27
+
17
28
  EMPTY = HttpStub::Server::Stub::Triggers.new.freeze
18
29
 
19
30
  def to_json(*args)
@@ -0,0 +1 @@
1
+ %a{ href: body.uri, class: :file }= body.uri
@@ -8,7 +8,12 @@
8
8
  %tr
9
9
  %td.title Body:
10
10
  %td
11
- %pre= partial "#{response.type}_response".to_sym, locals: { response: response }
11
+ %pre= partial "#{response.body.short_class_name}_response".to_sym, locals: { body: response.body }
12
12
  %tr
13
13
  %td.title Delay:
14
14
  %td= h(response.delay_in_seconds)
15
+ %tr
16
+ %td.title Blocks:
17
+ %td
18
+ - response.blocks.each do |block|
19
+ %pre= h(block.source)
@@ -0,0 +1 @@
1
+ = pp(body.text)
@@ -7,51 +7,51 @@ $color_font: black
7
7
  $color_peach: #FFF6EF
8
8
 
9
9
  body
10
- :background $color_background
11
- :font-family "Helvetica Neue", Helvetica, Arial, sans-serif
12
- :display flex
13
- :flex-direction column
14
- :align-items center
10
+ background: $color_background
11
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif
12
+ display: flex
13
+ flex-direction: column
14
+ align-items: center
15
15
 
16
16
  header
17
- :padding-left 1rem
18
- :text-align center
17
+ padding-left: 1rem
18
+ text-align: center
19
19
 
20
20
  section
21
- :display flex
22
- :align-items center
23
- :flex-direction column
24
- :max-width 800px
25
- :border-radius 10px
26
- :background white
27
- :padding 1rem
21
+ display: flex
22
+ align-items: center
23
+ flex-direction: column
24
+ max-width: 1000px
25
+ border-radius: 10px
26
+ background: white
27
+ padding: 1rem
28
28
 
29
29
  table
30
- :padding 1rem
31
- :border-collapse collapse
30
+ padding: 1rem
31
+ border-collapse: collapse
32
32
  tr
33
- :background $color_content_bg
33
+ background: $color_content_bg
34
34
  td
35
- :padding 1rem
36
- :max-width 600px
35
+ padding: 1rem
36
+ max-width: 800px
37
37
  &.name
38
- :font-weight bold
38
+ font-weight: bold
39
39
  &.title
40
- :font-weight bold
40
+ font-weight: bold
41
41
 
42
42
  .header-rule
43
- :border-bottom 1px solid $color_border
43
+ border-bottom: 1px solid $color_border
44
44
 
45
45
  a.link
46
- :border 1px solid $color_dark_border
47
- :border-radius 3px
48
- :padding 0.5rem
49
- :text-decoration none
50
- :color $color_font
46
+ border: 1px solid $color_dark_border
47
+ border-radius: 3px
48
+ padding: 0.5rem
49
+ text-decoration: none
50
+ color: $color_font
51
51
  &:hover
52
- :background $color_highlight
52
+ background: $color_highlight
53
53
 
54
54
  pre
55
- :white-space pre-wrap !important
56
- :word-wrap break-word !important
57
- :max-width 600px
55
+ white-space: pre-wrap !important
56
+ word-wrap: break-word !important
57
+ max-width: 800px
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.27.0".freeze
2
+ VERSION = "0.28.0.beta1".freeze
3
3
  end
@@ -1,16 +1,16 @@
1
- describe "Configurer Part acceptance" do
2
- include_context "configurer integration"
1
+ describe "Configurator Part acceptance" do
2
+ include_context "server integration"
3
3
 
4
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithParts } }
4
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithParts }
5
5
 
6
- context "when a configurer contains a part" do
6
+ context "when a configurator contains a part" do
7
7
 
8
8
  context "that contains a configure stub method" do
9
9
 
10
10
  let(:response) { issue_request("registered_in_configure_stub_method") }
11
11
 
12
12
  it "invokes the method" do
13
- expect(response.body).to eql("configure stub response")
13
+ expect(response.body).to eql("configured stub response")
14
14
  end
15
15
 
16
16
  end
@@ -20,7 +20,7 @@ describe "Configurer Part acceptance" do
20
20
  let(:response) { issue_request("registered_in_configure_stubs_method") }
21
21
 
22
22
  it "invokes the method" do
23
- expect(response.body).to eql("configure stubs response")
23
+ expect(response.body).to eql("configured stubs response")
24
24
  end
25
25
 
26
26
  end
@@ -30,7 +30,7 @@ describe "Configurer Part acceptance" do
30
30
  let(:response) { issue_request("registered_in_configure_scenario_method") }
31
31
 
32
32
  it "invokes the method" do
33
- expect(response.body).to eql("configure scenario response")
33
+ expect(response.body).to eql("configured scenario response")
34
34
  end
35
35
 
36
36
  end
@@ -40,7 +40,7 @@ describe "Configurer Part acceptance" do
40
40
  let(:response) { issue_request("registered_in_configure_scenarios_method") }
41
41
 
42
42
  it "invokes the method" do
43
- expect(response.body).to eql("configure scenarios response")
43
+ expect(response.body).to eql("configured scenarios response")
44
44
  end
45
45
 
46
46
  end
@@ -4,12 +4,10 @@ describe "Cross origin support acceptance" do
4
4
 
5
5
  let(:cross_origin_page) { CrossOriginServer::IndexPage.new(browser) }
6
6
 
7
- context "when a stub server with cross origin support is initialized" do
8
- include_context "configurer integration"
7
+ context "when a stub server with cross origin support is started" do
8
+ include_context "server integration"
9
9
 
10
- let(:configurer_specification) do
11
- { class: HttpStub::Examples::ConfigurerWithCrossOriginSupport, name: :cross_origin_stub, port: 8004 }
12
- end
10
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithCrossOriginSupport }
13
11
 
14
12
  context "and a browser page rendered by a different server requests a scenario be activated" do
15
13
 
@@ -48,9 +46,9 @@ describe "Cross origin support acceptance" do
48
46
 
49
47
  end
50
48
 
51
- context "and a scenario configuring OPTIONS request reponses is activated" do
49
+ context "and a scenario composing OPTIONS request reponses is activated" do
52
50
 
53
- before(:example) { stub_server.activate!("Options scenario") }
51
+ before(:example) { client.activate!("Options scenario") }
54
52
 
55
53
  context "and a matching pre-flight request is made" do
56
54
 
@@ -77,10 +75,10 @@ describe "Cross origin support acceptance" do
77
75
 
78
76
  end
79
77
 
80
- context "when a stub server without cross origin support is initialized" do
81
- include_context "configurer integration"
78
+ context "when a stub server without cross origin support is started" do
79
+ include_context "server integration"
82
80
 
83
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialScenarios } }
81
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithTrivialScenarios }
84
82
 
85
83
  context "and a browser page rendered by a different server requests a scenario be activated" do
86
84
 
@@ -101,7 +99,7 @@ describe "Cross origin support acceptance" do
101
99
 
102
100
  context "and a scenario is activated" do
103
101
 
104
- before(:example) { stub_server.activate!("Scenario 1") }
102
+ before(:example) { client.activate!("Scenario 1") }
105
103
 
106
104
  context "and a matching request is made" do
107
105
 
@@ -1,9 +1,9 @@
1
- describe "Endpoint Template acceptance" do
1
+ describe "Endpoint template acceptance" do
2
2
 
3
- context "when a configurer contains an endpoint template" do
4
- include_context "configurer integration"
3
+ context "when a server configured with an endpoint template is started" do
4
+ include_context "server integration"
5
5
 
6
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithEndpointTemplate } }
6
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithEndpointTemplate }
7
7
 
8
8
  it "does not register a stub when the template is defined" do
9
9
  response = issue_request("template_uri")
@@ -20,7 +20,7 @@ describe "Endpoint Template acceptance" do
20
20
 
21
21
  context "and a templated scenario is activated" do
22
22
 
23
- before(:example) { stub_server.activate!(scenario_name) }
23
+ before(:example) { client.activate!(scenario_name) }
24
24
 
25
25
  context "that customises the request matching rules" do
26
26
 
@@ -1,15 +1,15 @@
1
1
  describe "Scenario acceptance" do
2
2
 
3
- context "when a configurer that contains scenarios is initialized" do
4
- include_context "configurer integration"
3
+ context "when a server configured with scenario's is started" do
4
+ include_context "server integration"
5
5
 
6
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialScenarios } }
6
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithTrivialScenarios }
7
7
 
8
8
  context "and a scenario is activated" do
9
9
 
10
10
  context "containing stubs" do
11
11
 
12
- before(:example) { stub_server.activate!("Scenario 1") }
12
+ before(:example) { client.activate!("Scenario 1") }
13
13
 
14
14
  (1..3).each do |stub_number|
15
15
 
@@ -30,7 +30,7 @@ describe "Scenario acceptance" do
30
30
 
31
31
  context "containing triggered scenarios" do
32
32
 
33
- before(:example) { stub_server.activate!("Activates another scenario") }
33
+ before(:example) { client.activate!("Activates another scenario") }
34
34
 
35
35
  (1..3).each do |stub_number|
36
36
 
@@ -67,9 +67,9 @@ describe "Scenario acceptance" do
67
67
 
68
68
  context "and the response contains a file" do
69
69
 
70
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithFileResponses } }
70
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithFileResponses }
71
71
 
72
- before(:example) { stub_server.activate!("Scenario with file") }
72
+ before(:example) { client.activate!("Scenario with file") }
73
73
 
74
74
  context "and the stub request is made" do
75
75
 
@@ -77,7 +77,7 @@ describe "Scenario acceptance" do
77
77
 
78
78
  it "replays the stubbed response" do
79
79
  expect(response.code).to eql(200)
80
- expect(response).to contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
80
+ expect(response).to contain_file(HttpStub::Examples::ConfiguratorWithFileResponses::FILE_PATH)
81
81
  end
82
82
 
83
83
  end
@@ -1,9 +1,9 @@
1
1
  describe "Server defaults acceptance" do
2
2
 
3
- context "when a configurer defines server defaults" do
4
- include_context "configurer integration"
3
+ context "when a server configured with defaults is started" do
4
+ include_context "server integration"
5
5
 
6
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithServerDefaults } }
6
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithServerDefaults }
7
7
 
8
8
  it "matches requests that match the request default rules" do
9
9
  response = issue_matching_request("has_defaults")
@@ -1,16 +1,24 @@
1
1
  describe "Server memory acceptance" do
2
+ include_context "server integration"
2
3
 
3
- context "when a configurer with a stub is initialized" do
4
- include_context "configurer integration"
4
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithScenariosAndStubs }
5
5
 
6
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialStub } }
6
+ context "when a server configured with scenarios and stubs is started" do
7
7
 
8
8
  describe "GET /http_stub/memory" do
9
9
 
10
10
  let(:response) { HTTParty.get("#{server_uri}/http_stub/memory") }
11
11
 
12
- it "lists the stubs registered during initialization" do
13
- expect(response.body).to include("Class stub body")
12
+ it "lists scenarios activated initially" do
13
+ expect(response.body).to include("Activated initially body")
14
+ end
15
+
16
+ it "does not list scenario's that are not activated initially" do
17
+ expect(response.body).to_not include("Not activated initially body")
18
+ end
19
+
20
+ it "lists stubs" do
21
+ expect(response.body).to include("Stub body")
14
22
  end
15
23
 
16
24
  end
@@ -4,30 +4,13 @@ describe "Server status acceptance" do
4
4
 
5
5
  let(:response) { HTTParty.get("#{server_uri}/http_stub/status") }
6
6
 
7
- context "when a server is started without a configurer" do
7
+ context "when a server is started" do
8
8
  include_context "server integration"
9
9
 
10
- it "indicates the server has started" do
11
- expect(response.body).to eql("Started")
12
- end
13
-
14
- context "and the server is updated to reflect it is initialized" do
15
-
16
- before(:example) { HTTParty.post("#{server_uri}/http_stub/status/initialized") }
17
-
18
- it "indicates the server has been initialized" do
19
- expect(response.body).to eql("Initialized")
20
- end
21
-
22
- end
23
-
24
- end
25
-
26
- context "when a server with a configurer is started" do
27
- include_context "configurer integration"
10
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithTrivialStubs }
28
11
 
29
- it "indicates the server has been initialized" do
30
- expect(response.body).to eql("Initialized")
12
+ it "indicates the server is available" do
13
+ expect(response.body).to eql("OK")
31
14
  end
32
15
 
33
16
  end
@@ -1,16 +1,14 @@
1
1
  describe "Session acceptance" do
2
+ include_context "server integration"
2
3
 
3
- context "when a configurer that has a session support enabled is initialized" do
4
- include_context "configurer integration"
4
+ context "when a server configured with session support is started" do
5
5
 
6
- let(:configurer_specification) do
7
- { class: HttpStub::Examples::ConfigurerWithSessions, name: :session_based_stub, port: 8003 }
8
- end
6
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithSessions }
9
7
 
10
- context "when a stub is added to a session" do
8
+ context "and a stub is actviated in a session" do
11
9
 
12
10
  let(:stub_session_id) { "some_session" }
13
- let(:stub_session) { stub_server.session(stub_session_id) }
11
+ let(:stub_session) { client.session(stub_session_id) }
14
12
 
15
13
  let(:match_response) { HTTParty.get("#{server_uri}/matching_path", request_session_id_header) }
16
14
 
@@ -79,7 +77,7 @@ describe "Session acceptance" do
79
77
  context "when many sessions have been created" do
80
78
 
81
79
  let(:session_ids) { (1..3).map { |i| "session#{i}"} }
82
- let(:sessions) { session_ids.map { |session_id| stub_server.session(session_id) } }
80
+ let(:sessions) { session_ids.map { |session_id| client.session(session_id) } }
83
81
 
84
82
  before(:example) { sessions.each { |session| session.activate!("Some Scenario") } }
85
83
 
@@ -101,10 +99,9 @@ describe "Session acceptance" do
101
99
 
102
100
  end
103
101
 
104
- context "when a configurer that has a session support disabled is initialized" do
105
- include_context "configurer integration"
102
+ context "when a server configured without session support is started" do
106
103
 
107
- let(:configurer_specification) { { class: HttpStub::EmptyConfigurer } }
104
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithTrivialStubs }
108
105
 
109
106
  describe "the administration landing page" do
110
107
 
@@ -1,13 +1,13 @@
1
1
  describe "Scenario acceptance" do
2
2
 
3
- context "when a configurer that contains a stub matching a request body" do
4
- include_context "configurer integration"
3
+ context "when a server is started that is configured with a stub matching a request body" do
4
+ include_context "server integration"
5
5
 
6
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithStubRequestBody } }
6
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithStubRequestBody }
7
7
 
8
8
  context "against an exact match" do
9
9
 
10
- before(:example) { stub_server.activate!("Match body exactly") }
10
+ before(:example) { client.activate!("Match body exactly") }
11
11
 
12
12
  context "and a request is made with a request body" do
13
13
 
@@ -15,7 +15,7 @@ describe "Scenario acceptance" do
15
15
 
16
16
  let(:response) { issue_request(body: "Exactly matches") }
17
17
 
18
- it "responds with the configured response" do
18
+ it "responds with the composed response" do
19
19
  expect(response.code).to eql(204)
20
20
  end
21
21
 
@@ -51,7 +51,7 @@ describe "Scenario acceptance" do
51
51
 
52
52
  context "against a regular expression" do
53
53
 
54
- before(:example) { stub_server.activate!("Match body regex") }
54
+ before(:example) { client.activate!("Match body regex") }
55
55
 
56
56
  context "and a request is made with a request body" do
57
57
 
@@ -59,7 +59,7 @@ describe "Scenario acceptance" do
59
59
 
60
60
  let(:response) { issue_request(body: "matches with additional content") }
61
61
 
62
- it "responds with the configured response" do
62
+ it "responds with the composed response" do
63
63
  expect(response.code).to eql(204)
64
64
  end
65
65
 
@@ -95,7 +95,7 @@ describe "Scenario acceptance" do
95
95
 
96
96
  context "against a JSON schema" do
97
97
 
98
- before(:example) { stub_server.activate!("Match body JSON schema") }
98
+ before(:example) { client.activate!("Match body JSON schema") }
99
99
 
100
100
  context "and a request is made with a request body" do
101
101
 
@@ -107,7 +107,7 @@ describe "Scenario acceptance" do
107
107
  float_property: 77.7 }.to_json)
108
108
  end
109
109
 
110
- it "responds with the configured response" do
110
+ it "responds with the composed response" do
111
111
  expect(response.code).to eql(204)
112
112
  end
113
113