http_stub 0.27.0 → 0.28.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,6 +1,6 @@
1
1
  describe HttpStub::Server::Scenario do
2
2
 
3
- let(:args) { HttpStub::ScenarioFixture.new.server_payload }
3
+ let(:args) { HttpStub::Configurator::ScenarioBuilder.new.build_hash }
4
4
 
5
5
  describe "::create" do
6
6
 
@@ -1,14 +1,13 @@
1
1
  describe HttpStub::Server::Session::Controller do
2
2
 
3
- let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
4
- let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
5
- let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, sessions: session_registry) }
3
+ let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
4
+ let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, session_registry: session_registry) }
6
5
 
7
6
  let(:session_id) { "some session id" }
8
- let(:request) { instance_double(HttpStub::Server::Request::Request, session_id: session_id) }
7
+ let(:request) { HttpStub::Server::RequestFixture.create(session_id: session_id) }
9
8
  let(:logger) { instance_double(Logger) }
10
9
 
11
- let(:controller) { described_class.new(session_configuration, server_memory) }
10
+ let(:controller) { described_class.new(server_memory) }
12
11
 
13
12
  describe "#find" do
14
13
 
@@ -1,77 +1,44 @@
1
1
  describe HttpStub::Server::Session::IdentifierStrategy do
2
2
 
3
- let(:identifier_configuration) { {} }
4
- let(:session_configuration) do
5
- instance_double(HttpStub::Server::Session::Configuration, identifier_configuration: identifier_configuration)
6
- end
3
+ let(:identifier_setting) { {} }
7
4
 
8
- let(:identifier_strategy) { described_class.new(session_configuration) }
5
+ let(:identifier_strategy) { described_class.new(identifier_setting) }
9
6
 
10
7
  describe "#identifier_for" do
11
8
 
12
9
  let(:request_headers) { {} }
13
10
  let(:request_parameters) { {} }
14
11
  let(:sinatra_request) do
15
- instance_double(HttpStub::Server::Request::SinatraRequest, headers: request_headers,
16
- parameters: request_parameters)
12
+ HttpStub::Server::Request::SinatraRequestFixture.create(headers: request_headers, parameters: request_parameters)
17
13
  end
18
14
 
19
15
  subject { identifier_strategy.identifier_for(sinatra_request) }
20
16
 
21
- context "when the session identifier configuration has multiple entries" do
22
-
23
- let(:identifier_configuration) do
24
- [
25
- { header: :first_session_header },
26
- { parameter: :first_session_parameter },
27
- { header: :second_session_header },
28
- { parameter: :second_session_parameter }
29
- ]
30
- end
31
-
32
- context "and multiple session values are in the request" do
17
+ context "when a http stub session id header value is in the request" do
33
18
 
34
- let(:request_headers) do
35
- { second_session_header: "second session header value", another_header: "another header value" }
36
- end
37
- let(:request_parameters) do
38
- { first_session_parameter: "first session parameter value", another_parameter: "another parameter value" }
39
- end
40
-
41
- it "returns the first value from the configuration in the request" do
42
- expect(subject).to eql("first session parameter value")
43
- end
19
+ let(:request_headers) { { http_stub_session_id: "some header value" } }
44
20
 
21
+ it "returns the parameter value" do
22
+ expect(subject).to eql("some header value")
45
23
  end
46
24
 
47
- context "and one session value is in the request" do
48
-
49
- let(:request_headers) { { a_header: "a header value" } }
50
- let(:request_parameters) do
51
- { second_session_parameter: "second session parameter value", another_parameter: "another parameter value" }
52
- end
53
-
54
- it "returns the value" do
55
- expect(subject).to eql("second session parameter value")
56
- end
57
-
58
- end
25
+ end
59
26
 
60
- context "and the session value is not in the request" do
27
+ context "when a http stub session id parameter value is in the request" do
61
28
 
62
- it "returns nil" do
63
- expect(subject).to eql(nil)
64
- end
29
+ let(:request_parameters) { { http_stub_session_id: "some parameter value" } }
65
30
 
31
+ it "returns the parameter value" do
32
+ expect(subject).to eql("some parameter value")
66
33
  end
67
34
 
68
35
  end
69
36
 
70
- context "when the session identifier configuration has one entry" do
37
+ context "when an identifier setting is provided" do
71
38
 
72
39
  context "that is a header" do
73
40
 
74
- let(:identifier_configuration) { [ { header: :session_header } ] }
41
+ let(:identifier_setting) { { header: :session_header } }
75
42
 
76
43
  context "and the session value is in the request" do
77
44
 
@@ -95,7 +62,7 @@ describe HttpStub::Server::Session::IdentifierStrategy do
95
62
 
96
63
  context "that is a parameter" do
97
64
 
98
- let(:identifier_configuration) { [ { parameter: :session_parameter } ] }
65
+ let(:identifier_setting) { { parameter: :session_parameter } }
99
66
 
100
67
  context "and the session value is in the request" do
101
68
 
@@ -1,21 +1,19 @@
1
1
  describe HttpStub::Server::Session::Registry do
2
2
 
3
- let(:default_session_id) { "some default session id" }
4
- let(:session_configuration) do
5
- instance_double(HttpStub::Server::Session::Configuration, default_identifier: default_session_id)
6
- end
7
- let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
8
- let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
3
+ let(:transactional_session_id) { HttpStub::Server::Session::TRANSACTIONAL_SESSION_ID }
4
+
5
+ let(:scenario_registry) { instance_double(HttpStub::Server::Scenario::Registry) }
6
+ let(:initial_stubs) { (1..3).map { HttpStub::Server::StubFixture.create } }
9
7
 
10
8
  let(:logger) { instance_double(Logger) }
11
9
  let(:underlying_session_registry) { instance_double(HttpStub::Server::Registry) }
12
10
 
13
- let(:session_registry) { described_class.new(session_configuration, scenario_registry, memory_session) }
11
+ let(:session_registry) { described_class.new(scenario_registry, initial_stubs) }
14
12
 
15
13
  before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(underlying_session_registry) }
16
14
 
17
- it "uses an underlying simple registry that is initialized with the memory session" do
18
- expect(HttpStub::Server::Registry).to receive(:new).with("session", [ memory_session ])
15
+ it "uses an underlying simple registry" do
16
+ expect(HttpStub::Server::Registry).to receive(:new).with("session")
19
17
 
20
18
  session_registry
21
19
  end
@@ -80,8 +78,8 @@ describe HttpStub::Server::Session::Registry do
80
78
 
81
79
  let(:session_id) { nil }
82
80
 
83
- it "attempts to find a session with the default id defined in the session configuration" do
84
- expect(underlying_session_registry).to receive(:find).with(default_session_id, logger)
81
+ it "attempts to find the transactional session" do
82
+ expect(underlying_session_registry).to receive(:find).with(transactional_session_id, logger)
85
83
 
86
84
  subject
87
85
  end
@@ -92,8 +90,8 @@ describe HttpStub::Server::Session::Registry do
92
90
 
93
91
  before(:example) { allow(underlying_session_registry).to receive(:add) }
94
92
 
95
- it "creates a session with the default session id" do
96
- expect(HttpStub::Server::Session::Session).to receive(:new).with(default_session_id, anything, anything)
93
+ it "creates a transactional session" do
94
+ expect(HttpStub::Server::Session::Session).to receive(:new).with(transactional_session_id, anything, anything)
97
95
 
98
96
  subject
99
97
  end
@@ -134,8 +132,8 @@ describe HttpStub::Server::Session::Registry do
134
132
  subject
135
133
  end
136
134
 
137
- it "creates a session with the provided memory session" do
138
- expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, anything, memory_session)
135
+ it "creates a session with the provided initial stubs" do
136
+ expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, anything, initial_stubs)
139
137
 
140
138
  subject
141
139
  end
@@ -192,19 +190,8 @@ describe HttpStub::Server::Session::Registry do
192
190
 
193
191
  subject { session_registry.clear(logger) }
194
192
 
195
- before(:example) do
196
- allow(memory_session).to receive(:clear)
197
- allow(underlying_session_registry).to receive(:replace)
198
- end
199
-
200
- it "clears the memory session" do
201
- expect(memory_session).to receive(:clear).with(logger)
202
-
203
- subject
204
- end
205
-
206
- it "replaces all sessions in the underlying simple registry with the memory session" do
207
- expect(underlying_session_registry).to receive(:replace).with([ memory_session ], logger)
193
+ it "delegates to the underlying simple registry" do
194
+ expect(underlying_session_registry).to receive(:clear).with(logger)
208
195
 
209
196
  subject
210
197
  end
@@ -1,8 +1,8 @@
1
1
  describe HttpStub::Server::Session::Session do
2
2
 
3
- let(:id) { "Some session id" }
4
- let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
5
- let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
3
+ let(:id) { "some session id" }
4
+ let(:scenario_registry) { instance_double(HttpStub::Server::Scenario::Registry) }
5
+ let(:initial_stubs) { (1..3).map { HttpStub::Server::StubFixture.create } }
6
6
 
7
7
  let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry) }
8
8
  let(:stub_match_registry) { instance_double(HttpStub::Server::Registry) }
@@ -10,7 +10,7 @@ describe HttpStub::Server::Session::Session do
10
10
 
11
11
  let(:logger) { instance_double(Logger) }
12
12
 
13
- let(:session) { described_class.new(id, scenario_registry, memory_session) }
13
+ let(:session) { described_class.new(id, scenario_registry, initial_stubs) }
14
14
 
15
15
  before(:example) do
16
16
  allow(HttpStub::Server::Stub::Registry).to receive(:new).and_return(stub_registry)
@@ -18,8 +18,8 @@ describe HttpStub::Server::Session::Session do
18
18
  allow(HttpStub::Server::Registry).to receive(:new).with("stub miss").and_return(stub_miss_registry)
19
19
  end
20
20
 
21
- it "uses a stub registry that is initialized with the provided memory session" do
22
- expect(HttpStub::Server::Stub::Registry).to receive(:new).with(memory_session)
21
+ it "uses a stub registry that is initialized with the provided initial stubs" do
22
+ expect(HttpStub::Server::Stub::Registry).to receive(:new).with(initial_stubs)
23
23
 
24
24
  session
25
25
  end
@@ -75,38 +75,22 @@ describe HttpStub::Server::Session::Session do
75
75
 
76
76
  context "when the scenario is found" do
77
77
 
78
- let(:scenario_trigger_names) { (1..3).map { |i| "scenario trigger #{i}" } }
79
- let(:scenario_triggers) do
80
- scenario_trigger_names.map { |name| instance_double(HttpStub::Server::Scenario::Trigger, name: name) }
81
- end
82
- let(:triggered_scenarios) do
83
- (1..3).map { instance_double(HttpStub::Server::Scenario::Scenario, triggered_scenarios: [], stubs: []) }
84
- end
85
- let(:scenario_stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
86
- let(:scenario) do
87
- instance_double(HttpStub::Server::Scenario::Scenario, triggered_scenarios: scenario_triggers,
88
- stubs: scenario_stubs)
89
- end
78
+ let(:stubs_activated) { (1..3).map { HttpStub::Server::StubFixture.create } }
79
+ let(:scenario) { instance_double(HttpStub::Server::Scenario::Scenario) }
90
80
 
91
81
  before(:example) do
92
- scenario_trigger_names.zip(triggered_scenarios).each do |scenario_trigger_name, triggered_scenario|
93
- allow(scenario_registry).to(
94
- receive(:find).with(scenario_trigger_name, anything).and_return(triggered_scenario)
95
- )
96
- end
82
+ allow(scenario_registry).to receive(:stubs_activated_by).and_return(stubs_activated)
97
83
  allow(stub_registry).to receive(:concat)
98
84
  end
99
85
 
100
- it "triggers activation of the scenario triggers of the scenario" do
101
- scenario_trigger_names.zip(triggered_scenarios).each do |scenario_trigger_name, triggered_scenario|
102
- expect(scenario_registry).to receive(:find).with(scenario_trigger_name, logger).and_return(triggered_scenario)
103
- end
86
+ it "discovers the stubs activated by the scenario" do
87
+ expect(scenario_registry).to receive(:stubs_activated_by).with(scenario, logger)
104
88
 
105
89
  subject
106
90
  end
107
91
 
108
- it "adds the scenarios stubs to the stub registry" do
109
- expect(stub_registry).to receive(:concat).with(scenario_stubs, logger)
92
+ it "adds the stubs activated to the stub registry" do
93
+ expect(stub_registry).to receive(:concat).with(stubs_activated, logger)
110
94
 
111
95
  subject
112
96
  end
@@ -399,46 +383,4 @@ describe HttpStub::Server::Session::Session do
399
383
 
400
384
  end
401
385
 
402
- describe "#clear" do
403
-
404
- subject { session.clear(logger) }
405
-
406
- before(:example) do
407
- [ stub_registry, stub_match_registry, stub_miss_registry ].each { |registry| allow(registry).to receive(:clear) }
408
- end
409
-
410
- it "clears the stub registry" do
411
- expect(stub_registry).to receive(:clear).with(logger)
412
-
413
- subject
414
- end
415
-
416
- it "clears the stub miss registry" do
417
- expect(stub_miss_registry).to receive(:clear).with(logger)
418
-
419
- subject
420
- end
421
-
422
- it "clears the stub match registry" do
423
- expect(stub_match_registry).to receive(:clear).with(logger)
424
-
425
- subject
426
- end
427
-
428
- it "clears stub misses before the stubs" do
429
- expect(stub_miss_registry).to receive(:clear).ordered
430
- expect(stub_registry).to receive(:clear).ordered
431
-
432
- subject
433
- end
434
-
435
- it "clears stub matches before the stubs" do
436
- expect(stub_match_registry).to receive(:clear).ordered
437
- expect(stub_registry).to receive(:clear).ordered
438
-
439
- subject
440
- end
441
-
442
- end
443
-
444
386
  end
@@ -0,0 +1,17 @@
1
+ describe HttpStub::Server::StdoutLogger do
2
+
3
+ describe "::info" do
4
+
5
+ let(:message) { "some message"}
6
+
7
+ subject { described_class.info(message) }
8
+
9
+ it "writes the message to std out" do
10
+ expect(described_class).to receive(:puts).with(message)
11
+
12
+ subject
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -1,65 +1,19 @@
1
1
  describe HttpStub::Server::Stub::Controller do
2
2
 
3
- let(:request_parameters) { {} }
4
- let(:session) { instance_double(HttpStub::Server::Session::Session) }
5
- let(:request) do
6
- instance_double(HttpStub::Server::Request::Request, parameters: request_parameters, session: session)
7
- end
8
- let(:logger) { instance_double(Logger) }
9
- let(:payload) { HttpStub::StubFixture.new.server_payload }
10
- let(:stub_uri) { "/some/stub/uri" }
11
- let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub, uri: stub_uri) }
3
+ let(:request_parameters) { {} }
4
+ let(:request) { HttpStub::Server::RequestFixture.create(parameters: request_parameters) }
5
+ let(:session) { request.session }
6
+ let(:logger) { instance_double(Logger) }
7
+ let(:stub_uri) { "/some/stub/uri" }
8
+ let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub, uri: stub_uri) }
12
9
 
13
10
  let(:controller) { described_class.new }
14
11
 
15
- describe "#register" do
16
-
17
- subject { controller.register(request, logger) }
18
-
19
- before(:example) do
20
- allow(HttpStub::Server::Stub::Parser).to receive(:parse).and_return(payload)
21
- allow(HttpStub::Server::Stub).to receive(:create).and_return(the_stub)
22
- allow(session).to receive(:add_stub)
23
- end
24
-
25
- it "parses the payload from the request" do
26
- expect(HttpStub::Server::Stub::Parser).to receive(:parse).with(request).and_return(payload)
27
-
28
- subject
29
- end
30
-
31
- it "creates a stub with the parsed payload" do
32
- expect(HttpStub::Server::Stub).to receive(:create).with(payload).and_return(the_stub)
33
-
34
- subject
35
- end
36
-
37
- it "adds the stub to the users session" do
38
- expect(session).to receive(:add_stub).with(the_stub, logger)
39
-
40
- subject
41
- end
42
-
43
- it "creates an ok response with a location header containing the stubs uri" do
44
- expect(HttpStub::Server::Response).to receive(:ok).with("headers" => { "location" => stub_uri })
45
-
46
- subject
47
- end
48
-
49
- it "returns the ok response" do
50
- response = double("HttpStub::Server::Response")
51
- allow(HttpStub::Server::Response).to receive(:ok).and_return(response)
52
-
53
- expect(subject).to eql(response)
54
- end
55
-
56
- end
57
-
58
12
  describe "#match" do
59
13
 
60
14
  let(:matched_stub) { nil }
61
15
 
62
- let(:calculated_stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
16
+ let(:calculated_stub_response) { HttpStub::Server::Stub::ResponseFixture.create }
63
17
 
64
18
  subject { controller.match(request, logger) }
65
19
 
@@ -201,16 +155,4 @@ describe HttpStub::Server::Stub::Controller do
201
155
 
202
156
  end
203
157
 
204
- describe "#clear" do
205
-
206
- subject { controller.clear(request, logger) }
207
-
208
- it "clears the users session" do
209
- expect(session).to receive(:clear).with(logger)
210
-
211
- subject
212
- end
213
-
214
- end
215
-
216
158
  end
@@ -2,6 +2,14 @@ describe HttpStub::Server::Stub::Empty do
2
2
 
3
3
  let(:empty_stub) { HttpStub::Server::Stub::Empty::INSTANCE }
4
4
 
5
+ describe "#stub_id" do
6
+
7
+ it "is an empty string" do
8
+ expect(empty_stub.stub_id).to eql("")
9
+ end
10
+
11
+ end
12
+
5
13
  describe "#uri" do
6
14
 
7
15
  it "is an empty string" do