http_stub 0.25.1 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
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,10 +1,11 @@
1
1
  describe HttpStub::Configurer::Server::RequestProcessor do
2
2
 
3
- let(:configurer) { double(HttpStub::Configurer) }
4
- let(:command_processor) { instance_double(HttpStub::Configurer::Server::CommandProcessor) }
5
- let(:buffered_command_processor) { instance_double(HttpStub::Configurer::Server::BufferedCommandProcessor) }
3
+ let(:configuration) { double(HttpStub::Server::Application::Configuration) }
6
4
 
7
- let(:request_processor) { HttpStub::Configurer::Server::RequestProcessor.new(configurer) }
5
+ let(:command_processor) { instance_double(HttpStub::Configurer::Server::CommandProcessor) }
6
+ let(:buffered_command_processor) { instance_double(HttpStub::Configurer::Server::BufferedCommandProcessor) }
7
+
8
+ let(:request_processor) { described_class.new(configuration) }
8
9
 
9
10
  before(:example) do
10
11
  allow(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).and_return(command_processor)
@@ -15,8 +16,8 @@ describe HttpStub::Configurer::Server::RequestProcessor do
15
16
 
16
17
  describe "constructor" do
17
18
 
18
- it "creates a command processor for the configurer" do
19
- expect(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).with(configurer)
19
+ it "creates a command processor based on the servers configuration" do
20
+ expect(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).with(configuration)
20
21
 
21
22
  request_processor
22
23
  end
@@ -0,0 +1,336 @@
1
+ describe HttpStub::Configurer::Server::SessionFacade do
2
+
3
+ let(:session_id) { "some session id" }
4
+ let(:request_processor) { instance_double(HttpStub::Configurer::Server::RequestProcessor) }
5
+
6
+ let(:session_facade) { described_class.new(session_id, request_processor) }
7
+
8
+ describe "#mark_as_default" do
9
+
10
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
11
+
12
+ subject { session_facade.mark_as_default }
13
+
14
+ before(:example) do
15
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
16
+ allow(request_processor).to receive(:submit)
17
+ end
18
+
19
+ it "creates an POST request to mark the session as the default" do
20
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
21
+ receive(:post).with("sessions/default", anything).and_return(request)
22
+ )
23
+
24
+ subject
25
+ end
26
+
27
+ it "creates a POST request with the session id as a parameter" do
28
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
29
+ receive(:post).with(anything, http_stub_session_id: session_id).and_return(request)
30
+ )
31
+
32
+ subject
33
+ end
34
+
35
+ it "submits the request via the request processor" do
36
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
37
+
38
+ subject
39
+ end
40
+
41
+ it "describes the request as marking the session" do
42
+ expect(request_processor).to(
43
+ receive(:submit).with(hash_including(description: a_string_including("marking")))
44
+ )
45
+
46
+ subject
47
+ end
48
+
49
+ it "describes the request as scoped within the session" do
50
+ expect(request_processor).to(
51
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
52
+ )
53
+
54
+ subject
55
+ end
56
+
57
+ end
58
+
59
+ describe "#stub_response" do
60
+
61
+ let(:the_stub_description) { "some stub description" }
62
+ let(:the_stub) { instance_double(HttpStub::Configurer::Request::Stub, to_s: the_stub_description) }
63
+
64
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
65
+
66
+ subject { session_facade.stub_response(the_stub) }
67
+
68
+ before(:example) do
69
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
70
+ allow(request_processor).to receive(:submit)
71
+ end
72
+
73
+ it "creates a multipart request to add a stub" do
74
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
75
+ receive(:multipart).with("stubs", anything, anything)
76
+ )
77
+
78
+ subject
79
+ end
80
+
81
+ it "creates a multipart request with the provided stub" do
82
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(anything, the_stub, anything)
83
+
84
+ subject
85
+ end
86
+
87
+ it "creates a multipart request identifying the session" do
88
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
89
+ receive(:multipart).with(anything, anything, http_stub_session_id: session_id)
90
+ )
91
+
92
+ subject
93
+ end
94
+
95
+ it "submits the request via the request processor" do
96
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
97
+
98
+ subject
99
+ end
100
+
101
+ it "describes the stub via its string representation" do
102
+ expect(request_processor).to(
103
+ receive(:submit).with(hash_including(description: a_string_including("stubbing '#{the_stub_description}'")))
104
+ )
105
+
106
+ subject
107
+ end
108
+
109
+ it "describes the request as scoped within the session" do
110
+ expect(request_processor).to(
111
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
112
+ )
113
+
114
+ subject
115
+ end
116
+
117
+ end
118
+
119
+ describe "#activate" do
120
+
121
+ let(:scenario_names) { (1..3).map { |i| "scenario name #{i}" } }
122
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
123
+
124
+ subject { session_facade.activate(scenario_names) }
125
+
126
+ before(:example) do
127
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
128
+ allow(request_processor).to receive(:submit)
129
+ end
130
+
131
+ it "creates an POST request to activate the scenarios" do
132
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
133
+ receive(:post).with("scenarios/activate", anything).and_return(request)
134
+ )
135
+
136
+ subject
137
+ end
138
+
139
+ it "creates a POST request with the session id as a parameter" do
140
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
141
+ receive(:post).with(anything, hash_including(http_stub_session_id: session_id)).and_return(request)
142
+ )
143
+
144
+ subject
145
+ end
146
+
147
+ it "creates a POST request with the scenario names as an array parameter" do
148
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
149
+ receive(:post).with(anything, hash_including("names[]" => scenario_names)).and_return(request)
150
+ )
151
+
152
+ subject
153
+ end
154
+
155
+ it "submits the request via the request processor" do
156
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
157
+
158
+ subject
159
+ end
160
+
161
+
162
+
163
+ it "describes the activation request including the scenario names" do
164
+ quoted_scenario_names = scenario_names.map { |name| "'#{name}'" }
165
+ description_expectation = Regexp.new("activating #{quoted_scenario_names.join(", ")}")
166
+ expect(request_processor).to(
167
+ receive(:submit).with(hash_including(description: a_string_matching(description_expectation)))
168
+ )
169
+
170
+ subject
171
+ end
172
+
173
+ it "describes the request as scoped within the session" do
174
+ expect(request_processor).to(
175
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
176
+ )
177
+
178
+ subject
179
+ end
180
+
181
+ end
182
+
183
+ describe "#reset_stubs" do
184
+
185
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
186
+
187
+ subject { session_facade.reset_stubs }
188
+
189
+ before(:example) do
190
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
191
+ allow(request_processor).to receive(:submit)
192
+ end
193
+
194
+ it "creates a POST request to reset the stubs" do
195
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
196
+ receive(:post).with("stubs/reset", anything).and_return(request)
197
+ )
198
+
199
+ subject
200
+ end
201
+
202
+ it "creates a POST request with the session id as a parameter" do
203
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
204
+ receive(:post).with(anything, http_stub_session_id: session_id).and_return(request)
205
+ )
206
+
207
+ subject
208
+ end
209
+
210
+ it "submits the request via the request processor" do
211
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
212
+
213
+ subject
214
+ end
215
+
216
+ it "describes the request as resetting the stubs in memory" do
217
+ expect(request_processor).to(
218
+ receive(:submit).with(hash_including(description: a_string_including("resetting stubs")))
219
+ )
220
+
221
+ subject
222
+ end
223
+
224
+ it "describes the request as scoped within the session" do
225
+ expect(request_processor).to(
226
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
227
+ )
228
+
229
+ subject
230
+ end
231
+
232
+ end
233
+
234
+ describe "#clear_stubs" do
235
+
236
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
237
+
238
+ subject { session_facade.clear_stubs }
239
+
240
+ before(:example) do
241
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
242
+ allow(request_processor).to receive(:submit)
243
+ end
244
+
245
+ it "creates a DELETE request that deletes a stub" do
246
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
247
+ receive(:delete).with("stubs", anything).and_return(request)
248
+ )
249
+
250
+ subject
251
+ end
252
+
253
+ it "creates a DELETE request with the session id as a parameter" do
254
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
255
+ receive(:delete).with(anything, http_stub_session_id: session_id).and_return(request)
256
+ )
257
+
258
+ subject
259
+ end
260
+
261
+ it "submits the request via the request processor" do
262
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
263
+
264
+ subject
265
+ end
266
+
267
+ it "describes the request as clearing the server stubs" do
268
+ expect(request_processor).to(
269
+ receive(:submit).with(hash_including(description: a_string_including("clearing stubs")))
270
+ )
271
+
272
+ subject
273
+ end
274
+
275
+ it "describes the request as scoped within the session" do
276
+ expect(request_processor).to(
277
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
278
+ )
279
+
280
+ subject
281
+ end
282
+
283
+ end
284
+
285
+ describe "#delete" do
286
+
287
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
288
+
289
+ subject { session_facade.delete }
290
+
291
+ before(:example) do
292
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
293
+ allow(request_processor).to receive(:submit)
294
+ end
295
+
296
+ it "creates a DELETE request intended to delete a session" do
297
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
298
+ receive(:delete).with("sessions", anything).and_return(request)
299
+ )
300
+
301
+ subject
302
+ end
303
+
304
+ it "creates a DELETE request with the session id as a parameter" do
305
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
306
+ receive(:delete).with(anything, http_stub_session_id: session_id).and_return(request)
307
+ )
308
+
309
+ subject
310
+ end
311
+
312
+ it "submits the request via the request processor" do
313
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
314
+
315
+ subject
316
+ end
317
+
318
+ it "describes the request as clearing the server stubs" do
319
+ expect(request_processor).to(
320
+ receive(:submit).with(hash_including(description: a_string_including("deleting session '#{session_id}'")))
321
+ )
322
+
323
+ subject
324
+ end
325
+
326
+ it "describes the request as scoped within the session" do
327
+ expect(request_processor).to(
328
+ receive(:submit).with(hash_including(description: a_string_including("session '#{session_id}'")))
329
+ )
330
+
331
+ subject
332
+ end
333
+
334
+ end
335
+
336
+ end
@@ -0,0 +1,105 @@
1
+ describe HttpStub::Configurer do
2
+
3
+ class HttpStub::Configurer::TestableConfigurer
4
+ include HttpStub::Configurer
5
+ end
6
+
7
+ let(:configurer_class) { HttpStub::Configurer::TestableConfigurer }
8
+ let(:configurer) { configurer_class.new }
9
+
10
+ describe "::stub_server" do
11
+
12
+ subject { configurer_class.stub_server }
13
+
14
+ it "creates a server DSL" do
15
+ expect(HttpStub::Configurer::DSL::Server).to receive(:new)
16
+
17
+ subject
18
+ end
19
+
20
+ it "returns the created server DSL" do
21
+ server = instance_double(HttpStub::Configurer::DSL::Server)
22
+ allow(HttpStub::Configurer::DSL::Server).to receive(:new).and_return(server)
23
+
24
+ expect(subject).to eql(server)
25
+ end
26
+
27
+ it "reuses the stub server in subsequent requests" do
28
+ server = configurer_class.stub_server
29
+
30
+ expect(subject).to be(server)
31
+ end
32
+
33
+ end
34
+
35
+ describe "::initialize!" do
36
+
37
+ subject { configurer_class.initialize! }
38
+
39
+ before(:example) { allow(configurer_class.stub_server).to receive(:initialize!) }
40
+
41
+ context "when included in a class with an on_initialize class method" do
42
+
43
+ let(:configurer_class) do
44
+ Class.new do
45
+ include HttpStub::Configurer
46
+
47
+ def self.on_initialize
48
+ # Intentionally blank
49
+ end
50
+ end
51
+ end
52
+
53
+ context "and the class has not been initialized previously" do
54
+
55
+ it "invokes the on_initialize method" do
56
+ expect(configurer_class).to receive(:on_initialize)
57
+
58
+ subject
59
+ end
60
+
61
+ end
62
+
63
+ context "and the class has been initialized previously" do
64
+
65
+ before(:example) { configurer_class.initialize! }
66
+
67
+ it "does not re-invoke the on_initialize method" do
68
+ expect(configurer_class).to_not receive(:on_initialize)
69
+
70
+ subject
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ context "when included in a class without an on_initialize method" do
78
+
79
+ let(:configurer_class) { Class.new { include HttpStub::Configurer } }
80
+
81
+ it "executes without error" do
82
+ expect { subject }.to_not raise_error
83
+ end
84
+
85
+ end
86
+
87
+ it "initializes the stub server" do
88
+ expect(configurer_class.stub_server).to receive(:initialize!)
89
+
90
+ subject
91
+ end
92
+
93
+ end
94
+
95
+ describe "#stub_server" do
96
+
97
+ subject { configurer.stub_server }
98
+
99
+ it "returns the same server as the class method" do
100
+ expect(subject).to be(configurer_class.stub_server)
101
+ end
102
+
103
+ end
104
+
105
+ end