http_stub 0.19.1 → 0.20.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 +13 -5
- data/lib/http_stub.rb +26 -21
- data/lib/http_stub/configurer/server/command_processor.rb +1 -0
- data/lib/http_stub/server/application.rb +24 -46
- data/lib/http_stub/server/formatted_hash.rb +18 -0
- data/lib/http_stub/server/header_parser.rb +17 -0
- data/lib/http_stub/server/registry.rb +9 -9
- data/lib/http_stub/server/request.rb +19 -0
- data/lib/http_stub/server/request_pipeline.rb +27 -0
- data/lib/http_stub/server/response.rb +7 -3
- data/lib/http_stub/server/scenario.rb +1 -1
- data/lib/http_stub/server/scenario/activator.rb +4 -4
- data/lib/http_stub/server/scenario/controller.rb +8 -8
- data/lib/http_stub/server/scenario/{request_parser.rb → parser.rb} +2 -2
- data/lib/http_stub/server/scenario/{instance.rb → scenario.rb} +2 -2
- data/lib/http_stub/server/stub.rb +1 -1
- data/lib/http_stub/server/stub/controller.rb +8 -8
- data/lib/http_stub/server/stub/empty.rb +34 -0
- data/lib/http_stub/server/stub/match/exact_value_matcher.rb +17 -0
- data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +26 -0
- data/lib/http_stub/server/stub/match/match.rb +20 -0
- data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +23 -0
- data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +18 -0
- data/lib/http_stub/server/stub/match/rule/body.rb +49 -0
- data/lib/http_stub/server/stub/match/rule/headers.rb +31 -0
- data/lib/http_stub/server/stub/match/rule/json_body.rb +39 -0
- data/lib/http_stub/server/stub/match/rule/method.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/parameters.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/simple_body.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/uri.rb +27 -0
- data/lib/http_stub/server/stub/match/string_value_matcher.rb +33 -0
- data/lib/http_stub/server/stub/match/truthy_matcher.rb +25 -0
- data/lib/http_stub/server/stub/{request_parser.rb → parser.rb} +2 -2
- data/lib/http_stub/server/stub/payload_file_consolidator.rb +1 -1
- data/lib/http_stub/server/stub/registry.rb +16 -8
- data/lib/http_stub/server/stub/response/base.rb +2 -2
- data/lib/http_stub/server/stub/stub.rb +44 -0
- data/lib/http_stub/server/stub/triggers.rb +2 -2
- data/lib/http_stub/server/views/_match.haml +20 -0
- data/lib/http_stub/server/views/matches.haml +3 -0
- data/lib/http_stub/server/views/stub.haml +1 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/stub_control_values_spec.rb +6 -3
- data/spec/acceptance/stub_match_spec.rb +142 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +4 -0
- data/spec/lib/http_stub/server/application_integration_spec.rb +17 -18
- data/spec/lib/http_stub/server/application_spec.rb +81 -53
- data/spec/lib/http_stub/server/formatted_hash_spec.rb +54 -0
- data/spec/lib/http_stub/server/{stub/request_header_parser_spec.rb → header_parser_spec.rb} +9 -9
- data/spec/lib/http_stub/server/{request_file_consolidator_spec.rb → payload_file_consolidator_spec.rb} +4 -4
- data/spec/lib/http_stub/server/registry_spec.rb +13 -14
- data/spec/lib/http_stub/server/request_pipeline_spec.rb +80 -0
- data/spec/lib/http_stub/server/request_spec.rb +113 -0
- data/spec/lib/http_stub/server/response_spec.rb +46 -12
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +18 -18
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +18 -15
- data/spec/lib/http_stub/server/scenario/{request_parser_spec.rb → parser_spec.rb} +8 -8
- data/spec/lib/http_stub/server/scenario/{instance_spec.rb → scenario_spec.rb} +7 -5
- data/spec/lib/http_stub/server/scenario_spec.rb +3 -3
- data/spec/lib/http_stub/server/stub/controller_spec.rb +29 -14
- data/spec/lib/http_stub/server/stub/empty_spec.rb +68 -0
- data/spec/lib/http_stub/server/stub/{exact_value_matcher_spec.rb → match/exact_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{hash_with_string_value_matchers_spec.rb → match/hash_with_string_value_matchers_spec.rb} +27 -19
- data/spec/lib/http_stub/server/stub/match/match_spec.rb +40 -0
- data/spec/lib/http_stub/server/stub/{omitted_value_matcher_spec.rb → match/omitted_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{regexp_value_matcher_spec.rb → match/regexp_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{request_body_spec.rb → match/rule/body_spec.rb} +12 -12
- data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +90 -0
- data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb} +9 -10
- data/spec/lib/http_stub/server/stub/{method_spec.rb → match/rule/method_spec.rb} +6 -5
- data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb} +16 -10
- data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +46 -0
- data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +46 -0
- data/spec/lib/http_stub/server/stub/{string_value_matcher_spec.rb → match/string_value_matcher_spec.rb} +30 -26
- data/spec/lib/http_stub/server/stub/match/truthy_matcher_spec.rb +24 -0
- data/spec/lib/http_stub/server/stub/{request_parser_spec.rb → parser_spec.rb} +7 -7
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +5 -5
- data/spec/lib/http_stub/server/stub/registry_spec.rb +114 -43
- data/spec/lib/http_stub/server/stub/response/base_spec.rb +8 -2
- data/spec/lib/http_stub/server/stub/stub_spec.rb +294 -0
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +4 -4
- data/spec/lib/http_stub/server/stub_spec.rb +3 -3
- data/spec/spec_helper.rb +7 -3
- data/spec/support/configurer_integration.rb +1 -0
- data/spec/support/http_stub/empty_configurer.rb +7 -0
- data/spec/support/{scenario_fixture.rb → http_stub/scenario_fixture.rb} +0 -0
- data/spec/support/http_stub/server/request_fixture.rb +25 -0
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +15 -0
- data/spec/support/http_stub/server/stub/match/match_fixture.rb +17 -0
- data/spec/support/{stub_fixture.rb → http_stub/stub_fixture.rb} +0 -0
- data/spec/support/server_integration.rb +1 -0
- metadata +315 -290
- data/lib/http_stub/server/stub/exact_value_matcher.rb +0 -15
- data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +0 -22
- data/lib/http_stub/server/stub/headers.rb +0 -19
- data/lib/http_stub/server/stub/instance.rb +0 -32
- data/lib/http_stub/server/stub/json_request_body.rb +0 -35
- data/lib/http_stub/server/stub/method.rb +0 -23
- data/lib/http_stub/server/stub/omitted_value_matcher.rb +0 -21
- data/lib/http_stub/server/stub/regexp_value_matcher.rb +0 -16
- data/lib/http_stub/server/stub/request_body.rb +0 -44
- data/lib/http_stub/server/stub/request_header_parser.rb +0 -19
- data/lib/http_stub/server/stub/request_headers.rb +0 -28
- data/lib/http_stub/server/stub/request_parameters.rb +0 -23
- data/lib/http_stub/server/stub/simple_request_body.rb +0 -23
- data/lib/http_stub/server/stub/string_value_matcher.rb +0 -31
- data/lib/http_stub/server/stub/truthy_request_matcher.rb +0 -23
- data/lib/http_stub/server/stub/uri.rb +0 -23
- data/spec/lib/http_stub/server/stub/headers_spec.rb +0 -51
- data/spec/lib/http_stub/server/stub/instance_spec.rb +0 -235
- data/spec/lib/http_stub/server/stub/request_headers_spec.rb +0 -68
- data/spec/lib/http_stub/server/stub/simple_request_body_spec.rb +0 -43
- data/spec/lib/http_stub/server/stub/truthy_request_matcher_spec.rb +0 -23
- data/spec/lib/http_stub/server/stub/uri_spec.rb +0 -43
@@ -0,0 +1,113 @@
|
|
1
|
+
describe HttpStub::Server::Request do
|
2
|
+
|
3
|
+
let(:rack_path_info) { "/rack/path/info" }
|
4
|
+
let(:rack_request_method) { "some method" }
|
5
|
+
let(:rack_parameters) { { "parameter_key" => "parameter value" } }
|
6
|
+
let(:rack_body) { "some request body" }
|
7
|
+
let(:rack_request) do
|
8
|
+
instance_double(Rack::Request, path_info: rack_path_info,
|
9
|
+
request_method: rack_request_method,
|
10
|
+
params: rack_parameters,
|
11
|
+
body: StringIO.new(rack_body))
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:server_request) { described_class.new(rack_request) }
|
15
|
+
|
16
|
+
before(:example) do
|
17
|
+
allow(HttpStub::Server::HeaderParser).to receive(:parse).and_return({})
|
18
|
+
allow(HttpStub::Server::FormattedHash).to receive(:new)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#uri" do
|
22
|
+
|
23
|
+
it "is the rack request path information" do
|
24
|
+
expect(server_request.uri).to eql(rack_path_info)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#method" do
|
30
|
+
|
31
|
+
subject { server_request.method }
|
32
|
+
|
33
|
+
it "is the rack request method" do
|
34
|
+
expect(subject).to eql(rack_request_method)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#headers" do
|
40
|
+
|
41
|
+
let(:parsed_headers) { { "parsed_header_key" => "parsed header value" } }
|
42
|
+
let(:formatted_hash) { instance_double(HttpStub::Server::FormattedHash) }
|
43
|
+
|
44
|
+
subject { server_request.headers }
|
45
|
+
|
46
|
+
before(:example) do
|
47
|
+
allow(HttpStub::Server::HeaderParser).to receive(:parse).and_return(parsed_headers)
|
48
|
+
allow(HttpStub::Server::FormattedHash).to receive(:new).with(parsed_headers, anything).and_return(formatted_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "parses the headers from the rack request via the header parser" do
|
52
|
+
expect(HttpStub::Server::HeaderParser).to receive(:parse).with(rack_request)
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates a formatted hash containing the parsed headers" do
|
58
|
+
expect(HttpStub::Server::FormattedHash).to receive(:new).with(parsed_headers, anything)
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
it "creates a formatted hash formatted by a ':' request value delimiter" do
|
64
|
+
expect(HttpStub::Server::FormattedHash).to receive(:new).with(anything, ":")
|
65
|
+
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is the formattted hash" do
|
70
|
+
expect(subject).to eql(formatted_hash)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#parameters" do
|
76
|
+
|
77
|
+
let(:formatted_hash) { instance_double(HttpStub::Server::FormattedHash) }
|
78
|
+
|
79
|
+
subject { server_request.parameters }
|
80
|
+
|
81
|
+
before(:example) do
|
82
|
+
allow(HttpStub::Server::FormattedHash).to receive(:new).with(rack_parameters, anything).and_return(formatted_hash)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "creates a formatted hash containing the rack request parameters" do
|
86
|
+
expect(HttpStub::Server::FormattedHash).to receive(:new).with(rack_parameters, anything)
|
87
|
+
|
88
|
+
subject
|
89
|
+
end
|
90
|
+
|
91
|
+
it "creates a formatted hash with a '=' request value delimiter" do
|
92
|
+
expect(HttpStub::Server::FormattedHash).to receive(:new).with(anything, "=")
|
93
|
+
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
it "is the formatted hash" do
|
98
|
+
expect(subject).to eql(formatted_hash)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#body" do
|
104
|
+
|
105
|
+
subject { server_request.body }
|
106
|
+
|
107
|
+
it "is the read rack request body" do
|
108
|
+
expect(subject).to eql(rack_body)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -1,39 +1,73 @@
|
|
1
1
|
describe HttpStub::Server::Response do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
let(:response) { HttpStub::Server::Response::SUCCESS }
|
3
|
+
shared_examples_for "a success response" do
|
6
4
|
|
7
5
|
it "has a status of 200" do
|
8
|
-
expect(
|
6
|
+
expect(subject.status).to eql(200)
|
9
7
|
end
|
10
8
|
|
11
9
|
it "has a body containing OK to visually indicate success to those interacting via a browser" do
|
12
|
-
expect(
|
10
|
+
expect(subject.body).to match(/OK/)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "::success" do
|
16
|
+
|
17
|
+
subject { HttpStub::Server::Response::success }
|
18
|
+
|
19
|
+
it_behaves_like "a success response"
|
20
|
+
|
21
|
+
context "when headers are provided" do
|
22
|
+
|
23
|
+
let(:headers) { { "response_header_key" => "response header value" } }
|
24
|
+
|
25
|
+
subject { HttpStub::Server::Response::success(headers) }
|
26
|
+
|
27
|
+
it "established the headers" do
|
28
|
+
expect(subject.headers).to eql(headers)
|
29
|
+
end
|
30
|
+
|
13
31
|
end
|
14
32
|
|
15
33
|
end
|
16
34
|
|
17
|
-
describe "::
|
35
|
+
describe "::SUCCESS" do
|
36
|
+
|
37
|
+
subject { HttpStub::Server::Response::SUCCESS }
|
38
|
+
|
39
|
+
it_behaves_like "a success response"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "::NOT_FOUND" do
|
18
44
|
|
19
|
-
|
45
|
+
subject { HttpStub::Server::Response::NOT_FOUND }
|
20
46
|
|
21
47
|
it "has a status of 404" do
|
22
|
-
expect(
|
48
|
+
expect(subject.status).to eql(404)
|
23
49
|
end
|
24
50
|
|
25
|
-
it "has a body containing
|
26
|
-
expect(
|
51
|
+
it "has a body containing NOT FOUND to visually indicate the response to those interacting via a browser" do
|
52
|
+
expect(subject.body).to match(/NOT FOUND/)
|
27
53
|
end
|
28
54
|
|
29
55
|
end
|
30
56
|
|
31
57
|
describe "::EMPTY" do
|
32
58
|
|
33
|
-
|
59
|
+
subject { HttpStub::Server::Response::EMPTY }
|
60
|
+
|
61
|
+
it "has a status of 200" do
|
62
|
+
expect(subject.status).to eql(200)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has no body" do
|
66
|
+
expect(subject.body).to be(nil)
|
67
|
+
end
|
34
68
|
|
35
69
|
it "is empty" do
|
36
|
-
expect(
|
70
|
+
expect(subject).to be_empty
|
37
71
|
end
|
38
72
|
|
39
73
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
describe HttpStub::Server::Scenario::Activator do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:stubs)
|
3
|
+
let(:logger) { instance_double(Logger) }
|
4
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
5
5
|
let(:triggered_scenario_names) { [] }
|
6
|
-
let(:scenario)
|
6
|
+
let(:scenario) do
|
7
7
|
instance_double(
|
8
|
-
HttpStub::Server::Scenario::
|
8
|
+
HttpStub::Server::Scenario::Scenario, stubs: stubs, triggered_scenario_names: triggered_scenario_names
|
9
9
|
)
|
10
10
|
end
|
11
|
-
let(:scenario_registry)
|
12
|
-
let(:stub_registry)
|
13
|
-
let(:activator_class)
|
11
|
+
let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
12
|
+
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
13
|
+
let(:activator_class) { HttpStub::Server::Scenario::Activator }
|
14
14
|
|
15
15
|
let(:activator) { activator_class.new(scenario_registry, stub_registry) }
|
16
16
|
|
17
17
|
describe "#activate" do
|
18
18
|
|
19
|
-
subject { activator.activate(scenario,
|
19
|
+
subject { activator.activate(scenario, logger) }
|
20
20
|
|
21
|
-
it "adds the scenario's stubs to the stub registry with the provided
|
22
|
-
expect(stub_registry).to receive(:concat).with(stubs,
|
21
|
+
it "adds the scenario's stubs to the stub registry with the provided logger" do
|
22
|
+
expect(stub_registry).to receive(:concat).with(stubs, logger)
|
23
23
|
|
24
24
|
subject
|
25
25
|
end
|
@@ -29,14 +29,14 @@ describe HttpStub::Server::Scenario::Activator do
|
|
29
29
|
let(:triggered_scenario_names) { (1..3).map { |i| "triggered_scenario_name/#{i}" } }
|
30
30
|
let(:triggered_scenarios) do
|
31
31
|
triggered_scenario_names.map do
|
32
|
-
instance_double(HttpStub::Server::Scenario::
|
32
|
+
instance_double(HttpStub::Server::Scenario::Scenario, stubs: [], triggered_scenario_names: [])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
before(:each) do
|
37
37
|
triggered_scenario_names.zip(triggered_scenarios).each do |triggered_scenario_name, triggered_scenario|
|
38
38
|
allow(scenario_registry).to(
|
39
|
-
receive(:find).with(
|
39
|
+
receive(:find).with(triggered_scenario_name, anything).and_return(triggered_scenario)
|
40
40
|
)
|
41
41
|
end
|
42
42
|
end
|
@@ -44,7 +44,7 @@ describe HttpStub::Server::Scenario::Activator do
|
|
44
44
|
it "finds each triggered scenario in the scenario registry" do
|
45
45
|
triggered_scenario_names.zip(triggered_scenarios).each do |triggered_scenario_name, triggered_scenario|
|
46
46
|
expect(scenario_registry).to(
|
47
|
-
receive(:find).with(
|
47
|
+
receive(:find).with(triggered_scenario_name, logger).and_return(triggered_scenario)
|
48
48
|
)
|
49
49
|
end
|
50
50
|
|
@@ -62,8 +62,8 @@ describe HttpStub::Server::Scenario::Activator do
|
|
62
62
|
@activate_args = []
|
63
63
|
end
|
64
64
|
|
65
|
-
def activate(scenario,
|
66
|
-
@activate_args << [ scenario,
|
65
|
+
def activate(scenario, logger)
|
66
|
+
@activate_args << [ scenario, logger ]
|
67
67
|
super
|
68
68
|
end
|
69
69
|
|
@@ -72,8 +72,8 @@ describe HttpStub::Server::Scenario::Activator do
|
|
72
72
|
let(:activator_class) { HttpStub::Server::Scenario::ActivatorRetainingActivateArgs }
|
73
73
|
|
74
74
|
it "activates the scenario's" do
|
75
|
-
expected_activate_args = triggered_scenarios.reduce([ [ scenario,
|
76
|
-
result << [ triggered_scenario,
|
75
|
+
expected_activate_args = triggered_scenarios.reduce([ [ scenario, logger ] ]) do |result, triggered_scenario|
|
76
|
+
result << [ triggered_scenario, logger ]
|
77
77
|
end
|
78
78
|
|
79
79
|
subject
|
@@ -89,7 +89,7 @@ describe HttpStub::Server::Scenario::Activator do
|
|
89
89
|
|
90
90
|
before(:example) do
|
91
91
|
allow(scenario_registry).to(
|
92
|
-
receive(:find).with(
|
92
|
+
receive(:find).with(scenario_name_not_found, anything).and_return(nil)
|
93
93
|
)
|
94
94
|
end
|
95
95
|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
describe HttpStub::Server::Scenario::Controller do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:request) { instance_double(
|
3
|
+
let(:request_uri) { "/some/request/path" }
|
4
|
+
let(:request) { instance_double(HttpStub::Server::Request, uri: request_uri) }
|
5
|
+
let(:logger) { instance_double(Logger) }
|
5
6
|
let(:payload) { HttpStub::ScenarioFixture.new.server_payload }
|
6
|
-
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::
|
7
|
-
let(:scenario) { instance_double(HttpStub::Server::Scenario::
|
7
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
8
|
+
let(:scenario) { instance_double(HttpStub::Server::Scenario::Scenario, stubs: stubs) }
|
8
9
|
let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
9
10
|
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
10
11
|
let(:activator) { instance_double(HttpStub::Server::Scenario::Activator).as_null_object }
|
@@ -13,16 +14,16 @@ describe HttpStub::Server::Scenario::Controller do
|
|
13
14
|
|
14
15
|
before(:example) do
|
15
16
|
allow(HttpStub::Server::Scenario::Activator).to receive(:new).and_return(activator)
|
16
|
-
allow(HttpStub::Server::Scenario::
|
17
|
+
allow(HttpStub::Server::Scenario::Parser).to receive(:parse).and_return(payload)
|
17
18
|
allow(HttpStub::Server::Scenario).to receive(:create).and_return(scenario)
|
18
19
|
end
|
19
20
|
|
20
21
|
describe "#register" do
|
21
22
|
|
22
|
-
subject { controller.register(request) }
|
23
|
+
subject { controller.register(request, logger) }
|
23
24
|
|
24
25
|
it "parses the payload from the request" do
|
25
|
-
expect(HttpStub::Server::Scenario::
|
26
|
+
expect(HttpStub::Server::Scenario::Parser).to receive(:parse).with(request).and_return(payload)
|
26
27
|
|
27
28
|
subject
|
28
29
|
end
|
@@ -33,8 +34,8 @@ describe HttpStub::Server::Scenario::Controller do
|
|
33
34
|
subject
|
34
35
|
end
|
35
36
|
|
36
|
-
it "adds the created scenario to the scenario registry with the provided
|
37
|
-
expect(scenario_registry).to receive(:add).with(scenario,
|
37
|
+
it "adds the created scenario to the scenario registry with the provided logger" do
|
38
|
+
expect(scenario_registry).to receive(:add).with(scenario, logger)
|
38
39
|
|
39
40
|
subject
|
40
41
|
end
|
@@ -47,20 +48,20 @@ describe HttpStub::Server::Scenario::Controller do
|
|
47
48
|
|
48
49
|
describe "#activate" do
|
49
50
|
|
50
|
-
subject { controller.activate(request) }
|
51
|
+
subject { controller.activate(request, logger) }
|
51
52
|
|
52
53
|
it "finds a scenario whose name matches the request path omitting the '/' prefix" do
|
53
|
-
expect(scenario_registry).to receive(:find).with(
|
54
|
+
expect(scenario_registry).to receive(:find).with("some/request/path", logger)
|
54
55
|
|
55
56
|
subject
|
56
57
|
end
|
57
58
|
|
58
|
-
describe "when a scenario is found that
|
59
|
+
describe "when a scenario is found that matches the request" do
|
59
60
|
|
60
61
|
before(:example) { allow(scenario_registry).to receive(:find).and_return(scenario) }
|
61
62
|
|
62
63
|
it "activates the scenario via the activator" do
|
63
|
-
expect(activator).to receive(:activate).with(scenario,
|
64
|
+
expect(activator).to receive(:activate).with(scenario, logger)
|
64
65
|
|
65
66
|
subject
|
66
67
|
end
|
@@ -91,10 +92,12 @@ describe HttpStub::Server::Scenario::Controller do
|
|
91
92
|
|
92
93
|
describe "#clear" do
|
93
94
|
|
95
|
+
subject { controller.clear(logger) }
|
96
|
+
|
94
97
|
it "clears the scenario registry" do
|
95
|
-
expect(scenario_registry).to receive(:clear).with(
|
98
|
+
expect(scenario_registry).to receive(:clear).with(logger)
|
96
99
|
|
97
|
-
|
100
|
+
subject
|
98
101
|
end
|
99
102
|
|
100
103
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
describe HttpStub::Server::Scenario::
|
1
|
+
describe HttpStub::Server::Scenario::Parser do
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:parser) { described_class }
|
4
4
|
|
5
5
|
describe "::parse" do
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:body_hash)
|
9
|
-
let(:request)
|
7
|
+
let(:parameters) { {} }
|
8
|
+
let(:body_hash) { {} }
|
9
|
+
let(:request) { instance_double(HttpStub::Server::Request, parameters: parameters, body: body_hash.to_json) }
|
10
10
|
|
11
|
-
subject {
|
11
|
+
subject { parser.parse(request) }
|
12
12
|
|
13
13
|
context "when the request contains many stubs" do
|
14
14
|
|
15
15
|
let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(3).server_payload }
|
16
16
|
let(:stub_payloads) { payload["stubs"] }
|
17
|
-
let(:
|
17
|
+
let(:parameters) { { "payload" => payload.to_json } }
|
18
18
|
|
19
19
|
it "consolidates any files into each stub payload" do
|
20
20
|
stub_payloads.each do |stub_payload|
|
@@ -38,7 +38,7 @@ describe HttpStub::Server::Scenario::RequestParser do
|
|
38
38
|
|
39
39
|
let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(1).server_payload }
|
40
40
|
let(:stub_payload) { payload["stubs"].first }
|
41
|
-
let(:
|
41
|
+
let(:parameters) { { "payload" => payload.to_json } }
|
42
42
|
|
43
43
|
it "consolidates any file into the stub payload" do
|
44
44
|
expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, request)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
describe HttpStub::Server::Scenario::
|
1
|
+
describe HttpStub::Server::Scenario::Scenario do
|
2
2
|
|
3
3
|
let(:name) { "some_scenario_name" }
|
4
4
|
let(:number_of_stubs) { 3 }
|
5
|
-
let(:stubs) { (1..number_of_stubs).map { instance_double(HttpStub::Server::Stub::
|
5
|
+
let(:stubs) { (1..number_of_stubs).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
6
6
|
let(:triggered_scenario_names) { (1..3).map { |i| "triggered/scenario/name/#{i}" } }
|
7
7
|
let(:args) do
|
8
8
|
HttpStub::ScenarioFixture.new.with_name!(name).
|
@@ -11,7 +11,7 @@ describe HttpStub::Server::Scenario::Instance do
|
|
11
11
|
server_payload
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:scenario) { HttpStub::Server::Scenario::
|
14
|
+
let(:scenario) { HttpStub::Server::Scenario::Scenario.new(args) }
|
15
15
|
|
16
16
|
before(:example) { allow(HttpStub::Server::Stub).to receive(:create).and_return(*stubs) }
|
17
17
|
|
@@ -43,9 +43,11 @@ describe HttpStub::Server::Scenario::Instance do
|
|
43
43
|
|
44
44
|
end
|
45
45
|
|
46
|
-
describe "#
|
46
|
+
describe "#matches?" do
|
47
47
|
|
48
|
-
|
48
|
+
let(:logger) { instance_double(Logger) }
|
49
|
+
|
50
|
+
subject { scenario.matches?(other_name, logger) }
|
49
51
|
|
50
52
|
describe "when the scenario's name exactly matches the provided name" do
|
51
53
|
|
@@ -7,14 +7,14 @@ describe HttpStub::Server::Scenario do
|
|
7
7
|
subject { HttpStub::Server::Scenario.create(args) }
|
8
8
|
|
9
9
|
it "creates a scenario instance with the provided arguments" do
|
10
|
-
expect(HttpStub::Server::Scenario::
|
10
|
+
expect(HttpStub::Server::Scenario::Scenario).to receive(:new).with(args)
|
11
11
|
|
12
12
|
subject
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns the created scenario" do
|
16
|
-
scenario = instance_double(HttpStub::Server::Scenario::
|
17
|
-
allow(HttpStub::Server::Scenario::
|
16
|
+
scenario = instance_double(HttpStub::Server::Scenario::Scenario)
|
17
|
+
allow(HttpStub::Server::Scenario::Scenario).to receive(:new).and_return(scenario)
|
18
18
|
|
19
19
|
expect(subject).to eql(scenario)
|
20
20
|
end
|