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
@@ -1,4 +1,4 @@
1
- describe HttpStub::Server::Application::Routes::Session, "when an initialized server is running" do
1
+ describe HttpStub::Server::Application::Routes::Session, "when a server is running" do
2
2
  include_context "server integration"
3
3
 
4
4
  let(:response_document) { Nokogiri::HTML(response.body) }
@@ -1,28 +1,14 @@
1
1
  describe HttpStub::Server::Application::Routes::Status do
2
2
  include_context "http_stub rack application test"
3
3
 
4
- let(:status_controller) { instance_double(HttpStub::Server::Status::Controller) }
5
-
6
- before(:example) { allow(HttpStub::Server::Status::Controller).to receive(:new).and_return(status_controller) }
7
-
8
4
  context "when a request to show the servers current status is received" do
9
5
 
10
- let(:current_status) { "Some status" }
11
-
12
6
  subject { get "/http_stub/status" }
13
7
 
14
- before(:example) { allow(status_controller).to receive(:current).and_return(current_status) }
15
-
16
- it "retrieves the servers current status via the status controller" do
17
- expect(status_controller).to receive(:current).and_return("some status")
18
-
8
+ it "responds with a body indicating the server is running" do
19
9
  subject
20
- end
21
10
 
22
- it "responds with a body containing the servers current status" do
23
- subject
24
-
25
- expect(response.body).to eql(current_status)
11
+ expect(response.body).to eql("OK")
26
12
  end
27
13
 
28
14
  it "responds with a 200 status code" do
@@ -33,24 +19,4 @@ describe HttpStub::Server::Application::Routes::Status do
33
19
 
34
20
  end
35
21
 
36
- context "when a request to mark the server as initialized is received" do
37
-
38
- subject { post "/http_stub/status/initialized" }
39
-
40
- before(:example) { allow(status_controller).to receive(:initialized) }
41
-
42
- it "marks the server as initialized via the status controller" do
43
- expect(status_controller).to receive(:initialized)
44
-
45
- subject
46
- end
47
-
48
- it "responds without error" do
49
- subject
50
-
51
- expect(response.status).to eql(200)
52
- end
53
-
54
- end
55
-
56
22
  end
@@ -1,44 +1,13 @@
1
- describe HttpStub::Server::Application::Routes::Stub, "when an initialized server is running" do
1
+ describe HttpStub::Server::Application::Routes::Stub, "when a server is running" do
2
2
  include_context "server integration"
3
3
 
4
4
  let(:response_document) { Nokogiri::HTML(response.body) }
5
5
 
6
6
  before(:example) { initialize_server }
7
7
 
8
- describe "POST /http_stub/stubs" do
8
+ describe "and a configurator with multiple scenarios is initialized" do
9
9
 
10
- context "when provided with the minimum data required" do
11
-
12
- let(:response) do
13
- HTTParty.post(
14
- "#{server_uri}/http_stub/stubs",
15
- body: { uri: "/some/path", method: "get", response: { status: 200, body: "Some body" } }.to_json
16
- )
17
- end
18
-
19
- after(:example) { reset_session }
20
-
21
- it "returns a 200 response code" do
22
- expect(response.code).to eql(200)
23
- end
24
-
25
- it "registers a stub returning the provided response for a matching request" do
26
- response
27
-
28
- stubbed_response = HTTParty.get("#{server_uri}/some/path")
29
-
30
- expect(stubbed_response.code).to eql(200)
31
- expect(stubbed_response.body).to eql("Some body")
32
- end
33
-
34
- end
35
-
36
- end
37
-
38
- describe "and a configurer with multiple scenarios is initialized" do
39
- include_context "configurer integration"
40
-
41
- let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithExhaustiveScenarios } }
10
+ let(:configurator) { HttpStub::Examples::ConfiguratorWithExhaustiveScenarios }
42
11
 
43
12
  describe "GET /http_stub/stubs" do
44
13
 
@@ -9,34 +9,6 @@ describe HttpStub::Server::Application::Routes::Stub do
9
9
  allow(HttpStub::Server::Stub::Match::Controller).to receive(:new).and_return(stub_match_controller)
10
10
  end
11
11
 
12
- describe "when a stub registration request within a session is received" do
13
- include_context "request includes a session identifier"
14
-
15
- let(:payload) { { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } }.to_json }
16
-
17
- let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
18
-
19
- subject { post "/http_stub/stubs" }
20
-
21
- before(:example) do
22
- allow(request).to receive(:body).and_return(payload)
23
- allow(stub_controller).to receive(:register).and_return(registration_response)
24
- end
25
-
26
- it "registers the stub via the stub controller" do
27
- expect(stub_controller).to receive(:register).and_return(registration_response)
28
-
29
- subject
30
- end
31
-
32
- it "processes the stub controllers response via the response pipeline" do
33
- expect(response_pipeline).to receive(:process).with(registration_response)
34
-
35
- subject
36
- end
37
-
38
- end
39
-
40
12
  describe "when a request to list the stubs in a session is received" do
41
13
  include_context "request includes a session identifier"
42
14
 
@@ -98,27 +70,6 @@ describe HttpStub::Server::Application::Routes::Stub do
98
70
 
99
71
  end
100
72
 
101
- describe "when a request to clear the stubs in a session is received" do
102
- include_context "request includes a session identifier"
103
-
104
- subject { delete "/http_stub/stubs" }
105
-
106
- before(:example) { allow(stub_controller).to receive(:clear) }
107
-
108
- it "clears the stubs for the current user via the stub controller" do
109
- expect(stub_controller).to receive(:clear).with(request, anything)
110
-
111
- subject
112
- end
113
-
114
- it "responds with a 200 status code" do
115
- subject
116
-
117
- expect(response.status).to eql(200)
118
- end
119
-
120
- end
121
-
122
73
  describe "when a request to list the stub matches in a session is received" do
123
74
  include_context "request includes a session identifier"
124
75
 
@@ -139,7 +90,7 @@ describe HttpStub::Server::Application::Routes::Stub do
139
90
 
140
91
  let(:uri) { "/some/matched/uri" }
141
92
  let(:method) { "some http method" }
142
- let(:last_match_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
93
+ let(:last_match_response) { HttpStub::Server::Stub::ResponseFixture.create }
143
94
 
144
95
  subject { get "/http_stub/stubs/matches/last" }
145
96
 
@@ -154,8 +105,8 @@ describe HttpStub::Server::Application::Routes::Stub do
154
105
  subject
155
106
  end
156
107
 
157
- it "processes the match result controllers response via the response pipeline" do
158
- expect(response_pipeline).to receive(:process).with(last_match_response)
108
+ it "serves the match result controllers response" do
109
+ expect(last_match_response).to receive(:serve_on).with(an_instance_of(app_class))
159
110
 
160
111
  subject
161
112
  end
@@ -179,7 +130,7 @@ describe HttpStub::Server::Application::Routes::Stub do
179
130
 
180
131
  describe "when any other request is received" do
181
132
 
182
- let(:stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
133
+ let(:stub_response) { HttpStub::Server::Stub::ResponseFixture.create }
183
134
 
184
135
  subject { get "/some_path" }
185
136
 
@@ -191,8 +142,8 @@ describe HttpStub::Server::Application::Routes::Stub do
191
142
  subject
192
143
  end
193
144
 
194
- it "processes the response via the response pipeline" do
195
- expect(response_pipeline).to receive(:process).with(stub_response)
145
+ it "serves the response" do
146
+ expect(stub_response).to receive(:serve_on).with(an_instance_of(app_class))
196
147
 
197
148
  subject
198
149
  end
@@ -1,6 +1,10 @@
1
1
  describe HttpStub::Server::Daemon do
2
2
 
3
- let(:server) { HttpStub::Server::Daemon.new(name: :example_server_daemon, port: 8002) }
3
+ let(:server_name_in_rakefile) { :example_server_daemon }
4
+ let(:port_in_rakefile) { 8001 }
5
+
6
+ let(:configurator) { HttpStub::ConfiguratorFixture.create(port: port_in_rakefile) }
7
+ let(:server) { HttpStub::Server::Daemon.new(name: server_name_in_rakefile, configurator: configurator) }
4
8
 
5
9
  it_behaves_like "a managed http server"
6
10
 
@@ -1,11 +1,5 @@
1
1
  describe HttpStub::Server::Daemon do
2
2
 
3
- let(:server_port) { 8888 }
4
-
5
- let(:server_daemon) { create_daemon_without_configurer }
6
-
7
- before(:example) { allow(server_daemon.logger).to receive(:info) }
8
-
9
3
  describe "::log_dir" do
10
4
 
11
5
  before(:example) { @original_log_dir = HttpServerManager.log_dir }
@@ -36,84 +30,21 @@ describe HttpStub::Server::Daemon do
36
30
 
37
31
  describe "constructor" do
38
32
 
39
- context "when a configurer is provided" do
40
-
41
- let(:server_host) { "some_host" }
42
- let(:stub_server) { instance_double(HttpStub::Configurer::DSL::Server, host: server_host, port: server_port) }
43
- let(:configurer) { double(HttpStub::Configurer, stub_server: stub_server) }
44
-
45
- let(:server_daemon) { create_daemon_with_configurer }
46
-
47
- it "establishes the daemons host as the configurers server host" do
48
- expect(server_daemon.host).to eql(server_host)
49
- end
50
-
51
- it "establishes the daemons port as the configurers server port" do
52
- expect(server_daemon.port).to eql(server_port)
53
- end
54
-
55
- end
56
-
57
- context "when a configurer is not provided" do
58
-
59
- let(:server_daemon) { create_daemon_without_configurer }
60
-
61
- it "defaults the daemons host to 'localhost'" do
62
- expect(server_daemon.host).to eql("localhost")
63
- end
64
-
65
- it "establishes the daemons port as the provided value" do
66
- expect(server_daemon.port).to eql(server_port)
67
- end
68
-
69
- end
70
-
71
- end
72
-
73
- describe "#start!" do
74
-
75
- before(:example) { allow(server_daemon).to receive(:running?).and_return(true) }
76
-
77
- context "when a configurer is provided" do
78
-
79
- let(:configurer) { double(HttpStub::Configurer).as_null_object }
80
-
81
- let(:server_daemon) { create_daemon_with_configurer }
82
-
83
- it "initializes the configurer" do
84
- expect(configurer).to receive(:initialize!)
85
-
86
- server_daemon.start!
87
- end
33
+ let(:server_port) { 8888 }
34
+ let(:configurator) { Class.new { include HttpStub::Configurator } }
88
35
 
89
- it "logs that the server with the provided name has been initialized" do
90
- expect(server_daemon.logger).to receive(:info).with("sample_server_daemon initialized")
36
+ let(:server_daemon) { HttpStub::Server::Daemon.new(name: :sample_server_daemon, configurator: configurator) }
91
37
 
92
- server_daemon.start!
93
- end
38
+ before(:example) { configurator.state.port = server_port }
94
39
 
40
+ it "establishes the daemons host as localhost by default" do
41
+ expect(server_daemon.host).to eql("localhost")
95
42
  end
96
43
 
97
- context "when no configurer is provided" do
98
-
99
- let(:server_daemon) { create_daemon_without_configurer }
100
-
101
- it "does not log that the server has been initialized" do
102
- expect(server_daemon.logger).not_to receive(:info).with("sample_server_daemon initialized")
103
-
104
- server_daemon.start!
105
- end
106
-
44
+ it "establishes the daemons port as the configured port" do
45
+ expect(server_daemon.port).to eql(server_port)
107
46
  end
108
47
 
109
48
  end
110
49
 
111
- def create_daemon_with_configurer
112
- HttpStub::Server::Daemon.new(name: :sample_server_daemon, configurer: configurer)
113
- end
114
-
115
- def create_daemon_without_configurer
116
- HttpStub::Server::Daemon.new(name: :sample_server_daemon, port: server_port)
117
- end
118
-
119
50
  end
@@ -1,9 +1,8 @@
1
1
  describe HttpStub::Server::Memory::Controller do
2
2
 
3
- let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
4
- let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory) }
3
+ let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory) }
5
4
 
6
- let(:controller) { described_class.new(session_configuration, server_memory) }
5
+ let(:controller) { described_class.new(server_memory) }
7
6
 
8
7
  describe "#find_stubs" do
9
8
 
@@ -19,29 +18,4 @@ describe HttpStub::Server::Memory::Controller do
19
18
 
20
19
  end
21
20
 
22
- describe "#reset" do
23
-
24
- let(:logger) { instance_double(Logger) }
25
-
26
- subject { controller.reset(logger) }
27
-
28
- before(:example) do
29
- allow(session_configuration).to receive(:reset)
30
- allow(server_memory).to receive(:reset)
31
- end
32
-
33
- it "resets the servers session configuration" do
34
- expect(session_configuration).to receive(:reset)
35
-
36
- subject
37
- end
38
-
39
- it "resets the servers memory providing the logger" do
40
- expect(server_memory).to receive(:reset).with(logger)
41
-
42
- subject
43
- end
44
-
45
- end
46
-
47
21
  end
@@ -0,0 +1,57 @@
1
+ describe HttpStub::Server::Memory::InitialState do
2
+
3
+ let(:scenario_hashes) { (1..3).map { HttpStub::Configurator::ScenarioFixture.create_hash } }
4
+ let(:stub_hashes) { (1..3).map { HttpStub::Configurator::StubFixture.create_hash } }
5
+ let(:configurator_state) do
6
+ instance_double(HttpStub::Configurator::State, scenario_hashes: scenario_hashes, stub_hashes: stub_hashes)
7
+ end
8
+
9
+ let(:initial_state) { described_class.new(configurator_state) }
10
+
11
+ describe "#load_scenarios" do
12
+
13
+ subject { initial_state.load_scenarios }
14
+
15
+ it "returns the provided scenarios" do
16
+ expected_scenario_names = scenario_hashes.map { |hash| hash[:name] }.reverse
17
+
18
+ expect(subject.map(&:name)).to contain_exactly(*expected_scenario_names)
19
+ end
20
+
21
+ end
22
+
23
+ describe "#load_stubs" do
24
+
25
+ let(:scenario_registry) { HttpStub::Server::Scenario::Registry.new(scenarios) }
26
+
27
+ subject { initial_state.load_stubs(scenario_registry) }
28
+
29
+ context "when scenarios have been activated" do
30
+
31
+ let(:scenarios) { (1..3).map { |i| HttpStub::Server::ScenarioFixture.with_stubs(activated: i % 2 > 0) } }
32
+
33
+ it "contains the provided stubs and those activated by each activated scenario" do
34
+ activated_stubs = [ scenarios.first, scenarios.last ].map(&:stubs).flatten
35
+
36
+ expect_stub_ids_to_contain_exactly(stub_hashes.map { |hash| hash[:id] } + activated_stubs.map(&:stub_id))
37
+ end
38
+
39
+ end
40
+
41
+ context "when no scenarios have been activated" do
42
+
43
+ let(:scenarios) { (1..3).map { HttpStub::Server::ScenarioFixture.create(activated: false) } }
44
+
45
+ it "returns the provided stubs" do
46
+ expect_stub_ids_to_contain_exactly(stub_hashes.map { |hash| hash[:id] })
47
+ end
48
+
49
+ end
50
+
51
+ def expect_stub_ids_to_contain_exactly(expected_ids)
52
+ expect(subject.map(&:stub_id)).to contain_exactly(*expected_ids)
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -1,152 +1,64 @@
1
1
  describe HttpStub::Server::Memory::Memory do
2
2
 
3
- let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
3
+ let(:loaded_scenarios) { HttpStub::Server::ScenarioFixture.many }
4
+ let(:loaded_stubs) { HttpStub::Server::StubFixture.many }
4
5
 
5
- let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
6
- let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
7
- let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
6
+ let(:configurator_state) { HttpStub::Configurator::State.new }
8
7
 
9
- let(:memory) { described_class.new(session_configuration) }
10
-
11
- before(:example) do
12
- allow(HttpStub::Server::Session::Session).to receive(:new).and_return(memory_session)
13
- allow(HttpStub::Server::Registry).to receive(:new).and_return(scenario_registry)
14
- allow(HttpStub::Server::Session::Registry).to receive(:new).and_return(session_registry)
15
- end
16
-
17
- it "creates a simple scenario registry" do
18
- expect(HttpStub::Server::Registry).to receive(:new).with("scenario")
19
-
20
- memory
21
- end
22
-
23
- it "creates a memory session" do
24
- expect(HttpStub::Server::Session::Session).to(
25
- receive(:new).with(HttpStub::Server::Session::MEMORY_SESSION_ID, anything, anything)
26
- )
27
-
28
- memory
29
- end
30
-
31
- it "creates a memory session containing the scenario registry" do
32
- expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, scenario_registry, anything)
33
-
34
- memory
8
+ let(:initial_state) do
9
+ instance_double(HttpStub::Server::Memory::InitialState, load_scenarios: loaded_scenarios, load_stubs: loaded_stubs)
35
10
  end
36
11
 
37
- it "creates a memory session containing an empty memory session" do
38
- expect(HttpStub::Server::Session::Session).to(
39
- receive(:new).with(anything, anything, HttpStub::Server::Session::Empty)
40
- )
41
-
42
- memory
43
- end
44
-
45
- it "creates a session registry containing the session configuration" do
46
- expect(HttpStub::Server::Session::Registry).to receive(:new).with(session_configuration, anything, anything)
47
-
48
- memory
49
- end
50
-
51
- it "creates a session registry containing the scenario registry" do
52
- expect(HttpStub::Server::Session::Registry).to receive(:new).with(anything, scenario_registry, anything)
53
-
54
- memory
55
- end
56
-
57
- it "creates a session registry initalised with the memory session" do
58
- expect(HttpStub::Server::Session::Registry).to receive(:new).with(anything, anything, memory_session)
59
-
60
- memory
61
- end
62
-
63
- describe "#status" do
64
-
65
- subject { memory.status }
12
+ let(:memory) { described_class.new(configurator_state) }
66
13
 
67
- it "defaults to 'Started'" do
68
- expect(subject).to eql("Started")
69
- end
70
-
71
- context "when the memory has been initialized" do
14
+ before(:example) { expect(HttpStub::Server::Memory::InitialState).to receive(:new).and_return(initial_state) }
72
15
 
73
- before(:example) { memory.initialized! }
16
+ describe "#scenario_registry" do
74
17
 
75
- it "reflects the memory is 'Initialized'" do
76
- expect(subject).to eql("Initialized")
77
- end
18
+ subject { memory.scenario_registry }
78
19
 
20
+ it "returns a scenario registry" do
21
+ expect(subject).to be_an_instance_of(HttpStub::Server::Scenario::Registry)
79
22
  end
80
23
 
81
- end
82
-
83
- describe "#scenarios" do
84
-
85
- subject { memory.scenarios }
86
-
87
- it "returns the servers scenario registry" do
88
- expect(subject).to eql(scenario_registry)
89
- end
90
-
91
- end
92
-
93
- describe "#sessions" do
94
-
95
- subject { memory.sessions }
96
-
97
- it "returns the servers session registry" do
98
- expect(subject).to eql(session_registry)
24
+ it "contains the loaded scenarios" do
25
+ expect(subject.all.map(&:name)).to contain_exactly(*loaded_scenarios.map(&:name))
99
26
  end
100
27
 
101
28
  end
102
29
 
103
30
  describe "#stubs" do
104
31
 
105
- let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
106
-
107
32
  subject { memory.stubs }
108
33
 
109
- before(:example) { allow(memory_session).to receive(:stubs).and_return(stubs) }
110
-
111
- it "returns the stubs within the memory session" do
112
- expect(subject).to eql(stubs)
34
+ it "contains the loaded stubs" do
35
+ expect(subject).to eql(loaded_stubs)
113
36
  end
114
37
 
115
38
  end
116
39
 
117
- describe "#reset" do
40
+ describe "#session_registry" do
118
41
 
119
- let(:logger) { instance_double(Logger) }
42
+ let(:logger) { HttpStub::Server::SilentLogger }
120
43
 
121
- subject { memory.reset(logger) }
44
+ subject { memory.session_registry }
122
45
 
123
- before(:example) do
124
- allow(scenario_registry).to receive(:clear)
125
- allow(session_registry).to receive(:clear)
46
+ it "returns a session registry" do
47
+ expect(subject).to be_an_instance_of(HttpStub::Server::Session::Registry)
126
48
  end
127
49
 
128
- it "clears the servers scenarios" do
129
- expect(scenario_registry).to receive(:clear).with(logger)
130
-
131
- subject
50
+ it "contains the loaded scenarios" do
51
+ loaded_scenarios.each do |scenario|
52
+ expect { obtain_session.activate_scenario!(scenario.name, logger) }.to_not raise_error
53
+ end
132
54
  end
133
55
 
134
- it "clears the servers sessions" do
135
- expect(session_registry).to receive(:clear).with(logger)
136
-
137
- subject
56
+ it "contains the loaded stubs" do
57
+ expect(obtain_session.stubs.map(&:stub_id)).to contain_exactly(*loaded_stubs.map(&:stub_id))
138
58
  end
139
59
 
140
- context "when the memory had been initialized" do
141
-
142
- before(:example) { memory.initialized! }
143
-
144
- it "resets the servers status to the default value" do
145
- subject
146
-
147
- expect(memory.status).to eql("Started")
148
- end
149
-
60
+ def obtain_session
61
+ subject.find_or_create("some id", logger)
150
62
  end
151
63
 
152
64
  end