http_stub 0.14.2 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_stub/configurer/request/http/basic.rb +21 -0
- data/lib/http_stub/configurer/request/http/factory.rb +43 -0
- data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
- data/lib/http_stub/configurer/request/stub.rb +24 -8
- data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
- data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
- data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
- data/lib/http_stub/configurer/request/stub_response.rb +40 -0
- data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
- data/lib/http_stub/configurer/server/command.rb +5 -1
- data/lib/http_stub/configurer/server/command_processor.rb +1 -1
- data/lib/http_stub/configurer/server/dsl.rb +4 -4
- data/lib/http_stub/configurer/server/facade.rb +25 -11
- data/lib/http_stub/extensions/core/hash.rb +26 -0
- data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
- data/lib/http_stub/rake/server_tasks.rb +1 -1
- data/lib/http_stub/rake/task_generators.rb +3 -3
- data/lib/http_stub/server/application.rb +117 -0
- data/lib/http_stub/server/daemon.rb +39 -0
- data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
- data/lib/http_stub/{models → server}/headers.rb +1 -1
- data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/registry.rb +10 -3
- data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
- data/lib/http_stub/server/response.rb +13 -0
- data/lib/http_stub/server/response_pipeline.rb +18 -0
- data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
- data/lib/http_stub/server/stub.rb +37 -0
- data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
- data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
- data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
- data/lib/http_stub/server/stub_factory.rb +30 -0
- data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
- data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
- data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
- data/lib/http_stub/server/stub_response/base.rb +62 -0
- data/lib/http_stub/server/stub_response/file.rb +48 -0
- data/lib/http_stub/server/stub_response/text.rb +17 -0
- data/lib/http_stub/server/stub_response.rb +14 -0
- data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
- data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
- data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
- data/lib/http_stub/{views → server/views}/application.sass +0 -0
- data/lib/http_stub/{views → server/views}/layout.haml +0 -0
- data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
- data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub.rb +41 -24
- data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
- data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
- data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
- data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
- data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
- data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
- data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
- data/spec/lib/http_stub/server/application_spec.rb +205 -0
- data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
- data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
- data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
- data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
- data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
- data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
- data/spec/lib/http_stub/server/response_spec.rb +41 -0
- data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
- data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
- data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
- data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
- data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
- data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
- data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
- data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
- data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
- data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
- data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
- data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
- data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
- data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
- data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
- data/spec/resources/sample.pdf +0 -0
- data/spec/resources/sample.txt +1 -0
- data/spec/spec_helper.rb +13 -4
- data/spec/support/stub_fixture.rb +106 -0
- metadata +148 -102
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
- data/lib/http_stub/hash_extensions.rb +0 -22
- data/lib/http_stub/models/request_pipeline.rb +0 -13
- data/lib/http_stub/models/response.rb +0 -43
- data/lib/http_stub/models/stub.rb +0 -35
- data/lib/http_stub/server.rb +0 -114
- data/lib/http_stub/server_daemon.rb +0 -36
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
- data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
- data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
- data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
- data/spec/lib/http_stub/models/response_spec.rb +0 -206
- data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
- data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
- data/spec/lib/http_stub/server_spec.rb +0 -234
- data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
@@ -0,0 +1,205 @@
|
|
1
|
+
describe HttpStub::Server::Application 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::Server::StubRegistry).as_null_object }
|
8
|
+
let(:stub_activator_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
9
|
+
|
10
|
+
let(:stub_controller) { instance_double(HttpStub::Server::StubController).as_null_object }
|
11
|
+
let(:stub_activator_controller) { instance_double(HttpStub::Server::StubActivatorController).as_null_object }
|
12
|
+
|
13
|
+
let(:response_pipeline) { instance_double(HttpStub::Server::ResponsePipeline, process: nil) }
|
14
|
+
|
15
|
+
let(:app) { HttpStub::Server::Application.new! }
|
16
|
+
|
17
|
+
before(:example) do
|
18
|
+
allow(HttpStub::Server::StubRegistry).to receive(:new).and_return(stub_registry)
|
19
|
+
allow(HttpStub::Server::Registry).to receive(:new).with("stub_activator").and_return(stub_activator_registry)
|
20
|
+
allow(HttpStub::Server::StubController).to receive(:new).and_return(stub_controller)
|
21
|
+
allow(HttpStub::Server::StubActivatorController).to receive(:new).and_return(stub_activator_controller)
|
22
|
+
allow(HttpStub::Server::ResponsePipeline).to receive(:new).and_return(response_pipeline)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when a stub insertion request is received" do
|
26
|
+
|
27
|
+
let(:stub_controller_response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
28
|
+
|
29
|
+
subject do
|
30
|
+
post "/stubs", { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } }.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
before(:example) { allow(stub_controller).to receive(:register).and_return(stub_controller_response) }
|
34
|
+
|
35
|
+
it "registers the inserted stub via the controller" do
|
36
|
+
expect(stub_controller).to receive(:register).and_return(stub_controller_response)
|
37
|
+
|
38
|
+
subject
|
39
|
+
end
|
40
|
+
|
41
|
+
it "processes the stub controllers response via the response pipeline" do
|
42
|
+
expect(response_pipeline).to receive(:process).with(stub_controller_response)
|
43
|
+
|
44
|
+
subject
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when a request to commit the stubs to memory is received" do
|
50
|
+
|
51
|
+
subject { post "/stubs/memory" }
|
52
|
+
|
53
|
+
it "remembers the stubs in the stub registry" do
|
54
|
+
expect(stub_registry).to receive(:remember)
|
55
|
+
|
56
|
+
subject
|
57
|
+
end
|
58
|
+
|
59
|
+
it "responds with a 200 status code" do
|
60
|
+
subject
|
61
|
+
|
62
|
+
expect(response.status).to eql(200)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when a request to recall the stubs in memory is received" do
|
68
|
+
|
69
|
+
subject { get "/stubs/memory" }
|
70
|
+
|
71
|
+
it "recalls the stubs remembered by the stub registry" do
|
72
|
+
expect(stub_registry).to receive(:recall)
|
73
|
+
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
|
77
|
+
it "responds with a 200 status code" do
|
78
|
+
subject
|
79
|
+
|
80
|
+
expect(response.status).to eql(200)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when a request to clear the stubs has been received" do
|
86
|
+
|
87
|
+
subject { delete "/stubs" }
|
88
|
+
|
89
|
+
it "delegates clearing to the stub controller" do
|
90
|
+
expect(stub_controller).to receive(:clear)
|
91
|
+
|
92
|
+
subject
|
93
|
+
end
|
94
|
+
|
95
|
+
it "responds with a 200 status code" do
|
96
|
+
subject
|
97
|
+
|
98
|
+
expect(response.status).to eql(200)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when a stub activator insertion request is received" do
|
104
|
+
|
105
|
+
let(:stub_activator_response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
106
|
+
|
107
|
+
before(:example) { allow(stub_activator_controller).to receive(:register).and_return(stub_activator_response) }
|
108
|
+
|
109
|
+
subject do
|
110
|
+
post "/stubs/activators", {
|
111
|
+
activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
|
112
|
+
response: { status: 200, body: "Foo" }
|
113
|
+
}.to_json
|
114
|
+
end
|
115
|
+
|
116
|
+
it "registers the insertion via the stub activator controller" do
|
117
|
+
expect(stub_activator_controller).to receive(:register).and_return(stub_activator_response)
|
118
|
+
|
119
|
+
subject
|
120
|
+
end
|
121
|
+
|
122
|
+
it "processes the stub activators response via the response pipeline" do
|
123
|
+
expect(response_pipeline).to receive(:process).with(stub_activator_response)
|
124
|
+
|
125
|
+
subject
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when a request to clear the stub activators has been received" do
|
131
|
+
|
132
|
+
subject { delete "/stubs/activators" }
|
133
|
+
|
134
|
+
it "delegates clearing to the stub activator controller" do
|
135
|
+
expect(stub_activator_controller).to receive(:clear)
|
136
|
+
|
137
|
+
subject
|
138
|
+
end
|
139
|
+
|
140
|
+
it "responds with a 200 status code" do
|
141
|
+
subject
|
142
|
+
|
143
|
+
expect(response.status).to eql(200)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when another type of request is received" do
|
149
|
+
|
150
|
+
let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
151
|
+
|
152
|
+
subject { get "/a_path" }
|
153
|
+
|
154
|
+
before(:example) { allow(stub_controller).to receive(:replay).and_return(stub_response) }
|
155
|
+
|
156
|
+
context "and the stub controller replays a response" do
|
157
|
+
|
158
|
+
before(:example) { allow(stub_response).to receive(:empty?).and_return(false) }
|
159
|
+
|
160
|
+
it "processes the response via the response pipeline" do
|
161
|
+
expect(response_pipeline).to receive(:process).with(stub_response)
|
162
|
+
|
163
|
+
subject
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
context "and the stub controller does not replay a response" do
|
169
|
+
|
170
|
+
let(:stub_activator_response) { double(HttpStub::Server::StubResponse::Base, serve_on: nil) }
|
171
|
+
|
172
|
+
before(:example) do
|
173
|
+
allow(stub_response).to receive(:empty?).and_return(true)
|
174
|
+
allow(stub_activator_controller).to receive(:activate).and_return(stub_activator_response)
|
175
|
+
end
|
176
|
+
|
177
|
+
context "but the stub activator controller activates a stub" do
|
178
|
+
|
179
|
+
before(:each) { allow(stub_activator_response).to receive(:empty?).and_return(false) }
|
180
|
+
|
181
|
+
it "processes the stub activator response via the response pipeline" do
|
182
|
+
expect(response_pipeline).to receive(:process).with(stub_activator_response)
|
183
|
+
|
184
|
+
subject
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
context "and the stub activator controller does not activate a stub" do
|
190
|
+
|
191
|
+
before(:each) { allow(stub_activator_response).to receive(:empty?).and_return(true) }
|
192
|
+
|
193
|
+
it "processes an error response via the response pipeline" do
|
194
|
+
expect(response_pipeline).to receive(:process).with(HttpStub::Server::Response::ERROR)
|
195
|
+
|
196
|
+
subject
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::Daemon do
|
2
2
|
|
3
3
|
let(:configurer) { nil }
|
4
4
|
|
5
|
-
let(:server_daemon) { HttpStub::
|
5
|
+
let(:server_daemon) { HttpStub::Server::Daemon.new(name: :sample_server_daemon, port: 8888, configurer: configurer) }
|
6
6
|
|
7
7
|
before(:example) { allow(server_daemon.logger).to receive(:info) }
|
8
8
|
|
@@ -13,7 +13,7 @@ describe HttpStub::ServerDaemon do
|
|
13
13
|
after(:example) { HttpServerManager.log_dir = @original_log_dir }
|
14
14
|
|
15
15
|
it "establishes the HttpServerManager log_dir" do
|
16
|
-
HttpStub::
|
16
|
+
HttpStub::Server::Daemon.log_dir = "/some/log/dir"
|
17
17
|
|
18
18
|
expect(HttpServerManager.log_dir).to eql("/some/log/dir")
|
19
19
|
end
|
@@ -27,7 +27,7 @@ describe HttpStub::ServerDaemon do
|
|
27
27
|
after(:example) { HttpServerManager.pid_dir = @original_pid_dir }
|
28
28
|
|
29
29
|
it "establishes the HttpServerManager pid_dir" do
|
30
|
-
HttpStub::
|
30
|
+
HttpStub::Server::Daemon.pid_dir = "/some/pid/dir"
|
31
31
|
|
32
32
|
expect(HttpServerManager.pid_dir).to eql("/some/pid/dir")
|
33
33
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::ExactValueMatcher do
|
2
2
|
|
3
3
|
describe ".match?" do
|
4
4
|
|
@@ -25,7 +25,7 @@ describe HttpStub::Models::ExactValueMatcher do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def perform_match
|
28
|
-
HttpStub::
|
28
|
+
HttpStub::Server::ExactValueMatcher.match?(stub_value, actual_value)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::HashWithStringValueMatchers do
|
2
2
|
|
3
3
|
let(:stubbed_hash) do
|
4
4
|
(1..3).reduce({}) do |result, i|
|
@@ -8,13 +8,13 @@ describe HttpStub::Models::HashWithStringValueMatchers do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:value_matchers) do
|
11
|
-
stubbed_hash.values.map { |value| double(HttpStub::
|
11
|
+
stubbed_hash.values.map { |value| double(HttpStub::Server::StringValueMatcher, to_s: value).as_null_object }
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:value_matcher_hash) { HttpStub::
|
14
|
+
let(:value_matcher_hash) { HttpStub::Server::HashWithStringValueMatchers.new(stubbed_hash) }
|
15
15
|
|
16
16
|
before(:example) do
|
17
|
-
value_matchers.each { |value| allow(HttpStub::
|
17
|
+
value_matchers.each { |value| allow(HttpStub::Server::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value) }
|
18
18
|
end
|
19
19
|
|
20
20
|
it "is a hash" do
|
@@ -25,7 +25,7 @@ describe HttpStub::Models::HashWithStringValueMatchers do
|
|
25
25
|
|
26
26
|
it "creates a value matcher representation of each value in the hash" do
|
27
27
|
value_matchers.each do |value|
|
28
|
-
expect(HttpStub::
|
28
|
+
expect(HttpStub::Server::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
|
29
29
|
end
|
30
30
|
|
31
31
|
expect(value_matcher_hash.values).to eql(value_matchers)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::Headers do
|
2
2
|
|
3
3
|
let(:header_hash) { {} }
|
4
4
|
|
5
|
-
let(:headers) { HttpStub::
|
5
|
+
let(:headers) { HttpStub::Server::Headers.new(header_hash) }
|
6
6
|
|
7
7
|
it "is a Hash" do
|
8
8
|
expect(headers).to be_a(Hash)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::OmittedValueMatcher do
|
2
2
|
|
3
3
|
describe ".match?" do
|
4
4
|
|
@@ -50,7 +50,7 @@ describe HttpStub::Models::OmittedValueMatcher do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def perform_match
|
53
|
-
HttpStub::
|
53
|
+
HttpStub::Server::OmittedValueMatcher.match?(stub_value, actual_value)
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::RegexpValueMatcher do
|
2
2
|
|
3
3
|
describe ".match?" do
|
4
4
|
|
@@ -40,7 +40,7 @@ describe HttpStub::Models::RegexpValueMatcher do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def perform_match
|
43
|
-
HttpStub::
|
43
|
+
HttpStub::Server::RegexpValueMatcher.match?(stub_value, actual_value)
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::Registry do
|
2
2
|
|
3
3
|
let(:logger) { double("Logger").as_null_object }
|
4
4
|
let(:request) { double("HttpRequest", logger: logger, inspect: "Request inspect result") }
|
5
5
|
|
6
|
-
let(:registry) { HttpStub::
|
6
|
+
let(:registry) { HttpStub::Server::Registry.new("a_model") }
|
7
|
+
|
8
|
+
shared_context "register multiple models" do
|
9
|
+
|
10
|
+
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", :satisfies? => false, :clear => nil) } }
|
11
|
+
|
12
|
+
before(:example) { models.each { |model| registry.add(model, request) } }
|
13
|
+
|
14
|
+
end
|
7
15
|
|
8
16
|
describe "#add" do
|
9
17
|
|
10
18
|
it "logs that the model has been registered" do
|
11
|
-
model = double("HttpStub::
|
19
|
+
model = double("HttpStub::Server::Model", to_s: "Model as String")
|
12
20
|
expect(logger).to receive(:info).with(/Model as String/)
|
13
21
|
|
14
22
|
registry.add(model, request)
|
@@ -20,13 +28,7 @@ describe HttpStub::Models::Registry do
|
|
20
28
|
|
21
29
|
describe "when multiple models have been registered" do
|
22
30
|
|
23
|
-
|
24
|
-
(1..3).map { |i| double("HttpStub::Models::Model#{i}", :satisfies? => false) }
|
25
|
-
end
|
26
|
-
|
27
|
-
before(:example) do
|
28
|
-
models.each { |model| registry.add(model, request) }
|
29
|
-
end
|
31
|
+
include_context "register multiple models"
|
30
32
|
|
31
33
|
describe "and one registered model satisfies the request" do
|
32
34
|
|
@@ -52,9 +54,7 @@ describe HttpStub::Models::Registry do
|
|
52
54
|
|
53
55
|
describe "and multiple registered models satisfy the request" do
|
54
56
|
|
55
|
-
before(:example)
|
56
|
-
[0, 2].each { |i| allow(models[i]).to receive(:satisfies?).and_return(true) }
|
57
|
-
end
|
57
|
+
before(:example) { [0, 2].each { |i| allow(models[i]).to receive(:satisfies?).and_return(true) } }
|
58
58
|
|
59
59
|
it "supports model overrides by returning the last model registered" do
|
60
60
|
expect(registry.find_for(request)).to eql(models[2])
|
@@ -88,83 +88,80 @@ describe HttpStub::Models::Registry do
|
|
88
88
|
|
89
89
|
end
|
90
90
|
|
91
|
-
describe "#
|
92
|
-
|
93
|
-
describe "when multiple models have been registered" do
|
91
|
+
describe "#last" do
|
94
92
|
|
95
|
-
|
96
|
-
(1..3).map { |i| double("HttpStub::Models::Model#{i}", :satisfies? => false) }
|
97
|
-
end
|
93
|
+
context "when multiple models have been registered" do
|
98
94
|
|
99
|
-
|
100
|
-
models.each { |model| registry.add(model, request) }
|
101
|
-
end
|
95
|
+
include_context "register multiple models"
|
102
96
|
|
103
|
-
it "returns the
|
104
|
-
expect(registry.
|
97
|
+
it "returns the last added model" do
|
98
|
+
expect(registry.last).to eql(models.last)
|
105
99
|
end
|
106
100
|
|
107
101
|
end
|
108
102
|
|
109
|
-
|
103
|
+
context "when a model has been registered" do
|
110
104
|
|
111
|
-
|
112
|
-
|
105
|
+
let(:model) { double("HttpStub::Server::Model") }
|
106
|
+
|
107
|
+
before(:example) { registry.add(model, request) }
|
108
|
+
|
109
|
+
it "returns the model" do
|
110
|
+
expect(registry.last).to eql(model)
|
113
111
|
end
|
114
112
|
|
115
113
|
end
|
116
114
|
|
117
115
|
end
|
118
116
|
|
119
|
-
describe "#
|
120
|
-
|
121
|
-
class HttpStub::Models::CopyableModel
|
117
|
+
describe "#all" do
|
122
118
|
|
123
|
-
|
119
|
+
context "when multiple models have been registered" do
|
124
120
|
|
125
|
-
|
126
|
-
@name = name
|
127
|
-
end
|
121
|
+
include_context "register multiple models"
|
128
122
|
|
129
|
-
|
130
|
-
|
123
|
+
it "returns the registered models in the order they were added" do
|
124
|
+
expect(registry.all).to eql(models.reverse)
|
131
125
|
end
|
132
126
|
|
133
127
|
end
|
134
128
|
|
135
|
-
|
129
|
+
context "when no model has been registered" do
|
136
130
|
|
137
|
-
|
131
|
+
it "returns an empty list" do
|
132
|
+
expect(registry.all).to eql([])
|
133
|
+
end
|
138
134
|
|
139
|
-
|
135
|
+
end
|
140
136
|
|
141
|
-
|
137
|
+
end
|
142
138
|
|
143
|
-
|
144
|
-
result = subject
|
139
|
+
describe "#clear" do
|
145
140
|
|
146
|
-
|
147
|
-
|
141
|
+
subject { registry.clear(request) }
|
142
|
+
|
143
|
+
it "logs that the models are being cleared" do
|
144
|
+
expect(logger).to receive(:info).with(/clearing a_model/i)
|
148
145
|
|
146
|
+
subject
|
149
147
|
end
|
150
148
|
|
151
|
-
|
152
|
-
model_to_add = HttpStub::Models::CopyableModel.new("model_to_add")
|
149
|
+
context "when models have been added" do
|
153
150
|
|
154
|
-
|
151
|
+
include_context "register multiple models"
|
155
152
|
|
156
|
-
|
157
|
-
|
158
|
-
end
|
153
|
+
it "clears each model" do
|
154
|
+
models.each { |model| expect(model).to receive(:clear) }
|
159
155
|
|
160
|
-
|
156
|
+
subject
|
157
|
+
end
|
161
158
|
|
162
|
-
|
159
|
+
it "releases all knowledge of the models" do
|
160
|
+
subject
|
163
161
|
|
164
|
-
|
165
|
-
|
162
|
+
expect(registry.all).to be_empty
|
163
|
+
end
|
166
164
|
|
167
|
-
registry.clear(request)
|
168
165
|
end
|
169
166
|
|
170
167
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Server::RequestHeaderParser do
|
2
2
|
|
3
3
|
let(:non_header_env_elements) do
|
4
4
|
{
|
@@ -17,7 +17,7 @@ describe HttpStub::Models::RequestHeaderParser do
|
|
17
17
|
let(:header_env_elements) { { "KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3" } }
|
18
18
|
|
19
19
|
it "returns a hash containing those entries" do
|
20
|
-
expect(HttpStub::
|
20
|
+
expect(HttpStub::Server::RequestHeaderParser.parse(request)).to eql("KEY_1" => "value1",
|
21
21
|
"KEY_2" => "value2",
|
22
22
|
"KEY_3" => "value3")
|
23
23
|
end
|
@@ -29,7 +29,7 @@ describe HttpStub::Models::RequestHeaderParser do
|
|
29
29
|
let(:header_env_elements) { { "HTTP_KEY_1" => "value1", "HTTP_KEY_2" => "value2", "HTTP_KEY_3" => "value3" } }
|
30
30
|
|
31
31
|
it "returns a hash containing those entries with the prefix removed" do
|
32
|
-
expect(HttpStub::
|
32
|
+
expect(HttpStub::Server::RequestHeaderParser.parse(request)).to include("KEY_1" => "value1",
|
33
33
|
"KEY_2" => "value2",
|
34
34
|
"KEY_3" => "value3")
|
35
35
|
end
|
@@ -41,7 +41,7 @@ describe HttpStub::Models::RequestHeaderParser do
|
|
41
41
|
let(:header_env_elements) { {} }
|
42
42
|
|
43
43
|
it "returns an empty hash" do
|
44
|
-
expect(HttpStub::
|
44
|
+
expect(HttpStub::Server::RequestHeaderParser.parse(request)).to eql({})
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe HttpStub::Server::ResponsePipeline do
|
2
|
+
|
3
|
+
let(:server) { instance_double(HttpStub::Server) }
|
4
|
+
|
5
|
+
let(:response_pipeline) { HttpStub::Server::ResponsePipeline.new(server) }
|
6
|
+
|
7
|
+
describe "#process" do
|
8
|
+
|
9
|
+
let(:response) { double(HttpStub::Server::StubResponse::Base, delay_in_seconds: 5, serve_on: nil) }
|
10
|
+
|
11
|
+
before(:example) { allow(response_pipeline).to receive(:sleep) }
|
12
|
+
|
13
|
+
subject { response_pipeline.process(response) }
|
14
|
+
|
15
|
+
it "sleeps for the duration declared in the response" do
|
16
|
+
expect(response_pipeline).to receive(:sleep).with(5)
|
17
|
+
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
|
21
|
+
it "serves the response via the server" do
|
22
|
+
expect(response).to receive(:serve_on).with(server)
|
23
|
+
|
24
|
+
subject
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe HttpStub::Server::Response do
|
2
|
+
|
3
|
+
describe "::SUCCESS" do
|
4
|
+
|
5
|
+
let(:response) { HttpStub::Server::Response::SUCCESS }
|
6
|
+
|
7
|
+
it "has a status of 200" do
|
8
|
+
expect(response.status).to eql(200)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a body containing OK to visually indicate success to those interacting via a browser" do
|
12
|
+
expect(response.body).to match(/OK/)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "::ERROR" do
|
18
|
+
|
19
|
+
let(:response) { HttpStub::Server::Response::ERROR }
|
20
|
+
|
21
|
+
it "has a status of 404" do
|
22
|
+
expect(response.status).to eql(404)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a body containing ERROR to visually indicate the error to those interacting via a browser" do
|
26
|
+
expect(response.body).to match(/ERROR/)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "::EMPTY" do
|
32
|
+
|
33
|
+
let(:response) { HttpStub::Server::Response::EMPTY }
|
34
|
+
|
35
|
+
it "is empty" do
|
36
|
+
expect(response.empty?).to be(true)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|