http_stub 0.15.1 → 0.15.2
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.rb +1 -1
- data/lib/http_stub/server/{stub_factory.rb → request_parser.rb} +5 -6
- data/lib/http_stub/server/stub_activator.rb +0 -4
- data/lib/http_stub/server/stub_activator_controller.rb +2 -1
- data/lib/http_stub/server/stub_controller.rb +2 -1
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer_integration_spec.rb +32 -9
- data/spec/lib/http_stub/server/request_parser_spec.rb +90 -0
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +18 -8
- data/spec/lib/http_stub/server/stub_activator_spec.rb +4 -35
- data/spec/lib/http_stub/server/stub_controller_spec.rb +17 -7
- metadata +5 -5
- data/spec/lib/http_stub/server/stub_factory_spec.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 473cfd88f509d2e18bbf47ffbcd7d013d5bae137
|
4
|
+
data.tar.gz: 3c2afdb69d93618e52df58e22a7e1fd9de623756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e024dcbeb70730ee13353fde8845fff7f6b2bedb3a668d3f33428f5069c40b3f0ed3a7104ef6c6f803644fe8f5bf42a74b6511524e07ff33cec4c00744f40f97
|
7
|
+
data.tar.gz: d191926b0caf32e8553cc7c109912f23ada60a360f211c682214476bfca9ea41f269bce5ebce0fae1d615c1b6da4b9660d1fe7f07e46108c49428f28ca4b61fa
|
data/lib/http_stub.rb
CHANGED
@@ -31,8 +31,8 @@ require_relative 'http_stub/server/stub_response'
|
|
31
31
|
require_relative 'http_stub/server/response'
|
32
32
|
require_relative 'http_stub/server/stub_triggers'
|
33
33
|
require_relative 'http_stub/server/stub'
|
34
|
-
require_relative 'http_stub/server/stub_factory'
|
35
34
|
require_relative 'http_stub/server/stub_activator'
|
35
|
+
require_relative 'http_stub/server/request_parser'
|
36
36
|
require_relative 'http_stub/server/registry'
|
37
37
|
require_relative 'http_stub/server/stub_registry'
|
38
38
|
require_relative 'http_stub/server/response_pipeline'
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module HttpStub
|
2
2
|
module Server
|
3
3
|
|
4
|
-
class
|
4
|
+
class RequestParser
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def parse(request)
|
9
|
+
JSON.parse(request.params["payload"] || request.body.read).tap do |payload|
|
10
|
+
consolidate_files_into_payload(payload, request)
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -19,7 +19,6 @@ module HttpStub
|
|
19
19
|
payload["triggers"].each do |trigger_payload|
|
20
20
|
consolidate_files_into_payload(trigger_payload, request)
|
21
21
|
end if payload["triggers"]
|
22
|
-
payload
|
23
22
|
end
|
24
23
|
|
25
24
|
end
|
@@ -9,7 +9,8 @@ module HttpStub
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def register(request)
|
12
|
-
|
12
|
+
stub_activator = HttpStub::Server::StubActivator.new(HttpStub::Server::RequestParser.parse(request))
|
13
|
+
@stub_activator_registry.add(stub_activator, request)
|
13
14
|
HttpStub::Server::Response::SUCCESS
|
14
15
|
end
|
15
16
|
|
@@ -8,7 +8,8 @@ module HttpStub
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def register(request)
|
11
|
-
|
11
|
+
stub = HttpStub::Server::Stub.new(HttpStub::Server::RequestParser.parse(request))
|
12
|
+
@registry.add(stub, request)
|
12
13
|
HttpStub::Server::Response::SUCCESS
|
13
14
|
end
|
14
15
|
|
data/lib/http_stub/version.rb
CHANGED
@@ -19,15 +19,38 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
19
19
|
|
20
20
|
context "and a stub is activated" do
|
21
21
|
|
22
|
-
|
22
|
+
context "and the response contains text" do
|
23
23
|
|
24
|
-
|
24
|
+
before(:example) { configurer.activate!("/an_activator") }
|
25
25
|
|
26
|
-
|
26
|
+
context "and the stub request is made" do
|
27
|
+
|
28
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_path") }
|
29
|
+
|
30
|
+
it "replays the stubbed response" do
|
31
|
+
expect(response.code).to eql(200)
|
32
|
+
expect(response.body).to eql("Stub activator body")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "and the response contains a file" do
|
40
|
+
|
41
|
+
let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponse.new }
|
42
|
+
|
43
|
+
before(:example) { configurer.activate!("/a_file_activator") }
|
44
|
+
|
45
|
+
context "and the stub request is made" do
|
46
|
+
|
47
|
+
let(:response) { HTTParty.get("#{server_uri}/activated_response_with_file") }
|
48
|
+
|
49
|
+
it "replays the stubbed response" do
|
50
|
+
expect(response.code).to eql(200)
|
51
|
+
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponse::FILE_PATH)
|
52
|
+
end
|
27
53
|
|
28
|
-
it "replays the stubbed response" do
|
29
|
-
expect(response.code).to eql(200)
|
30
|
-
expect(response.body).to eql("Stub activator body")
|
31
54
|
end
|
32
55
|
|
33
56
|
end
|
@@ -584,7 +607,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
584
607
|
|
585
608
|
it "replays the triggered response" do
|
586
609
|
expect(response.code).to eql(201)
|
587
|
-
|
610
|
+
expect_response_to_contain_file(pdf_file_path)
|
588
611
|
end
|
589
612
|
|
590
613
|
end
|
@@ -655,7 +678,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
655
678
|
end
|
656
679
|
|
657
680
|
it "responds with the file" do
|
658
|
-
|
681
|
+
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponse::FILE_PATH)
|
659
682
|
end
|
660
683
|
|
661
684
|
end
|
@@ -781,7 +804,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
781
804
|
|
782
805
|
end
|
783
806
|
|
784
|
-
def
|
807
|
+
def expect_response_to_contain_file(path)
|
785
808
|
response_file = Tempfile.new(File.basename(path)).tap do |file|
|
786
809
|
file.write(response.parsed_response)
|
787
810
|
file.flush
|
@@ -0,0 +1,90 @@
|
|
1
|
+
describe HttpStub::Server::RequestParser do
|
2
|
+
|
3
|
+
let(:request_parser) { HttpStub::Server::RequestParser }
|
4
|
+
|
5
|
+
describe "::parse" do
|
6
|
+
|
7
|
+
let(:params) { {} }
|
8
|
+
let(:body_hash) { {} }
|
9
|
+
let(:request) { instance_double(Rack::Request, params: params, body: StringIO.new(body_hash.to_json)) }
|
10
|
+
|
11
|
+
subject { request_parser.parse(request) }
|
12
|
+
|
13
|
+
context "when the request contains a payload parameter" do
|
14
|
+
|
15
|
+
let(:payload) { HttpStub::StubFixture.new.server_payload }
|
16
|
+
let(:params) { { "payload" => payload.to_json } }
|
17
|
+
|
18
|
+
it "returns the payload" do
|
19
|
+
expect(subject).to eql(payload)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the request body contains the payload (for API backwards compatibility)" do
|
25
|
+
|
26
|
+
let(:body_hash) { HttpStub::StubFixture.new.server_payload }
|
27
|
+
|
28
|
+
it "returns the request body" do
|
29
|
+
expect(subject).to eql(body_hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when the payload contains a response file and has a corresponding file parameter" do
|
35
|
+
|
36
|
+
let(:payload_fixture) { HttpStub::StubFixture.new.with_file_response! }
|
37
|
+
let(:payload) { payload_fixture.server_payload }
|
38
|
+
let(:file_params) { { "response_file_#{payload_fixture.id}" => payload_fixture.file_parameter } }
|
39
|
+
let(:params) { { "payload" => payload.to_json }.merge(file_params) }
|
40
|
+
|
41
|
+
it "returns the payload with a response body that contains the file parameter value" do
|
42
|
+
expected_payload = payload.clone.tap { |hash| hash["response"]["body"] = payload_fixture.file_parameter }
|
43
|
+
|
44
|
+
expect(subject).to eql(expected_payload)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when the payload contains triggers" do
|
50
|
+
|
51
|
+
let(:payload_fixture) { HttpStub::StubFixture.new.with_triggers!(trigger_fixtures) }
|
52
|
+
let(:payload) { payload_fixture.server_payload }
|
53
|
+
|
54
|
+
context "and the trigger payloads contain response text" do
|
55
|
+
|
56
|
+
let(:trigger_fixtures) { (1..3).map { HttpStub::StubFixture.new.with_text_response! } }
|
57
|
+
let(:params) { { "payload" => payload.to_json } }
|
58
|
+
|
59
|
+
it "returns the payload unchanged" do
|
60
|
+
expect(subject).to eql(payload)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
context "and the trigger payloads contain a response file with corresponding file parameters" do
|
66
|
+
|
67
|
+
let(:trigger_fixtures) { (1..3).map { HttpStub::StubFixture.new.with_file_response! } }
|
68
|
+
let(:file_params) do
|
69
|
+
trigger_fixtures.reduce({}) do |result, fixture|
|
70
|
+
result.merge("response_file_#{fixture.id}" => fixture.file_parameter)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
let(:params) { { "payload" => payload.to_json }.merge(file_params) }
|
74
|
+
|
75
|
+
it "returns the payload with the trigger response bodies replaced by the files" do
|
76
|
+
expected_payload = payload_fixture.server_payload
|
77
|
+
expected_payload["triggers"].zip(trigger_fixtures.map(&:file_parameter)).each do |trigger, file_param|
|
78
|
+
trigger["response"]["body"] = file_param
|
79
|
+
end
|
80
|
+
|
81
|
+
expect(subject).to eql(expected_payload)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -1,21 +1,31 @@
|
|
1
1
|
describe HttpStub::Server::StubActivatorController do
|
2
2
|
|
3
|
-
let(:request) {
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
3
|
+
let(:request) { instance_double(Rack::Request) }
|
4
|
+
let(:payload) { HttpStub::StubFixture.new.server_payload.merge("activation_uri" => "/some/activation/uri") }
|
5
|
+
let(:the_stub) { instance_double(HttpStub::Server::Stub) }
|
6
|
+
let(:stub_activator) { instance_double(HttpStub::Server::StubActivator, the_stub: the_stub) }
|
7
|
+
let(:stub_activator_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
8
|
+
let(:stub_registry) { instance_double(HttpStub::Server::StubRegistry).as_null_object }
|
8
9
|
|
9
10
|
let(:controller) { HttpStub::Server::StubActivatorController.new(stub_activator_registry, stub_registry) }
|
10
11
|
|
11
|
-
before(:example)
|
12
|
+
before(:example) do
|
13
|
+
allow(HttpStub::Server::RequestParser).to receive(:parse).and_return(payload)
|
14
|
+
allow(HttpStub::Server::StubActivator).to receive(:new).and_return(stub_activator)
|
15
|
+
end
|
12
16
|
|
13
17
|
describe "#register" do
|
14
18
|
|
15
19
|
subject { controller.register(request) }
|
16
20
|
|
17
|
-
it "
|
18
|
-
expect(HttpStub::Server::
|
21
|
+
it "parses the payload from the request" do
|
22
|
+
expect(HttpStub::Server::RequestParser).to receive(:parse).with(request).and_return(payload)
|
23
|
+
|
24
|
+
subject
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates a stub activator with the parsed payload" do
|
28
|
+
expect(HttpStub::Server::StubActivator).to receive(:new).with(payload).and_return(stub_activator)
|
19
29
|
|
20
30
|
subject
|
21
31
|
end
|
@@ -8,43 +8,12 @@ describe HttpStub::Server::StubActivator do
|
|
8
8
|
|
9
9
|
before(:example) { allow(HttpStub::Server::Stub).to receive(:new).and_return(underlying_stub) }
|
10
10
|
|
11
|
-
describe "
|
11
|
+
describe "#constructor" do
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
subject { HttpStub::Server::StubActivator.create_from(request) }
|
16
|
-
|
17
|
-
shared_context "verification a stub activator is created from a request" do
|
18
|
-
|
19
|
-
it "creates a stub activator with JSON parsed from the request payload" do
|
20
|
-
expect(HttpStub::Server::StubActivator).to receive(:new).with(args)
|
21
|
-
|
22
|
-
subject
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns the created stub activator" do
|
26
|
-
created_stub_activator = instance_double(HttpStub::Server::StubActivator)
|
27
|
-
allow(HttpStub::Server::StubActivator).to receive(:new).and_return(created_stub_activator)
|
28
|
-
|
29
|
-
expect(subject).to eql(created_stub_activator)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when the request body contains the payload" do
|
35
|
-
|
36
|
-
let(:request) { double("HttpRequest", params: {}, body: double("RequestBody", read: payload)) }
|
37
|
-
|
38
|
-
include_context "verification a stub activator is created from a request"
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when the request contains a payload parameter" do
|
43
|
-
|
44
|
-
let(:request) { double("HttpRequest", params: { "payload" => payload }) }
|
45
|
-
|
46
|
-
include_context "verification a stub activator is created from a request"
|
13
|
+
it "creates an underlying stub from the provided arguments" do
|
14
|
+
expect(HttpStub::Server::Stub).to receive(:new).with(args)
|
47
15
|
|
16
|
+
stub_activator
|
48
17
|
end
|
49
18
|
|
50
19
|
end
|
@@ -1,20 +1,30 @@
|
|
1
1
|
describe HttpStub::Server::StubController do
|
2
2
|
|
3
|
-
let(:request)
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
3
|
+
let(:request) { instance_double(Rack::Request) }
|
4
|
+
let(:payload) { HttpStub::StubFixture.new.server_payload }
|
5
|
+
let(:response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
6
|
+
let(:the_stub) { instance_double(HttpStub::Server::Stub, response: response) }
|
7
|
+
let(:registry) { instance_double(HttpStub::Server::StubRegistry).as_null_object }
|
7
8
|
|
8
9
|
let(:controller) { HttpStub::Server::StubController.new(registry) }
|
9
10
|
|
10
|
-
before(:example)
|
11
|
+
before(:example) do
|
12
|
+
allow(HttpStub::Server::RequestParser).to receive(:parse).and_return(payload)
|
13
|
+
allow(HttpStub::Server::Stub).to receive(:new).and_return(the_stub)
|
14
|
+
end
|
11
15
|
|
12
16
|
describe "#register" do
|
13
17
|
|
14
18
|
subject { controller.register(request) }
|
15
19
|
|
16
|
-
it "
|
17
|
-
expect(HttpStub::Server::
|
20
|
+
it "parses the payload from the request" do
|
21
|
+
expect(HttpStub::Server::RequestParser).to receive(:parse).with(request).and_return(payload)
|
22
|
+
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates a stub with the parsed payload" do
|
27
|
+
expect(HttpStub::Server::Stub).to receive(:new).with(payload).and_return(the_stub)
|
18
28
|
|
19
29
|
subject
|
20
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_stub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ueckerman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -290,6 +290,7 @@ files:
|
|
290
290
|
- "./lib/http_stub/server/regexp_value_matcher.rb"
|
291
291
|
- "./lib/http_stub/server/registry.rb"
|
292
292
|
- "./lib/http_stub/server/request_header_parser.rb"
|
293
|
+
- "./lib/http_stub/server/request_parser.rb"
|
293
294
|
- "./lib/http_stub/server/response.rb"
|
294
295
|
- "./lib/http_stub/server/response_pipeline.rb"
|
295
296
|
- "./lib/http_stub/server/string_value_matcher.rb"
|
@@ -297,7 +298,6 @@ files:
|
|
297
298
|
- "./lib/http_stub/server/stub_activator.rb"
|
298
299
|
- "./lib/http_stub/server/stub_activator_controller.rb"
|
299
300
|
- "./lib/http_stub/server/stub_controller.rb"
|
300
|
-
- "./lib/http_stub/server/stub_factory.rb"
|
301
301
|
- "./lib/http_stub/server/stub_headers.rb"
|
302
302
|
- "./lib/http_stub/server/stub_parameters.rb"
|
303
303
|
- "./lib/http_stub/server/stub_registry.rb"
|
@@ -350,13 +350,13 @@ files:
|
|
350
350
|
- "./spec/lib/http_stub/server/regexp_value_matcher_spec.rb"
|
351
351
|
- "./spec/lib/http_stub/server/registry_spec.rb"
|
352
352
|
- "./spec/lib/http_stub/server/request_header_parser_spec.rb"
|
353
|
+
- "./spec/lib/http_stub/server/request_parser_spec.rb"
|
353
354
|
- "./spec/lib/http_stub/server/response_pipeline_spec.rb"
|
354
355
|
- "./spec/lib/http_stub/server/response_spec.rb"
|
355
356
|
- "./spec/lib/http_stub/server/string_value_matcher_spec.rb"
|
356
357
|
- "./spec/lib/http_stub/server/stub_activator_controller_spec.rb"
|
357
358
|
- "./spec/lib/http_stub/server/stub_activator_spec.rb"
|
358
359
|
- "./spec/lib/http_stub/server/stub_controller_spec.rb"
|
359
|
-
- "./spec/lib/http_stub/server/stub_factory_spec.rb"
|
360
360
|
- "./spec/lib/http_stub/server/stub_headers_spec.rb"
|
361
361
|
- "./spec/lib/http_stub/server/stub_parameters_spec.rb"
|
362
362
|
- "./spec/lib/http_stub/server/stub_registry_integration_spec.rb"
|
@@ -435,13 +435,13 @@ test_files:
|
|
435
435
|
- "./spec/lib/http_stub/server/regexp_value_matcher_spec.rb"
|
436
436
|
- "./spec/lib/http_stub/server/registry_spec.rb"
|
437
437
|
- "./spec/lib/http_stub/server/request_header_parser_spec.rb"
|
438
|
+
- "./spec/lib/http_stub/server/request_parser_spec.rb"
|
438
439
|
- "./spec/lib/http_stub/server/response_pipeline_spec.rb"
|
439
440
|
- "./spec/lib/http_stub/server/response_spec.rb"
|
440
441
|
- "./spec/lib/http_stub/server/string_value_matcher_spec.rb"
|
441
442
|
- "./spec/lib/http_stub/server/stub_activator_controller_spec.rb"
|
442
443
|
- "./spec/lib/http_stub/server/stub_activator_spec.rb"
|
443
444
|
- "./spec/lib/http_stub/server/stub_controller_spec.rb"
|
444
|
-
- "./spec/lib/http_stub/server/stub_factory_spec.rb"
|
445
445
|
- "./spec/lib/http_stub/server/stub_headers_spec.rb"
|
446
446
|
- "./spec/lib/http_stub/server/stub_parameters_spec.rb"
|
447
447
|
- "./spec/lib/http_stub/server/stub_registry_integration_spec.rb"
|
@@ -1,117 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::StubFactory do
|
2
|
-
|
3
|
-
describe "::create" do
|
4
|
-
|
5
|
-
let(:params) { {} }
|
6
|
-
let(:body_hash) { {} }
|
7
|
-
let(:request) { instance_double(Rack::Request, params: params, body: StringIO.new(body_hash.to_json)) }
|
8
|
-
|
9
|
-
subject { HttpStub::Server::StubFactory.create(request) }
|
10
|
-
|
11
|
-
shared_context "returns the created stub" do
|
12
|
-
|
13
|
-
it "returns the created stub" do
|
14
|
-
stub = instance_double(HttpStub::Server::Stub)
|
15
|
-
allow(HttpStub::Server::Stub).to receive(:new).and_return(stub)
|
16
|
-
|
17
|
-
expect(subject).to eql(stub)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context "when the request contains a payload parameter" do
|
23
|
-
|
24
|
-
let(:payload) { HttpStub::StubFixture.new.server_payload }
|
25
|
-
let(:params) { { "payload" => payload.to_json } }
|
26
|
-
|
27
|
-
it "creates the stub with the payload" do
|
28
|
-
expect(HttpStub::Server::Stub).to receive(:new).with(payload)
|
29
|
-
|
30
|
-
subject
|
31
|
-
end
|
32
|
-
|
33
|
-
include_context "returns the created stub"
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when the request body contains the payload (for API backwards compatibility)" do
|
38
|
-
|
39
|
-
let(:body_hash) { HttpStub::StubFixture.new.server_payload }
|
40
|
-
|
41
|
-
it "creates the stub with the request body" do
|
42
|
-
expect(HttpStub::Server::Stub).to receive(:new).with(body_hash)
|
43
|
-
|
44
|
-
subject
|
45
|
-
end
|
46
|
-
|
47
|
-
include_context "returns the created stub"
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when a stub payload contains a response file and has a corresponding file parameter" do
|
52
|
-
|
53
|
-
let(:stub_fixture) { HttpStub::StubFixture.new.with_file_response! }
|
54
|
-
let(:payload) { stub_fixture.server_payload }
|
55
|
-
let(:file_params) { { "response_file_#{stub_fixture.id}" => stub_fixture.file_parameter } }
|
56
|
-
let(:params) { { "payload" => payload.to_json }.merge(file_params) }
|
57
|
-
|
58
|
-
it "creates the stub with a response body that contains the file parameter value" do
|
59
|
-
expected_args = payload.clone.tap { |hash| hash["response"]["body"] = stub_fixture.file_parameter }
|
60
|
-
expect(HttpStub::Server::Stub).to receive(:new).with(expected_args)
|
61
|
-
|
62
|
-
subject
|
63
|
-
end
|
64
|
-
|
65
|
-
include_context "returns the created stub"
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when a stub payload contains triggers" do
|
70
|
-
|
71
|
-
let(:stub_fixture) { HttpStub::StubFixture.new.with_triggers!(trigger_fixtures) }
|
72
|
-
let(:payload) { stub_fixture.server_payload }
|
73
|
-
|
74
|
-
context "and the trigger payloads contain response text" do
|
75
|
-
|
76
|
-
let(:trigger_fixtures) { (1..3).map { HttpStub::StubFixture.new.with_text_response! } }
|
77
|
-
let(:params) { { "payload" => payload.to_json } }
|
78
|
-
|
79
|
-
it "creates the stub with the stub payload unchanged" do
|
80
|
-
expect(HttpStub::Server::Stub).to receive(:new).with(payload)
|
81
|
-
|
82
|
-
subject
|
83
|
-
end
|
84
|
-
|
85
|
-
include_context "returns the created stub"
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
context "and the trigger payloads contain a response file with corresponding file parameters" do
|
90
|
-
|
91
|
-
let(:trigger_fixtures) { (1..3).map { HttpStub::StubFixture.new.with_file_response! } }
|
92
|
-
let(:file_params) do
|
93
|
-
trigger_fixtures.reduce({}) do |result, fixture|
|
94
|
-
result.merge("response_file_#{fixture.id}" => fixture.file_parameter)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
let(:params) { { "payload" => payload.to_json }.merge(file_params) }
|
98
|
-
|
99
|
-
it "creates the stub with the trigger response bodies replaced by the files" do
|
100
|
-
expected_args = stub_fixture.server_payload
|
101
|
-
expected_args["triggers"].zip(trigger_fixtures.map(&:file_parameter)).each do |trigger, file_param|
|
102
|
-
trigger["response"]["body"] = file_param
|
103
|
-
end
|
104
|
-
expect(HttpStub::Server::Stub).to receive(:new).with(expected_args)
|
105
|
-
|
106
|
-
subject
|
107
|
-
end
|
108
|
-
|
109
|
-
include_context "returns the created stub"
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|