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,8 +1,8 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::StringValueMatcher do
|
|
2
2
|
|
|
3
3
|
let(:stub_value) { "some stub value" }
|
|
4
4
|
|
|
5
|
-
let(:string_value_matcher) { HttpStub::
|
|
5
|
+
let(:string_value_matcher) { HttpStub::Server::StringValueMatcher.new(stub_value) }
|
|
6
6
|
|
|
7
7
|
describe "#match?" do
|
|
8
8
|
|
|
@@ -11,37 +11,37 @@ describe HttpStub::Models::StringValueMatcher do
|
|
|
11
11
|
shared_examples_for "a StringValueMatcher that matches an expected stub value" do
|
|
12
12
|
|
|
13
13
|
it "determines if actual value should be omitted" do
|
|
14
|
-
expect(HttpStub::
|
|
14
|
+
expect(HttpStub::Server::OmittedValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
15
15
|
|
|
16
16
|
perform_match
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "determines if the actual value matches a regular expression" do
|
|
20
|
-
expect(HttpStub::
|
|
20
|
+
expect(HttpStub::Server::RegexpValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
21
21
|
|
|
22
22
|
perform_match
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "determines if the actual value exactly matches the stub value" do
|
|
26
|
-
expect(HttpStub::
|
|
26
|
+
expect(HttpStub::Server::ExactValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
27
27
|
|
|
28
28
|
perform_match
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "determines if actual value should be omitted" do
|
|
32
|
-
expect(HttpStub::
|
|
32
|
+
expect(HttpStub::Server::OmittedValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
33
33
|
|
|
34
34
|
perform_match
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "determines if the actual value matches a regular expression" do
|
|
38
|
-
expect(HttpStub::
|
|
38
|
+
expect(HttpStub::Server::RegexpValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
39
39
|
|
|
40
40
|
perform_match
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "determines if the actual value exactly matches the stub value" do
|
|
44
|
-
expect(HttpStub::
|
|
44
|
+
expect(HttpStub::Server::ExactValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
|
45
45
|
|
|
46
46
|
perform_match
|
|
47
47
|
end
|
|
@@ -68,7 +68,7 @@ describe HttpStub::Models::StringValueMatcher do
|
|
|
68
68
|
|
|
69
69
|
context "when an omitted match occurs" do
|
|
70
70
|
|
|
71
|
-
before(:example) { expect(HttpStub::
|
|
71
|
+
before(:example) { expect(HttpStub::Server::OmittedValueMatcher).to receive(:match?).and_return(true) }
|
|
72
72
|
|
|
73
73
|
it "returns true" do
|
|
74
74
|
expect(perform_match).to be_truthy
|
|
@@ -78,7 +78,7 @@ describe HttpStub::Models::StringValueMatcher do
|
|
|
78
78
|
|
|
79
79
|
context "when a regular expression match occurs" do
|
|
80
80
|
|
|
81
|
-
before(:example) { expect(HttpStub::
|
|
81
|
+
before(:example) { expect(HttpStub::Server::RegexpValueMatcher).to receive(:match?).and_return(true) }
|
|
82
82
|
|
|
83
83
|
it "returns true" do
|
|
84
84
|
expect(perform_match).to be_truthy
|
|
@@ -88,7 +88,7 @@ describe HttpStub::Models::StringValueMatcher do
|
|
|
88
88
|
|
|
89
89
|
context "when an exact match occurs" do
|
|
90
90
|
|
|
91
|
-
before(:example) { expect(HttpStub::
|
|
91
|
+
before(:example) { expect(HttpStub::Server::ExactValueMatcher).to receive(:match?).and_return(true) }
|
|
92
92
|
|
|
93
93
|
it "returns true" do
|
|
94
94
|
expect(perform_match).to be_truthy
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
describe HttpStub::Server::StubActivatorController do
|
|
2
|
+
|
|
3
|
+
let(:request) { double("HttpRequest") }
|
|
4
|
+
let(:the_stub) { double(HttpStub::Server::Stub) }
|
|
5
|
+
let(:stub_activator) { double(HttpStub::Server::StubActivator, the_stub: the_stub) }
|
|
6
|
+
let(:stub_activator_registry) { double("HttpStub::Server::StubActivatorRegistry").as_null_object }
|
|
7
|
+
let(:stub_registry) { double("HttpStub::Server::StubRegistry").as_null_object }
|
|
8
|
+
|
|
9
|
+
let(:controller) { HttpStub::Server::StubActivatorController.new(stub_activator_registry, stub_registry) }
|
|
10
|
+
|
|
11
|
+
before(:example) { allow(HttpStub::Server::StubActivator).to receive(:create_from).and_return(stub_activator) }
|
|
12
|
+
|
|
13
|
+
describe "#register" do
|
|
14
|
+
|
|
15
|
+
subject { controller.register(request) }
|
|
16
|
+
|
|
17
|
+
it "creates a stub activator from the provided request" do
|
|
18
|
+
expect(HttpStub::Server::StubActivator).to receive(:create_from).with(request).and_return(stub_activator)
|
|
19
|
+
|
|
20
|
+
subject
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "adds the created activator to the activator registry with the provided request" do
|
|
24
|
+
expect(stub_activator_registry).to receive(:add).with(stub_activator, request)
|
|
25
|
+
|
|
26
|
+
subject
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns a success response" do
|
|
30
|
+
expect(subject).to eql(HttpStub::Server::Response::SUCCESS)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#activate" do
|
|
36
|
+
|
|
37
|
+
describe "when a stub activator has been registered that is activated by the request" do
|
|
38
|
+
|
|
39
|
+
before(:example) do
|
|
40
|
+
allow(stub_activator_registry).to receive(:find_for).with(request).and_return(stub_activator)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "adds the activators stub to the stub registry" do
|
|
44
|
+
expect(stub_registry).to receive(:add).with(the_stub, request)
|
|
45
|
+
|
|
46
|
+
controller.activate(request)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "returns a success response" do
|
|
50
|
+
expect(controller.activate(request)).to eql(HttpStub::Server::Response::SUCCESS)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "when no stub activator is activated by the request" do
|
|
56
|
+
|
|
57
|
+
before(:example) do
|
|
58
|
+
allow(stub_activator_registry).to receive(:find_for).with(request).and_return(nil)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "does not add a stub to the registry" do
|
|
62
|
+
expect(stub_registry).not_to receive(:add)
|
|
63
|
+
|
|
64
|
+
controller.activate(request)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "returns an empty response" do
|
|
68
|
+
expect(controller.activate(request)).to eql(HttpStub::Server::Response::EMPTY)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "#clear" do
|
|
76
|
+
|
|
77
|
+
it "clears the activator registry" do
|
|
78
|
+
expect(stub_activator_registry).to receive(:clear).with(request)
|
|
79
|
+
|
|
80
|
+
controller.clear(request)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
describe HttpStub::Server::StubActivator do
|
|
2
|
+
|
|
3
|
+
let(:activation_uri) { "/some/activation/uri" }
|
|
4
|
+
let(:args) { { "activation_uri" => activation_uri } }
|
|
5
|
+
let(:underlying_stub) { instance_double(HttpStub::Server::Stub) }
|
|
6
|
+
|
|
7
|
+
let(:stub_activator) { HttpStub::Server::StubActivator.new(args) }
|
|
8
|
+
|
|
9
|
+
before(:example) { allow(HttpStub::Server::Stub).to receive(:new).and_return(underlying_stub) }
|
|
10
|
+
|
|
11
|
+
describe "::create_from" do
|
|
12
|
+
|
|
13
|
+
let(:payload) { args.to_json }
|
|
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"
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "#satisfies?" do
|
|
53
|
+
|
|
54
|
+
let(:request) { double("HttpRequest", path_info: request_path_info) }
|
|
55
|
+
|
|
56
|
+
describe "when the request uri exactly matches the activator's activation uri" do
|
|
57
|
+
|
|
58
|
+
let(:request_path_info) { activation_uri }
|
|
59
|
+
|
|
60
|
+
it "returns true" do
|
|
61
|
+
expect(stub_activator.satisfies?(request)).to be_truthy
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "when the activator's activation uri is a substring of the request uri" do
|
|
67
|
+
|
|
68
|
+
let(:request_path_info) { "#{activation_uri}/with/additional/paths" }
|
|
69
|
+
|
|
70
|
+
it "returns false" do
|
|
71
|
+
expect(stub_activator.satisfies?(request)).to be_falsey
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "when the request uri is completely different to the activator's activation uri" do
|
|
77
|
+
|
|
78
|
+
let(:request_path_info) { "/completely/different/path" }
|
|
79
|
+
|
|
80
|
+
it "returns false" do
|
|
81
|
+
expect(stub_activator.satisfies?(request)).to be_falsey
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "#the_stub" do
|
|
89
|
+
|
|
90
|
+
it "returns a HttpStub::Server::Stub constructed from the activator's arguments" do
|
|
91
|
+
expect(stub_activator.the_stub).to eql(underlying_stub)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "#activation_uri" do
|
|
97
|
+
|
|
98
|
+
it "returns the value provided in the request body" do
|
|
99
|
+
expect(stub_activator.activation_uri).to eql(activation_uri)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "#clear" do
|
|
105
|
+
|
|
106
|
+
it "delegates to a HttpStub::Server::Stub constructed from the activator's arguments" do
|
|
107
|
+
expect(underlying_stub).to receive(:clear)
|
|
108
|
+
|
|
109
|
+
expect(stub_activator.clear)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe "#to_s" do
|
|
115
|
+
|
|
116
|
+
it "returns the string representation of the activation arguments" do
|
|
117
|
+
expect(args).to receive(:to_s).and_return("activation args string")
|
|
118
|
+
|
|
119
|
+
expect(stub_activator.to_s).to eql("activation args string")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
describe HttpStub::Server::StubController do
|
|
2
|
+
|
|
3
|
+
let(:request) { double("HttpRequest") }
|
|
4
|
+
let(:response) { double(HttpStub::Server::Response) }
|
|
5
|
+
let(:the_stub) { double(HttpStub::Server::Stub, response: response) }
|
|
6
|
+
let(:registry) { double(HttpStub::Server::Registry).as_null_object }
|
|
7
|
+
|
|
8
|
+
let(:controller) { HttpStub::Server::StubController.new(registry) }
|
|
9
|
+
|
|
10
|
+
before(:example) { allow(HttpStub::Server::StubFactory).to receive(:create).and_return(the_stub) }
|
|
11
|
+
|
|
12
|
+
describe "#register" do
|
|
13
|
+
|
|
14
|
+
subject { controller.register(request) }
|
|
15
|
+
|
|
16
|
+
it "creates a stub from the provided request via the factory" do
|
|
17
|
+
expect(HttpStub::Server::StubFactory).to receive(:create).with(request).and_return(the_stub)
|
|
18
|
+
|
|
19
|
+
subject
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "adds the stub to the stub registry" do
|
|
23
|
+
expect(registry).to receive(:add).with(the_stub, request)
|
|
24
|
+
|
|
25
|
+
subject
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "returns a success response" do
|
|
29
|
+
expect(subject).to eql(HttpStub::Server::Response::SUCCESS)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#replay" do
|
|
35
|
+
|
|
36
|
+
describe "when a stub has been registered that should be replayed for the request" do
|
|
37
|
+
|
|
38
|
+
before(:example) do
|
|
39
|
+
allow(registry).to receive(:find_for).with(request).and_return(the_stub)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "returns the stubs response" do
|
|
43
|
+
expect(the_stub).to receive(:response).and_return(response)
|
|
44
|
+
|
|
45
|
+
expect(controller.replay(request)).to eql(response)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "when no stub should be replayed for the request" do
|
|
51
|
+
|
|
52
|
+
before(:example) do
|
|
53
|
+
allow(registry).to receive(:find_for).with(request).and_return(nil)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "returns an empty response" do
|
|
57
|
+
expect(controller.replay(request)).to eql(HttpStub::Server::Response::EMPTY)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "#clear" do
|
|
65
|
+
|
|
66
|
+
it "clears the stub registry" do
|
|
67
|
+
expect(registry).to receive(:clear).with(request)
|
|
68
|
+
|
|
69
|
+
controller.clear(request)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::StubHeaders do
|
|
2
2
|
|
|
3
3
|
let(:request) { double("HttpRequest") }
|
|
4
4
|
let(:stubbed_headers) { { "stub_key" => "value" } }
|
|
5
5
|
|
|
6
|
-
let(:stub_headers) { HttpStub::
|
|
6
|
+
let(:stub_headers) { HttpStub::Server::StubHeaders.new(stubbed_headers) }
|
|
7
7
|
|
|
8
8
|
it "is Headers" do
|
|
9
|
-
expect(stub_headers).to be_a(HttpStub::
|
|
9
|
+
expect(stub_headers).to be_a(HttpStub::Server::Headers)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
describe "when stubbed headers are provided" do
|
|
@@ -14,7 +14,7 @@ describe HttpStub::Models::StubHeaders do
|
|
|
14
14
|
it "creates a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
|
|
15
15
|
downcased_and_underscored_hash = { "another_stub_key" => "value" }
|
|
16
16
|
expect(stubbed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
|
17
|
-
expect(HttpStub::
|
|
17
|
+
expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with(downcased_and_underscored_hash)
|
|
18
18
|
|
|
19
19
|
stub_headers
|
|
20
20
|
end
|
|
@@ -26,7 +26,7 @@ describe HttpStub::Models::StubHeaders do
|
|
|
26
26
|
let(:stubbed_headers) { nil }
|
|
27
27
|
|
|
28
28
|
it "creates a regexpable representation of an empty hash" do
|
|
29
|
-
expect(HttpStub::
|
|
29
|
+
expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with({})
|
|
30
30
|
|
|
31
31
|
stub_headers
|
|
32
32
|
end
|
|
@@ -36,15 +36,15 @@ describe HttpStub::Models::StubHeaders do
|
|
|
36
36
|
describe "#match?" do
|
|
37
37
|
|
|
38
38
|
let(:request_headers) { { "request_key" => "value" } }
|
|
39
|
-
let(:regexpable_stubbed_headers) { double(HttpStub::
|
|
39
|
+
let(:regexpable_stubbed_headers) { double(HttpStub::Server::HashWithStringValueMatchers).as_null_object }
|
|
40
40
|
|
|
41
41
|
before(:example) do
|
|
42
|
-
allow(HttpStub::
|
|
43
|
-
allow(HttpStub::
|
|
42
|
+
allow(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_headers)
|
|
43
|
+
allow(HttpStub::Server::RequestHeaderParser).to receive(:parse).with(request).and_return(request_headers)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "parses the requests headers into a hash" do
|
|
47
|
-
expect(HttpStub::
|
|
47
|
+
expect(HttpStub::Server::RequestHeaderParser).to receive(:parse).with(request).and_return(request_headers)
|
|
48
48
|
|
|
49
49
|
stub_headers.match?(request)
|
|
50
50
|
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::StubParameters do
|
|
2
2
|
|
|
3
3
|
let(:request_parameters) { double("RequestParameters") }
|
|
4
4
|
let(:request) { double("HttpRequest", params: request_parameters) }
|
|
5
5
|
|
|
6
6
|
let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
|
|
7
|
-
let(:regexpable_stubbed_paremeters) { double(HttpStub::
|
|
7
|
+
let(:regexpable_stubbed_paremeters) { double(HttpStub::Server::HashWithStringValueMatchers).as_null_object }
|
|
8
8
|
|
|
9
|
-
let(:stub_parameters) { HttpStub::
|
|
9
|
+
let(:stub_parameters) { HttpStub::Server::StubParameters.new(stubbed_parameters) }
|
|
10
10
|
|
|
11
11
|
describe "when stubbed parameters are provided" do
|
|
12
12
|
|
|
13
13
|
it "creates a regexpable representation of the stubbed parameters" do
|
|
14
|
-
expect(HttpStub::
|
|
14
|
+
expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
|
|
15
15
|
|
|
16
16
|
stub_parameters
|
|
17
17
|
end
|
|
@@ -23,7 +23,7 @@ describe HttpStub::Models::StubParameters do
|
|
|
23
23
|
let(:stubbed_parameters) { nil }
|
|
24
24
|
|
|
25
25
|
it "creates a regexpable representation of an empty hash" do
|
|
26
|
-
expect(HttpStub::
|
|
26
|
+
expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with({})
|
|
27
27
|
|
|
28
28
|
stub_parameters
|
|
29
29
|
end
|
|
@@ -33,7 +33,7 @@ describe HttpStub::Models::StubParameters do
|
|
|
33
33
|
describe "#match?" do
|
|
34
34
|
|
|
35
35
|
it "delegates to the regexpable representation of the stubbed parameters to determine a match" do
|
|
36
|
-
allow(HttpStub::
|
|
36
|
+
allow(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_paremeters)
|
|
37
37
|
expect(regexpable_stubbed_paremeters).to receive(:match?).with(request_parameters).and_return(true)
|
|
38
38
|
|
|
39
39
|
expect(stub_parameters.match?(request)).to be(true)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
describe HttpStub::
|
|
1
|
+
describe HttpStub::Server::StubRegistry, "integrating with real stubs" do
|
|
2
2
|
|
|
3
3
|
let(:logger) { double("Logger").as_null_object }
|
|
4
4
|
let(:request) { double("HttpRequest", logger: logger) }
|
|
5
5
|
|
|
6
|
-
let(:stub_registry) { HttpStub::
|
|
6
|
+
let(:stub_registry) { HttpStub::Server::StubRegistry.new }
|
|
7
7
|
|
|
8
8
|
describe "#recall" do
|
|
9
9
|
|
|
@@ -44,7 +44,7 @@ describe HttpStub::Models::StubRegistry, "integrating with real stubs" do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def create_stub(number)
|
|
47
|
-
HttpStub::
|
|
47
|
+
HttpStub::Server::Stub.new(
|
|
48
48
|
{
|
|
49
49
|
"uri" => "/uri#{number}",
|
|
50
50
|
"method" => "get",
|