http_stub 0.13.5 → 0.14.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +13 -4
- data/lib/http_stub/configurer.rb +9 -63
- data/lib/http_stub/configurer/deprecated_dsl.rb +57 -0
- data/lib/http_stub/configurer/request/stub.rb +7 -13
- data/lib/http_stub/configurer/request/stub_activator.rb +8 -4
- data/lib/http_stub/configurer/request/stub_activator_payload_builder.rb +25 -0
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +44 -0
- data/lib/http_stub/configurer/server/buffered_command_processor.rb +24 -0
- data/lib/http_stub/configurer/server/command.rb +18 -0
- data/lib/http_stub/configurer/server/command_processor.rb +38 -0
- data/lib/http_stub/configurer/server/dsl.rb +56 -0
- data/lib/http_stub/configurer/server/facade.rb +57 -0
- data/lib/http_stub/configurer/server/request_processor.rb +30 -0
- data/lib/http_stub/models/registry.rb +4 -0
- data/lib/http_stub/models/stub.rb +2 -1
- data/lib/http_stub/models/stub_registry.rb +29 -0
- data/lib/http_stub/models/stub_triggers.rb +23 -0
- data/lib/http_stub/rake/server_tasks.rb +2 -5
- data/lib/http_stub/server.rb +14 -4
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub/views/_stub.haml +7 -0
- data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +232 -0
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +8 -8
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +8 -8
- data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +14 -14
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +74 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +19 -26
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +18 -157
- data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +35 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +62 -0
- data/spec/lib/http_stub/configurer/server/command_spec.rb +25 -0
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +241 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +253 -0
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +99 -0
- data/spec/lib/http_stub/configurer_integration_spec.rb +172 -122
- data/spec/lib/http_stub/configurer_spec.rb +4 -4
- data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +25 -25
- data/spec/lib/http_stub/controllers/stub_controller_spec.rb +22 -22
- data/spec/lib/http_stub/hash_extensions_spec.rb +24 -24
- data/spec/lib/http_stub/models/exact_value_matcher_spec.rb +4 -4
- data/spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb +29 -29
- data/spec/lib/http_stub/models/headers_spec.rb +10 -10
- data/spec/lib/http_stub/models/omitted_value_matcher_spec.rb +8 -8
- data/spec/lib/http_stub/models/regexp_value_matcher_spec.rb +6 -6
- data/spec/lib/http_stub/models/registry_spec.rb +71 -28
- data/spec/lib/http_stub/models/request_header_parser_spec.rb +4 -4
- data/spec/lib/http_stub/models/request_pipeline_spec.rb +2 -2
- data/spec/lib/http_stub/models/response_spec.rb +38 -38
- data/spec/lib/http_stub/models/string_value_matcher_spec.rb +25 -25
- data/spec/lib/http_stub/models/stub_activator_spec.rb +15 -15
- data/spec/lib/http_stub/models/stub_headers_spec.rb +18 -18
- data/spec/lib/http_stub/models/stub_parameters_spec.rb +16 -16
- data/spec/lib/http_stub/models/stub_registry_integration_spec.rb +62 -0
- data/spec/lib/http_stub/models/stub_registry_spec.rb +152 -0
- data/spec/lib/http_stub/models/stub_spec.rb +67 -43
- data/spec/lib/http_stub/models/stub_triggers_spec.rb +64 -0
- data/spec/lib/http_stub/models/stub_uri_spec.rb +9 -9
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +7 -7
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +5 -5
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +17 -15
- data/spec/lib/http_stub/server_daemon_spec.rb +16 -16
- data/spec/lib/http_stub/server_integration_spec.rb +112 -65
- data/spec/lib/http_stub/server_spec.rb +134 -96
- data/spec/spec_helper.rb +1 -1
- data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +27 -0
- data/spec/support/server_integration.rb +2 -2
- metadata +69 -30
- data/lib/http_stub/configurer/command.rb +0 -26
- data/lib/http_stub/configurer/command_processor.rb +0 -36
- data/lib/http_stub/configurer/impatient_command_chain.rb +0 -13
- data/lib/http_stub/configurer/patient_command_chain.rb +0 -25
- data/spec/lib/http_stub/configurer/command_processor_integration_spec.rb +0 -63
- data/spec/lib/http_stub/configurer/command_spec.rb +0 -40
- data/spec/lib/http_stub/configurer/impatient_command_chain_spec.rb +0 -17
- data/spec/lib/http_stub/configurer/patient_command_chain_spec.rb +0 -73
@@ -10,38 +10,38 @@ describe HttpStub::Models::StringValueMatcher do
|
|
10
10
|
|
11
11
|
shared_examples_for "a StringValueMatcher that matches an expected stub value" do
|
12
12
|
|
13
|
-
it "
|
14
|
-
HttpStub::Models::OmittedValueMatcher.
|
13
|
+
it "determines if actual value should be omitted" do
|
14
|
+
expect(HttpStub::Models::OmittedValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
15
15
|
|
16
16
|
perform_match
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
20
|
-
HttpStub::Models::RegexpValueMatcher.
|
19
|
+
it "determines if the actual value matches a regular expression" do
|
20
|
+
expect(HttpStub::Models::RegexpValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
21
21
|
|
22
22
|
perform_match
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
26
|
-
HttpStub::Models::ExactValueMatcher.
|
25
|
+
it "determines if the actual value exactly matches the stub value" do
|
26
|
+
expect(HttpStub::Models::ExactValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
27
27
|
|
28
28
|
perform_match
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
32
|
-
HttpStub::Models::OmittedValueMatcher.
|
31
|
+
it "determines if actual value should be omitted" do
|
32
|
+
expect(HttpStub::Models::OmittedValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
33
33
|
|
34
34
|
perform_match
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
38
|
-
HttpStub::Models::RegexpValueMatcher.
|
37
|
+
it "determines if the actual value matches a regular expression" do
|
38
|
+
expect(HttpStub::Models::RegexpValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
39
39
|
|
40
40
|
perform_match
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
44
|
-
HttpStub::Models::ExactValueMatcher.
|
43
|
+
it "determines if the actual value exactly matches the stub value" do
|
44
|
+
expect(HttpStub::Models::ExactValueMatcher).to receive(:match?).with(expected_stub_match_value, actual_value)
|
45
45
|
|
46
46
|
perform_match
|
47
47
|
end
|
@@ -68,38 +68,38 @@ describe HttpStub::Models::StringValueMatcher do
|
|
68
68
|
|
69
69
|
context "when an omitted match occurs" do
|
70
70
|
|
71
|
-
before(:
|
71
|
+
before(:example) { expect(HttpStub::Models::OmittedValueMatcher).to receive(:match?).and_return(true) }
|
72
72
|
|
73
|
-
it "
|
74
|
-
perform_match.
|
73
|
+
it "returns true" do
|
74
|
+
expect(perform_match).to be_truthy
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
79
|
context "when a regular expression match occurs" do
|
80
80
|
|
81
|
-
before(:
|
81
|
+
before(:example) { expect(HttpStub::Models::RegexpValueMatcher).to receive(:match?).and_return(true) }
|
82
82
|
|
83
|
-
it "
|
84
|
-
perform_match.
|
83
|
+
it "returns true" do
|
84
|
+
expect(perform_match).to be_truthy
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
88
88
|
|
89
89
|
context "when an exact match occurs" do
|
90
90
|
|
91
|
-
before(:
|
91
|
+
before(:example) { expect(HttpStub::Models::ExactValueMatcher).to receive(:match?).and_return(true) }
|
92
92
|
|
93
|
-
it "
|
94
|
-
perform_match.
|
93
|
+
it "returns true" do
|
94
|
+
expect(perform_match).to be_truthy
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
98
98
|
|
99
99
|
context "when no match occurs" do
|
100
100
|
|
101
|
-
it "
|
102
|
-
perform_match.
|
101
|
+
it "returns false" do
|
102
|
+
expect(perform_match).to be_falsey
|
103
103
|
end
|
104
104
|
|
105
105
|
end
|
@@ -112,8 +112,8 @@ describe HttpStub::Models::StringValueMatcher do
|
|
112
112
|
|
113
113
|
describe "#to_s" do
|
114
114
|
|
115
|
-
it "
|
116
|
-
string_value_matcher.to_s.
|
115
|
+
it "returns the stub value provided" do
|
116
|
+
expect(string_value_matcher.to_s).to eql(stub_value)
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
@@ -6,7 +6,7 @@ describe HttpStub::Models::StubActivator do
|
|
6
6
|
end
|
7
7
|
let(:stub_activator) { HttpStub::Models::StubActivator.new(args) }
|
8
8
|
|
9
|
-
before(:
|
9
|
+
before(:example) { allow(HttpStub::Models::Stub).to receive(:new).and_return(double(HttpStub::Models::Stub)) }
|
10
10
|
|
11
11
|
describe "#satisfies?" do
|
12
12
|
|
@@ -16,8 +16,8 @@ describe HttpStub::Models::StubActivator do
|
|
16
16
|
|
17
17
|
let(:request_path_info) { activation_uri }
|
18
18
|
|
19
|
-
it "
|
20
|
-
stub_activator.satisfies?(request).
|
19
|
+
it "returns true" do
|
20
|
+
expect(stub_activator.satisfies?(request)).to be_truthy
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -26,8 +26,8 @@ describe HttpStub::Models::StubActivator do
|
|
26
26
|
|
27
27
|
let(:request_path_info) { "#{activation_uri}/with/additional/paths" }
|
28
28
|
|
29
|
-
it "
|
30
|
-
stub_activator.satisfies?(request).
|
29
|
+
it "returns false" do
|
30
|
+
expect(stub_activator.satisfies?(request)).to be_falsey
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -36,8 +36,8 @@ describe HttpStub::Models::StubActivator do
|
|
36
36
|
|
37
37
|
let(:request_path_info) { "/completely/different/path" }
|
38
38
|
|
39
|
-
it "
|
40
|
-
stub_activator.satisfies?(request).
|
39
|
+
it "returns false" do
|
40
|
+
expect(stub_activator.satisfies?(request)).to be_falsey
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -46,29 +46,29 @@ describe HttpStub::Models::StubActivator do
|
|
46
46
|
|
47
47
|
describe "#the_stub" do
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "returns a HttpStub::Models::Stub constructed from the activator's arguments" do
|
50
50
|
stub = double(HttpStub::Models::Stub)
|
51
|
-
HttpStub::Models::Stub.
|
51
|
+
expect(HttpStub::Models::Stub).to receive(:new).with(args).and_return(stub)
|
52
52
|
|
53
|
-
stub_activator.the_stub.
|
53
|
+
expect(stub_activator.the_stub).to eql(stub)
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "#activation_uri" do
|
59
59
|
|
60
|
-
it "
|
61
|
-
stub_activator.activation_uri.
|
60
|
+
it "returns the value provided in the request body" do
|
61
|
+
expect(stub_activator.activation_uri).to eql(activation_uri)
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "#to_s" do
|
67
67
|
|
68
|
-
it "
|
69
|
-
args.
|
68
|
+
it "returns the string representation of the activation arguments" do
|
69
|
+
expect(args).to receive(:to_s).and_return("activation args string")
|
70
70
|
|
71
|
-
stub_activator.to_s.
|
71
|
+
expect(stub_activator.to_s).to eql("activation args string")
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -5,16 +5,16 @@ describe HttpStub::Models::StubHeaders do
|
|
5
5
|
|
6
6
|
let(:stub_headers) { HttpStub::Models::StubHeaders.new(stubbed_headers) }
|
7
7
|
|
8
|
-
it "
|
9
|
-
stub_headers.
|
8
|
+
it "is Headers" do
|
9
|
+
expect(stub_headers).to be_a(HttpStub::Models::Headers)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "when stubbed headers are provided" do
|
13
13
|
|
14
|
-
it "
|
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
|
-
stubbed_headers.
|
17
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
16
|
+
expect(stubbed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
17
|
+
expect(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).with(downcased_and_underscored_hash)
|
18
18
|
|
19
19
|
stub_headers
|
20
20
|
end
|
@@ -25,8 +25,8 @@ describe HttpStub::Models::StubHeaders do
|
|
25
25
|
|
26
26
|
let(:stubbed_headers) { nil }
|
27
27
|
|
28
|
-
it "
|
29
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
28
|
+
it "creates a regexpable representation of an empty hash" do
|
29
|
+
expect(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).with({})
|
30
30
|
|
31
31
|
stub_headers
|
32
32
|
end
|
@@ -38,29 +38,29 @@ describe HttpStub::Models::StubHeaders do
|
|
38
38
|
let(:request_headers) { { "request_key" => "value" } }
|
39
39
|
let(:regexpable_stubbed_headers) { double(HttpStub::Models::HashWithStringValueMatchers).as_null_object }
|
40
40
|
|
41
|
-
before(:
|
42
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
43
|
-
HttpStub::Models::RequestHeaderParser.
|
41
|
+
before(:example) do
|
42
|
+
allow(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_headers)
|
43
|
+
allow(HttpStub::Models::RequestHeaderParser).to receive(:parse).with(request).and_return(request_headers)
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
47
|
-
HttpStub::Models::RequestHeaderParser.
|
46
|
+
it "parses the requests headers into a hash" do
|
47
|
+
expect(HttpStub::Models::RequestHeaderParser).to receive(:parse).with(request).and_return(request_headers)
|
48
48
|
|
49
49
|
stub_headers.match?(request)
|
50
50
|
end
|
51
51
|
|
52
|
-
it "
|
53
|
-
request_headers.
|
52
|
+
it "downcases and underscore the keys in the request header hash" do
|
53
|
+
expect(request_headers).to receive(:downcase_and_underscore_keys)
|
54
54
|
|
55
55
|
stub_headers.match?(request)
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
58
|
+
it "delegates to the regexpable representation of the stubbed headers to determine a match" do
|
59
59
|
downcased_and_underscored_hash = { "another_request_key" => "value" }
|
60
|
-
request_headers.
|
61
|
-
regexpable_stubbed_headers.
|
60
|
+
allow(request_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
61
|
+
expect(regexpable_stubbed_headers).to receive(:match?).with(downcased_and_underscored_hash).and_return(true)
|
62
62
|
|
63
|
-
stub_headers.match?(request).
|
63
|
+
expect(stub_headers.match?(request)).to be_truthy
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
@@ -10,8 +10,8 @@ describe HttpStub::Models::StubParameters do
|
|
10
10
|
|
11
11
|
describe "when stubbed parameters are provided" do
|
12
12
|
|
13
|
-
it "
|
14
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
13
|
+
it "creates a regexpable representation of the stubbed parameters" do
|
14
|
+
expect(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
|
15
15
|
|
16
16
|
stub_parameters
|
17
17
|
end
|
@@ -22,8 +22,8 @@ describe HttpStub::Models::StubParameters do
|
|
22
22
|
|
23
23
|
let(:stubbed_parameters) { nil }
|
24
24
|
|
25
|
-
it "
|
26
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
25
|
+
it "creates a regexpable representation of an empty hash" do
|
26
|
+
expect(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).with({})
|
27
27
|
|
28
28
|
stub_parameters
|
29
29
|
end
|
@@ -32,11 +32,11 @@ describe HttpStub::Models::StubParameters do
|
|
32
32
|
|
33
33
|
describe "#match?" do
|
34
34
|
|
35
|
-
it "
|
36
|
-
HttpStub::Models::HashWithStringValueMatchers.
|
37
|
-
regexpable_stubbed_paremeters.
|
35
|
+
it "delegates to the regexpable representation of the stubbed parameters to determine a match" do
|
36
|
+
allow(HttpStub::Models::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_paremeters)
|
37
|
+
expect(regexpable_stubbed_paremeters).to receive(:match?).with(request_parameters).and_return(true)
|
38
38
|
|
39
|
-
stub_parameters.match?(request).
|
39
|
+
expect(stub_parameters.match?(request)).to be(true)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -47,14 +47,14 @@ describe HttpStub::Models::StubParameters do
|
|
47
47
|
|
48
48
|
let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "returns a string containing each parameter formatted as a conventional request parameter" do
|
51
51
|
result = stub_parameters.to_s
|
52
52
|
|
53
|
-
stubbed_parameters.each { |key, value| result.
|
53
|
+
stubbed_parameters.each { |key, value| expect(result).to match(/#{key}=#{value}/) }
|
54
54
|
end
|
55
55
|
|
56
|
-
it "
|
57
|
-
stub_parameters.to_s.
|
56
|
+
it "separates each parameter with the conventional request parameter delimiter" do
|
57
|
+
expect(stub_parameters.to_s).to match(/key\d.value\d\&key\d.value\d\&key\d.value\d/)
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -63,8 +63,8 @@ describe HttpStub::Models::StubParameters do
|
|
63
63
|
|
64
64
|
let(:stubbed_parameters) { {} }
|
65
65
|
|
66
|
-
it "
|
67
|
-
stub_parameters.to_s.
|
66
|
+
it "returns an empty string" do
|
67
|
+
expect(stub_parameters.to_s).to eql("")
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
@@ -73,8 +73,8 @@ describe HttpStub::Models::StubParameters do
|
|
73
73
|
|
74
74
|
let(:stubbed_parameters) { nil }
|
75
75
|
|
76
|
-
it "
|
77
|
-
stub_parameters.to_s.
|
76
|
+
it "returns an empty string" do
|
77
|
+
expect(stub_parameters.to_s).to eql("")
|
78
78
|
end
|
79
79
|
|
80
80
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
describe HttpStub::Models::StubRegistry, "integrating with real stubs" do
|
2
|
+
|
3
|
+
let(:logger) { double("Logger").as_null_object }
|
4
|
+
let(:request) { double("HttpRequest", logger: logger) }
|
5
|
+
|
6
|
+
let(:stub_registry) { HttpStub::Models::StubRegistry.new }
|
7
|
+
|
8
|
+
describe "#recall" do
|
9
|
+
|
10
|
+
subject { stub_registry.recall }
|
11
|
+
|
12
|
+
context "when stubs have been added" do
|
13
|
+
|
14
|
+
let(:stubs) do
|
15
|
+
(1..3).map { |i| create_stub(i) }
|
16
|
+
end
|
17
|
+
|
18
|
+
before(:example) do
|
19
|
+
stubs.each { |stub| stub_registry.add(stub, request) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "and remembered" do
|
23
|
+
|
24
|
+
before(:example) { stub_registry.remember }
|
25
|
+
|
26
|
+
context "and a stub subsequently added" do
|
27
|
+
|
28
|
+
let(:stub_to_add) { create_stub(4) }
|
29
|
+
|
30
|
+
before(:example) { stub_registry.add(stub_to_add, request) }
|
31
|
+
|
32
|
+
it "should restore all known stubs to the remembered state" do
|
33
|
+
subject
|
34
|
+
|
35
|
+
expect(stub_registry.all).not_to include(stub_to_add)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_stub(number)
|
47
|
+
HttpStub::Models::Stub.new(
|
48
|
+
{
|
49
|
+
"uri" => "/uri#{number}",
|
50
|
+
"method" => "get",
|
51
|
+
"headers" => {"header_key_#{number}" => "header_value_#{number}"},
|
52
|
+
"parameters" => {"parameter_key_#{number}" => "parameter_value_#{number}"},
|
53
|
+
"response" => {
|
54
|
+
"status" => 200 + number,
|
55
|
+
"body" => "Body #{number}"
|
56
|
+
},
|
57
|
+
"triggers" => []
|
58
|
+
}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
describe HttpStub::Models::StubRegistry do
|
2
|
+
|
3
|
+
let(:registry) { instance_double(HttpStub::Models::Registry) }
|
4
|
+
|
5
|
+
let(:stub_registry) { HttpStub::Models::StubRegistry.new }
|
6
|
+
|
7
|
+
before(:example) { allow(HttpStub::Models::Registry).to receive(:new).and_return(registry) }
|
8
|
+
|
9
|
+
describe "#add" do
|
10
|
+
|
11
|
+
let(:stub) { instance_double(HttpStub::Models::Stub) }
|
12
|
+
let(:request) { double("HttpRequest") }
|
13
|
+
|
14
|
+
it "delegates to an underlying simple registry" do
|
15
|
+
expect(registry).to receive(:add).with(stub, request)
|
16
|
+
|
17
|
+
stub_registry.add(stub, request)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#find_for" do
|
23
|
+
|
24
|
+
let(:request) { double("HttpRequest") }
|
25
|
+
|
26
|
+
subject { stub_registry.find_for(request) }
|
27
|
+
|
28
|
+
it "delegates to an underlying simple registry" do
|
29
|
+
expect(registry).to receive(:find_for).with(request)
|
30
|
+
|
31
|
+
subject
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when a stub is found" do
|
35
|
+
|
36
|
+
let(:triggers) { instance_double(HttpStub::Models::StubTriggers) }
|
37
|
+
let(:stub) { instance_double(HttpStub::Models::Stub, triggers: triggers) }
|
38
|
+
|
39
|
+
before(:example) { allow(registry).to receive(:find_for).and_return(stub) }
|
40
|
+
|
41
|
+
it "should add the stubs triggers to the registry" do
|
42
|
+
expect(triggers).to receive(:add_to).with(stub_registry, request)
|
43
|
+
|
44
|
+
subject
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns the stub found in the underlying registry" do
|
48
|
+
allow(triggers).to receive(:add_to)
|
49
|
+
|
50
|
+
expect(subject).to eql(stub)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when a stub is not found" do
|
56
|
+
|
57
|
+
before(:example) { allow(registry).to receive(:find_for).and_return(nil) }
|
58
|
+
|
59
|
+
it "returns the result from the underlying registry" do
|
60
|
+
expect(subject).to eql(nil)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#remember" do
|
68
|
+
|
69
|
+
it "copies the underlying registry" do
|
70
|
+
expect(registry).to receive(:copy)
|
71
|
+
|
72
|
+
stub_registry.remember
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#recall" do
|
78
|
+
|
79
|
+
subject { stub_registry.recall }
|
80
|
+
|
81
|
+
context "when the state of the registry has been remembered" do
|
82
|
+
|
83
|
+
let(:remembered_registry) { instance_double(HttpStub::Models::Registry) }
|
84
|
+
let(:copy_of_remembered_registry) { instance_double(HttpStub::Models::Registry) }
|
85
|
+
|
86
|
+
before(:example) do
|
87
|
+
allow(registry).to receive(:copy).and_return(remembered_registry)
|
88
|
+
allow(remembered_registry).to receive(:copy).and_return(copy_of_remembered_registry)
|
89
|
+
stub_registry.remember
|
90
|
+
end
|
91
|
+
|
92
|
+
it "copies the remembered registry to ensure subsequent recalls recall the same stubs" do
|
93
|
+
expect(remembered_registry).to receive(:copy)
|
94
|
+
|
95
|
+
subject
|
96
|
+
end
|
97
|
+
|
98
|
+
it "causes subsequent method calls to delegate to the copy" do
|
99
|
+
subject
|
100
|
+
|
101
|
+
expect(copy_of_remembered_registry).to receive(:all)
|
102
|
+
stub_registry.all
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when the state of the registry has not been remembered" do
|
108
|
+
|
109
|
+
it "does not effect subsequent method calls" do
|
110
|
+
subject
|
111
|
+
|
112
|
+
expect(registry).to receive(:all)
|
113
|
+
stub_registry.all
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#all" do
|
121
|
+
|
122
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Models::Stub) } }
|
123
|
+
|
124
|
+
subject { stub_registry.all }
|
125
|
+
|
126
|
+
it "delegates to an underlying simple registry" do
|
127
|
+
expect(registry).to receive(:all)
|
128
|
+
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns the result from the underlying registry" do
|
133
|
+
allow(registry).to receive(:all).and_return(stubs)
|
134
|
+
|
135
|
+
expect(subject).to eql(stubs)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#clear" do
|
141
|
+
|
142
|
+
let(:request) { double("HttpRequest") }
|
143
|
+
|
144
|
+
it "delegates to an underlying simple registry" do
|
145
|
+
expect(registry).to receive(:clear).with(request)
|
146
|
+
|
147
|
+
stub_registry.clear(request)
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|