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
@@ -4,52 +4,52 @@ describe HttpStub::ServerDaemon do
|
|
4
4
|
|
5
5
|
let(:server_daemon) { HttpStub::ServerDaemon.new(name: :sample_server_daemon, port: 8888, configurer: configurer) }
|
6
6
|
|
7
|
-
before(:
|
7
|
+
before(:example) { allow(server_daemon.logger).to receive(:info) }
|
8
8
|
|
9
9
|
describe ".log_dir" do
|
10
10
|
|
11
|
-
before(:
|
11
|
+
before(:example) { @original_log_dir = HttpServerManager.log_dir }
|
12
12
|
|
13
|
-
after(:
|
13
|
+
after(:example) { HttpServerManager.log_dir = @original_log_dir }
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "establishes the HttpServerManager log_dir" do
|
16
16
|
HttpStub::ServerDaemon.log_dir = "/some/log/dir"
|
17
17
|
|
18
|
-
HttpServerManager.log_dir.
|
18
|
+
expect(HttpServerManager.log_dir).to eql("/some/log/dir")
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe ".pid_dir" do
|
24
24
|
|
25
|
-
before(:
|
25
|
+
before(:example) { @original_pid_dir = HttpServerManager.pid_dir }
|
26
26
|
|
27
|
-
after(:
|
27
|
+
after(:example) { HttpServerManager.pid_dir = @original_pid_dir }
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "establishes the HttpServerManager pid_dir" do
|
30
30
|
HttpStub::ServerDaemon.pid_dir = "/some/pid/dir"
|
31
31
|
|
32
|
-
HttpServerManager.pid_dir.
|
32
|
+
expect(HttpServerManager.pid_dir).to eql("/some/pid/dir")
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "#start!" do
|
38
38
|
|
39
|
-
before(:
|
39
|
+
before(:example) { allow(server_daemon).to receive(:running?).and_return(true) }
|
40
40
|
|
41
41
|
context "when a configurer is provided" do
|
42
42
|
|
43
43
|
let(:configurer) { double(HttpStub::Configurer).as_null_object }
|
44
44
|
|
45
|
-
it "
|
46
|
-
configurer.
|
45
|
+
it "initializes the configurer" do
|
46
|
+
expect(configurer).to receive(:initialize!)
|
47
47
|
|
48
48
|
server_daemon.start!
|
49
49
|
end
|
50
50
|
|
51
|
-
it "
|
52
|
-
server_daemon.logger.
|
51
|
+
it "logs that the server with the provided name has been initialized" do
|
52
|
+
expect(server_daemon.logger).to receive(:info).with("sample_server_daemon initialized")
|
53
53
|
|
54
54
|
server_daemon.start!
|
55
55
|
end
|
@@ -58,8 +58,8 @@ describe HttpStub::ServerDaemon do
|
|
58
58
|
|
59
59
|
context "when no configurer is provided" do
|
60
60
|
|
61
|
-
it "
|
62
|
-
server_daemon.logger.
|
61
|
+
it "does not log that the server has been initialized" do
|
62
|
+
expect(server_daemon.logger).not_to receive(:info).with("sample_server_daemon initialized")
|
63
63
|
|
64
64
|
server_daemon.start!
|
65
65
|
end
|
@@ -8,22 +8,22 @@ describe HttpStub::Server, "when the server is running" do
|
|
8
8
|
|
9
9
|
context "when provided with the minimum data required" do
|
10
10
|
|
11
|
-
before(:
|
11
|
+
before(:example) do
|
12
12
|
@response = HTTParty.post(
|
13
13
|
"#{server_uri}/stubs",
|
14
14
|
body: { uri: "/some/path", method: "get", response: { status: 200, body: "Some body" } }.to_json
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
19
|
-
@response.code.
|
18
|
+
it "returns a 200 response code" do
|
19
|
+
expect(@response.code).to eql(200)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "registers a stub returning the provided response for a matching request" do
|
23
23
|
stubbed_response = HTTParty.get("#{server_uri}/some/path")
|
24
24
|
|
25
|
-
stubbed_response.code.
|
26
|
-
stubbed_response.body.
|
25
|
+
expect(stubbed_response.code).to eql(200)
|
26
|
+
expect(stubbed_response.body).to eql("Some body")
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
@@ -32,104 +32,151 @@ describe HttpStub::Server, "when the server is running" do
|
|
32
32
|
|
33
33
|
describe "and a configurer with multiple stub activators is initialized" do
|
34
34
|
|
35
|
-
before(:
|
36
|
-
HttpStub::Examples::ConfigurerWithManyActivators
|
37
|
-
|
38
|
-
|
35
|
+
before(:context) do
|
36
|
+
configurer = HttpStub::Examples::ConfigurerWithManyActivators
|
37
|
+
configurer.host(server_host)
|
38
|
+
configurer.port(server_port)
|
39
|
+
configurer.initialize!
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
|
44
|
-
let(:response_document) { Nokogiri::HTML(response.body) }
|
42
|
+
shared_context "the response contains HTML describing the configurers stubs" do
|
45
43
|
|
46
|
-
it "
|
47
|
-
response.code.
|
44
|
+
it "returns a 200 response code" do
|
45
|
+
expect(response.code).to eql(200)
|
48
46
|
end
|
49
47
|
|
50
|
-
it "
|
51
|
-
|
52
|
-
|
48
|
+
it "returns a response whose body contains the uri of each stub" do
|
49
|
+
(1..3).each do |stub_number|
|
50
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}")}/)
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
it "
|
57
|
-
(1..3).each
|
54
|
+
it "returns a response whose body contains the uri of each stub trigger" do
|
55
|
+
(1..3).each do |stub_number|
|
56
|
+
(1..3).each do |trigger_number|
|
57
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}_trigger_#{trigger_number}")}/)
|
58
|
+
end
|
59
|
+
end
|
58
60
|
end
|
59
61
|
|
60
|
-
it "
|
61
|
-
(1..3).each
|
62
|
+
it "returns a response whose body contains the request headers of each stub" do
|
63
|
+
(1..3).each do |stub_number|
|
64
|
+
expect(response.body).to match(/request_header_#{stub_number}:request_header_value_#{stub_number}/)
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
|
-
it "
|
65
|
-
(1..3).each
|
68
|
+
it "returns a response whose body contains the request headers of each stub trigger" do
|
69
|
+
(1..3).each do |stub_number|
|
70
|
+
(1..3).each do |trigger_number|
|
71
|
+
expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
|
72
|
+
expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
|
73
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
74
|
+
end
|
75
|
+
end
|
66
76
|
end
|
67
77
|
|
68
|
-
it "
|
69
|
-
(1..3).each
|
78
|
+
it "returns a response whose body contains the parameters of each stub" do
|
79
|
+
(1..3).each do |stub_number|
|
80
|
+
expect(response.body).to match(/parameter_#{stub_number}=parameter_value_#{stub_number}/)
|
81
|
+
end
|
70
82
|
end
|
71
83
|
|
72
|
-
it "
|
73
|
-
(1..3).each
|
84
|
+
it "returns a response whose body contains the parameters of each stub trigger" do
|
85
|
+
(1..3).each do |stub_number|
|
86
|
+
(1..3).each do |trigger_number|
|
87
|
+
expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
|
88
|
+
expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
|
89
|
+
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
90
|
+
end
|
91
|
+
end
|
74
92
|
end
|
75
93
|
|
76
|
-
it "
|
77
|
-
response.body.
|
78
|
-
response.body.should match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
|
79
|
-
response.body.should match(/#{escape_html("<html><body>HTML body</body></html>")}/)
|
94
|
+
it "returns a response whose body contains the response status of each stub" do
|
95
|
+
(1..3).each { |stub_number| expect(response.body).to match(/20#{stub_number}/) }
|
80
96
|
end
|
81
97
|
|
82
|
-
it "
|
83
|
-
(1..3).each
|
98
|
+
it "returns a response whose body contains the response status of each stub trigger" do
|
99
|
+
(1..3).each do |stub_number|
|
100
|
+
(1..3).each do |trigger_number|
|
101
|
+
expect(response.body).to match(/30#{stub_number * trigger_number}/)
|
102
|
+
end
|
103
|
+
end
|
84
104
|
end
|
85
105
|
|
86
|
-
|
106
|
+
it "returns a response whose body contains the response headers of each stub" do
|
107
|
+
(1..3).each do |stub_number|
|
108
|
+
expected_header_key = "response_header_#{stub_number}"
|
109
|
+
expected_header_value = "response_header_value_#{stub_number}"
|
110
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
111
|
+
end
|
112
|
+
end
|
87
113
|
|
88
|
-
|
114
|
+
it "returns a response whose body contains the response headers of each stub trigger" do
|
115
|
+
(1..3).each do |stub_number|
|
116
|
+
(1..3).each do |trigger_number|
|
117
|
+
expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
|
118
|
+
expected_header_value = "response_header_value_#{stub_number}_trigger_#{trigger_number}"
|
119
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
89
123
|
|
90
|
-
|
124
|
+
it "returns a response whose body contains the response body of each stub" do
|
125
|
+
expect(response.body).to match(/Plain text body/)
|
126
|
+
expect(response.body).to match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
|
127
|
+
expect(response.body).to match(/#{escape_html("<html><body>HTML body</body></html>")}/)
|
128
|
+
end
|
91
129
|
|
92
|
-
|
93
|
-
|
130
|
+
it "returns a response whose body contains the response body of each stub trigger" do
|
131
|
+
(1..3).each do |stub_number|
|
132
|
+
(1..3).each do |trigger_number|
|
133
|
+
expect(response.body).to match(/Body of activator #{stub_number}_trigger_#{trigger_number}/)
|
134
|
+
end
|
94
135
|
end
|
136
|
+
end
|
95
137
|
|
96
|
-
|
97
|
-
|
138
|
+
it "returns a response whose body contains the response delay of each stub" do
|
139
|
+
(1..3).each { |stub_number| expect(response.body).to include("#{8 * stub_number}") }
|
140
|
+
end
|
98
141
|
|
99
|
-
|
100
|
-
|
142
|
+
it "returns a response whose body contains the response delay of each stub trigger" do
|
143
|
+
(1..3).each do |stub_number|
|
144
|
+
(1..3).each do |trigger_number|
|
145
|
+
expect(response.body).to include("#{3 * stub_number * trigger_number}")
|
146
|
+
end
|
101
147
|
end
|
148
|
+
end
|
102
149
|
|
103
|
-
|
104
|
-
(1..3).each { |i| response.body.should match(/#{escape_html("/path_#{i}")}/) }
|
105
|
-
end
|
150
|
+
end
|
106
151
|
|
107
|
-
|
108
|
-
(1..3).each { |i| response.body.should match(/request_header_#{i}:request_header_value_#{i}/) }
|
109
|
-
end
|
152
|
+
describe "GET #stubs/activators" do
|
110
153
|
|
111
|
-
|
112
|
-
|
113
|
-
end
|
154
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
|
155
|
+
let(:response_document) { Nokogiri::HTML(response.body) }
|
114
156
|
|
115
|
-
|
116
|
-
|
157
|
+
it "returns response whose body contains links to each activator in alphabetical order" do
|
158
|
+
response_document.css("a").each_with_index do |link, i|
|
159
|
+
expect(link['href']).to eql("/activator_#{i + 1}")
|
117
160
|
end
|
161
|
+
end
|
118
162
|
|
119
|
-
|
120
|
-
(1..3).each { |i| response.body.should match(/response_header_#{i}:response_header_value_#{i}/) }
|
121
|
-
end
|
163
|
+
include_context "the response contains HTML describing the configurers stubs"
|
122
164
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "GET #stubs" do
|
168
|
+
|
169
|
+
describe "when multiple stubs are configured" do
|
128
170
|
|
129
|
-
|
130
|
-
(1..3).each { |i|
|
171
|
+
before(:context) do
|
172
|
+
(1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") }
|
131
173
|
end
|
132
174
|
|
175
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs") }
|
176
|
+
let(:response_document) { Nokogiri::HTML(response.body) }
|
177
|
+
|
178
|
+
include_context "the response contains HTML describing the configurers stubs"
|
179
|
+
|
133
180
|
end
|
134
181
|
|
135
182
|
end
|
@@ -1,168 +1,228 @@
|
|
1
1
|
describe HttpStub::Server do
|
2
2
|
include Rack::Test::Methods
|
3
3
|
|
4
|
-
let(:response)
|
4
|
+
let(:response) { last_response }
|
5
5
|
let(:response_body) { response.body.to_s }
|
6
6
|
|
7
|
-
let(:stub_registry)
|
8
|
-
let(:stub_activator_registry) {
|
7
|
+
let(:stub_registry) { instance_double(HttpStub::Models::StubRegistry).as_null_object }
|
8
|
+
let(:stub_activator_registry) { instance_double(HttpStub::Models::Registry).as_null_object }
|
9
9
|
|
10
|
-
let(:stub_controller)
|
11
|
-
let(:stub_activator_controller) {
|
10
|
+
let(:stub_controller) { instance_double(HttpStub::Controllers::StubController).as_null_object }
|
11
|
+
let(:stub_activator_controller) { instance_double(HttpStub::Controllers::StubActivatorController).as_null_object }
|
12
12
|
|
13
13
|
let(:app) { HttpStub::Server.new! }
|
14
14
|
|
15
|
-
before(:
|
16
|
-
HttpStub::Models::
|
17
|
-
HttpStub::Models::Registry.
|
18
|
-
HttpStub::Controllers::StubController.
|
19
|
-
HttpStub::Controllers::StubActivatorController.
|
15
|
+
before(:example) do
|
16
|
+
allow(HttpStub::Models::StubRegistry).to receive(:new).and_return(stub_registry)
|
17
|
+
allow(HttpStub::Models::Registry).to receive(:new).with("stub_activator").and_return(stub_activator_registry)
|
18
|
+
allow(HttpStub::Controllers::StubController).to receive(:new).and_return(stub_controller)
|
19
|
+
allow(HttpStub::Controllers::StubActivatorController).to receive(:new).and_return(stub_activator_controller)
|
20
20
|
end
|
21
21
|
|
22
|
-
context "when a stub insertion is received" do
|
22
|
+
context "when a stub insertion request is received" do
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
subject do
|
25
|
+
post "/stubs", {
|
26
|
+
uri: "/a_path", method: "a method",
|
27
|
+
response: { status: 200, body: "Foo" }
|
28
|
+
}.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
it "registers the insertion via the stub controller" do
|
32
|
+
expect(stub_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
|
26
33
|
|
27
|
-
|
34
|
+
subject
|
28
35
|
end
|
29
36
|
|
30
|
-
it "
|
31
|
-
stub_controller.
|
37
|
+
it "responds with the response provided by the controller" do
|
38
|
+
allow(stub_controller).to receive(:register).and_return(HttpStub::Models::Response.new("status" => 202, "body" => ""))
|
32
39
|
|
33
|
-
|
40
|
+
subject
|
34
41
|
|
35
|
-
response.status.
|
42
|
+
expect(response.status).to eql(202)
|
36
43
|
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when a request to commit the stubs to memory is received" do
|
48
|
+
|
49
|
+
subject { post "/stubs/memory" }
|
50
|
+
|
51
|
+
it "remembers the stubs in the stub registry" do
|
52
|
+
expect(stub_registry).to receive(:remember)
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
it "responds with a 200 status code" do
|
58
|
+
subject
|
59
|
+
|
60
|
+
expect(response.status).to eql(200)
|
43
61
|
end
|
44
62
|
|
45
63
|
end
|
46
64
|
|
47
|
-
context "when a
|
65
|
+
context "when a request to recall the stubs in memory is received" do
|
66
|
+
|
67
|
+
subject { get "/stubs/memory" }
|
48
68
|
|
49
|
-
it "
|
50
|
-
|
69
|
+
it "recalls the stubs remembered by the stub registry" do
|
70
|
+
expect(stub_registry).to receive(:recall)
|
51
71
|
|
52
|
-
|
72
|
+
subject
|
53
73
|
end
|
54
74
|
|
55
|
-
it "
|
56
|
-
|
57
|
-
|
58
|
-
)
|
75
|
+
it "responds with a 200 status code" do
|
76
|
+
subject
|
77
|
+
|
78
|
+
expect(response.status).to eql(200)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when a request to clear the stubs has been received" do
|
84
|
+
|
85
|
+
subject { delete "/stubs" }
|
59
86
|
|
60
|
-
|
87
|
+
it "delegates clearing to the stub controller" do
|
88
|
+
expect(stub_controller).to receive(:clear)
|
61
89
|
|
62
|
-
|
90
|
+
subject
|
63
91
|
end
|
64
92
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}.to_json
|
93
|
+
it "responds with a 200 status code" do
|
94
|
+
subject
|
95
|
+
|
96
|
+
expect(response.status).to eql(200)
|
70
97
|
end
|
71
98
|
|
72
99
|
end
|
73
100
|
|
74
|
-
context "when a
|
101
|
+
context "when a stub activator insertion request is received" do
|
102
|
+
|
103
|
+
subject do
|
104
|
+
post "/stubs/activators", {
|
105
|
+
activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
|
106
|
+
response: { status: 200, body: "Foo" }
|
107
|
+
}.to_json
|
108
|
+
end
|
75
109
|
|
76
|
-
it "
|
77
|
-
|
110
|
+
it "registers the insertion via the stub activator controller" do
|
111
|
+
expect(stub_activator_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
|
78
112
|
|
79
|
-
|
113
|
+
subject
|
80
114
|
end
|
81
115
|
|
82
|
-
it "
|
83
|
-
|
116
|
+
it "responds with the response provided by the controller" do
|
117
|
+
allow(stub_activator_controller).to(
|
118
|
+
receive(:register).and_return(HttpStub::Models::Response.new("status" => 302, "body" => ""))
|
119
|
+
)
|
120
|
+
|
121
|
+
subject
|
84
122
|
|
85
|
-
response.status.
|
123
|
+
expect(response.status).to eql(302)
|
86
124
|
end
|
87
125
|
|
88
126
|
end
|
89
127
|
|
90
128
|
context "when a request to clear the stub activators has been received" do
|
91
129
|
|
92
|
-
|
93
|
-
stub_activator_controller.should_receive(:clear)
|
130
|
+
subject { delete "/stubs/activators" }
|
94
131
|
|
95
|
-
|
132
|
+
it "delegates clearing to the stub activator controller" do
|
133
|
+
expect(stub_activator_controller).to receive(:clear)
|
134
|
+
|
135
|
+
subject
|
96
136
|
end
|
97
137
|
|
98
|
-
it "
|
99
|
-
|
138
|
+
it "responds with a 200 status code" do
|
139
|
+
subject
|
100
140
|
|
101
|
-
response.status.
|
141
|
+
expect(response.status).to eql(200)
|
102
142
|
end
|
103
143
|
|
104
144
|
end
|
105
145
|
|
106
146
|
context "when another type of request is received" do
|
107
147
|
|
148
|
+
subject { get "/a_path" }
|
149
|
+
|
108
150
|
context "and the stub controller replays a response" do
|
109
151
|
|
110
|
-
|
111
|
-
|
152
|
+
let(:controller_response) do
|
153
|
+
HttpStub::Models::Response.new(
|
154
|
+
"status" => 222,
|
155
|
+
"headers" => { "content-type" => "application/xhtml" },
|
156
|
+
"body" => "Some body"
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
before(:example) { allow(stub_controller).to receive(:replay).and_return(controller_response) }
|
161
|
+
|
162
|
+
it "responds with the replay status code" do
|
163
|
+
subject
|
164
|
+
|
165
|
+
expect(response.status).to eql(222)
|
112
166
|
end
|
113
167
|
|
114
|
-
it "
|
115
|
-
|
168
|
+
it "responds with the replay body" do
|
169
|
+
subject
|
116
170
|
|
117
|
-
|
171
|
+
expect(response_body).to eql("Some body")
|
118
172
|
end
|
119
173
|
|
120
|
-
it "
|
121
|
-
|
174
|
+
it "responds with the replay content type" do
|
175
|
+
subject
|
122
176
|
|
123
|
-
|
177
|
+
expect(response.content_type).to eql("application/xhtml")
|
178
|
+
end
|
179
|
+
|
180
|
+
it "allows the request pipeline to process the response before the processing of the request halts" do
|
181
|
+
expect(HttpStub::Models::RequestPipeline).to receive(:before_halt).with(controller_response)
|
182
|
+
|
183
|
+
subject
|
124
184
|
end
|
125
185
|
|
126
186
|
end
|
127
187
|
|
128
188
|
context "and the stub controller does not replay a response" do
|
129
189
|
|
130
|
-
before(:
|
131
|
-
stub_controller.
|
190
|
+
before(:example) do
|
191
|
+
allow(stub_controller).to receive(:replay).and_return(HttpStub::Models::Response::EMPTY)
|
132
192
|
end
|
133
193
|
|
134
194
|
context "but the stub activator controller activates a stub" do
|
135
195
|
|
136
|
-
before(:
|
137
|
-
stub_activator_controller.
|
196
|
+
before(:example) do
|
197
|
+
allow(stub_activator_controller).to receive(:activate).and_return(
|
138
198
|
HttpStub::Models::Response.new("status" => 300, "body" => "A body")
|
139
199
|
)
|
140
200
|
end
|
141
201
|
|
142
|
-
it "
|
143
|
-
|
202
|
+
it "responds with the activation response status code" do
|
203
|
+
subject
|
144
204
|
|
145
|
-
response.status.
|
205
|
+
expect(response.status).to eql(300)
|
146
206
|
end
|
147
207
|
|
148
|
-
it "
|
149
|
-
|
208
|
+
it "responds with the activation response body" do
|
209
|
+
subject
|
150
210
|
|
151
|
-
response_body.
|
211
|
+
expect(response_body).to eql("A body")
|
152
212
|
end
|
153
213
|
|
154
214
|
end
|
155
215
|
|
156
216
|
context "and the stub activator controller does not activate a stub" do
|
157
217
|
|
158
|
-
before(:
|
159
|
-
stub_activator_controller.
|
218
|
+
before(:example) do
|
219
|
+
allow(stub_activator_controller).to receive(:activate).and_return(HttpStub::Models::Response::EMPTY)
|
160
220
|
end
|
161
221
|
|
162
|
-
it "
|
163
|
-
|
222
|
+
it "responds with a 404 status code" do
|
223
|
+
subject
|
164
224
|
|
165
|
-
response.status.
|
225
|
+
expect(response.status).to eql(404)
|
166
226
|
end
|
167
227
|
|
168
228
|
end
|
@@ -171,26 +231,4 @@ describe HttpStub::Server do
|
|
171
231
|
|
172
232
|
end
|
173
233
|
|
174
|
-
context "when a request to replay a stub is received" do
|
175
|
-
|
176
|
-
it "should handle processing of the response via the request pipeline" do
|
177
|
-
HttpStub::Models::RequestPipeline.should_receive(:before_halt).with(duck_type(:status, :body))
|
178
|
-
|
179
|
-
get "/some/stubbed/uri"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should respond with the response's content type" do
|
183
|
-
stub_controller.stub(:replay).and_return(
|
184
|
-
HttpStub::Models::Response.new(
|
185
|
-
"status" => 200, "headers" => { "content-type" => "application/xhtml" }, "body" => "A body"
|
186
|
-
)
|
187
|
-
)
|
188
|
-
|
189
|
-
get "/some/stubbed/uri"
|
190
|
-
|
191
|
-
response.content_type.should eql("application/xhtml")
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
234
|
end
|