http_stub 0.22.4 → 0.23.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.rb +15 -5
- data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +19 -0
- data/lib/http_stub/configurer/dsl/request_referencer.rb +24 -0
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +2 -2
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +2 -2
- data/lib/http_stub/configurer/dsl/server.rb +4 -4
- data/lib/http_stub/configurer/dsl/stub_builder.rb +5 -3
- data/lib/http_stub/configurer/request/controllable_value.rb +1 -3
- data/lib/http_stub/configurer/request/http/factory.rb +2 -2
- data/lib/http_stub/configurer/request/omittable.rb +2 -4
- data/lib/http_stub/configurer/request/regexpable.rb +3 -8
- data/lib/http_stub/configurer/server/command_processor.rb +5 -7
- data/lib/http_stub/configurer/server/facade.rb +2 -4
- data/lib/http_stub/extensions/core/hash.rb +4 -11
- data/lib/http_stub/extensions/core/hash/formatted.rb +23 -0
- data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +24 -0
- data/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access.rb +18 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -1
- data/lib/http_stub/rake/task_generators.rb +1 -1
- data/lib/http_stub/server/application.rb +10 -11
- data/lib/http_stub/server/application_helpers.rb +3 -5
- data/lib/http_stub/server/daemon.rb +5 -6
- data/lib/http_stub/server/request.rb +3 -10
- data/lib/http_stub/server/request/headers.rb +25 -0
- data/lib/http_stub/server/request/parameters.rb +21 -0
- data/lib/http_stub/server/request/request.rb +21 -0
- data/lib/http_stub/server/scenario/links.rb +1 -1
- data/lib/http_stub/server/stub/controller.rb +1 -1
- data/lib/http_stub/server/stub/empty.rb +4 -0
- data/lib/http_stub/server/stub/match/hash_matcher.rb +19 -0
- data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -3
- data/lib/http_stub/server/stub/match/rule/body.rb +2 -4
- data/lib/http_stub/server/stub/match/rule/headers.rb +5 -11
- data/lib/http_stub/server/stub/match/rule/json_body.rb +3 -5
- data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
- data/lib/http_stub/server/stub/match/rule/parameters.rb +4 -7
- data/lib/http_stub/server/stub/match/rule/simple_body.rb +3 -3
- data/lib/http_stub/server/stub/match/rule/truthy.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/uri.rb +3 -3
- data/lib/http_stub/server/stub/match/string_value_matcher.rb +4 -13
- data/lib/http_stub/server/stub/response.rb +5 -2
- data/lib/http_stub/server/stub/response/attribute/body.rb +32 -0
- data/lib/http_stub/server/stub/response/attribute/headers.rb +26 -0
- data/lib/http_stub/server/stub/response/attribute/interpolator.rb +26 -0
- data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +27 -0
- data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +27 -0
- data/lib/http_stub/server/stub/response/base.rb +5 -16
- data/lib/http_stub/server/stub/response/file.rb +6 -2
- data/lib/http_stub/server/stub/response/text.rb +12 -0
- data/lib/http_stub/server/stub/stub.rb +4 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/request_reference_spec.rb +44 -0
- data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +37 -0
- data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +37 -0
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +14 -14
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +2 -6
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +34 -8
- data/spec/lib/http_stub/{server/formatted_hash_spec.rb → extensions/core/hash/formatted_spec.rb} +4 -6
- data/spec/lib/http_stub/{hash_with_indifferent_and_insensitive_access_spec.rb → extensions/core/hash/indifferent_and_insensitive_access_spec.rb} +8 -4
- data/spec/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access_spec.rb +41 -0
- data/spec/lib/http_stub/extensions/core/hash_spec.rb +11 -129
- data/spec/lib/http_stub/server/application_spec.rb +1 -1
- data/spec/lib/http_stub/server/payload_file_consolidator_spec.rb +1 -1
- data/spec/lib/http_stub/server/request/headers_spec.rb +89 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +60 -0
- data/spec/lib/http_stub/server/request/request_spec.rb +84 -0
- data/spec/lib/http_stub/server/request_spec.rb +9 -98
- data/spec/lib/http_stub/server/response_spec.rb +2 -6
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +1 -1
- data/spec/lib/http_stub/server/scenario/parser_spec.rb +3 -1
- data/spec/lib/http_stub/server/stub/controller_spec.rb +11 -4
- data/spec/lib/http_stub/server/stub/empty_spec.rb +10 -0
- data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +122 -0
- data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +4 -4
- data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +54 -45
- data/spec/lib/http_stub/server/stub/match/rule/json_body_spec.rb +5 -5
- data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +19 -17
- data/spec/lib/http_stub/server/stub/match/rule/parameters_spec.rb +26 -33
- data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +16 -25
- data/spec/lib/http_stub/server/stub/match/{truthy_matcher_spec.rb → rule/truthy_spec.rb} +3 -5
- data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +16 -25
- data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +2 -12
- data/spec/lib/http_stub/server/stub/parser_spec.rb +5 -3
- data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +98 -0
- data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +57 -0
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +53 -0
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +53 -0
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +41 -0
- data/spec/lib/http_stub/server/stub/response/base_spec.rb +6 -53
- data/spec/lib/http_stub/server/stub/response/file_spec.rb +48 -7
- data/spec/lib/http_stub/server/stub/response/text_spec.rb +66 -1
- data/spec/lib/http_stub/server/stub/stub_spec.rb +25 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/support/http_stub/server/request_fixture.rb +1 -1
- metadata +86 -26
- data/lib/http_stub/hash_with_indifferent_and_insensitive_access.rb +0 -18
- data/lib/http_stub/server/formatted_hash.rb +0 -18
- data/lib/http_stub/server/header_parser.rb +0 -17
- data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +0 -26
- data/lib/http_stub/server/stub/match/truthy_matcher.rb +0 -25
- data/spec/lib/http_stub/server/header_parser_spec.rb +0 -51
- data/spec/lib/http_stub/server/stub/match/hash_with_string_value_matchers_spec.rb +0 -166
@@ -0,0 +1,57 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Response::Attribute::Headers do
|
2
|
+
|
3
|
+
let(:stub_headers) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value #{i}" } }
|
4
|
+
|
5
|
+
let(:headers) { described_class.new(stub_headers) }
|
6
|
+
|
7
|
+
describe "#with_values_from" do
|
8
|
+
|
9
|
+
let(:request) { HttpStub::Server::Request::Request }
|
10
|
+
|
11
|
+
let(:interpolated_headers) do
|
12
|
+
stub_headers.keys.each_with_object({}).with_index do |(name, result), i|
|
13
|
+
result[name] = "interpolated value #{i + 1}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { headers.with_values_from(request) }
|
18
|
+
|
19
|
+
it "interpolates each header value with values from the request" do
|
20
|
+
stub_headers.values.each do |header_value|
|
21
|
+
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
22
|
+
receive(:interpolate).with(header_value, request)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns a hash containing the interpolated values" do
|
30
|
+
stub_headers.values.zip(interpolated_headers.values).each do |header_value, interpolated_value|
|
31
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
32
|
+
receive(:interpolate).with(header_value, anything).and_return(interpolated_value)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(subject).to eql(interpolated_headers)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_s" do
|
42
|
+
|
43
|
+
subject { headers.to_s }
|
44
|
+
|
45
|
+
it "returns a string with each header name and value separated by ':'" do
|
46
|
+
result = subject
|
47
|
+
|
48
|
+
stub_headers.each { |name, value| expect(result).to match(/#{name}:#{value}/) }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "separates each header with comma for readability" do
|
52
|
+
expect(subject).to match(/key\d.value \d, key\d.value \d, key\d.value \d/)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers do
|
2
|
+
|
3
|
+
describe "::interpolate" do
|
4
|
+
|
5
|
+
let(:request_headers) { instance_double(HttpStub::Server::Request::Headers) }
|
6
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request, headers: request_headers) }
|
7
|
+
|
8
|
+
subject { described_class.interpolate(value, request) }
|
9
|
+
|
10
|
+
context "when the value has header references" do
|
11
|
+
|
12
|
+
let(:value) do
|
13
|
+
"control:request.headers[name1] some text control:request.parameters[name1] control:request.headers[name2]"
|
14
|
+
end
|
15
|
+
|
16
|
+
context "and the headers are present in the request" do
|
17
|
+
|
18
|
+
before(:example) do
|
19
|
+
allow(request_headers).to receive(:[]).with("name1").and_return("value1")
|
20
|
+
allow(request_headers).to receive(:[]).with("name2").and_return("value2")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the value with the header references interpolated" do
|
24
|
+
expect(subject).to eql("value1 some text control:request.parameters[name1] value2")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and the headers are not present in the request" do
|
30
|
+
|
31
|
+
before(:example) { allow(request_headers).to receive(:[]).and_return(nil) }
|
32
|
+
|
33
|
+
it "returns the value with the header references removed" do
|
34
|
+
expect(subject).to eql(" some text control:request.parameters[name1] ")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the value does not have header references" do
|
42
|
+
|
43
|
+
let(:value) { "some value without header references control:request.parameters[name1]" }
|
44
|
+
|
45
|
+
it "returns the value unchanged" do
|
46
|
+
expect(subject).to eql(value)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters do
|
2
|
+
|
3
|
+
describe "::interpolate" do
|
4
|
+
|
5
|
+
let(:request_parameters) { instance_double(HttpStub::Server::Request::Parameters) }
|
6
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request, parameters: request_parameters) }
|
7
|
+
|
8
|
+
subject { described_class.interpolate(value, request) }
|
9
|
+
|
10
|
+
context "when the value has parameter references" do
|
11
|
+
|
12
|
+
let(:value) do
|
13
|
+
"control:request.parameters[name1] some text control:request.headers[name1] control:request.parameters[name2]"
|
14
|
+
end
|
15
|
+
|
16
|
+
context "and the parameters are present in the request" do
|
17
|
+
|
18
|
+
before(:example) do
|
19
|
+
allow(request_parameters).to receive(:[]).with("name1").and_return("value1")
|
20
|
+
allow(request_parameters).to receive(:[]).with("name2").and_return("value2")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the value with the parameter references interpolated" do
|
24
|
+
expect(subject).to eql("value1 some text control:request.headers[name1] value2")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and the parameters are not present in the request" do
|
30
|
+
|
31
|
+
before(:example) { allow(request_parameters).to receive(:[]).and_return(nil) }
|
32
|
+
|
33
|
+
it "returns the value with the parameter references removed" do
|
34
|
+
expect(subject).to eql(" some text control:request.headers[name1] ")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the value does not have parameter references" do
|
42
|
+
|
43
|
+
let(:value) { "some value without parameter references control:request.headers[name1]" }
|
44
|
+
|
45
|
+
it "returns the value unchanged" do
|
46
|
+
expect(subject).to eql(value)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Response::Attribute::Interpolator do
|
2
|
+
|
3
|
+
describe "::interpolate" do
|
4
|
+
|
5
|
+
let(:value) { "some value" }
|
6
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
7
|
+
|
8
|
+
subject { described_class.interpolate(value, request) }
|
9
|
+
|
10
|
+
it "interpolates header references in the provided value" do
|
11
|
+
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers).to(
|
12
|
+
receive(:interpolate).with(value, request).and_return("")
|
13
|
+
)
|
14
|
+
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
|
18
|
+
it "combines the result of header interpolation to include parameter interpolation" do
|
19
|
+
value_with_header_interpolation = "some value with header interpolation"
|
20
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers).to(
|
21
|
+
receive(:interpolate).and_return(value_with_header_interpolation)
|
22
|
+
)
|
23
|
+
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters).to(
|
24
|
+
receive(:interpolate).with(value_with_header_interpolation, request)
|
25
|
+
)
|
26
|
+
|
27
|
+
subject
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the result of parameter interpolation as the overall result" do
|
31
|
+
overall_result = "overall_result"
|
32
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters).to(
|
33
|
+
receive(:interpolate).and_return(overall_result)
|
34
|
+
)
|
35
|
+
|
36
|
+
expect(subject).to eql(overall_result)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -2,13 +2,10 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
2
2
|
|
3
3
|
let(:status) { 202 }
|
4
4
|
let(:headers) { nil }
|
5
|
-
let(:body) { "A response body" }
|
6
5
|
let(:delay_in_seconds) { 18 }
|
7
|
-
let(:args)
|
8
|
-
{ "status" => status, "headers" => headers, "body" => body, "delay_in_seconds" => delay_in_seconds }
|
9
|
-
end
|
6
|
+
let(:args) { { "status" => status, "headers" => headers, "delay_in_seconds" => delay_in_seconds } }
|
10
7
|
|
11
|
-
let(:testable_response_class) { Class.new(
|
8
|
+
let(:testable_response_class) { Class.new(described_class) }
|
12
9
|
|
13
10
|
let(:response) { testable_response_class.new(args) }
|
14
11
|
|
@@ -38,7 +35,7 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
38
35
|
|
39
36
|
context "when the status is not provided in the arguments" do
|
40
37
|
|
41
|
-
let(:args) { { "
|
38
|
+
let(:args) { { "headers" => headers } }
|
42
39
|
|
43
40
|
it "defaults to 200" do
|
44
41
|
expect(response.status).to eql(200)
|
@@ -48,14 +45,6 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
48
45
|
|
49
46
|
end
|
50
47
|
|
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
48
|
describe "#delay_in_seconds" do
|
60
49
|
|
61
50
|
context "when a value is provided in the arguments" do
|
@@ -82,7 +71,7 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
82
71
|
|
83
72
|
context "when a value is not provided in the arguments" do
|
84
73
|
|
85
|
-
let(:args) { { "status" => status
|
74
|
+
let(:args) { { "status" => status } }
|
86
75
|
|
87
76
|
it "defaults to 0" do
|
88
77
|
expect(response.delay_in_seconds).to eql(0)
|
@@ -96,14 +85,8 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
96
85
|
|
97
86
|
let(:response_header_hash) { response.headers.to_hash }
|
98
87
|
|
99
|
-
it "is
|
100
|
-
expect(response.headers).to be_a(HttpStub::Server::
|
101
|
-
end
|
102
|
-
|
103
|
-
it "formats the hash with a ':' key value delimiter" do
|
104
|
-
expect(HttpStub::Server::FormattedHash).to receive(:new).with(anything, ":")
|
105
|
-
|
106
|
-
response.headers
|
88
|
+
it "is interpolateable headers" do
|
89
|
+
expect(response.headers).to be_a(HttpStub::Server::Stub::Response::Attribute::Headers)
|
107
90
|
end
|
108
91
|
|
109
92
|
context "when default headers have been added" do
|
@@ -203,34 +186,4 @@ describe HttpStub::Server::Stub::Response::Base do
|
|
203
186
|
|
204
187
|
end
|
205
188
|
|
206
|
-
describe "#empty?" do
|
207
|
-
|
208
|
-
context "when the response is EMPTY" do
|
209
|
-
|
210
|
-
let(:response) { HttpStub::Server::Response::EMPTY }
|
211
|
-
|
212
|
-
it "returns true" do
|
213
|
-
expect(response).to be_empty
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
|
218
|
-
context "when the response is not EMPTY" do
|
219
|
-
|
220
|
-
it "returns false" do
|
221
|
-
expect(response).not_to be_empty
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "#to_s" do
|
229
|
-
|
230
|
-
it "returns the string representation of the provided arguments" do
|
231
|
-
expect(response.to_s).to eql(args.to_s)
|
232
|
-
end
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
189
|
end
|
@@ -4,13 +4,8 @@ describe HttpStub::Server::Stub::Response::File do
|
|
4
4
|
let(:headers) { {} }
|
5
5
|
let(:file_name) { "sample.txt" }
|
6
6
|
let(:temp_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/#{file_name}" }
|
7
|
-
let(:
|
8
|
-
|
9
|
-
"status" => status,
|
10
|
-
"headers" => headers,
|
11
|
-
"body" => { filename: file_name, tempfile: File.new(temp_file_path) }
|
12
|
-
}
|
13
|
-
end
|
7
|
+
let(:body) { { filename: file_name, tempfile: File.new(temp_file_path) } }
|
8
|
+
let(:args) { { "status" => status, "headers" => headers, "body" => body } }
|
14
9
|
|
15
10
|
let(:response_file) { HttpStub::Server::Stub::Response::File.new(args) }
|
16
11
|
|
@@ -32,6 +27,52 @@ describe HttpStub::Server::Stub::Response::File do
|
|
32
27
|
|
33
28
|
end
|
34
29
|
|
30
|
+
describe "#with_values_from" do
|
31
|
+
|
32
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
33
|
+
let(:interpolated_headers) { { interpolated_header_name: "some interpolated header value" } }
|
34
|
+
let(:response_headers) do
|
35
|
+
instance_double(HttpStub::Server::Stub::Response::Attribute::Headers, with_values_from: interpolated_headers)
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { response_file.with_values_from(request) }
|
39
|
+
|
40
|
+
before(:example) do
|
41
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Headers).to receive(:new).and_return(response_headers)
|
42
|
+
ensure_response_file_is_created!
|
43
|
+
end
|
44
|
+
|
45
|
+
it "interpolates headers with values from the request" do
|
46
|
+
expect(response_headers).to receive(:with_values_from).with(request)
|
47
|
+
|
48
|
+
subject
|
49
|
+
end
|
50
|
+
|
51
|
+
it "creates a new response file with the interpolated headers" do
|
52
|
+
expect(described_class).to receive(:new).with(hash_including("headers" => interpolated_headers))
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates a new response file with other arguments preserved" do
|
58
|
+
expect(described_class).to receive(:new).with(hash_including("status" => status, "body" => body))
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the created file response" do
|
64
|
+
new_file_response = instance_double(described_class)
|
65
|
+
expect(described_class).to receive(:new).and_return(new_file_response)
|
66
|
+
|
67
|
+
expect(subject).to eql(new_file_response)
|
68
|
+
end
|
69
|
+
|
70
|
+
def ensure_response_file_is_created!
|
71
|
+
response_file
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
35
76
|
describe "#serve_on" do
|
36
77
|
|
37
78
|
let(:server) { instance_double(Sinatra::Base) }
|
@@ -3,14 +3,79 @@ describe HttpStub::Server::Stub::Response::Text do
|
|
3
3
|
let(:status) { 123 }
|
4
4
|
let(:headers) { {} }
|
5
5
|
let(:body) { "Some text body" }
|
6
|
-
let(:args)
|
6
|
+
let(:args) { { "status" => status, "headers" => headers, "body" => body } }
|
7
7
|
|
8
8
|
let(:response_text) { HttpStub::Server::Stub::Response::Text.new(args) }
|
9
9
|
|
10
|
+
describe "#body" do
|
11
|
+
|
12
|
+
it "returns the value provided in the arguments" do
|
13
|
+
expect(response_text.body).to eql("Some text body")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
10
18
|
it "is a base response" do
|
11
19
|
expect(response_text).to be_a(HttpStub::Server::Stub::Response::Base)
|
12
20
|
end
|
13
21
|
|
22
|
+
describe "#with_values_from" do
|
23
|
+
|
24
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
25
|
+
let(:interpolated_headers) { { interpolated_header_name: "some interpolated header value" } }
|
26
|
+
let(:response_headers) do
|
27
|
+
instance_double(HttpStub::Server::Stub::Response::Attribute::Headers, with_values_from: interpolated_headers)
|
28
|
+
end
|
29
|
+
let(:interpolated_body) { "some interpolated body" }
|
30
|
+
let(:response_body) do
|
31
|
+
instance_double(HttpStub::Server::Stub::Response::Attribute::Body, with_values_from: interpolated_body )
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { response_text.with_values_from(request) }
|
35
|
+
|
36
|
+
before(:example) do
|
37
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Headers).to receive(:new).and_return(response_headers)
|
38
|
+
allow(HttpStub::Server::Stub::Response::Attribute::Body).to receive(:new).and_return(response_body)
|
39
|
+
ensure_response_text_is_created!
|
40
|
+
end
|
41
|
+
|
42
|
+
it "interpolates headers with values from the request" do
|
43
|
+
expect(response_headers).to receive(:with_values_from).with(request)
|
44
|
+
|
45
|
+
subject
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a new response text with the interpolated headers" do
|
49
|
+
expect(described_class).to receive(:new).with(hash_including("headers" => interpolated_headers))
|
50
|
+
|
51
|
+
subject
|
52
|
+
end
|
53
|
+
|
54
|
+
it "creates a new response text with the interpolated body" do
|
55
|
+
expect(described_class).to receive(:new).with(hash_including("body" => interpolated_body))
|
56
|
+
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it "creates a new response text with other arguments preserved" do
|
61
|
+
expect(described_class).to receive(:new).with(hash_including("status" => status))
|
62
|
+
|
63
|
+
subject
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns the created text response" do
|
67
|
+
new_text_response = instance_double(described_class)
|
68
|
+
expect(described_class).to receive(:new).and_return(new_text_response)
|
69
|
+
|
70
|
+
expect(subject).to eql(new_text_response)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ensure_response_text_is_created!
|
74
|
+
response_text
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
14
79
|
describe "#serve_on" do
|
15
80
|
|
16
81
|
let(:server) { instance_double(Sinatra::Base) }
|