http_stub 0.25.1 → 0.26.0

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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +32 -9
  3. data/lib/http_stub/configurer.rb +2 -10
  4. data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
  5. data/lib/http_stub/configurer/dsl/server.rb +32 -43
  6. data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
  7. data/lib/http_stub/configurer/dsl/session.rb +55 -0
  8. data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
  9. data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
  10. data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
  11. data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
  12. data/lib/http_stub/configurer/request/http/basic.rb +9 -3
  13. data/lib/http_stub/configurer/request/http/factory.rb +7 -16
  14. data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
  15. data/lib/http_stub/configurer/request/stub.rb +3 -3
  16. data/lib/http_stub/configurer/request/triggers.rb +25 -0
  17. data/lib/http_stub/configurer/server/command_processor.rb +8 -10
  18. data/lib/http_stub/configurer/server/configuration.rb +33 -0
  19. data/lib/http_stub/configurer/server/facade.rb +21 -43
  20. data/lib/http_stub/configurer/server/request_processor.rb +2 -2
  21. data/lib/http_stub/configurer/server/session_facade.rb +64 -0
  22. data/lib/http_stub/extensions/core/uri.rb +28 -0
  23. data/lib/http_stub/extensions/rack/handler.rb +1 -0
  24. data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
  25. data/lib/http_stub/rake/server_tasks.rb +1 -4
  26. data/lib/http_stub/server/application/application.rb +17 -98
  27. data/lib/http_stub/server/application/configuration.rb +38 -0
  28. data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
  29. data/lib/http_stub/server/application/request_support.rb +38 -0
  30. data/lib/http_stub/server/application/response_support.rb +19 -0
  31. data/lib/http_stub/server/application/routes/memory.rb +37 -0
  32. data/lib/http_stub/server/application/routes/resource.rb +23 -0
  33. data/lib/http_stub/server/application/routes/scenario.rb +52 -0
  34. data/lib/http_stub/server/application/routes/session.rb +65 -0
  35. data/lib/http_stub/server/application/routes/stub.rb +75 -0
  36. data/lib/http_stub/server/application/session_uri_support.rb +15 -0
  37. data/lib/http_stub/server/memory/controller.rb +25 -0
  38. data/lib/http_stub/server/memory/memory.rb +32 -0
  39. data/lib/http_stub/server/registry.rb +25 -8
  40. data/lib/http_stub/server/request/factory.rb +23 -0
  41. data/lib/http_stub/server/request/parameters.rb +2 -2
  42. data/lib/http_stub/server/request/request.rb +6 -11
  43. data/lib/http_stub/server/request/sinatra_request.rb +26 -0
  44. data/lib/http_stub/server/scenario/controller.rb +16 -11
  45. data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
  46. data/lib/http_stub/server/session.rb +14 -0
  47. data/lib/http_stub/server/session/configuration.rb +32 -0
  48. data/lib/http_stub/server/session/controller.rb +40 -0
  49. data/lib/http_stub/server/session/empty.rb +15 -0
  50. data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
  51. data/lib/http_stub/server/session/registry.rb +38 -0
  52. data/lib/http_stub/server/session/session.rb +80 -0
  53. data/lib/http_stub/server/stub/controller.rb +18 -12
  54. data/lib/http_stub/server/stub/empty.rb +1 -1
  55. data/lib/http_stub/server/stub/match/controller.rb +9 -5
  56. data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
  57. data/lib/http_stub/server/stub/registry.rb +6 -13
  58. data/lib/http_stub/server/stub/triggers.rb +11 -9
  59. data/lib/http_stub/server/views/_home.haml +2 -0
  60. data/lib/http_stub/server/views/_post_link_function.haml +26 -0
  61. data/lib/http_stub/server/views/_session.haml +16 -0
  62. data/lib/http_stub/server/views/_stub.haml +8 -2
  63. data/lib/http_stub/server/views/_stubs.haml +4 -0
  64. data/lib/http_stub/server/views/application.sass +4 -1
  65. data/lib/http_stub/server/views/layout.haml +1 -0
  66. data/lib/http_stub/server/views/scenario.haml +4 -3
  67. data/lib/http_stub/server/views/scenarios.haml +7 -6
  68. data/lib/http_stub/server/views/session.haml +3 -0
  69. data/lib/http_stub/server/views/sessions.haml +6 -0
  70. data/lib/http_stub/server/views/stubs.haml +1 -4
  71. data/lib/http_stub/server/views/transactional_session.haml +2 -0
  72. data/lib/http_stub/version.rb +1 -1
  73. data/spec/acceptance/configurer_initialization_spec.rb +40 -51
  74. data/spec/acceptance/configurer_part_spec.rb +5 -7
  75. data/spec/acceptance/cross_origin_support_spec.rb +7 -13
  76. data/spec/acceptance/endpoint_template_spec.rb +2 -4
  77. data/spec/acceptance/request_reference_spec.rb +1 -3
  78. data/spec/acceptance/scenario_spec.rb +7 -9
  79. data/spec/acceptance/server_defaults_spec.rb +2 -4
  80. data/spec/acceptance/server_memory_spec.rb +20 -0
  81. data/spec/acceptance/session_spec.rb +125 -0
  82. data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
  83. data/spec/acceptance/stub_control_values_spec.rb +19 -18
  84. data/spec/acceptance/stub_match_last_spec.rb +0 -4
  85. data/spec/acceptance/stub_match_list_spec.rb +0 -4
  86. data/spec/acceptance/stub_miss_list_spec.rb +0 -4
  87. data/spec/acceptance/stub_spec.rb +11 -11
  88. data/spec/acceptance/stub_trigger_spec.rb +60 -13
  89. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
  90. data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
  91. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
  92. data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
  93. data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
  94. data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
  95. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
  96. data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
  97. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
  98. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
  99. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
  100. data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
  101. data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
  102. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
  103. data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
  104. data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
  105. data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
  106. data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
  107. data/spec/lib/http_stub/configurer_spec.rb +105 -0
  108. data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
  109. data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
  110. data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
  111. data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
  112. data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
  113. data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
  114. data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
  115. data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
  116. data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
  117. data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
  118. data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
  119. data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
  120. data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
  121. data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
  122. data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
  123. data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
  124. data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
  125. data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
  126. data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
  127. data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
  128. data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
  129. data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
  130. data/spec/lib/http_stub/server/registry_spec.rb +153 -34
  131. data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
  132. data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
  133. data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
  134. data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
  135. data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
  136. data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
  137. data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
  138. data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
  139. data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
  140. data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
  141. data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
  142. data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
  143. data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
  144. data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
  145. data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
  146. data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
  147. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
  148. data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
  149. data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
  150. data/spec/spec_helper.rb +13 -1
  151. data/spec/support/contain_file.rb +23 -0
  152. data/spec/support/cross_origin_server/application.rb +1 -1
  153. data/spec/support/cross_origin_server/index_page.rb +2 -2
  154. data/spec/support/cross_origin_server/integration.rb +3 -2
  155. data/spec/support/cross_origin_server/public/index.html +2 -1
  156. data/spec/support/http_stub/configurer_integration.rb +12 -14
  157. data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
  158. data/spec/support/http_stub/server/driver.rb +56 -0
  159. data/spec/support/http_stub/server/memory_fixture.rb +17 -0
  160. data/spec/support/http_stub/server/request_fixture.rb +7 -6
  161. data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
  162. data/spec/support/http_stub/server/session_fixture.rb +27 -0
  163. data/spec/support/http_stub/server_integration.rb +12 -17
  164. data/spec/support/http_stub/stub_fixture.rb +19 -6
  165. data/spec/support/include_in_json.rb +4 -4
  166. data/spec/support/rack/rack_application_test.rb +9 -0
  167. data/spec/support/rack/request_fixture.rb +13 -0
  168. data/spec/support/surpressed_output.rb +10 -0
  169. metadata +149 -36
  170. data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
  171. data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
  172. data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
  173. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
  174. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
  175. data/lib/http_stub/server/request.rb +0 -12
  176. data/lib/http_stub/server/scenario/activator.rb +0 -25
  177. data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
  178. data/lib/http_stub/server/views/index.haml +0 -8
  179. data/spec/acceptance/activator_spec.rb +0 -81
  180. data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
  181. data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
  182. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
  183. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
  184. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
  185. data/spec/lib/http_stub/server/request_spec.rb +0 -24
  186. data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
  187. data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -1,255 +0,0 @@
1
- describe HttpStub::Configurer::DSL::EndpointTemplate do
2
-
3
- let(:server) { instance_double(HttpStub::Configurer::DSL::Server) }
4
- let(:response_defaults) { {} }
5
- let(:template_stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
6
-
7
- let(:endpoint_template) { HttpStub::Configurer::DSL::EndpointTemplate.new(server) }
8
-
9
- before(:example) do
10
- allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(template_stub_builder)
11
- end
12
-
13
- it "creates a stub builder to hold the templated default values" do
14
- expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(no_args)
15
-
16
- endpoint_template
17
- end
18
-
19
- describe "#match_requests" do
20
-
21
- let(:args) { { key: :value } }
22
-
23
- subject { endpoint_template.match_requests(args) }
24
-
25
- it "delegates to the templates stub builder" do
26
- expect(template_stub_builder).to receive(:match_requests).with(args)
27
-
28
- subject
29
- end
30
-
31
- end
32
-
33
- describe "#schema" do
34
-
35
- let(:type) { :some_type }
36
- let(:definition) { { key: :value } }
37
-
38
- subject { endpoint_template.schema(type, definition) }
39
-
40
- it "delegates to the templates stub builder" do
41
- expect(template_stub_builder).to receive(:schema).with(type, definition)
42
-
43
- subject
44
- end
45
-
46
- end
47
-
48
- describe "#respond_with" do
49
-
50
- let(:args) { { status: 204 } }
51
-
52
- subject { endpoint_template.respond_with(args) }
53
-
54
- it "delegates to the templates stub builder" do
55
- expect(template_stub_builder).to receive(:respond_with).with(args)
56
-
57
- subject
58
- end
59
-
60
- end
61
-
62
- describe "#trigger" do
63
-
64
- let(:trigger) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
65
-
66
- subject { endpoint_template.trigger(trigger) }
67
-
68
- it "delegates to the templates stub builder" do
69
- expect(template_stub_builder).to receive(:trigger).with(trigger)
70
-
71
- subject
72
- end
73
-
74
- end
75
-
76
- describe "#invoke" do
77
-
78
- let(:block_verifier) { double("BlockVerifier") }
79
- let(:block) { lambda { block_verifier.verify } }
80
-
81
- subject { endpoint_template.invoke(&block) }
82
-
83
- it "delegates to the templates stub builder" do
84
- expect(template_stub_builder).to receive(:invoke).and_yield
85
- expect(block_verifier).to receive(:verify)
86
-
87
- subject
88
- end
89
-
90
- end
91
-
92
- shared_examples_for "an endpoint template method composing a stub" do
93
-
94
- it "merges the added stub with the default stub builder" do
95
- expect(stub_builder).to receive(:merge!).with(template_stub_builder)
96
-
97
- subject_without_overrides_and_block
98
- end
99
-
100
- context "when response overrides are provided" do
101
-
102
- let(:response_overrides) { { status: 302 } }
103
-
104
- subject { subject_with_response_overrides(response_overrides) }
105
-
106
- it "informs the stub builder to respond with the response overrides" do
107
- expect(stub_builder).to receive(:respond_with).with(response_overrides)
108
-
109
- subject
110
- end
111
-
112
- end
113
-
114
- context "when response overrides are not provided" do
115
-
116
- subject { subject_without_overrides_and_block }
117
-
118
- it "does not change the stub builder by requesting it respond with an empty hash" do
119
- expect(stub_builder).to receive(:respond_with).with({})
120
-
121
- subject
122
- end
123
-
124
- end
125
-
126
- it "merges the response defaults before applying the response overrides" do
127
- expect(stub_builder).to receive(:merge!).ordered
128
- expect(stub_builder).to receive(:respond_with).ordered
129
-
130
- subject_without_overrides_and_block
131
- end
132
-
133
- context "when a block is provided" do
134
-
135
- let(:block_verifier) { double("BlockVerifier") }
136
- let(:block) { lambda { block_verifier.verify } }
137
-
138
- subject { subject_with_block(&block) }
139
-
140
- it "requests the added stub builder invoke the provided block" do
141
- expect(stub_builder).to receive(:invoke).and_yield
142
- expect(block_verifier).to receive(:verify)
143
-
144
- subject
145
- end
146
-
147
- it "applies the response overrides before invoking the provided block" do
148
- expect(stub_builder).to receive(:respond_with).ordered
149
- expect(stub_builder).to receive(:invoke).ordered
150
-
151
- subject
152
- end
153
-
154
- end
155
-
156
- context "when a block is not provided" do
157
-
158
- subject { subject_without_overrides_and_block }
159
-
160
- it "does not requests the added stub builder invoke a block" do
161
- expect(stub_builder).not_to receive(:invoke)
162
-
163
- subject
164
- end
165
-
166
- end
167
-
168
- end
169
-
170
- describe "#build_stub" do
171
-
172
- let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
173
-
174
- before(:example) { allow(server).to receive(:build_stub).and_yield(stub_builder) }
175
-
176
- def subject_without_overrides_and_block
177
- endpoint_template.build_stub
178
- end
179
-
180
- def subject_with_response_overrides(overrides)
181
- endpoint_template.build_stub(overrides)
182
- end
183
-
184
- def subject_with_block(&block)
185
- endpoint_template.build_stub(&block)
186
- end
187
-
188
- it "builds a stub on the server" do
189
- expect(server).to receive(:build_stub)
190
-
191
- subject_without_overrides_and_block
192
- end
193
-
194
- it_behaves_like "an endpoint template method composing a stub"
195
-
196
- end
197
-
198
- describe "#add_stub!" do
199
-
200
- let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
201
-
202
- before(:example) { allow(server).to receive(:add_stub!).and_yield(stub_builder) }
203
-
204
- def subject_without_overrides_and_block
205
- endpoint_template.add_stub!
206
- end
207
-
208
- def subject_with_response_overrides(overrides)
209
- endpoint_template.add_stub!(overrides)
210
- end
211
-
212
- def subject_with_block(&block)
213
- endpoint_template.add_stub!(&block)
214
- end
215
-
216
- it "builds a stub on the server" do
217
- expect(server).to receive(:add_stub!)
218
-
219
- subject_without_overrides_and_block
220
- end
221
-
222
- it_behaves_like "an endpoint template method composing a stub"
223
-
224
- end
225
-
226
- describe "#add_scenario!" do
227
-
228
- let(:name) { "Some scenario name" }
229
- let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
230
-
231
- before(:example) { allow(server).to receive(:add_scenario_with_one_stub!).and_yield(stub_builder) }
232
-
233
- def subject_without_overrides_and_block
234
- endpoint_template.add_scenario!(name)
235
- end
236
-
237
- def subject_with_response_overrides(overrides)
238
- endpoint_template.add_scenario!(name, overrides)
239
- end
240
-
241
- def subject_with_block(&block)
242
- endpoint_template.add_scenario!(name, &block)
243
- end
244
-
245
- it "adds a one stub scenario to the server" do
246
- expect(server).to receive(:add_scenario_with_one_stub!).with(name)
247
-
248
- subject_without_overrides_and_block
249
- end
250
-
251
- it_behaves_like "an endpoint template method composing a stub"
252
-
253
- end
254
-
255
- end
@@ -1,62 +0,0 @@
1
- describe HttpStub::Configurer::DSL::ScenarioActivator do
2
-
3
- class HttpStub::Configurer::DSL::TestableScenarioActivator
4
- include HttpStub::Configurer::DSL::ScenarioActivator
5
-
6
- def activate_all!(_names)
7
- # Intentionally blank
8
- end
9
-
10
- end
11
-
12
- let(:activator) { HttpStub::Configurer::DSL::TestableScenarioActivator.new }
13
-
14
- describe "#activate!" do
15
-
16
- subject { activator.activate!(name) }
17
-
18
- context "when a name is provided" do
19
-
20
- let(:name) { "some name" }
21
-
22
- it "delegates to activate all with the provided name" do
23
- expect(activator).to receive(:activate_all!).with([ name ])
24
-
25
- subject
26
- end
27
-
28
- end
29
-
30
- context "when multiple names are provided" do
31
-
32
- let(:names) { (1..3).map { |i| "name #{i}" } }
33
-
34
- context "as multiple arguments" do
35
-
36
- subject { activator.activate!(*names) }
37
-
38
- it "delegates to activate all the provided names" do
39
- expect(activator).to receive(:activate_all!).with(names)
40
-
41
- subject
42
- end
43
-
44
- end
45
-
46
- context "as an array" do
47
-
48
- subject { activator.activate!(names) }
49
-
50
- it "delegates to activate all the provided names" do
51
- expect(activator).to receive(:activate_all!).with(names)
52
-
53
- subject
54
- end
55
-
56
- end
57
-
58
- end
59
-
60
- end
61
-
62
- end
@@ -1,120 +0,0 @@
1
- describe HttpStub::Configurer::DSL::StubActivatorBuilder do
2
-
3
- let(:stub_fixture) { HttpStub::StubFixture.new }
4
-
5
- let(:response_defaults) { {} }
6
- let(:activation_uri) { "/some/activation/uri" }
7
- let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
8
- let(:scenario_builder) do
9
- instance_double(HttpStub::Configurer::DSL::ScenarioBuilder, build: scenario, add_stub!: nil)
10
- end
11
- let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
12
-
13
- let(:builder) { HttpStub::Configurer::DSL::StubActivatorBuilder.new(response_defaults) }
14
-
15
- before(:example) do
16
- allow(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).and_return(scenario_builder)
17
- allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder)
18
- end
19
-
20
- describe "#on" do
21
-
22
- subject { builder.on(activation_uri) }
23
-
24
- it "creates a scenario builder with the response defaults and activation uri" do
25
- expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(response_defaults, activation_uri)
26
-
27
- subject
28
- end
29
-
30
- it "creates a stub builder with the response defaults" do
31
- expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(response_defaults)
32
-
33
- subject
34
- end
35
-
36
- it "adds the stub builder to the scenario builder" do
37
- expect(scenario_builder).to receive(:add_stub!).with(stub_builder)
38
-
39
- subject
40
- end
41
-
42
- end
43
-
44
- describe "#match_requests" do
45
-
46
- let(:request_payload) { stub_fixture.request.configurer_payload }
47
-
48
- before(:example) { builder.on(activation_uri) }
49
-
50
- it "delegates to a stub builder" do
51
- expect(stub_builder).to receive(:match_requests).with(request_payload)
52
-
53
- builder.match_requests(request_payload)
54
- end
55
-
56
- end
57
-
58
- describe "#respond_with" do
59
-
60
- let(:response_payload) { stub_fixture.response.configurer_payload }
61
-
62
- before(:example) { builder.on(activation_uri) }
63
-
64
- it "delegates to a stub builder" do
65
- expect(stub_builder).to receive(:respond_with).with(response_payload)
66
-
67
- builder.respond_with(response_payload)
68
- end
69
-
70
- end
71
-
72
- describe "#trigger" do
73
-
74
- before(:example) { builder.on(activation_uri) }
75
-
76
- context "when one triggered stub is provided" do
77
-
78
- let(:trigger_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
79
-
80
- it "delegates to a stub builder" do
81
- expect(stub_builder).to receive(:trigger).with(trigger_builder)
82
-
83
- builder.trigger(trigger_builder)
84
- end
85
-
86
- end
87
-
88
- context "when many triggered stubs are provided" do
89
-
90
- let(:trigger_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
91
-
92
- it "delegates to a stub builder" do
93
- expect(stub_builder).to receive(:trigger).with(trigger_builders)
94
-
95
- builder.trigger(trigger_builders)
96
- end
97
-
98
- end
99
-
100
- end
101
-
102
- describe "#build" do
103
-
104
- subject { builder.build }
105
-
106
- before(:example) { builder.on(activation_uri) }
107
-
108
- it "builds a scenario" do
109
- expect(scenario_builder).to receive(:build)
110
-
111
- subject
112
- end
113
-
114
- it "returns the built scenario" do
115
- expect(subject).to eql(scenario)
116
- end
117
-
118
- end
119
-
120
- end
@@ -1,85 +0,0 @@
1
- describe HttpStub::Configurer::DSL::StubBuilderProducer do
2
-
3
- class HttpStub::Configurer::DSL::TestableStubBuilderProducer
4
- include HttpStub::Configurer::DSL::StubBuilderProducer
5
-
6
- def initialize(default_stub_builder)
7
- @default_stub_builder = default_stub_builder
8
- @builders = []
9
- end
10
-
11
- def add_stub!(builder)
12
- @builders << builder
13
- end
14
-
15
- end
16
-
17
- let(:default_stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
18
-
19
- let(:producer) { HttpStub::Configurer::DSL::TestableStubBuilderProducer.new(default_stub_builder) }
20
-
21
- describe "#build_stub" do
22
-
23
- let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
24
-
25
- before(:example) { allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder) }
26
-
27
- subject { producer.build_stub }
28
-
29
- it "creates a stub builder containing the producers default stub builder" do
30
- expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(default_stub_builder)
31
-
32
- subject
33
- end
34
-
35
- context "when a block is provided" do
36
-
37
- let(:block) { lambda { |_stub_builder| "some block" } }
38
-
39
- subject { producer.build_stub(&block) }
40
-
41
- before(:example) { allow(stub_builder).to receive(:invoke) }
42
-
43
- it "requests the stub builder invoke block" do
44
- expect(stub_builder).to receive(:invoke).and_yield(block)
45
-
46
- subject
47
- end
48
-
49
- it "returns the stub builder" do
50
- expect(subject).to eql(stub_builder)
51
- end
52
-
53
- end
54
-
55
- context "when a block is not provided" do
56
-
57
- subject { producer.build_stub }
58
-
59
- it "returns the stub builder" do
60
- expect(subject).to eql(stub_builder)
61
- end
62
-
63
- end
64
-
65
- end
66
-
67
- describe "#add_stubs!" do
68
-
69
- context "when multiple stub builders are provided" do
70
-
71
- let(:stub_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
72
-
73
- subject { producer.add_stubs!(stub_builders) }
74
-
75
- it "adds each stub to the producer" do
76
- stub_builders.each { |stub_builder| expect(producer).to receive(:add_stub!).with(stub_builder) }
77
-
78
- subject
79
- end
80
-
81
- end
82
-
83
- end
84
-
85
- end