http_stub 0.14.2 → 0.15.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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub/configurer/request/http/basic.rb +21 -0
  3. data/lib/http_stub/configurer/request/http/factory.rb +43 -0
  4. data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
  5. data/lib/http_stub/configurer/request/stub.rb +24 -8
  6. data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
  7. data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
  8. data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
  9. data/lib/http_stub/configurer/request/stub_response.rb +40 -0
  10. data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
  11. data/lib/http_stub/configurer/server/command.rb +5 -1
  12. data/lib/http_stub/configurer/server/command_processor.rb +1 -1
  13. data/lib/http_stub/configurer/server/dsl.rb +4 -4
  14. data/lib/http_stub/configurer/server/facade.rb +25 -11
  15. data/lib/http_stub/extensions/core/hash.rb +26 -0
  16. data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
  17. data/lib/http_stub/rake/server_tasks.rb +1 -1
  18. data/lib/http_stub/rake/task_generators.rb +3 -3
  19. data/lib/http_stub/server/application.rb +117 -0
  20. data/lib/http_stub/server/daemon.rb +39 -0
  21. data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
  22. data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
  23. data/lib/http_stub/{models → server}/headers.rb +1 -1
  24. data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
  25. data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
  26. data/lib/http_stub/{models → server}/registry.rb +10 -3
  27. data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
  28. data/lib/http_stub/server/response.rb +13 -0
  29. data/lib/http_stub/server/response_pipeline.rb +18 -0
  30. data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
  31. data/lib/http_stub/server/stub.rb +37 -0
  32. data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
  33. data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
  34. data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
  35. data/lib/http_stub/server/stub_factory.rb +30 -0
  36. data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
  37. data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
  38. data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
  39. data/lib/http_stub/server/stub_response/base.rb +62 -0
  40. data/lib/http_stub/server/stub_response/file.rb +48 -0
  41. data/lib/http_stub/server/stub_response/text.rb +17 -0
  42. data/lib/http_stub/server/stub_response.rb +14 -0
  43. data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
  44. data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
  45. data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
  46. data/lib/http_stub/{views → server/views}/application.sass +0 -0
  47. data/lib/http_stub/{views → server/views}/layout.haml +0 -0
  48. data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
  49. data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
  50. data/lib/http_stub/version.rb +1 -1
  51. data/lib/http_stub.rb +41 -24
  52. data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
  53. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
  54. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
  55. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
  56. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
  57. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
  58. data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
  59. data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
  60. data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
  61. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
  62. data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
  63. data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
  64. data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
  65. data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
  66. data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
  67. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
  68. data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
  69. data/spec/lib/http_stub/server/application_spec.rb +205 -0
  70. data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
  71. data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
  72. data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
  73. data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
  74. data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
  75. data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
  76. data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
  77. data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
  78. data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
  79. data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
  80. data/spec/lib/http_stub/server/response_spec.rb +41 -0
  81. data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
  82. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
  83. data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
  84. data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
  85. data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
  86. data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
  87. data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
  88. data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
  89. data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
  90. data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
  91. data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
  92. data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
  93. data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
  94. data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
  95. data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
  96. data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
  97. data/spec/resources/sample.pdf +0 -0
  98. data/spec/resources/sample.txt +1 -0
  99. data/spec/spec_helper.rb +13 -4
  100. data/spec/support/stub_fixture.rb +106 -0
  101. metadata +148 -102
  102. data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
  103. data/lib/http_stub/hash_extensions.rb +0 -22
  104. data/lib/http_stub/models/request_pipeline.rb +0 -13
  105. data/lib/http_stub/models/response.rb +0 -43
  106. data/lib/http_stub/models/stub.rb +0 -35
  107. data/lib/http_stub/server.rb +0 -114
  108. data/lib/http_stub/server_daemon.rb +0 -36
  109. data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
  110. data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
  111. data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
  112. data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
  113. data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
  114. data/spec/lib/http_stub/models/response_spec.rb +0 -206
  115. data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
  116. data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
  117. data/spec/lib/http_stub/server_spec.rb +0 -234
  118. data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
@@ -1,76 +0,0 @@
1
- describe HttpStub::Models::StubActivator do
2
-
3
- let(:activation_uri) { "/some/activation/uri" }
4
- let(:args) do
5
- { "activation_uri" => activation_uri }
6
- end
7
- let(:stub_activator) { HttpStub::Models::StubActivator.new(args) }
8
-
9
- before(:example) { allow(HttpStub::Models::Stub).to receive(:new).and_return(double(HttpStub::Models::Stub)) }
10
-
11
- describe "#satisfies?" do
12
-
13
- let(:request) { double("HttpRequest", path_info: request_path_info) }
14
-
15
- describe "when the request uri exactly matches the activator's activation uri" do
16
-
17
- let(:request_path_info) { activation_uri }
18
-
19
- it "returns true" do
20
- expect(stub_activator.satisfies?(request)).to be_truthy
21
- end
22
-
23
- end
24
-
25
- describe "when the activator's activation uri is a substring of the request uri" do
26
-
27
- let(:request_path_info) { "#{activation_uri}/with/additional/paths" }
28
-
29
- it "returns false" do
30
- expect(stub_activator.satisfies?(request)).to be_falsey
31
- end
32
-
33
- end
34
-
35
- describe "when the request uri is completely different to the activator's activation uri" do
36
-
37
- let(:request_path_info) { "/completely/different/path" }
38
-
39
- it "returns false" do
40
- expect(stub_activator.satisfies?(request)).to be_falsey
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- describe "#the_stub" do
48
-
49
- it "returns a HttpStub::Models::Stub constructed from the activator's arguments" do
50
- stub = double(HttpStub::Models::Stub)
51
- expect(HttpStub::Models::Stub).to receive(:new).with(args).and_return(stub)
52
-
53
- expect(stub_activator.the_stub).to eql(stub)
54
- end
55
-
56
- end
57
-
58
- describe "#activation_uri" do
59
-
60
- it "returns the value provided in the request body" do
61
- expect(stub_activator.activation_uri).to eql(activation_uri)
62
- end
63
-
64
- end
65
-
66
- describe "#to_s" do
67
-
68
- it "returns the string representation of the activation arguments" do
69
- expect(args).to receive(:to_s).and_return("activation args string")
70
-
71
- expect(stub_activator.to_s).to eql("activation args string")
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,7 +0,0 @@
1
- describe HttpStub::ServerDaemon do
2
-
3
- let(:server) { HttpStub::ServerDaemon.new(name: :example_server_daemon, port: 8002) }
4
-
5
- it_should_behave_like "a managed http server"
6
-
7
- end
@@ -1,234 +0,0 @@
1
- describe HttpStub::Server do
2
- include Rack::Test::Methods
3
-
4
- let(:response) { last_response }
5
- let(:response_body) { response.body.to_s }
6
-
7
- let(:stub_registry) { instance_double(HttpStub::Models::StubRegistry).as_null_object }
8
- let(:stub_activator_registry) { instance_double(HttpStub::Models::Registry).as_null_object }
9
-
10
- let(:stub_controller) { instance_double(HttpStub::Controllers::StubController).as_null_object }
11
- let(:stub_activator_controller) { instance_double(HttpStub::Controllers::StubActivatorController).as_null_object }
12
-
13
- let(:app) { HttpStub::Server.new! }
14
-
15
- before(:example) do
16
- allow(HttpStub::Models::StubRegistry).to receive(:new).and_return(stub_registry)
17
- allow(HttpStub::Models::Registry).to receive(:new).with("stub_activator").and_return(stub_activator_registry)
18
- allow(HttpStub::Controllers::StubController).to receive(:new).and_return(stub_controller)
19
- allow(HttpStub::Controllers::StubActivatorController).to receive(:new).and_return(stub_activator_controller)
20
- end
21
-
22
- context "when a stub insertion request is received" do
23
-
24
- subject do
25
- post "/stubs", {
26
- uri: "/a_path", method: "a method",
27
- response: { status: 200, body: "Foo" }
28
- }.to_json
29
- end
30
-
31
- it "registers the insertion via the stub controller" do
32
- expect(stub_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
33
-
34
- subject
35
- end
36
-
37
- it "responds with the response provided by the controller" do
38
- allow(stub_controller).to receive(:register).and_return(HttpStub::Models::Response.new("status" => 202, "body" => ""))
39
-
40
- subject
41
-
42
- expect(response.status).to eql(202)
43
- end
44
-
45
- end
46
-
47
- context "when a request to commit the stubs to memory is received" do
48
-
49
- subject { post "/stubs/memory" }
50
-
51
- it "remembers the stubs in the stub registry" do
52
- expect(stub_registry).to receive(:remember)
53
-
54
- subject
55
- end
56
-
57
- it "responds with a 200 status code" do
58
- subject
59
-
60
- expect(response.status).to eql(200)
61
- end
62
-
63
- end
64
-
65
- context "when a request to recall the stubs in memory is received" do
66
-
67
- subject { get "/stubs/memory" }
68
-
69
- it "recalls the stubs remembered by the stub registry" do
70
- expect(stub_registry).to receive(:recall)
71
-
72
- subject
73
- end
74
-
75
- it "responds with a 200 status code" do
76
- subject
77
-
78
- expect(response.status).to eql(200)
79
- end
80
-
81
- end
82
-
83
- context "when a request to clear the stubs has been received" do
84
-
85
- subject { delete "/stubs" }
86
-
87
- it "delegates clearing to the stub controller" do
88
- expect(stub_controller).to receive(:clear)
89
-
90
- subject
91
- end
92
-
93
- it "responds with a 200 status code" do
94
- subject
95
-
96
- expect(response.status).to eql(200)
97
- end
98
-
99
- end
100
-
101
- context "when a stub activator insertion request is received" do
102
-
103
- subject do
104
- post "/stubs/activators", {
105
- activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
106
- response: { status: 200, body: "Foo" }
107
- }.to_json
108
- end
109
-
110
- it "registers the insertion via the stub activator controller" do
111
- expect(stub_activator_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
112
-
113
- subject
114
- end
115
-
116
- it "responds with the response provided by the controller" do
117
- allow(stub_activator_controller).to(
118
- receive(:register).and_return(HttpStub::Models::Response.new("status" => 302, "body" => ""))
119
- )
120
-
121
- subject
122
-
123
- expect(response.status).to eql(302)
124
- end
125
-
126
- end
127
-
128
- context "when a request to clear the stub activators has been received" do
129
-
130
- subject { delete "/stubs/activators" }
131
-
132
- it "delegates clearing to the stub activator controller" do
133
- expect(stub_activator_controller).to receive(:clear)
134
-
135
- subject
136
- end
137
-
138
- it "responds with a 200 status code" do
139
- subject
140
-
141
- expect(response.status).to eql(200)
142
- end
143
-
144
- end
145
-
146
- context "when another type of request is received" do
147
-
148
- subject { get "/a_path" }
149
-
150
- context "and the stub controller replays a response" do
151
-
152
- let(:controller_response) do
153
- HttpStub::Models::Response.new(
154
- "status" => 222,
155
- "headers" => { "content-type" => "application/xhtml" },
156
- "body" => "Some body"
157
- )
158
- end
159
-
160
- before(:example) { allow(stub_controller).to receive(:replay).and_return(controller_response) }
161
-
162
- it "responds with the replay status code" do
163
- subject
164
-
165
- expect(response.status).to eql(222)
166
- end
167
-
168
- it "responds with the replay body" do
169
- subject
170
-
171
- expect(response_body).to eql("Some body")
172
- end
173
-
174
- it "responds with the replay content type" do
175
- subject
176
-
177
- expect(response.content_type).to eql("application/xhtml")
178
- end
179
-
180
- it "allows the request pipeline to process the response before the processing of the request halts" do
181
- expect(HttpStub::Models::RequestPipeline).to receive(:before_halt).with(controller_response)
182
-
183
- subject
184
- end
185
-
186
- end
187
-
188
- context "and the stub controller does not replay a response" do
189
-
190
- before(:example) do
191
- allow(stub_controller).to receive(:replay).and_return(HttpStub::Models::Response::EMPTY)
192
- end
193
-
194
- context "but the stub activator controller activates a stub" do
195
-
196
- before(:example) do
197
- allow(stub_activator_controller).to receive(:activate).and_return(
198
- HttpStub::Models::Response.new("status" => 300, "body" => "A body")
199
- )
200
- end
201
-
202
- it "responds with the activation response status code" do
203
- subject
204
-
205
- expect(response.status).to eql(300)
206
- end
207
-
208
- it "responds with the activation response body" do
209
- subject
210
-
211
- expect(response_body).to eql("A body")
212
- end
213
-
214
- end
215
-
216
- context "and the stub activator controller does not activate a stub" do
217
-
218
- before(:example) do
219
- allow(stub_activator_controller).to receive(:activate).and_return(HttpStub::Models::Response::EMPTY)
220
- end
221
-
222
- it "responds with a 404 status code" do
223
- subject
224
-
225
- expect(response.status).to eql(404)
226
- end
227
-
228
- end
229
-
230
- end
231
-
232
- end
233
-
234
- end
@@ -1,27 +0,0 @@
1
- shared_context "stub payload builder arguments" do
2
-
3
- let(:uri) { "/some/uri" }
4
- let(:stub_method) { "Some Method" }
5
- let(:request_headers) { { request_header_name: "value" } }
6
- let(:request_parameters) { { parameter_name: "value" } }
7
- let(:request_options) do
8
- {
9
- method: stub_method,
10
- headers: request_headers,
11
- parameters: request_parameters
12
- }
13
- end
14
- let(:response_status) { 500 }
15
- let(:response_headers) { { response_header_name: "value" } }
16
- let(:response_body) { "Some body" }
17
- let(:response_delay_in_seconds) { 7 }
18
- let(:response_options) do
19
- {
20
- status: response_status,
21
- headers: response_headers,
22
- body: response_body,
23
- delay_in_seconds: response_delay_in_seconds
24
- }
25
- end
26
-
27
- end