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.
Files changed (114) hide show
  1. checksums.yaml +13 -5
  2. data/lib/http_stub.rb +26 -21
  3. data/lib/http_stub/configurer/server/command_processor.rb +1 -0
  4. data/lib/http_stub/server/application.rb +24 -46
  5. data/lib/http_stub/server/formatted_hash.rb +18 -0
  6. data/lib/http_stub/server/header_parser.rb +17 -0
  7. data/lib/http_stub/server/registry.rb +9 -9
  8. data/lib/http_stub/server/request.rb +19 -0
  9. data/lib/http_stub/server/request_pipeline.rb +27 -0
  10. data/lib/http_stub/server/response.rb +7 -3
  11. data/lib/http_stub/server/scenario.rb +1 -1
  12. data/lib/http_stub/server/scenario/activator.rb +4 -4
  13. data/lib/http_stub/server/scenario/controller.rb +8 -8
  14. data/lib/http_stub/server/scenario/{request_parser.rb → parser.rb} +2 -2
  15. data/lib/http_stub/server/scenario/{instance.rb → scenario.rb} +2 -2
  16. data/lib/http_stub/server/stub.rb +1 -1
  17. data/lib/http_stub/server/stub/controller.rb +8 -8
  18. data/lib/http_stub/server/stub/empty.rb +34 -0
  19. data/lib/http_stub/server/stub/match/exact_value_matcher.rb +17 -0
  20. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +26 -0
  21. data/lib/http_stub/server/stub/match/match.rb +20 -0
  22. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +23 -0
  23. data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +18 -0
  24. data/lib/http_stub/server/stub/match/rule/body.rb +49 -0
  25. data/lib/http_stub/server/stub/match/rule/headers.rb +31 -0
  26. data/lib/http_stub/server/stub/match/rule/json_body.rb +39 -0
  27. data/lib/http_stub/server/stub/match/rule/method.rb +27 -0
  28. data/lib/http_stub/server/stub/match/rule/parameters.rb +27 -0
  29. data/lib/http_stub/server/stub/match/rule/simple_body.rb +27 -0
  30. data/lib/http_stub/server/stub/match/rule/uri.rb +27 -0
  31. data/lib/http_stub/server/stub/match/string_value_matcher.rb +33 -0
  32. data/lib/http_stub/server/stub/match/truthy_matcher.rb +25 -0
  33. data/lib/http_stub/server/stub/{request_parser.rb → parser.rb} +2 -2
  34. data/lib/http_stub/server/stub/payload_file_consolidator.rb +1 -1
  35. data/lib/http_stub/server/stub/registry.rb +16 -8
  36. data/lib/http_stub/server/stub/response/base.rb +2 -2
  37. data/lib/http_stub/server/stub/stub.rb +44 -0
  38. data/lib/http_stub/server/stub/triggers.rb +2 -2
  39. data/lib/http_stub/server/views/_match.haml +20 -0
  40. data/lib/http_stub/server/views/matches.haml +3 -0
  41. data/lib/http_stub/server/views/stub.haml +1 -0
  42. data/lib/http_stub/version.rb +1 -1
  43. data/spec/acceptance/stub_control_values_spec.rb +6 -3
  44. data/spec/acceptance/stub_match_spec.rb +142 -0
  45. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +4 -0
  46. data/spec/lib/http_stub/server/application_integration_spec.rb +17 -18
  47. data/spec/lib/http_stub/server/application_spec.rb +81 -53
  48. data/spec/lib/http_stub/server/formatted_hash_spec.rb +54 -0
  49. data/spec/lib/http_stub/server/{stub/request_header_parser_spec.rb → header_parser_spec.rb} +9 -9
  50. data/spec/lib/http_stub/server/{request_file_consolidator_spec.rb → payload_file_consolidator_spec.rb} +4 -4
  51. data/spec/lib/http_stub/server/registry_spec.rb +13 -14
  52. data/spec/lib/http_stub/server/request_pipeline_spec.rb +80 -0
  53. data/spec/lib/http_stub/server/request_spec.rb +113 -0
  54. data/spec/lib/http_stub/server/response_spec.rb +46 -12
  55. data/spec/lib/http_stub/server/scenario/activator_spec.rb +18 -18
  56. data/spec/lib/http_stub/server/scenario/controller_spec.rb +18 -15
  57. data/spec/lib/http_stub/server/scenario/{request_parser_spec.rb → parser_spec.rb} +8 -8
  58. data/spec/lib/http_stub/server/scenario/{instance_spec.rb → scenario_spec.rb} +7 -5
  59. data/spec/lib/http_stub/server/scenario_spec.rb +3 -3
  60. data/spec/lib/http_stub/server/stub/controller_spec.rb +29 -14
  61. data/spec/lib/http_stub/server/stub/empty_spec.rb +68 -0
  62. data/spec/lib/http_stub/server/stub/{exact_value_matcher_spec.rb → match/exact_value_matcher_spec.rb} +2 -2
  63. data/spec/lib/http_stub/server/stub/{hash_with_string_value_matchers_spec.rb → match/hash_with_string_value_matchers_spec.rb} +27 -19
  64. data/spec/lib/http_stub/server/stub/match/match_spec.rb +40 -0
  65. data/spec/lib/http_stub/server/stub/{omitted_value_matcher_spec.rb → match/omitted_value_matcher_spec.rb} +2 -2
  66. data/spec/lib/http_stub/server/stub/{regexp_value_matcher_spec.rb → match/regexp_value_matcher_spec.rb} +2 -2
  67. data/spec/lib/http_stub/server/stub/{request_body_spec.rb → match/rule/body_spec.rb} +12 -12
  68. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +90 -0
  69. data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb} +9 -10
  70. data/spec/lib/http_stub/server/stub/{method_spec.rb → match/rule/method_spec.rb} +6 -5
  71. data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb} +16 -10
  72. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +46 -0
  73. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +46 -0
  74. data/spec/lib/http_stub/server/stub/{string_value_matcher_spec.rb → match/string_value_matcher_spec.rb} +30 -26
  75. data/spec/lib/http_stub/server/stub/match/truthy_matcher_spec.rb +24 -0
  76. data/spec/lib/http_stub/server/stub/{request_parser_spec.rb → parser_spec.rb} +7 -7
  77. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/registry_spec.rb +114 -43
  79. data/spec/lib/http_stub/server/stub/response/base_spec.rb +8 -2
  80. data/spec/lib/http_stub/server/stub/stub_spec.rb +294 -0
  81. data/spec/lib/http_stub/server/stub/triggers_spec.rb +4 -4
  82. data/spec/lib/http_stub/server/stub_spec.rb +3 -3
  83. data/spec/spec_helper.rb +7 -3
  84. data/spec/support/configurer_integration.rb +1 -0
  85. data/spec/support/http_stub/empty_configurer.rb +7 -0
  86. data/spec/support/{scenario_fixture.rb → http_stub/scenario_fixture.rb} +0 -0
  87. data/spec/support/http_stub/server/request_fixture.rb +25 -0
  88. data/spec/support/http_stub/server/scenario/scenario_fixture.rb +15 -0
  89. data/spec/support/http_stub/server/stub/match/match_fixture.rb +17 -0
  90. data/spec/support/{stub_fixture.rb → http_stub/stub_fixture.rb} +0 -0
  91. data/spec/support/server_integration.rb +1 -0
  92. metadata +315 -290
  93. data/lib/http_stub/server/stub/exact_value_matcher.rb +0 -15
  94. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +0 -22
  95. data/lib/http_stub/server/stub/headers.rb +0 -19
  96. data/lib/http_stub/server/stub/instance.rb +0 -32
  97. data/lib/http_stub/server/stub/json_request_body.rb +0 -35
  98. data/lib/http_stub/server/stub/method.rb +0 -23
  99. data/lib/http_stub/server/stub/omitted_value_matcher.rb +0 -21
  100. data/lib/http_stub/server/stub/regexp_value_matcher.rb +0 -16
  101. data/lib/http_stub/server/stub/request_body.rb +0 -44
  102. data/lib/http_stub/server/stub/request_header_parser.rb +0 -19
  103. data/lib/http_stub/server/stub/request_headers.rb +0 -28
  104. data/lib/http_stub/server/stub/request_parameters.rb +0 -23
  105. data/lib/http_stub/server/stub/simple_request_body.rb +0 -23
  106. data/lib/http_stub/server/stub/string_value_matcher.rb +0 -31
  107. data/lib/http_stub/server/stub/truthy_request_matcher.rb +0 -23
  108. data/lib/http_stub/server/stub/uri.rb +0 -23
  109. data/spec/lib/http_stub/server/stub/headers_spec.rb +0 -51
  110. data/spec/lib/http_stub/server/stub/instance_spec.rb +0 -235
  111. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +0 -68
  112. data/spec/lib/http_stub/server/stub/simple_request_body_spec.rb +0 -43
  113. data/spec/lib/http_stub/server/stub/truthy_request_matcher_spec.rb +0 -23
  114. data/spec/lib/http_stub/server/stub/uri_spec.rb +0 -43
@@ -1,235 +0,0 @@
1
- describe HttpStub::Server::Stub::Instance do
2
-
3
- let(:request_header_payload) do
4
- {
5
- "header1" => "header_value1",
6
- "header2" => "header_value2",
7
- "header3" => "header_value3"
8
- }
9
- end
10
- let(:request_parameter_payload) do
11
- {
12
- "param1" => "param_value1",
13
- "param2" => "param_value2",
14
- "param3" => "param_value3"
15
- }
16
- end
17
- let(:request_method_payload) { "get" }
18
- let(:trigger_payload) 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
- "body" => { "schema" => { "json" => "trigger schema definition" } },
25
- "response" => {
26
- "status" => 203,
27
- "body" => "Triggered body"
28
- }
29
- }
30
- end
31
- let(:stub_payload) do
32
- {
33
- "uri" => "/a_path",
34
- "method" => stub_method,
35
- "headers" => request_header_payload,
36
- "parameters" => request_parameter_payload,
37
- "body" => { "schema" => { "json" => "stub schema definition" } },
38
- "response" => {
39
- "status" => 201,
40
- "body" => "Some body"
41
- },
42
- "triggers" => [ trigger_payload ]
43
- }
44
- end
45
- let(:stub_method) { instance_double(HttpStub::Server::Stub::Method, match?: true) }
46
- let(:uri) { instance_double(HttpStub::Server::Stub::Uri, match?: true) }
47
- let(:request_headers) { instance_double(HttpStub::Server::Stub::RequestHeaders, match?: true) }
48
- let(:request_parameters) { instance_double(HttpStub::Server::Stub::RequestParameters, match?: true) }
49
- let(:request_body) { double("HttpStub::Server::Stub::SomeRequestBody", match?: true) }
50
- let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
51
- let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers) }
52
-
53
- let(:the_stub) { HttpStub::Server::Stub::Instance.new(stub_payload) }
54
-
55
- before(:example) do
56
- allow(HttpStub::Server::Stub::Method).to receive(:new).and_return(stub_method)
57
- allow(HttpStub::Server::Stub::Uri).to receive(:new).and_return(uri)
58
- allow(HttpStub::Server::Stub::RequestHeaders).to receive(:new).and_return(request_headers)
59
- allow(HttpStub::Server::Stub::RequestParameters).to receive(:new).and_return(request_parameters)
60
- allow(HttpStub::Server::Stub::RequestBody).to receive(:create).and_return(request_body)
61
- allow(HttpStub::Server::Stub::Response).to receive(:create).and_return(response)
62
- allow(HttpStub::Server::Stub::Triggers).to receive(:new).and_return(triggers)
63
- end
64
-
65
- describe "#satisfies?" do
66
-
67
- let(:request_method) { request_method_payload }
68
- let(:request_uri) { "/a_request_uri" }
69
- let(:request) { instance_double(Rack::Request, :request_method => request_method_payload) }
70
-
71
- subject { the_stub.satisfies?(request) }
72
-
73
- describe "when the request uri matches" do
74
-
75
- before(:example) { allow(uri).to receive(:match?).with(request).and_return(true) }
76
-
77
- describe "and the request method matches" do
78
-
79
- describe "and a header match is configured" do
80
-
81
- describe "that matches" do
82
-
83
- before(:example) { allow(request_headers).to receive(:match?).with(request).and_return(true) }
84
-
85
- describe "and a parameter match is configured" do
86
-
87
- describe "that matches" do
88
-
89
- before(:example) { allow(request_parameters).to receive(:match?).with(request).and_return(true) }
90
-
91
- describe "and a body match is configured" do
92
-
93
- describe "that matches" do
94
-
95
- before(:example) { allow(request_body).to receive(:match?).with(request).and_return(true) }
96
-
97
- it "returns true" do
98
- expect(subject).to be(true)
99
- end
100
-
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- end
110
-
111
- end
112
-
113
- end
114
-
115
- end
116
-
117
- describe "when the request uri does not match" do
118
-
119
- before(:example) { allow(uri).to receive(:match?).with(request).and_return(false) }
120
-
121
- it "returns false" do
122
- expect(subject).to be(false)
123
- end
124
-
125
- end
126
-
127
- describe "when the request method does not match" do
128
-
129
- before(:example) { allow(stub_method).to receive(:match?).with(request).and_return(false) }
130
-
131
- it "returns false" do
132
- expect(subject).to be(false)
133
- end
134
-
135
- end
136
-
137
- describe "when the headers do not match" do
138
-
139
- before(:example) { allow(request_headers).to receive(:match?).with(request).and_return(false) }
140
-
141
- it "returns false" do
142
- expect(subject).to be(false)
143
- end
144
-
145
- end
146
-
147
- describe "when the parameters do not match" do
148
-
149
- before(:example) { allow(request_parameters).to receive(:match?).with(request).and_return(false) }
150
-
151
- it "returns false" do
152
- expect(subject).to be(false)
153
- end
154
-
155
- end
156
-
157
- describe "when the bodies do not match" do
158
-
159
- before(:example) { allow(request_body).to receive(:match?).with(request).and_return(false) }
160
-
161
- it "returns false" do
162
- expect(subject).to be(false)
163
- end
164
-
165
- end
166
-
167
- end
168
-
169
- describe "#method" do
170
-
171
- it "returns the method model encapsulating the method provided in the request body" do
172
- expect(the_stub.method).to eql(stub_method)
173
- end
174
-
175
- end
176
-
177
- describe "#uri" do
178
-
179
- it "returns the rui model encapsulating the uri provided in the request body" do
180
- expect(the_stub.uri).to eql(uri)
181
- end
182
-
183
- end
184
-
185
- describe "#headers" do
186
-
187
- it "returns the headers model encapsulating the headers provided in the request body" do
188
- expect(the_stub.headers).to eql(request_headers)
189
- end
190
-
191
- end
192
-
193
- describe "#parameters" do
194
-
195
- it "returns the parameters model encapsulating the parameters provided in the request body" do
196
- expect(the_stub.parameters).to eql(request_parameters)
197
- end
198
-
199
- end
200
-
201
- describe "#body" do
202
-
203
- it "returns the body model encapsulating the body provided in the request body" do
204
- expect(the_stub.body).to eql(request_body)
205
- end
206
-
207
- end
208
-
209
- describe "#response" do
210
-
211
- it "exposes the response model encapsulating the response provided in the request body" do
212
- expect(the_stub.response).to eql(response)
213
- end
214
-
215
- end
216
-
217
- describe "#triggers" do
218
-
219
- it "returns the triggers model encapsulating the triggers provided in the request body" do
220
- expect(the_stub.triggers).to eql(triggers)
221
- end
222
-
223
- end
224
-
225
- describe "#to_s" do
226
-
227
- it "returns a string representation of the stub arguments" do
228
- expect(stub_payload).to receive(:to_s).and_return("stub arguments string")
229
-
230
- expect(the_stub.to_s).to eql("stub arguments string")
231
- end
232
-
233
- end
234
-
235
- end
@@ -1,68 +0,0 @@
1
- describe HttpStub::Server::Stub::RequestHeaders do
2
-
3
- let(:request) { instance_double(Rack::Request) }
4
- let(:stubbed_headers) { { "stub_key" => "value" } }
5
-
6
- let(:request_headers) { HttpStub::Server::Stub::RequestHeaders.new(stubbed_headers) }
7
-
8
- it "is Headers" do
9
- expect(request_headers).to be_a(HttpStub::Server::Stub::Headers)
10
- end
11
-
12
- describe "when stubbed headers are provided" do
13
-
14
- it "creates a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
15
- downcased_and_underscored_hash = { "another_stub_key" => "value" }
16
- expect(stubbed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
17
- expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with(downcased_and_underscored_hash)
18
-
19
- request_headers
20
- end
21
-
22
- end
23
-
24
- describe "when the stubbed headers are nil" do
25
-
26
- let(:stubbed_headers) { nil }
27
-
28
- it "creates a regexpable representation of an empty hash" do
29
- expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with({})
30
-
31
- request_headers
32
- end
33
-
34
- end
35
-
36
- describe "#match?" do
37
-
38
- let(:parsed_headers) { { "request_key" => "value" } }
39
- let(:regexpable_stubbed_headers) { double(HttpStub::Server::Stub::HashWithStringValueMatchers).as_null_object }
40
-
41
- before(:example) do
42
- allow(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_headers)
43
- allow(HttpStub::Server::Stub::RequestHeaderParser).to receive(:parse).with(request).and_return(parsed_headers)
44
- end
45
-
46
- it "parses the requests headers into a hash" do
47
- expect(HttpStub::Server::Stub::RequestHeaderParser).to receive(:parse).with(request).and_return(parsed_headers)
48
-
49
- request_headers.match?(request)
50
- end
51
-
52
- it "downcases and underscore the keys in the request header hash" do
53
- expect(parsed_headers).to receive(:downcase_and_underscore_keys)
54
-
55
- request_headers.match?(request)
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(parsed_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
-
63
- expect(request_headers.match?(request)).to be_truthy
64
- end
65
-
66
- end
67
-
68
- end
@@ -1,43 +0,0 @@
1
- describe HttpStub::Server::Stub::SimpleRequestBody do
2
-
3
- let(:raw_body) { "some body" }
4
- let(:value_matcher) { instance_double(HttpStub::Server::Stub::StringValueMatcher).as_null_object }
5
-
6
- let(:simple_request_body) { HttpStub::Server::Stub::SimpleRequestBody.new(raw_body) }
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 body" do
13
- expect(HttpStub::Server::Stub::StringValueMatcher).to receive(:new).with(raw_body)
14
-
15
- simple_request_body
16
- end
17
-
18
- end
19
-
20
- describe "#match?" do
21
-
22
- let(:request_body) { "some request body" }
23
- let(:request) { instance_double(Rack::Request, body: double("Rack::Body", read: request_body)) }
24
-
25
- it "delegates to the value matcher to match the request body" do
26
- expect(value_matcher).to receive(:match?).with(request_body).and_return(true)
27
-
28
- expect(simple_request_body.match?(request)).to be(true)
29
- end
30
-
31
- end
32
-
33
- describe "#to_s" do
34
-
35
- it "delegates to the value matcher representation of the provided body" do
36
- expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
37
-
38
- expect(simple_request_body.to_s).to eql("some value matcher string")
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,23 +0,0 @@
1
- describe HttpStub::Server::Stub::TruthyRequestMatcher do
2
-
3
- let(:truthy_request_matcher) { HttpStub::Server::Stub::TruthyRequestMatcher }
4
-
5
- describe "::match?" do
6
-
7
- let(:request) { instance_double(Rack::Request) }
8
-
9
- it "returns true" do
10
- expect(truthy_request_matcher.match?(request)).to be(true)
11
- end
12
-
13
- end
14
-
15
- describe "::to_s" do
16
-
17
- it "returns an empty string" do
18
- expect(truthy_request_matcher.to_s).to eql("")
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,43 +0,0 @@
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(true)
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