http_stub 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,90 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::Headers do
|
2
|
+
|
3
|
+
let(:request) { instance_double(HttpStub::Server::Request) }
|
4
|
+
|
5
|
+
let(:stubbed_headers) { { "stub_key" => "value" } }
|
6
|
+
|
7
|
+
let(:request_headers) { described_class.new(stubbed_headers) }
|
8
|
+
|
9
|
+
describe "when stubbed headers are provided" do
|
10
|
+
|
11
|
+
it "creates a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
|
12
|
+
downcased_and_underscored_hash = { "another_stub_key" => "value" }
|
13
|
+
expect(stubbed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
14
|
+
expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to(
|
15
|
+
receive(:new).with(downcased_and_underscored_hash)
|
16
|
+
)
|
17
|
+
|
18
|
+
request_headers
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when the stubbed headers are nil" do
|
24
|
+
|
25
|
+
let(:stubbed_headers) { nil }
|
26
|
+
|
27
|
+
it "creates a regexpable representation of an empty hash" do
|
28
|
+
expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to receive(:new).with({})
|
29
|
+
|
30
|
+
request_headers
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#matches?" do
|
36
|
+
|
37
|
+
let(:request_header_hash) { { "header_key" => "header value" } }
|
38
|
+
let(:regexpable_stubbed_headers) do
|
39
|
+
double(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).as_null_object
|
40
|
+
end
|
41
|
+
let(:logger) { double(Logger) }
|
42
|
+
|
43
|
+
subject { request_headers.matches?(request, logger) }
|
44
|
+
|
45
|
+
before(:example) do
|
46
|
+
allow(request).to receive(:headers).and_return(request_header_hash)
|
47
|
+
allow(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to(
|
48
|
+
receive(:new).and_return(regexpable_stubbed_headers)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "downcases and underscore the keys in the request header hash" do
|
53
|
+
expect(request_header_hash).to receive(:downcase_and_underscore_keys)
|
54
|
+
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
|
58
|
+
it "delegates to the regexpable representation of the stubbed headers to determine a match" do
|
59
|
+
downcased_and_underscored_hash = { "another_request_key" => "value" }
|
60
|
+
allow(request_header_hash).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
61
|
+
expect(regexpable_stubbed_headers).to receive(:matches?).with(downcased_and_underscored_hash).and_return(true)
|
62
|
+
|
63
|
+
expect(subject).to eql(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#to_s" do
|
69
|
+
|
70
|
+
let(:readable_hash) { instance_double(HttpStub::Server::FormattedHash, to_s: "readable header hash string") }
|
71
|
+
|
72
|
+
subject { request_headers.to_s }
|
73
|
+
|
74
|
+
before(:example) do
|
75
|
+
allow(HttpStub::Server::FormattedHash).to receive(:new).with(stubbed_headers, anything).and_return(readable_hash)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns the string representation of the readable header hash" do
|
79
|
+
expect(subject).to eql("readable header hash string")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "formats the headers with a ':' key value delimiter" do
|
83
|
+
expect(HttpStub::Server::FormattedHash).to receive(:new).with(stubbed_headers, ":")
|
84
|
+
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb}
RENAMED
@@ -1,24 +1,23 @@
|
|
1
|
-
describe HttpStub::Server::Stub::
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::JsonBody do
|
2
2
|
|
3
3
|
let(:stubbed_schema_definition) { { "type" => "object", "properties" => { "some_property" => "some_type" } } }
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:json_body) { described_class.new(stubbed_schema_definition) }
|
6
6
|
|
7
|
-
describe "#
|
7
|
+
describe "#matches?" do
|
8
8
|
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:request) { instance_double(Rack::Request, logger: logger, body: request_body) }
|
9
|
+
let(:request_body) { { "some_json_property" => "some_json_value" }.to_json }
|
10
|
+
let(:request) { instance_double(HttpStub::Server::Request, body: request_body) }
|
11
|
+
let(:logger) { instance_double(Logger, info: nil) }
|
13
12
|
|
14
13
|
let(:validation_errors) { [] }
|
15
14
|
|
16
|
-
subject {
|
15
|
+
subject { json_body.matches?(request, logger) }
|
17
16
|
|
18
17
|
before(:example) { allow(JSON::Validator).to receive(:fully_validate).and_return(validation_errors) }
|
19
18
|
|
20
19
|
it "validates the request body using the stubbed schema definition" do
|
21
|
-
expect(JSON::Validator).to receive(:fully_validate).with(stubbed_schema_definition,
|
20
|
+
expect(JSON::Validator).to receive(:fully_validate).with(stubbed_schema_definition, request_body, anything)
|
22
21
|
|
23
22
|
subject
|
24
23
|
end
|
@@ -91,7 +90,7 @@ describe HttpStub::Server::Stub::JsonRequestBody do
|
|
91
90
|
|
92
91
|
describe "#to_s" do
|
93
92
|
|
94
|
-
subject {
|
93
|
+
subject { json_body.to_s }
|
95
94
|
|
96
95
|
it "returns the JSON representation of the schema definition" do
|
97
96
|
expect(subject).to eql(stubbed_schema_definition.to_json)
|
@@ -1,15 +1,16 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Method do
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::Method do
|
2
2
|
|
3
3
|
let(:raw_stub_method) { "put" }
|
4
4
|
|
5
|
-
let(:the_method) {
|
5
|
+
let(:the_method) { described_class.new(raw_stub_method) }
|
6
6
|
|
7
|
-
describe "#
|
7
|
+
describe "#matches?" do
|
8
8
|
|
9
9
|
let(:request_method) { "get" }
|
10
|
-
let(:request) { instance_double(
|
10
|
+
let(:request) { instance_double(HttpStub::Server::Request, method: request_method) }
|
11
|
+
let(:logger) { instance_double(Logger) }
|
11
12
|
|
12
|
-
subject { the_method.
|
13
|
+
subject { the_method.matches?(request, logger) }
|
13
14
|
|
14
15
|
context "when the request method is identical to the stub method" do
|
15
16
|
|
data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb}
RENAMED
@@ -1,17 +1,19 @@
|
|
1
|
-
describe HttpStub::Server::Stub::
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::Parameters do
|
2
2
|
|
3
3
|
let(:raw_request_parameters) { double("RequestParameters") }
|
4
|
-
let(:request) { instance_double(
|
4
|
+
let(:request) { instance_double(HttpStub::Server::Request, parameters: raw_request_parameters) }
|
5
5
|
|
6
6
|
let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
|
7
|
-
let(:regexpable_stubbed_paremeters)
|
7
|
+
let(:regexpable_stubbed_paremeters) do
|
8
|
+
double(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).as_null_object
|
9
|
+
end
|
8
10
|
|
9
|
-
let(:request_parameters) {
|
11
|
+
let(:request_parameters) { described_class.new(stubbed_parameters) }
|
10
12
|
|
11
13
|
describe "when stubbed parameters are provided" do
|
12
14
|
|
13
15
|
it "creates a regexpable representation of the stubbed parameters" do
|
14
|
-
expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
|
16
|
+
expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
|
15
17
|
|
16
18
|
request_parameters
|
17
19
|
end
|
@@ -23,20 +25,24 @@ describe HttpStub::Server::Stub::RequestParameters do
|
|
23
25
|
let(:stubbed_parameters) { nil }
|
24
26
|
|
25
27
|
it "creates a regexpable representation of an empty hash" do
|
26
|
-
expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with({})
|
28
|
+
expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to receive(:new).with({})
|
27
29
|
|
28
30
|
request_parameters
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
32
34
|
|
33
|
-
describe "#
|
35
|
+
describe "#matches?" do
|
36
|
+
|
37
|
+
let(:logger) { instance_double(Logger) }
|
34
38
|
|
35
39
|
it "delegates to the regexpable representation of the stubbed parameters to determine a match" do
|
36
|
-
allow(HttpStub::Server::Stub::HashWithStringValueMatchers).to
|
37
|
-
|
40
|
+
allow(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to(
|
41
|
+
receive(:new).and_return(regexpable_stubbed_paremeters)
|
42
|
+
)
|
43
|
+
expect(regexpable_stubbed_paremeters).to receive(:matches?).with(raw_request_parameters).and_return(true)
|
38
44
|
|
39
|
-
expect(request_parameters.
|
45
|
+
expect(request_parameters.matches?(request, logger)).to be(true)
|
40
46
|
end
|
41
47
|
|
42
48
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::SimpleBody do
|
2
|
+
|
3
|
+
let(:raw_body) { "some body" }
|
4
|
+
let(:value_matcher) { instance_double(HttpStub::Server::Stub::Match::StringValueMatcher).as_null_object }
|
5
|
+
|
6
|
+
let(:simple_body) { described_class.new(raw_body) }
|
7
|
+
|
8
|
+
before(:example) do
|
9
|
+
allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).and_return(value_matcher)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "constructor" do
|
13
|
+
|
14
|
+
it "creates a value matcher for the provided body" do
|
15
|
+
expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(raw_body)
|
16
|
+
|
17
|
+
simple_body
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#matches?" do
|
23
|
+
|
24
|
+
let(:request_body) { "some request body" }
|
25
|
+
let(:request) { instance_double(HttpStub::Server::Request, body: request_body) }
|
26
|
+
let(:logger) { instance_double(Logger) }
|
27
|
+
|
28
|
+
it "delegates to the value matcher to match the request body" do
|
29
|
+
expect(value_matcher).to receive(:matches?).with(request_body).and_return(true)
|
30
|
+
|
31
|
+
expect(simple_body.matches?(request, logger)).to be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#to_s" do
|
37
|
+
|
38
|
+
it "delegates to the value matcher representation of the provided body" do
|
39
|
+
expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
|
40
|
+
|
41
|
+
expect(simple_body.to_s).to eql("some value matcher string")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Rule::Uri do
|
2
|
+
|
3
|
+
let(:raw_uri) { "/some/uri" }
|
4
|
+
let(:value_matcher) { instance_double(HttpStub::Server::Stub::Match::StringValueMatcher).as_null_object }
|
5
|
+
|
6
|
+
let(:uri) { described_class.new(raw_uri) }
|
7
|
+
|
8
|
+
before(:example) do
|
9
|
+
allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).and_return(value_matcher)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "constructor" do
|
13
|
+
|
14
|
+
it "creates a value matcher for the provided uri" do
|
15
|
+
expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(raw_uri)
|
16
|
+
|
17
|
+
uri
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#matches?" do
|
23
|
+
|
24
|
+
let(:request_uri) { "/some/uri" }
|
25
|
+
let(:request) { instance_double(HttpStub::Server::Request, uri: request_uri) }
|
26
|
+
let(:logger) { instance_double(Logger) }
|
27
|
+
|
28
|
+
it "delegates to the value matcher representation of the provided uri" do
|
29
|
+
expect(value_matcher).to receive(:matches?).with(request_uri).and_return(true)
|
30
|
+
|
31
|
+
expect(uri.matches?(request, logger)).to be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#to_s" do
|
37
|
+
|
38
|
+
it "delegates to the value matcher representation of the provided uri" do
|
39
|
+
expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
|
40
|
+
|
41
|
+
expect(uri.to_s).to eql("some value matcher string")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,61 +1,63 @@
|
|
1
|
-
describe HttpStub::Server::Stub::StringValueMatcher do
|
1
|
+
describe HttpStub::Server::Stub::Match::StringValueMatcher do
|
2
2
|
|
3
3
|
let(:stub_value) { "some stub value" }
|
4
4
|
|
5
|
-
let(:string_value_matcher) { HttpStub::Server::Stub::StringValueMatcher.new(stub_value) }
|
5
|
+
let(:string_value_matcher) { HttpStub::Server::Stub::Match::StringValueMatcher.new(stub_value) }
|
6
6
|
|
7
|
-
describe "#
|
7
|
+
describe "#matches?" do
|
8
8
|
|
9
9
|
let(:actual_value) { "some actual value" }
|
10
10
|
|
11
|
+
subject { string_value_matcher.matches?(actual_value) }
|
12
|
+
|
11
13
|
shared_examples_for "a StringValueMatcher that matches an expected stub value" do
|
12
14
|
|
13
15
|
it "determines if actual value should be omitted" do
|
14
|
-
expect(HttpStub::Server::Stub::OmittedValueMatcher).to(
|
16
|
+
expect(HttpStub::Server::Stub::Match::OmittedValueMatcher).to(
|
15
17
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
16
18
|
)
|
17
19
|
|
18
|
-
|
20
|
+
subject
|
19
21
|
end
|
20
22
|
|
21
23
|
it "determines if the actual value matches a regular expression" do
|
22
|
-
expect(HttpStub::Server::Stub::RegexpValueMatcher).to(
|
24
|
+
expect(HttpStub::Server::Stub::Match::RegexpValueMatcher).to(
|
23
25
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
24
26
|
)
|
25
27
|
|
26
|
-
|
28
|
+
subject
|
27
29
|
end
|
28
30
|
|
29
31
|
it "determines if the actual value exactly matches the stub value" do
|
30
|
-
expect(HttpStub::Server::Stub::ExactValueMatcher).to(
|
32
|
+
expect(HttpStub::Server::Stub::Match::ExactValueMatcher).to(
|
31
33
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
32
34
|
)
|
33
35
|
|
34
|
-
|
36
|
+
subject
|
35
37
|
end
|
36
38
|
|
37
39
|
it "determines if actual value should be omitted" do
|
38
|
-
expect(HttpStub::Server::Stub::OmittedValueMatcher).to(
|
40
|
+
expect(HttpStub::Server::Stub::Match::OmittedValueMatcher).to(
|
39
41
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
40
42
|
)
|
41
43
|
|
42
|
-
|
44
|
+
subject
|
43
45
|
end
|
44
46
|
|
45
47
|
it "determines if the actual value matches a regular expression" do
|
46
|
-
expect(HttpStub::Server::Stub::RegexpValueMatcher).to(
|
48
|
+
expect(HttpStub::Server::Stub::Match::RegexpValueMatcher).to(
|
47
49
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
48
50
|
)
|
49
51
|
|
50
|
-
|
52
|
+
subject
|
51
53
|
end
|
52
54
|
|
53
55
|
it "determines if the actual value exactly matches the stub value" do
|
54
|
-
expect(HttpStub::Server::Stub::ExactValueMatcher).to(
|
56
|
+
expect(HttpStub::Server::Stub::Match::ExactValueMatcher).to(
|
55
57
|
receive(:match?).with(expected_stub_match_value, actual_value)
|
56
58
|
)
|
57
59
|
|
58
|
-
|
60
|
+
subject
|
59
61
|
end
|
60
62
|
|
61
63
|
end
|
@@ -80,30 +82,36 @@ describe HttpStub::Server::Stub::StringValueMatcher do
|
|
80
82
|
|
81
83
|
context "when an omitted match occurs" do
|
82
84
|
|
83
|
-
before(:example)
|
85
|
+
before(:example) do
|
86
|
+
expect(HttpStub::Server::Stub::Match::OmittedValueMatcher).to receive(:match?).and_return(true)
|
87
|
+
end
|
84
88
|
|
85
89
|
it "returns true" do
|
86
|
-
expect(
|
90
|
+
expect(subject).to be(true)
|
87
91
|
end
|
88
92
|
|
89
93
|
end
|
90
94
|
|
91
95
|
context "when a regular expression match occurs" do
|
92
96
|
|
93
|
-
before(:example)
|
97
|
+
before(:example) do
|
98
|
+
expect(HttpStub::Server::Stub::Match::RegexpValueMatcher).to receive(:match?).and_return(true)
|
99
|
+
end
|
94
100
|
|
95
101
|
it "returns true" do
|
96
|
-
expect(
|
102
|
+
expect(subject).to be(true)
|
97
103
|
end
|
98
104
|
|
99
105
|
end
|
100
106
|
|
101
107
|
context "when an exact match occurs" do
|
102
108
|
|
103
|
-
before(:example)
|
109
|
+
before(:example) do
|
110
|
+
expect(HttpStub::Server::Stub::Match::ExactValueMatcher).to receive(:match?).and_return(true)
|
111
|
+
end
|
104
112
|
|
105
113
|
it "returns true" do
|
106
|
-
expect(
|
114
|
+
expect(subject).to be(true)
|
107
115
|
end
|
108
116
|
|
109
117
|
end
|
@@ -111,14 +119,10 @@ describe HttpStub::Server::Stub::StringValueMatcher do
|
|
111
119
|
context "when no match occurs" do
|
112
120
|
|
113
121
|
it "returns false" do
|
114
|
-
expect(
|
122
|
+
expect(subject).to be(false)
|
115
123
|
end
|
116
124
|
|
117
125
|
end
|
118
|
-
|
119
|
-
def perform_match
|
120
|
-
string_value_matcher.match?(actual_value)
|
121
|
-
end
|
122
126
|
|
123
127
|
end
|
124
128
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::TruthyMatcher do
|
2
|
+
|
3
|
+
let(:truthy_matcher) { described_class }
|
4
|
+
|
5
|
+
describe "::matches?" do
|
6
|
+
|
7
|
+
let(:request) { instance_double(HttpStub::Server::Request) }
|
8
|
+
let(:logger) { instance_double(Logger) }
|
9
|
+
|
10
|
+
it "returns true" do
|
11
|
+
expect(truthy_matcher.matches?(request, logger)).to be(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "::to_s" do
|
17
|
+
|
18
|
+
it "returns an empty string" do
|
19
|
+
expect(truthy_matcher.to_s).to eql("")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|