http_stub 0.15.5 → 0.16.0.pre1
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 +37 -27
- data/lib/http_stub/configurer.rb +2 -2
- data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
- data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
- data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
- data/lib/http_stub/configurer/request/http/factory.rb +8 -2
- data/lib/http_stub/configurer/request/scenario.rb +29 -0
- data/lib/http_stub/configurer/server/facade.rb +7 -7
- data/lib/http_stub/server/application.rb +21 -14
- data/lib/http_stub/server/registry.rb +7 -3
- data/lib/http_stub/server/response.rb +3 -3
- data/lib/http_stub/server/scenario.rb +12 -0
- data/lib/http_stub/server/scenario/activator.rb +25 -0
- data/lib/http_stub/server/scenario/controller.rb +36 -0
- data/lib/http_stub/server/scenario/instance.rb +36 -0
- data/lib/http_stub/server/scenario/request_parser.rb +19 -0
- data/lib/http_stub/server/stub.rb +3 -23
- data/lib/http_stub/server/stub/controller.rb +30 -0
- data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
- data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
- data/lib/http_stub/server/stub/headers.rb +19 -0
- data/lib/http_stub/server/stub/instance.rb +31 -0
- data/lib/http_stub/server/stub/method.rb +23 -0
- data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
- data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
- data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
- data/lib/http_stub/server/stub/registry.rb +31 -0
- data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
- data/lib/http_stub/server/stub/request_headers.rb +28 -0
- data/lib/http_stub/server/stub/request_parameters.rb +23 -0
- data/lib/http_stub/server/stub/request_parser.rb +17 -0
- data/lib/http_stub/server/stub/response.rb +16 -0
- data/lib/http_stub/server/stub/response/base.rb +64 -0
- data/lib/http_stub/server/stub/response/file.rb +36 -0
- data/lib/http_stub/server/stub/response/text.rb +19 -0
- data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
- data/lib/http_stub/server/stub/triggers.rb +25 -0
- data/lib/http_stub/server/stub/uri.rb +23 -0
- data/lib/http_stub/server/views/_scenario.haml +16 -0
- data/lib/http_stub/server/views/application.sass +4 -0
- data/lib/http_stub/server/views/scenarios.haml +3 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/activator_spec.rb +81 -0
- data/spec/acceptance/configurer_initialization_spec.rb +158 -0
- data/spec/acceptance/scenario_spec.rb +91 -0
- data/spec/acceptance/stub_control_values_spec.rb +160 -0
- data/spec/acceptance/stub_spec.rb +290 -0
- data/spec/acceptance/stub_trigger_spec.rb +144 -0
- data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
- data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
- data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
- data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
- data/spec/lib/http_stub/configurer_spec.rb +1 -1
- data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
- data/spec/lib/http_stub/server/application_spec.rb +40 -38
- data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
- data/spec/lib/http_stub/server/registry_spec.rb +66 -17
- data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
- data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
- data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
- data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
- data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
- data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
- data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
- data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
- data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
- data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
- data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
- data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
- data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
- data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
- data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
- data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
- data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
- data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
- data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
- data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
- data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
- data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
- data/spec/lib/http_stub/server/stub_spec.rb +10 -185
- data/spec/spec_helper.rb +10 -5
- data/spec/support/configurer_integration.rb +24 -0
- data/spec/support/scenario_fixture.rb +33 -0
- data/spec/support/stub_fixture.rb +1 -1
- metadata +126 -84
- data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
- data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
- data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
- data/lib/http_stub/server/exact_value_matcher.rb +0 -13
- data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
- data/lib/http_stub/server/headers.rb +0 -17
- data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
- data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
- data/lib/http_stub/server/request_header_parser.rb +0 -17
- data/lib/http_stub/server/request_parser.rb +0 -29
- data/lib/http_stub/server/string_value_matcher.rb +0 -29
- data/lib/http_stub/server/stub_activator.rb +0 -30
- data/lib/http_stub/server/stub_activator_controller.rb +0 -34
- data/lib/http_stub/server/stub_controller.rb +0 -28
- data/lib/http_stub/server/stub_headers.rb +0 -24
- data/lib/http_stub/server/stub_parameters.rb +0 -21
- data/lib/http_stub/server/stub_registry.rb +0 -29
- data/lib/http_stub/server/stub_response.rb +0 -14
- data/lib/http_stub/server/stub_response/base.rb +0 -62
- data/lib/http_stub/server/stub_response/file.rb +0 -34
- data/lib/http_stub/server/stub_response/text.rb +0 -17
- data/lib/http_stub/server/stub_triggers.rb +0 -23
- data/lib/http_stub/server/stub_uri.rb +0 -21
- data/lib/http_stub/server/views/stub_activators.haml +0 -6
- data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
- data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
- data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
- data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
- data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
- data/spec/lib/http_stub/server/stub_uri_spec.rb +0 -42
@@ -0,0 +1,56 @@
|
|
1
|
+
describe HttpStub::Server::Stub::RequestParser do
|
2
|
+
|
3
|
+
let(:request_parser) { described_class }
|
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 "consolidates any files into the payload" do
|
19
|
+
expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(payload, request)
|
20
|
+
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the consolidated payload" do
|
25
|
+
consolidated_payload = { consolidated_payload_key: "consolidated payload value" }
|
26
|
+
allow(HttpStub::Server::Stub::PayloadFileConsolidator).to(
|
27
|
+
receive(:consolidate!).and_return(consolidated_payload)
|
28
|
+
)
|
29
|
+
|
30
|
+
expect(subject).to eql(consolidated_payload)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the request body contains the payload (for API backwards compatibility)" do
|
36
|
+
|
37
|
+
let(:body_hash) { HttpStub::StubFixture.new.server_payload }
|
38
|
+
|
39
|
+
it "consolidates any files into the body" do
|
40
|
+
expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(body_hash, request)
|
41
|
+
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns the consolidated body" do
|
46
|
+
consolidated_body = { consolidated_body_key: "consolidated body value" }
|
47
|
+
allow(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).and_return(consolidated_body)
|
48
|
+
|
49
|
+
expect(subject).to eql(consolidated_body)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::Stub::Response::Base do
|
2
2
|
|
3
3
|
let(:status) { 202 }
|
4
4
|
let(:headers) { nil }
|
@@ -8,7 +8,7 @@ describe HttpStub::Server::StubResponse::Base do
|
|
8
8
|
{ "status" => status, "headers" => headers, "body" => body, "delay_in_seconds" => delay_in_seconds }
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:testable_response_class) { Class.new(HttpStub::Server::
|
11
|
+
let(:testable_response_class) { Class.new(HttpStub::Server::Stub::Response::Base) }
|
12
12
|
|
13
13
|
let(:response) { testable_response_class.new(args) }
|
14
14
|
|
@@ -97,7 +97,7 @@ describe HttpStub::Server::StubResponse::Base do
|
|
97
97
|
let(:response_header_hash) { response.headers.to_hash }
|
98
98
|
|
99
99
|
it "is Headers" do
|
100
|
-
expect(response.headers).to be_a(HttpStub::Server::Headers)
|
100
|
+
expect(response.headers).to be_a(HttpStub::Server::Stub::Headers)
|
101
101
|
end
|
102
102
|
|
103
103
|
context "when default headers have been added" do
|
@@ -186,10 +186,10 @@ describe HttpStub::Server::StubResponse::Base do
|
|
186
186
|
|
187
187
|
describe "#type" do
|
188
188
|
|
189
|
-
class HttpStub::Server::
|
189
|
+
class HttpStub::Server::Stub::Response::TestableBaseClass < HttpStub::Server::Stub::Response::Base
|
190
190
|
end
|
191
191
|
|
192
|
-
let(:testable_response_class) { HttpStub::Server::
|
192
|
+
let(:testable_response_class) { HttpStub::Server::Stub::Response::TestableBaseClass }
|
193
193
|
|
194
194
|
it "returns the name of the concrete base instance underscored" do
|
195
195
|
expect(response.type).to eql("testable_base_class")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::Stub::Response::File do
|
2
2
|
|
3
3
|
let(:status) { 321 }
|
4
4
|
let(:headers) { {} }
|
@@ -12,10 +12,10 @@ describe HttpStub::Server::StubResponse::File do
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:response_file) { HttpStub::Server::
|
15
|
+
let(:response_file) { HttpStub::Server::Stub::Response::File.new(args) }
|
16
16
|
|
17
17
|
it "is a base response" do
|
18
|
-
expect(response_file).to be_a(HttpStub::Server::
|
18
|
+
expect(response_file).to be_a(HttpStub::Server::Stub::Response::Base)
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#uri" do
|
@@ -1,14 +1,14 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::Stub::Response::Text do
|
2
2
|
|
3
3
|
let(:status) { 123 }
|
4
4
|
let(:headers) { {} }
|
5
5
|
let(:body) { "Some text body" }
|
6
6
|
let(:args) { { "status" => status, "headers" => headers, "body" => body } }
|
7
7
|
|
8
|
-
let(:response_text) { HttpStub::Server::
|
8
|
+
let(:response_text) { HttpStub::Server::Stub::Response::Text.new(args) }
|
9
9
|
|
10
10
|
it "is a base response" do
|
11
|
-
expect(response_text).to be_a(HttpStub::Server::
|
11
|
+
expect(response_text).to be_a(HttpStub::Server::Stub::Response::Base)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#serve_on" do
|
@@ -1,24 +1,24 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::Stub::Response do
|
2
2
|
|
3
3
|
describe "::create" do
|
4
4
|
|
5
5
|
let(:response_args) { { "body" => body } }
|
6
6
|
|
7
|
-
subject { HttpStub::Server::
|
7
|
+
subject { HttpStub::Server::Stub::Response.create(response_args) }
|
8
8
|
|
9
9
|
context "when the body contains text" do
|
10
10
|
|
11
11
|
let(:body) { "some text" }
|
12
12
|
|
13
13
|
it "creates a text response" do
|
14
|
-
expect(HttpStub::Server::
|
14
|
+
expect(HttpStub::Server::Stub::Response::Text).to receive(:new).with(response_args)
|
15
15
|
|
16
16
|
subject
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns the created response" do
|
20
|
-
response = instance_double(HttpStub::Server::
|
21
|
-
allow(HttpStub::Server::
|
20
|
+
response = instance_double(HttpStub::Server::Stub::Response::Text)
|
21
|
+
allow(HttpStub::Server::Stub::Response::Text).to receive(:new).and_return(response)
|
22
22
|
|
23
23
|
expect(subject).to eql(response)
|
24
24
|
end
|
@@ -30,14 +30,14 @@ describe HttpStub::Server::StubResponse do
|
|
30
30
|
let(:body) { { "file" => { "path" => "a/file.path", "name" => "a_file.name" } } }
|
31
31
|
|
32
32
|
it "creates a file response" do
|
33
|
-
expect(HttpStub::Server::
|
33
|
+
expect(HttpStub::Server::Stub::Response::File).to receive(:new).with(response_args)
|
34
34
|
|
35
35
|
subject
|
36
36
|
end
|
37
37
|
|
38
38
|
it "returns the created response" do
|
39
|
-
response = instance_double(HttpStub::Server::
|
40
|
-
allow(HttpStub::Server::
|
39
|
+
response = instance_double(HttpStub::Server::Stub::Response::File)
|
40
|
+
allow(HttpStub::Server::Stub::Response::File).to receive(:new).and_return(response)
|
41
41
|
|
42
42
|
expect(subject).to eql(response)
|
43
43
|
end
|
data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
|
-
describe HttpStub::Server::StringValueMatcher do
|
1
|
+
describe HttpStub::Server::Stub::StringValueMatcher do
|
2
2
|
|
3
3
|
let(:stub_value) { "some stub value" }
|
4
4
|
|
5
|
-
let(:string_value_matcher) { HttpStub::Server::StringValueMatcher.new(stub_value) }
|
5
|
+
let(:string_value_matcher) { HttpStub::Server::Stub::StringValueMatcher.new(stub_value) }
|
6
6
|
|
7
7
|
describe "#match?" do
|
8
8
|
|
@@ -11,37 +11,49 @@ describe HttpStub::Server::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::Server::OmittedValueMatcher).to
|
14
|
+
expect(HttpStub::Server::Stub::OmittedValueMatcher).to(
|
15
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
16
|
+
)
|
15
17
|
|
16
18
|
perform_match
|
17
19
|
end
|
18
20
|
|
19
21
|
it "determines if the actual value matches a regular expression" do
|
20
|
-
expect(HttpStub::Server::RegexpValueMatcher).to
|
22
|
+
expect(HttpStub::Server::Stub::RegexpValueMatcher).to(
|
23
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
24
|
+
)
|
21
25
|
|
22
26
|
perform_match
|
23
27
|
end
|
24
28
|
|
25
29
|
it "determines if the actual value exactly matches the stub value" do
|
26
|
-
expect(HttpStub::Server::ExactValueMatcher).to
|
30
|
+
expect(HttpStub::Server::Stub::ExactValueMatcher).to(
|
31
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
32
|
+
)
|
27
33
|
|
28
34
|
perform_match
|
29
35
|
end
|
30
36
|
|
31
37
|
it "determines if actual value should be omitted" do
|
32
|
-
expect(HttpStub::Server::OmittedValueMatcher).to
|
38
|
+
expect(HttpStub::Server::Stub::OmittedValueMatcher).to(
|
39
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
40
|
+
)
|
33
41
|
|
34
42
|
perform_match
|
35
43
|
end
|
36
44
|
|
37
45
|
it "determines if the actual value matches a regular expression" do
|
38
|
-
expect(HttpStub::Server::RegexpValueMatcher).to
|
46
|
+
expect(HttpStub::Server::Stub::RegexpValueMatcher).to(
|
47
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
48
|
+
)
|
39
49
|
|
40
50
|
perform_match
|
41
51
|
end
|
42
52
|
|
43
53
|
it "determines if the actual value exactly matches the stub value" do
|
44
|
-
expect(HttpStub::Server::ExactValueMatcher).to
|
54
|
+
expect(HttpStub::Server::Stub::ExactValueMatcher).to(
|
55
|
+
receive(:match?).with(expected_stub_match_value, actual_value)
|
56
|
+
)
|
45
57
|
|
46
58
|
perform_match
|
47
59
|
end
|
@@ -50,7 +62,7 @@ describe HttpStub::Server::StringValueMatcher do
|
|
50
62
|
|
51
63
|
context "when the provided stub value is a string" do
|
52
64
|
|
53
|
-
let(:stub_value)
|
65
|
+
let(:stub_value) { "some stub value" }
|
54
66
|
let(:expected_stub_match_value) { "some stub value" }
|
55
67
|
|
56
68
|
it_should_behave_like "a StringValueMatcher that matches an expected stub value"
|
@@ -59,7 +71,7 @@ describe HttpStub::Server::StringValueMatcher do
|
|
59
71
|
|
60
72
|
context "when the provided stub value is not a string" do
|
61
73
|
|
62
|
-
let(:stub_value)
|
74
|
+
let(:stub_value) { 88 }
|
63
75
|
let(:expected_stub_match_value) { "88" }
|
64
76
|
|
65
77
|
it_should_behave_like "a StringValueMatcher that matches an expected stub value"
|
@@ -68,7 +80,7 @@ describe HttpStub::Server::StringValueMatcher do
|
|
68
80
|
|
69
81
|
context "when an omitted match occurs" do
|
70
82
|
|
71
|
-
before(:example) { expect(HttpStub::Server::OmittedValueMatcher).to receive(:match?).and_return(true) }
|
83
|
+
before(:example) { expect(HttpStub::Server::Stub::OmittedValueMatcher).to receive(:match?).and_return(true) }
|
72
84
|
|
73
85
|
it "returns true" do
|
74
86
|
expect(perform_match).to be_truthy
|
@@ -78,7 +90,7 @@ describe HttpStub::Server::StringValueMatcher do
|
|
78
90
|
|
79
91
|
context "when a regular expression match occurs" do
|
80
92
|
|
81
|
-
before(:example) { expect(HttpStub::Server::RegexpValueMatcher).to receive(:match?).and_return(true) }
|
93
|
+
before(:example) { expect(HttpStub::Server::Stub::RegexpValueMatcher).to receive(:match?).and_return(true) }
|
82
94
|
|
83
95
|
it "returns true" do
|
84
96
|
expect(perform_match).to be_truthy
|
@@ -88,7 +100,7 @@ describe HttpStub::Server::StringValueMatcher do
|
|
88
100
|
|
89
101
|
context "when an exact match occurs" do
|
90
102
|
|
91
|
-
before(:example) { expect(HttpStub::Server::ExactValueMatcher).to receive(:match?).and_return(true) }
|
103
|
+
before(:example) { expect(HttpStub::Server::Stub::ExactValueMatcher).to receive(:match?).and_return(true) }
|
92
104
|
|
93
105
|
it "returns true" do
|
94
106
|
expect(perform_match).to be_truthy
|
@@ -1,18 +1,16 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::Stub::Triggers do
|
2
2
|
|
3
3
|
let(:trigger_bodies) { (1..3).map { |i| "trigger body #{i}" } }
|
4
|
-
let(:stubs_for_triggers) { (1..trigger_bodies.length).map { instance_double(HttpStub::Server::Stub) } }
|
5
|
-
let(:stub_triggers) { HttpStub::Server::
|
4
|
+
let(:stubs_for_triggers) { (1..trigger_bodies.length).map { instance_double(HttpStub::Server::Stub::Instance) } }
|
5
|
+
let(:stub_triggers) { HttpStub::Server::Stub::Triggers.new(trigger_bodies) }
|
6
6
|
|
7
|
-
before(:example)
|
8
|
-
allow(HttpStub::Server::Stub).to receive(:new).and_return(*stubs_for_triggers)
|
9
|
-
end
|
7
|
+
before(:example) { allow(HttpStub::Server::Stub).to receive(:create).and_return(*stubs_for_triggers) }
|
10
8
|
|
11
9
|
describe "constructor" do
|
12
10
|
|
13
11
|
it "creates a stub for each provided trigger" do
|
14
12
|
trigger_bodies.zip(stubs_for_triggers).each do |body, stub|
|
15
|
-
expect(HttpStub::Server::Stub).to receive(:
|
13
|
+
expect(HttpStub::Server::Stub).to receive(:create).with(body).and_return(stub)
|
16
14
|
end
|
17
15
|
|
18
16
|
stub_triggers
|
@@ -22,8 +20,8 @@ describe HttpStub::Server::StubTriggers do
|
|
22
20
|
|
23
21
|
describe "#add_to" do
|
24
22
|
|
25
|
-
let(:registry) { instance_double(HttpStub::Server::
|
26
|
-
let(:request) { instance_double(
|
23
|
+
let(:registry) { instance_double(HttpStub::Server::Stub::Registry) }
|
24
|
+
let(:request) { instance_double(Rack::Request) }
|
27
25
|
|
28
26
|
it "adds each stub to the provided registry" do
|
29
27
|
stubs_for_triggers.each { |stub_for_trigger| expect(registry).to receive(:add).with(stub_for_trigger, request) }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Uri do
|
2
|
+
|
3
|
+
let(:raw_uri) { "/some/uri" }
|
4
|
+
let(:value_matcher) { instance_double(HttpStub::Server::Stub::StringValueMatcher).as_null_object }
|
5
|
+
|
6
|
+
let(:uri) { HttpStub::Server::Stub::Uri.new(raw_uri) }
|
7
|
+
|
8
|
+
before(:example) { allow(HttpStub::Server::Stub::StringValueMatcher).to receive(:new).and_return(value_matcher) }
|
9
|
+
|
10
|
+
describe "constructor" do
|
11
|
+
|
12
|
+
it "creates a value matcher for the provided uri" do
|
13
|
+
expect(HttpStub::Server::Stub::StringValueMatcher).to receive(:new).with(raw_uri)
|
14
|
+
|
15
|
+
uri
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#match?" do
|
21
|
+
|
22
|
+
let(:request_uri) { "/some/uri" }
|
23
|
+
let(:request) { instance_double(Rack::Request, path_info: request_uri) }
|
24
|
+
|
25
|
+
it "delegates to the value matcher representation of the provided uri" do
|
26
|
+
expect(value_matcher).to receive(:match?).with(request_uri).and_return(true)
|
27
|
+
|
28
|
+
expect(uri.match?(request)).to be_truthy
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_s" do
|
34
|
+
|
35
|
+
it "delegates to the value matcher representation of the provided uri" do
|
36
|
+
expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
|
37
|
+
|
38
|
+
expect(uri.to_s).to eql("some value matcher string")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -1,197 +1,22 @@
|
|
1
1
|
describe HttpStub::Server::Stub do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
{
|
5
|
-
"header1" => "header_value1",
|
6
|
-
"header2" => "header_value2",
|
7
|
-
"header3" => "header_value3"
|
8
|
-
}
|
9
|
-
end
|
10
|
-
let(:raw_stub_parameters) do
|
11
|
-
{
|
12
|
-
"param1" => "param_value1",
|
13
|
-
"param2" => "param_value2",
|
14
|
-
"param3" => "param_value3"
|
15
|
-
}
|
16
|
-
end
|
17
|
-
let(:stub_method) { "get" }
|
18
|
-
let(:stub_trigger) do
|
19
|
-
{
|
20
|
-
"uri" => "/a_triggered_path",
|
21
|
-
"method" => "post",
|
22
|
-
"headers" => { "triggered_header" => "triggered_header_value" },
|
23
|
-
"parameters" => { "triggered_parameter" => "triggered_parameter_value" },
|
24
|
-
"response" => {
|
25
|
-
"status" => 203,
|
26
|
-
"body" => "Triggered body"
|
27
|
-
}
|
28
|
-
}
|
29
|
-
end
|
30
|
-
let(:stub_args) do
|
31
|
-
{
|
32
|
-
"uri" => "/a_path",
|
33
|
-
"method" => stub_method,
|
34
|
-
"headers" => raw_stub_headers,
|
35
|
-
"parameters" => raw_stub_parameters,
|
36
|
-
"response" => {
|
37
|
-
"status" => 201,
|
38
|
-
"body" => "Some body"
|
39
|
-
},
|
40
|
-
"triggers" => [ stub_trigger ]
|
41
|
-
}
|
42
|
-
end
|
43
|
-
let(:stub_uri) { instance_double(HttpStub::Server::StubUri, match?: true) }
|
44
|
-
let(:stub_headers) { instance_double(HttpStub::Server::StubHeaders, match?: true) }
|
45
|
-
let(:stub_parameters) { instance_double(HttpStub::Server::StubParameters, match?: true) }
|
46
|
-
let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
47
|
-
let(:stub_triggers) { instance_double(HttpStub::Server::StubTriggers) }
|
48
|
-
|
49
|
-
let(:the_stub) { HttpStub::Server::Stub.new(stub_args) }
|
50
|
-
|
51
|
-
before(:example) do
|
52
|
-
allow(HttpStub::Server::StubUri).to receive(:new).and_return(stub_uri)
|
53
|
-
allow(HttpStub::Server::StubHeaders).to receive(:new).and_return(stub_headers)
|
54
|
-
allow(HttpStub::Server::StubParameters).to receive(:new).and_return(stub_parameters)
|
55
|
-
allow(HttpStub::Server::StubResponse).to receive(:create).and_return(stub_response)
|
56
|
-
allow(HttpStub::Server::StubTriggers).to receive(:new).and_return(stub_triggers)
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#satisfies?" do
|
60
|
-
|
61
|
-
let(:request_uri) { "/a_request_uri" }
|
62
|
-
let(:request_method) { stub_method }
|
63
|
-
let(:request) { instance_double(Rack::Request, :request_method => request_method) }
|
64
|
-
|
65
|
-
describe "when the request uri matches" do
|
66
|
-
|
67
|
-
before(:example) { allow(stub_uri).to receive(:match?).with(request).and_return(true) }
|
68
|
-
|
69
|
-
describe "and the request method matches" do
|
70
|
-
|
71
|
-
describe "and a header match is configured" do
|
72
|
-
|
73
|
-
describe "that matches" do
|
74
|
-
|
75
|
-
before(:example) { allow(stub_headers).to receive(:match?).with(request).and_return(true) }
|
76
|
-
|
77
|
-
describe "and a parameter match is configured" do
|
78
|
-
|
79
|
-
describe "that matches" do
|
80
|
-
|
81
|
-
before(:example) { allow(stub_parameters).to receive(:match?).with(request).and_return(true) }
|
82
|
-
|
83
|
-
it "returns true" do
|
84
|
-
expect(the_stub.satisfies?(request)).to be_truthy
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "when the request uri does not match" do
|
100
|
-
|
101
|
-
before(:example) { allow(stub_uri).to receive(:match?).with(request).and_return(false) }
|
102
|
-
|
103
|
-
it "returns false" do
|
104
|
-
expect(the_stub.satisfies?(request)).to be_falsey
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "when the request method does not match" do
|
110
|
-
|
111
|
-
let(:request_method) { "post" }
|
112
|
-
|
113
|
-
it "returns false" do
|
114
|
-
expect(the_stub.satisfies?(request)).to be_falsey
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "when the headers do not match" do
|
3
|
+
let(:args) { HttpStub::StubFixture.new.server_payload }
|
120
4
|
|
121
|
-
|
5
|
+
describe "::create" do
|
122
6
|
|
123
|
-
|
124
|
-
expect(the_stub.satisfies?(request)).to be_falsey
|
125
|
-
end
|
7
|
+
subject { HttpStub::Server::Stub.create(args) }
|
126
8
|
|
127
|
-
|
128
|
-
|
129
|
-
describe "when the parameters do not match" do
|
130
|
-
|
131
|
-
before(:example) { allow(stub_parameters).to receive(:match?).with(request).and_return(false) }
|
132
|
-
|
133
|
-
it "returns false" do
|
134
|
-
expect(the_stub.satisfies?(request)).to be_falsey
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#uri" do
|
142
|
-
|
143
|
-
it "returns the parameters model encapsulating the uri provided in the request body" do
|
144
|
-
expect(the_stub.uri).to eql(stub_uri)
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "#method" do
|
150
|
-
|
151
|
-
it "returns the value provided in the request body" do
|
152
|
-
expect(the_stub.method).to eql(stub_method)
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "#headers" do
|
9
|
+
it "creates a stub instance with the provided arguments" do
|
10
|
+
expect(HttpStub::Server::Stub::Instance).to receive(:new).with(args)
|
158
11
|
|
159
|
-
|
160
|
-
expect(the_stub.headers).to eql(stub_headers)
|
12
|
+
subject
|
161
13
|
end
|
162
14
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
it "returns the parameters model encapsulating the parameters provided in the request body" do
|
168
|
-
expect(the_stub.parameters).to eql(stub_parameters)
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "#response" do
|
174
|
-
|
175
|
-
it "exposes the response model encapsulating the response provided in the request body" do
|
176
|
-
expect(the_stub.response).to eql(stub_response)
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "#triggers" do
|
182
|
-
|
183
|
-
it "returns the triggers model encapsulating the triggers provided in the request body" do
|
184
|
-
expect(the_stub.triggers).to eql(stub_triggers)
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "#to_s" do
|
190
|
-
|
191
|
-
it "returns a string representation of the stub arguments" do
|
192
|
-
expect(stub_args).to receive(:to_s).and_return("stub arguments string")
|
15
|
+
it "returns the created stub" do
|
16
|
+
the_stub = instance_double(HttpStub::Server::Stub::Instance)
|
17
|
+
allow(HttpStub::Server::Stub::Instance).to receive(:new).and_return(the_stub)
|
193
18
|
|
194
|
-
expect(
|
19
|
+
expect(subject).to eql(the_stub)
|
195
20
|
end
|
196
21
|
|
197
22
|
end
|