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
@@ -0,0 +1,162 @@
1
+ describe HttpStub::Configurator::Scenario do
2
+
3
+ let(:name) { "some scenario name" }
4
+ let(:default_stub_template) { instance_double(HttpStub::Configurator::Stub::Template) }
5
+
6
+ let(:scenario) { HttpStub::Configurator::Scenario.new(name, default_stub_template) }
7
+
8
+ describe "#build_stub" do
9
+
10
+ let(:response_overrides) { { status: 201 } }
11
+ let(:block_verifier) { double("BlockVerifier") }
12
+ let(:block) { lambda { block_verifier.verify } }
13
+
14
+ subject { scenario.build_stub(response_overrides, &block) }
15
+
16
+ it "delegates to the provided default stub template" do
17
+ expect(default_stub_template).to receive(:build_stub).with(response_overrides).and_yield
18
+ expect(block_verifier).to receive(:verify)
19
+
20
+ subject
21
+ end
22
+
23
+ it "returns the built stub" do
24
+ built_stub = instance_double(HttpStub::Configurator::Stub::Stub)
25
+ allow(default_stub_template).to receive(:build_stub).and_return(built_stub)
26
+
27
+ expect(subject).to eql(built_stub)
28
+ end
29
+
30
+ end
31
+
32
+ describe "#add_stub!" do
33
+
34
+ let(:stub_hash) { { stub_key: "stub value" } }
35
+ let(:built_stub) { instance_double(HttpStub::Configurator::Stub::Stub, to_hash: stub_hash) }
36
+
37
+ context "when a block is provided" do
38
+
39
+ let(:block_verifier) { double("BlockVerifier") }
40
+ let(:block) { lambda { block_verifier.verify } }
41
+
42
+ subject { scenario.add_stub!(&block) }
43
+
44
+ before(:example) { allow(default_stub_template).to receive(:build_stub).and_return(built_stub) }
45
+
46
+ it "builds a stub whose values are initialized via the provided block" do
47
+ expect(default_stub_template).to receive(:build_stub).with(no_args).and_yield.and_return(built_stub)
48
+ expect(block_verifier).to receive(:verify)
49
+
50
+ subject
51
+ end
52
+
53
+ it "adds the stub to the scenario" do
54
+ subject
55
+
56
+ expect(scenario.to_hash).to include(stubs: [ stub_hash ])
57
+ end
58
+
59
+ end
60
+
61
+ context "when a stub is provided" do
62
+
63
+ subject { scenario.add_stub!(built_stub) }
64
+
65
+ it "adds the stub to the scenario" do
66
+ subject
67
+
68
+ expect(scenario.to_hash).to include(stubs: [ stub_hash ])
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ describe "#add_stubs!" do
76
+
77
+ let(:stub_hashes) { (1..3).map { |i| { "stub_#{i}_key" => "stub value #{i}" } } }
78
+ let(:stubs) { stub_hashes.map { |hash| instance_double(HttpStub::Configurator::Stub::Stub, to_hash: hash) } }
79
+
80
+ subject { scenario.add_stubs!(stubs) }
81
+
82
+ it "adds each stub to the scenario" do
83
+ subject
84
+
85
+ expect(scenario.to_hash).to include(stubs: stub_hashes)
86
+ end
87
+
88
+ end
89
+
90
+ describe "#activate_scenarios!" do
91
+
92
+ let(:scenario_names) { (1..3).map { |i| "scenario name #{i}" } }
93
+
94
+ context "when the scenario names are provided as an array" do
95
+
96
+ subject { scenario.activate_scenarios!(scenario_names) }
97
+
98
+ it "adds the scenario names to scenarios triggered by this scenario" do
99
+ subject
100
+
101
+ expect(scenario.to_hash).to include(triggered_scenario_names: scenario_names)
102
+ end
103
+
104
+ end
105
+
106
+ context "when the scenario names are provided as a list of parameters" do
107
+
108
+ subject { scenario.activate_scenarios!(*scenario_names) }
109
+
110
+ it "adds the scenario names to scenarios triggered by this scenario" do
111
+ subject
112
+
113
+ expect(scenario.to_hash).to include(triggered_scenario_names: scenario_names)
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ describe "#activate!" do
121
+
122
+ context "when the scenario is activated" do
123
+
124
+ subject { scenario.activate! }
125
+
126
+ it "marks the scenario as immediately active" do
127
+ subject
128
+
129
+ expect(scenario.to_hash).to include(activated: true)
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
136
+ describe "#to_hash" do
137
+
138
+ subject { scenario.to_hash }
139
+
140
+ it "includes the name of the scenario" do
141
+ expect(subject).to include(name: name)
142
+ end
143
+
144
+ context "when the scenario is unchanged" do
145
+
146
+ it "includes an activated flag that is false" do
147
+ expect(scenario.to_hash).to include(activated: false)
148
+ end
149
+
150
+ it "includes stubs that are empty" do
151
+ expect(scenario.to_hash).to include(stubs: [])
152
+ end
153
+
154
+ it "includes triggered scenario names that are empty" do
155
+ expect(scenario.to_hash).to include(triggered_scenario_names: [])
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+
162
+ end
@@ -0,0 +1,344 @@
1
+ describe HttpStub::Configurator::Server do
2
+
3
+ let(:state) { instance_double(HttpStub::Configurator::State) }
4
+ let(:server_stub_template) { instance_double(HttpStub::Configurator::Stub::Template) }
5
+
6
+ let(:block_verifier) { double("BlockVerifier") }
7
+
8
+ let(:server) { described_class.new(state) }
9
+
10
+ before(:example) { allow(HttpStub::Configurator::Stub::Template).to receive(:new).and_return(server_stub_template) }
11
+
12
+ it "creates a stub template to hold the default stub settings for the server" do
13
+ expect(HttpStub::Configurator::Stub::Template).to receive(:new).with(no_args)
14
+
15
+ server
16
+ end
17
+
18
+ shared_context "a server with a port configured" do
19
+
20
+ before(:example) { server.port = 8888 }
21
+
22
+ end
23
+
24
+ describe "#port=" do
25
+
26
+ let(:port) { "8888" }
27
+
28
+ subject { server.port = port }
29
+
30
+ it "delegates to the servers state" do
31
+ allow(state).to receive(:port=).with(port)
32
+
33
+ subject
34
+ end
35
+
36
+ end
37
+
38
+ describe "#external_base_uri" do
39
+
40
+ let(:external_base_uri) { "http://some/external/base/uri" }
41
+
42
+ subject { server.external_base_uri }
43
+
44
+ it "delegates to the servers state" do
45
+ allow(state).to receive(:external_base_uri).and_return(external_base_uri)
46
+
47
+ expect(subject).to eql(external_base_uri)
48
+ end
49
+
50
+ end
51
+
52
+ describe "#session_identifer=" do
53
+
54
+ let(:session_identifier) { { headers: :some_session_identifier } }
55
+
56
+ subject { server.session_identifier = session_identifier }
57
+
58
+ it "delegates to the servers state" do
59
+ expect(state).to receive(:session_identifier=).with(session_identifier)
60
+
61
+ subject
62
+ end
63
+
64
+ end
65
+
66
+ describe "#enable" do
67
+
68
+ let(:feature) { :a_feature }
69
+
70
+ subject { server.enable(feature) }
71
+
72
+ it "delegates to the servers state" do
73
+ expect(state).to receive(:enable).with(feature)
74
+
75
+ subject
76
+ end
77
+
78
+ end
79
+
80
+ describe "#request_defaults=" do
81
+
82
+ let(:args) { { request_rule_key: "request rule value" } }
83
+
84
+ subject { server.request_defaults = args }
85
+
86
+ it "establishes request matching rules on the default stub template" do
87
+ expect(server_stub_template).to receive(:match_requests).with(args)
88
+
89
+ subject
90
+ end
91
+
92
+ end
93
+
94
+ describe "#response_defaults=" do
95
+
96
+ let(:args) { { response_key: "response value" } }
97
+
98
+ subject { server.response_defaults = args }
99
+
100
+ it "establishes response values on the default stub template" do
101
+ expect(server_stub_template).to receive(:respond_with).with(args)
102
+
103
+ subject
104
+ end
105
+
106
+ end
107
+
108
+ describe "#endpoint_template" do
109
+
110
+ let(:block) { lambda { block_verifier.verify } }
111
+ let(:endpoint_template) { instance_double(HttpStub::Configurator::EndpointTemplate) }
112
+
113
+ subject { server.endpoint_template(&block) }
114
+
115
+ before(:example) { allow(HttpStub::Configurator::EndpointTemplate).to receive(:new).and_return(endpoint_template) }
116
+
117
+ it "creates an endpoint template for the server" do
118
+ expect(HttpStub::Configurator::EndpointTemplate).to receive(:new).with(server, anything)
119
+
120
+ subject
121
+ end
122
+
123
+ it "creates an endpoint template extending the servers stub template" do
124
+ expect(HttpStub::Configurator::EndpointTemplate).to receive(:new).with(anything, server_stub_template)
125
+
126
+ subject
127
+ end
128
+
129
+ it "creates an endpoint template using any provided block to initialize the template" do
130
+ allow(HttpStub::Configurator::EndpointTemplate).to receive(:new).and_yield
131
+ expect(block_verifier).to receive(:verify)
132
+
133
+ subject
134
+ end
135
+
136
+ it "returns the created endpoint template" do
137
+ expect(subject).to eql(endpoint_template)
138
+ end
139
+
140
+ end
141
+
142
+ describe "#add_scenario!" do
143
+
144
+ let(:scenario_name) { "some/scenario/name" }
145
+ let(:block) { lambda { |_scenario| "some block" } }
146
+
147
+ let(:scenario) { instance_double(HttpStub::Configurator::Scenario) }
148
+
149
+ subject { server.add_scenario!(scenario_name, &block) }
150
+
151
+ before(:example) do
152
+ allow(HttpStub::Configurator::Scenario).to receive(:new).and_return(scenario)
153
+ allow(state).to receive(:add_scenario)
154
+ end
155
+
156
+ it "creates a scenario containing the provided scenario name" do
157
+ expect(HttpStub::Configurator::Scenario).to receive(:new).with(scenario_name, anything)
158
+
159
+ subject
160
+ end
161
+
162
+ it "creates a scenario extending the servers stub template" do
163
+ expect(HttpStub::Configurator::Scenario).to receive(:new).with(anything, server_stub_template)
164
+
165
+ subject
166
+ end
167
+
168
+ it "yields the created scenario to the provided block" do
169
+ expect { |block| server.add_scenario!(scenario_name, &block) }.to yield_with_args(scenario)
170
+ end
171
+
172
+ it "adds the scenario to submit the configurators state" do
173
+ expect(state).to receive(:add_scenario).with(scenario)
174
+
175
+ subject
176
+ end
177
+
178
+ end
179
+
180
+ describe "#add_scenario_with_one_stub!" do
181
+
182
+ let(:scenario_name) { "Some scenario name" }
183
+ let(:block) { lambda { block_verifier.verify } }
184
+
185
+ let(:scenario) { instance_double(HttpStub::Configurator::Scenario, add_stub!: nil) }
186
+ let(:the_stub) { instance_double(HttpStub::Configurator::Stub::Stub, invoke: nil) }
187
+
188
+ subject { server.add_scenario_with_one_stub!(scenario_name, the_stub) }
189
+
190
+ before(:each) { allow(server).to receive(:add_scenario!).and_yield(scenario) }
191
+
192
+ it "adds a scenario with the provided name" do
193
+ expect(server).to receive(:add_scenario!).with(scenario_name)
194
+
195
+ subject
196
+ end
197
+
198
+ context "when a stub is provided" do
199
+
200
+ subject { server.add_scenario_with_one_stub!(scenario_name, the_stub) }
201
+
202
+ it "adds the stub to the scenario" do
203
+ expect(scenario).to receive(:add_stub!).with(the_stub)
204
+
205
+ subject
206
+ end
207
+
208
+ end
209
+
210
+ context "when a block is provided" do
211
+
212
+ subject { server.add_scenario_with_one_stub!(scenario_name, &block) }
213
+
214
+ before(:example) { allow(scenario).to receive(:add_stub!).and_yield(the_stub) }
215
+
216
+ it "adds an empty stub to the scenario" do
217
+ expect(scenario).to receive(:add_stub!).with(nil)
218
+
219
+ subject
220
+ end
221
+
222
+ context "that accepts the stub as an argument" do
223
+
224
+ let(:block) { lambda { |_stub| block_verifier.verify } }
225
+
226
+ it "invokes the stub with no additional argument" do
227
+ expect(the_stub).to receive(:invoke).with(nil).and_yield(the_stub)
228
+ expect(block_verifier).to receive(:verify)
229
+
230
+ subject
231
+ end
232
+
233
+ end
234
+
235
+ context "that accepts the stub and scenario as arguments" do
236
+
237
+ let(:block) { lambda { |_stub, _scenario| block_verifier.verify } }
238
+
239
+ it "invokes the stub and supplies the scenario" do
240
+ expect(the_stub).to receive(:invoke).with(scenario).and_yield(the_stub, scenario)
241
+ expect(block_verifier).to receive(:verify)
242
+
243
+ subject
244
+ end
245
+
246
+ end
247
+
248
+ end
249
+
250
+ end
251
+
252
+ describe "#build_stub" do
253
+
254
+ let(:block) { lambda { block_verifier.verify } }
255
+
256
+ subject { server.build_stub(&block) }
257
+
258
+ it "delegates to the servers stub template" do
259
+ expect(server_stub_template).to receive(:build_stub)
260
+
261
+ subject
262
+ end
263
+
264
+ it "initializes the built stub using the provided block" do
265
+ allow(server_stub_template).to receive(:build_stub).and_yield
266
+ expect(block_verifier).to receive(:verify)
267
+
268
+ subject
269
+ end
270
+
271
+ it "returns the built stub" do
272
+ built_stub = instance_double(HttpStub::Configurator::Stub::Stub)
273
+ allow(server_stub_template).to receive(:build_stub).and_return(built_stub)
274
+
275
+ expect(subject).to eql(built_stub)
276
+ end
277
+
278
+ end
279
+
280
+ describe "#add_stub!" do
281
+
282
+ let(:the_stub) { instance_double(HttpStub::Configurator::Stub::Stub) }
283
+
284
+ context "when a stub is provided" do
285
+
286
+ subject { server.add_stub!(the_stub) }
287
+
288
+ it "adds the stub to the configurators state" do
289
+ expect(state).to receive(:add_stub).with(the_stub)
290
+
291
+ subject
292
+ end
293
+
294
+ end
295
+
296
+ context "when a block is provided" do
297
+
298
+ let(:block) { lambda { block_verifier.verify } }
299
+
300
+ subject { server.add_stub!(&block) }
301
+
302
+ before(:each) do
303
+ allow(server_stub_template).to receive(:build_stub).and_return(the_stub)
304
+ allow(state).to receive(:add_stub)
305
+ end
306
+
307
+ it "builds a stub via the servers stub template" do
308
+ expect(server_stub_template).to receive(:build_stub)
309
+
310
+ subject
311
+ end
312
+
313
+ it "invokes the block with the created stub" do
314
+ allow(server_stub_template).to receive(:build_stub).and_yield
315
+ expect(block_verifier).to receive(:verify)
316
+
317
+ subject
318
+ end
319
+
320
+ it "adds the stub to the configurators state" do
321
+ expect(state).to receive(:add_stub).with(the_stub)
322
+
323
+ subject
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+
330
+ describe "#add_stubs!" do
331
+
332
+ let(:the_stubs) { (1..3).map { instance_double(HttpStub::Configurator::Stub::Stub) } }
333
+
334
+ subject { server.add_stubs!(the_stubs) }
335
+
336
+ it "add the stubs to the configurators state" do
337
+ the_stubs.each { |the_stub| expect(state).to receive(:add_stub).with(the_stub) }
338
+
339
+ subject
340
+ end
341
+
342
+ end
343
+
344
+ end