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.
- 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
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::StubRegistry do
|
|
2
2
|
|
|
3
|
-
let(:registry) { instance_double(HttpStub::
|
|
3
|
+
let(:registry) { instance_double(HttpStub::Server::Registry) }
|
|
4
4
|
|
|
5
|
-
let(:stub_registry) { HttpStub::
|
|
5
|
+
let(:stub_registry) { HttpStub::Server::StubRegistry.new }
|
|
6
6
|
|
|
7
|
-
before(:example) { allow(HttpStub::
|
|
7
|
+
before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(registry) }
|
|
8
8
|
|
|
9
9
|
describe "#add" do
|
|
10
10
|
|
|
11
|
-
let(:stub) { instance_double(HttpStub::
|
|
11
|
+
let(:stub) { instance_double(HttpStub::Server::Stub) }
|
|
12
12
|
let(:request) { double("HttpRequest") }
|
|
13
13
|
|
|
14
14
|
it "delegates to an underlying simple registry" do
|
|
@@ -33,8 +33,8 @@ describe HttpStub::Models::StubRegistry do
|
|
|
33
33
|
|
|
34
34
|
context "when a stub is found" do
|
|
35
35
|
|
|
36
|
-
let(:triggers) { instance_double(HttpStub::
|
|
37
|
-
let(:stub) { instance_double(HttpStub::
|
|
36
|
+
let(:triggers) { instance_double(HttpStub::Server::StubTriggers) }
|
|
37
|
+
let(:stub) { instance_double(HttpStub::Server::Stub, triggers: triggers) }
|
|
38
38
|
|
|
39
39
|
before(:example) { allow(registry).to receive(:find_for).and_return(stub) }
|
|
40
40
|
|
|
@@ -64,53 +64,33 @@ describe HttpStub::Models::StubRegistry do
|
|
|
64
64
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
describe "#remember" do
|
|
68
|
-
|
|
69
|
-
it "copies the underlying registry" do
|
|
70
|
-
expect(registry).to receive(:copy)
|
|
71
|
-
|
|
72
|
-
stub_registry.remember
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
|
|
77
67
|
describe "#recall" do
|
|
78
68
|
|
|
79
69
|
subject { stub_registry.recall }
|
|
80
70
|
|
|
81
71
|
context "when the state of the registry has been remembered" do
|
|
82
72
|
|
|
83
|
-
let(:
|
|
84
|
-
let(:copy_of_remembered_registry) { instance_double(HttpStub::Models::Registry) }
|
|
73
|
+
let(:last_stub_remembered) { instance_double(HttpStub::Server::Stub) }
|
|
85
74
|
|
|
86
75
|
before(:example) do
|
|
87
|
-
allow(registry).to receive(:
|
|
88
|
-
allow(remembered_registry).to receive(:copy).and_return(copy_of_remembered_registry)
|
|
76
|
+
allow(registry).to receive(:last).and_return(last_stub_remembered)
|
|
89
77
|
stub_registry.remember
|
|
90
78
|
end
|
|
91
79
|
|
|
92
|
-
it "
|
|
93
|
-
expect(
|
|
80
|
+
it "causes the underlying registry to rollback to the last stub added before the state was remembered" do
|
|
81
|
+
expect(registry).to receive(:rollback_to).with(last_stub_remembered)
|
|
94
82
|
|
|
95
83
|
subject
|
|
96
84
|
end
|
|
97
85
|
|
|
98
|
-
it "causes subsequent method calls to delegate to the copy" do
|
|
99
|
-
subject
|
|
100
|
-
|
|
101
|
-
expect(copy_of_remembered_registry).to receive(:all)
|
|
102
|
-
stub_registry.all
|
|
103
|
-
end
|
|
104
|
-
|
|
105
86
|
end
|
|
106
87
|
|
|
107
88
|
context "when the state of the registry has not been remembered" do
|
|
108
89
|
|
|
109
|
-
it "does not
|
|
110
|
-
|
|
90
|
+
it "does not rollback the underlying registry" do
|
|
91
|
+
expect(registry).to_not receive(:rollback_to)
|
|
111
92
|
|
|
112
|
-
|
|
113
|
-
stub_registry.all
|
|
93
|
+
subject
|
|
114
94
|
end
|
|
115
95
|
|
|
116
96
|
end
|
|
@@ -119,7 +99,7 @@ describe HttpStub::Models::StubRegistry do
|
|
|
119
99
|
|
|
120
100
|
describe "#all" do
|
|
121
101
|
|
|
122
|
-
let(:stubs) { (1..3).map { instance_double(HttpStub::
|
|
102
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub) } }
|
|
123
103
|
|
|
124
104
|
subject { stub_registry.all }
|
|
125
105
|
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
describe HttpStub::Server::StubResponse::Base do
|
|
2
|
+
|
|
3
|
+
let(:status) { 202 }
|
|
4
|
+
let(:headers) { nil }
|
|
5
|
+
let(:body) { "A response body" }
|
|
6
|
+
let(:delay_in_seconds) { 18 }
|
|
7
|
+
let(:args) do
|
|
8
|
+
{ "status" => status, "headers" => headers, "body" => body, "delay_in_seconds" => delay_in_seconds }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:testable_response_class) { Class.new(HttpStub::Server::StubResponse::Base) }
|
|
12
|
+
|
|
13
|
+
let(:response) { testable_response_class.new(args) }
|
|
14
|
+
|
|
15
|
+
describe "#status" do
|
|
16
|
+
|
|
17
|
+
context "when a value is provided in the arguments" do
|
|
18
|
+
|
|
19
|
+
context "that is an integer" do
|
|
20
|
+
|
|
21
|
+
it "returns the value provided" do
|
|
22
|
+
expect(response.status).to eql(status)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "that is an empty string" do
|
|
28
|
+
|
|
29
|
+
let(:status) { "" }
|
|
30
|
+
|
|
31
|
+
it "defaults to 200" do
|
|
32
|
+
expect(response.status).to eql(200)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "when the status is not provided in the arguments" do
|
|
40
|
+
|
|
41
|
+
let(:args) { { "body" => body, "delay_in_seconds" => delay_in_seconds } }
|
|
42
|
+
|
|
43
|
+
it "defaults to 200" do
|
|
44
|
+
expect(response.status).to eql(200)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#body" do
|
|
52
|
+
|
|
53
|
+
it "returns the value provided in the arguments" do
|
|
54
|
+
expect(response.body).to eql("A response body")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#delay_in_seconds" do
|
|
60
|
+
|
|
61
|
+
context "when a value is provided in the arguments" do
|
|
62
|
+
|
|
63
|
+
context "that is an integer" do
|
|
64
|
+
|
|
65
|
+
it "returns the value" do
|
|
66
|
+
expect(response.delay_in_seconds).to eql(delay_in_seconds)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "that is an empty string" do
|
|
72
|
+
|
|
73
|
+
let(:delay_in_seconds) { "" }
|
|
74
|
+
|
|
75
|
+
it "defaults to 0" do
|
|
76
|
+
expect(response.delay_in_seconds).to eql(0)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "when a value is not provided in the arguments" do
|
|
84
|
+
|
|
85
|
+
let(:args) { { "status" => status, "body" => body } }
|
|
86
|
+
|
|
87
|
+
it "defaults to 0" do
|
|
88
|
+
expect(response.delay_in_seconds).to eql(0)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "#headers" do
|
|
96
|
+
|
|
97
|
+
let(:response_header_hash) { response.headers.to_hash }
|
|
98
|
+
|
|
99
|
+
it "is Headers" do
|
|
100
|
+
expect(response.headers).to be_a(HttpStub::Server::Headers)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when default headers have been added" do
|
|
104
|
+
|
|
105
|
+
let(:default_headers) do
|
|
106
|
+
{ "a_default_header" => "a default value", "another_default_header" => "some other default value" }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
before(:example) { testable_response_class.add_default_headers(default_headers) }
|
|
110
|
+
|
|
111
|
+
context "and headers are provided" do
|
|
112
|
+
|
|
113
|
+
context "that have some names matching the defaults" do
|
|
114
|
+
|
|
115
|
+
let(:headers) { { "a_default_header" => "an overridde value" } }
|
|
116
|
+
|
|
117
|
+
it "replaces the matching default values with those provided" do
|
|
118
|
+
expect(response_header_hash["a_default_header"]).to eql("an overridde value")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "preserves the default values that do not match" do
|
|
122
|
+
expect(response_header_hash["another_default_header"]).to eql("some other default value")
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context "that do not have names matching the defaults" do
|
|
128
|
+
|
|
129
|
+
let(:headers) do
|
|
130
|
+
{
|
|
131
|
+
"a_header" => "some header",
|
|
132
|
+
"another_header" => "another value",
|
|
133
|
+
"yet_another_header" => "yet another value"
|
|
134
|
+
}
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "returns the defaults headers combined with the provided headers" do
|
|
138
|
+
expect(response_header_hash).to eql(default_headers.merge(headers))
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
context "and no headers are provided" do
|
|
146
|
+
|
|
147
|
+
it "returns the default headers" do
|
|
148
|
+
expect(response_header_hash).to eql(default_headers)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context "when no default headers have been added" do
|
|
156
|
+
|
|
157
|
+
context "and headers are provided" do
|
|
158
|
+
|
|
159
|
+
let(:headers) do
|
|
160
|
+
{
|
|
161
|
+
"a_header" => "some header",
|
|
162
|
+
"another_header" => "another value",
|
|
163
|
+
"yet_another_header" => "yet another value"
|
|
164
|
+
}
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "returns the headers" do
|
|
168
|
+
expect(response_header_hash).to eql(headers)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context "and no headers are provided" do
|
|
174
|
+
|
|
175
|
+
let(:headers) { nil }
|
|
176
|
+
|
|
177
|
+
it "returns an empty hash" do
|
|
178
|
+
expect(response_header_hash).to eql({})
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe "#empty?" do
|
|
188
|
+
|
|
189
|
+
context "when the response is EMPTY" do
|
|
190
|
+
|
|
191
|
+
let(:response) { HttpStub::Server::Response::EMPTY }
|
|
192
|
+
|
|
193
|
+
it "returns true" do
|
|
194
|
+
expect(response).to be_empty
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
context "when the response is not EMPTY" do
|
|
200
|
+
|
|
201
|
+
it "returns false" do
|
|
202
|
+
expect(response).not_to be_empty
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
describe "#clear" do
|
|
210
|
+
|
|
211
|
+
it "executes without error" do
|
|
212
|
+
expect { response.clear }.to_not raise_error
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
describe "#to_s" do
|
|
218
|
+
|
|
219
|
+
it "returns the string representation of the provided arguments" do
|
|
220
|
+
expect(response.to_s).to eql(args.to_s)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
describe HttpStub::Server::StubResponse::File do
|
|
2
|
+
|
|
3
|
+
let(:status) { 321 }
|
|
4
|
+
let(:headers) { {} }
|
|
5
|
+
let(:file_name) { "sample.txt" }
|
|
6
|
+
let(:temp_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/#{file_name}" }
|
|
7
|
+
let(:args) do
|
|
8
|
+
{
|
|
9
|
+
"status" => status,
|
|
10
|
+
"headers" => headers,
|
|
11
|
+
"body" => { filename: file_name, tempfile: File.new(temp_file_path) }
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:expected_file_path) { "#{HttpStub::BASE_DIR}/tmp/response_files/#{file_name}" }
|
|
16
|
+
|
|
17
|
+
let(:response_file) { HttpStub::Server::StubResponse::File.new(args) }
|
|
18
|
+
|
|
19
|
+
after(:example) { FileUtils.rm_rf(expected_file_path) }
|
|
20
|
+
|
|
21
|
+
it "is a base response" do
|
|
22
|
+
expect(response_file).to be_a(HttpStub::Server::StubResponse::Base)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "constructor" do
|
|
26
|
+
|
|
27
|
+
it "stores the temporary file provided for subsequent use" do
|
|
28
|
+
response_file
|
|
29
|
+
|
|
30
|
+
expect(FileUtils.identical?(expected_file_path, temp_file_path)).to be(true)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#serve_on" do
|
|
36
|
+
|
|
37
|
+
let(:server) { instance_double(Sinatra::Base) }
|
|
38
|
+
|
|
39
|
+
subject { response_file.serve_on(server) }
|
|
40
|
+
|
|
41
|
+
it "sends the file via the server" do
|
|
42
|
+
expect(server).to receive(:send_file).with(expected_file_path, anything)
|
|
43
|
+
|
|
44
|
+
subject
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "sends the file with the responses status" do
|
|
48
|
+
expect(server).to receive(:send_file).with(anything, hash_including(status: status))
|
|
49
|
+
|
|
50
|
+
subject
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "when a content type header is specified" do
|
|
54
|
+
|
|
55
|
+
let(:content_type) { "plain/text" }
|
|
56
|
+
let(:headers) { { "content-type" => content_type } }
|
|
57
|
+
|
|
58
|
+
it "sends the file with a type that is the provided content type" do
|
|
59
|
+
expect(server).to receive(:send_file).with(anything, hash_including(type: content_type))
|
|
60
|
+
|
|
61
|
+
subject
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "when no content type header is specified" do
|
|
67
|
+
|
|
68
|
+
let(:headers) { {} }
|
|
69
|
+
|
|
70
|
+
it "sends the file with a type of application/octet-stream" do
|
|
71
|
+
expect(server).to receive(:send_file).with(anything, hash_including(type: "application/octet-stream"))
|
|
72
|
+
|
|
73
|
+
subject
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when a last modified header is specified" do
|
|
79
|
+
|
|
80
|
+
let(:last_modified_date) { "Thu, 14 May 2015 12:56:00 GMT" }
|
|
81
|
+
let(:headers) { { "last-modified" => last_modified_date } }
|
|
82
|
+
|
|
83
|
+
it "sends the file with the last modified date" do
|
|
84
|
+
expect(server).to receive(:send_file).with(anything, hash_including(last_modified: last_modified_date))
|
|
85
|
+
|
|
86
|
+
subject
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "when no last modified header is specified" do
|
|
92
|
+
|
|
93
|
+
let(:headers) { {} }
|
|
94
|
+
|
|
95
|
+
it "sends the file without a last modified date" do
|
|
96
|
+
expect(server).to receive(:send_file).with(anything, hash_excluding(:last_modified))
|
|
97
|
+
|
|
98
|
+
subject
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when a content disposition header is specified" do
|
|
104
|
+
|
|
105
|
+
let(:content_disposition) { "attachment" }
|
|
106
|
+
let(:headers) { { "content-disposition" => content_disposition } }
|
|
107
|
+
|
|
108
|
+
it "sends the file with a disposition whose value is the provided content disposition" do
|
|
109
|
+
expect(server).to receive(:send_file).with(anything, hash_including(disposition: content_disposition))
|
|
110
|
+
|
|
111
|
+
subject
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context "when a content disposition header is not specified" do
|
|
117
|
+
|
|
118
|
+
let(:headers) { {} }
|
|
119
|
+
|
|
120
|
+
it "sends the file without a disposition" do
|
|
121
|
+
expect(server).to receive(:send_file).with(anything, hash_excluding(:disposition))
|
|
122
|
+
|
|
123
|
+
subject
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe "#clear" do
|
|
131
|
+
|
|
132
|
+
it "deletes the stored file" do
|
|
133
|
+
response_file.clear
|
|
134
|
+
|
|
135
|
+
expect(File.exist?(expected_file_path)).to be(false)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
describe HttpStub::Server::StubResponse::Text do
|
|
2
|
+
|
|
3
|
+
let(:status) { 123 }
|
|
4
|
+
let(:headers) { {} }
|
|
5
|
+
let(:body) { "Some text body" }
|
|
6
|
+
let(:args) { { "status" => status, "headers" => headers, "body" => body } }
|
|
7
|
+
|
|
8
|
+
let(:response_text) { HttpStub::Server::StubResponse::Text.new(args) }
|
|
9
|
+
|
|
10
|
+
it "is a base response" do
|
|
11
|
+
expect(response_text).to be_a(HttpStub::Server::StubResponse::Base)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#serve_on" do
|
|
15
|
+
|
|
16
|
+
let(:server) { instance_double(Sinatra::Base) }
|
|
17
|
+
|
|
18
|
+
subject { response_text.serve_on(server) }
|
|
19
|
+
|
|
20
|
+
it "halts processing of the servers request" do
|
|
21
|
+
expect(server).to receive(:halt)
|
|
22
|
+
|
|
23
|
+
subject
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "halts with the responses status" do
|
|
27
|
+
expect(server).to receive(:halt).with(status, anything, anything)
|
|
28
|
+
|
|
29
|
+
subject
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "when headers are provided" do
|
|
33
|
+
|
|
34
|
+
context "that contain a content-type" do
|
|
35
|
+
|
|
36
|
+
let(:headers) do
|
|
37
|
+
{
|
|
38
|
+
"content-type" => "some/content/type",
|
|
39
|
+
"another-header" => "some value",
|
|
40
|
+
"yet-another-header" => "some other value"
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "halts with the provided headers" do
|
|
45
|
+
expect(server).to receive(:halt).with(anything, headers, anything)
|
|
46
|
+
|
|
47
|
+
subject
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "that do not contain a content-type" do
|
|
53
|
+
|
|
54
|
+
let(:headers) do
|
|
55
|
+
{
|
|
56
|
+
"a-header" => "some value",
|
|
57
|
+
"another-header" => "another value",
|
|
58
|
+
"yet-another-header" => "yet another value"
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "halts with the provided headers" do
|
|
63
|
+
expect(server).to receive(:halt).with(anything, hash_including(headers), anything)
|
|
64
|
+
|
|
65
|
+
subject
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "halts with a default content-type of application/json" do
|
|
69
|
+
expect_server_to_halt_with_default_content_type
|
|
70
|
+
|
|
71
|
+
subject
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when no headers are provided" do
|
|
79
|
+
|
|
80
|
+
let(:headers) { {} }
|
|
81
|
+
|
|
82
|
+
it "halts with a default content-type of application/json" do
|
|
83
|
+
expect_server_to_halt_with_default_content_type
|
|
84
|
+
|
|
85
|
+
subject
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "halts with the responses body" do
|
|
91
|
+
expect(server).to receive(:halt).with(anything, anything, body)
|
|
92
|
+
|
|
93
|
+
subject
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def expect_server_to_halt_with_default_content_type
|
|
97
|
+
expected_content_type_entry = { "content-type" => "application/json" }
|
|
98
|
+
expect(server).to receive(:halt).with(anything, hash_including(expected_content_type_entry), anything)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
describe HttpStub::Server::StubResponse do
|
|
2
|
+
|
|
3
|
+
describe "::create" do
|
|
4
|
+
|
|
5
|
+
let(:response_args) { { "body" => body } }
|
|
6
|
+
|
|
7
|
+
subject { HttpStub::Server::StubResponse.create(response_args) }
|
|
8
|
+
|
|
9
|
+
context "when the body contains text" do
|
|
10
|
+
|
|
11
|
+
let(:body) { "some text" }
|
|
12
|
+
|
|
13
|
+
it "creates a text response" do
|
|
14
|
+
expect(HttpStub::Server::StubResponse::Text).to receive(:new).with(response_args)
|
|
15
|
+
|
|
16
|
+
subject
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "returns the created response" do
|
|
20
|
+
response = instance_double(HttpStub::Server::StubResponse::Text)
|
|
21
|
+
allow(HttpStub::Server::StubResponse::Text).to receive(:new).and_return(response)
|
|
22
|
+
|
|
23
|
+
expect(subject).to eql(response)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when the body contains a file" do
|
|
29
|
+
|
|
30
|
+
let(:body) { { "file" => { "path" => "a/file.path", "name" => "a_file.name" } } }
|
|
31
|
+
|
|
32
|
+
it "creates a file response" do
|
|
33
|
+
expect(HttpStub::Server::StubResponse::File).to receive(:new).with(response_args)
|
|
34
|
+
|
|
35
|
+
subject
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "returns the created response" do
|
|
39
|
+
response = instance_double(HttpStub::Server::StubResponse::File)
|
|
40
|
+
allow(HttpStub::Server::StubResponse::File).to receive(:new).and_return(response)
|
|
41
|
+
|
|
42
|
+
expect(subject).to eql(response)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::Stub do
|
|
2
2
|
|
|
3
3
|
let(:raw_stub_headers) do
|
|
4
4
|
{
|
|
@@ -40,25 +40,27 @@ describe HttpStub::Models::Stub do
|
|
|
40
40
|
"triggers" => [ stub_trigger ]
|
|
41
41
|
}
|
|
42
42
|
end
|
|
43
|
-
let(:stub_uri) { instance_double(HttpStub::
|
|
44
|
-
let(:stub_headers) { instance_double(HttpStub::
|
|
45
|
-
let(:stub_parameters) { instance_double(HttpStub::
|
|
46
|
-
let(:
|
|
43
|
+
let(:stub_uri) { instance_double(HttpStub::Server::StubUri, match?: true) }
|
|
44
|
+
let(:stub_headers) { instance_double(HttpStub::Server::StubHeaders, match?: true) }
|
|
45
|
+
let(:stub_parameters) { instance_double(HttpStub::Server::StubParameters, match?: true) }
|
|
46
|
+
let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base, clear: nil) }
|
|
47
|
+
let(:stub_triggers) { instance_double(HttpStub::Server::StubTriggers, clear: nil) }
|
|
47
48
|
|
|
48
|
-
let(:the_stub) { HttpStub::
|
|
49
|
+
let(:the_stub) { HttpStub::Server::Stub.new(stub_args) }
|
|
49
50
|
|
|
50
51
|
before(:example) do
|
|
51
|
-
allow(HttpStub::
|
|
52
|
-
allow(HttpStub::
|
|
53
|
-
allow(HttpStub::
|
|
54
|
-
allow(HttpStub::
|
|
52
|
+
allow(HttpStub::Server::StubUri).to receive(:new).and_return(stub_uri)
|
|
53
|
+
allow(HttpStub::Server::StubHeaders).to receive(:new).and_return(stub_headers)
|
|
54
|
+
allow(HttpStub::Server::StubParameters).to receive(:new).and_return(stub_parameters)
|
|
55
|
+
allow(HttpStub::Server::StubResponse).to receive(:create).and_return(stub_response)
|
|
56
|
+
allow(HttpStub::Server::StubTriggers).to receive(:new).and_return(stub_triggers)
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
describe "#satisfies?" do
|
|
58
60
|
|
|
59
|
-
let(:request_uri)
|
|
61
|
+
let(:request_uri) { "/a_request_uri" }
|
|
60
62
|
let(:request_method) { stub_method }
|
|
61
|
-
let(:request)
|
|
63
|
+
let(:request) { instance_double(Rack::Request, :request_method => request_method) }
|
|
62
64
|
|
|
63
65
|
describe "when the request uri matches" do
|
|
64
66
|
|
|
@@ -170,12 +172,8 @@ describe HttpStub::Models::Stub do
|
|
|
170
172
|
|
|
171
173
|
describe "#response" do
|
|
172
174
|
|
|
173
|
-
it "exposes the
|
|
174
|
-
expect(the_stub.response
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
it "exposes the provided response body" do
|
|
178
|
-
expect(the_stub.response.body).to eql("Some body")
|
|
175
|
+
it "exposes the response model encapsulating the response provided in the request body" do
|
|
176
|
+
expect(the_stub.response).to eql(stub_response)
|
|
179
177
|
end
|
|
180
178
|
|
|
181
179
|
end
|
|
@@ -188,6 +186,24 @@ describe HttpStub::Models::Stub do
|
|
|
188
186
|
|
|
189
187
|
end
|
|
190
188
|
|
|
189
|
+
describe "#clear" do
|
|
190
|
+
|
|
191
|
+
subject { the_stub.clear }
|
|
192
|
+
|
|
193
|
+
it "clears the stub response" do
|
|
194
|
+
expect(stub_response).to receive(:clear)
|
|
195
|
+
|
|
196
|
+
subject
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it "clears the stub triggers" do
|
|
200
|
+
expect(stub_triggers).to receive(:clear)
|
|
201
|
+
|
|
202
|
+
subject
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
191
207
|
describe "#to_s" do
|
|
192
208
|
|
|
193
209
|
it "returns a string representation of the stub arguments" do
|