http_stub 0.13.5 → 0.14.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +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
@@ -2,179 +2,40 @@ describe HttpStub::Configurer::Request::Stub do
|
|
2
2
|
|
3
3
|
describe "#initialize" do
|
4
4
|
|
5
|
-
context "when provided a
|
6
|
-
|
7
|
-
let(:uri) { "/some/uri" }
|
8
|
-
let(:stub_method) { "Some Method" }
|
9
|
-
let(:request_headers) { { "request_header_name" => "value" } }
|
10
|
-
let(:request_parameters) { { "parameter_name" => "value" } }
|
11
|
-
let(:response_status) { 500 }
|
12
|
-
let(:response_headers) { { "response_header_name" => "value" } }
|
13
|
-
let(:response_body) { "Some body" }
|
14
|
-
let(:response_delay_in_seconds) { 7 }
|
15
|
-
|
16
|
-
let(:stub_args) do
|
17
|
-
{
|
18
|
-
method: stub_method,
|
19
|
-
headers: request_headers,
|
20
|
-
parameters: request_parameters,
|
21
|
-
response: {
|
22
|
-
status: response_status,
|
23
|
-
headers: response_headers,
|
24
|
-
body: response_body,
|
25
|
-
delay_in_seconds: response_delay_in_seconds
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
5
|
+
context "when provided a payload" do
|
29
6
|
|
30
|
-
let(:
|
31
|
-
let(:request_body) { JSON.parse(request.body) }
|
7
|
+
let(:payload) { { payload_key: "payload value" } }
|
32
8
|
|
33
|
-
|
9
|
+
let(:request) { HttpStub::Configurer::Request::Stub.new(payload) }
|
34
10
|
|
35
|
-
it "
|
36
|
-
request.method.
|
11
|
+
it "creates a HTTP POST request" do
|
12
|
+
expect(request.method).to eql("POST")
|
37
13
|
end
|
38
14
|
|
39
|
-
it "
|
40
|
-
request.path.
|
15
|
+
it "submits the request to '/stubs'" do
|
16
|
+
expect(request.path).to eql("/stubs")
|
41
17
|
end
|
42
18
|
|
43
|
-
it "
|
44
|
-
request.content_type.
|
19
|
+
it "sets the content type to json" do
|
20
|
+
expect(request.content_type).to eql("application/json")
|
45
21
|
end
|
46
22
|
|
47
|
-
|
48
|
-
|
49
|
-
it "should format the headers into control values" do
|
50
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with(request_headers)
|
51
|
-
|
52
|
-
request
|
53
|
-
end
|
54
|
-
|
23
|
+
it "sets the body to the JSON representation of the provided payload" do
|
24
|
+
expect(request.body).to eql(payload.to_json)
|
55
25
|
end
|
56
26
|
|
57
|
-
|
58
|
-
|
59
|
-
let(:request_headers) { nil }
|
60
|
-
|
61
|
-
it "should format an empty header hash" do
|
62
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with({})
|
63
|
-
|
64
|
-
request
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when a request parameter argument is provided" do
|
70
|
-
|
71
|
-
it "should format the request parameters into control values" do
|
72
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with(request_parameters)
|
73
|
-
|
74
|
-
request
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when no request parameter argument is provided" do
|
80
|
-
|
81
|
-
let(:request_parameters) { nil }
|
82
|
-
|
83
|
-
it "should format an empty parameter hash" do
|
84
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with({})
|
85
|
-
|
86
|
-
request
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
context "generates a JSON body which" do
|
92
|
-
|
93
|
-
it "should have an entry containing the control value representation of the uri" do
|
94
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with(uri).and_return("uri as a string")
|
95
|
-
|
96
|
-
request_body.should include("uri" => "uri as a string")
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should have an entry for the method argument" do
|
100
|
-
request_body.should include("method" => stub_method)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should have an entry containing the string representation of the request headers" do
|
104
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format)
|
105
|
-
.with(request_headers).and_return("request headers as string")
|
106
|
-
|
107
|
-
request_body.should include("headers" => "request headers as string")
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should have an entry containing the string representation of the request parameters" do
|
111
|
-
HttpStub::Configurer::Request::ControllableValue.should_receive(:format)
|
112
|
-
.with(request_parameters).and_return("request parameters as string")
|
113
|
-
|
114
|
-
request_body.should include("parameters" => "request parameters as string")
|
115
|
-
end
|
116
|
-
|
117
|
-
context "when a status response argument is provided" do
|
118
|
-
|
119
|
-
it "should have a response entry for the argument" do
|
120
|
-
request_body["response"].should include("status" => response_status)
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when no status response argument is provided" do
|
126
|
-
|
127
|
-
let(:response_status) { nil }
|
128
|
-
|
129
|
-
it "should have a response entry with an empty status code" do
|
130
|
-
request_body["response"].should include("status" => "")
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should have an entry for the response body argument" do
|
136
|
-
request_body["response"].should include("body" => response_body)
|
137
|
-
end
|
138
|
-
|
139
|
-
context "when a delay argument is provided" do
|
140
|
-
|
141
|
-
it "should have a response entry for the argument" do
|
142
|
-
request_body["response"].should include("delay_in_seconds" => response_delay_in_seconds)
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
context "when a delay argument is not provided" do
|
148
|
-
|
149
|
-
let(:response_delay_in_seconds) { nil }
|
150
|
-
|
151
|
-
it "should have a response entry with an empty delay" do
|
152
|
-
request_body["response"].should include("delay_in_seconds" => "")
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
context "when response headers are provided" do
|
158
|
-
|
159
|
-
let(:response_headers) { { "response_header_name" => "value" } }
|
160
|
-
|
161
|
-
it "should have a headers response entry containing the the provided headers" do
|
162
|
-
request_body["response"]["headers"].should eql(response_headers)
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
27
|
+
end
|
166
28
|
|
167
|
-
|
29
|
+
end
|
168
30
|
|
169
|
-
|
31
|
+
describe "#stub_uri" do
|
170
32
|
|
171
|
-
|
172
|
-
request_body["response"]["headers"].should eql({})
|
173
|
-
end
|
174
|
-
end
|
33
|
+
let(:stub_uri) { "/some/stub/uri" }
|
175
34
|
|
176
|
-
|
35
|
+
let(:request) { HttpStub::Configurer::Request::Stub.new(uri: stub_uri) }
|
177
36
|
|
37
|
+
it "should return the uri from the payload" do
|
38
|
+
expect(request.stub_uri).to eql(stub_uri)
|
178
39
|
end
|
179
40
|
|
180
41
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::BufferedCommandProcessor do
|
2
|
+
|
3
|
+
let(:command_processor) { instance_double(HttpStub::Configurer::Server::CommandProcessor) }
|
4
|
+
|
5
|
+
let(:buffered_command_processor) { HttpStub::Configurer::Server::BufferedCommandProcessor.new(command_processor) }
|
6
|
+
|
7
|
+
describe "#flush" do
|
8
|
+
|
9
|
+
subject { buffered_command_processor.flush }
|
10
|
+
|
11
|
+
describe "when a number of commands have been buffered via processing" do
|
12
|
+
|
13
|
+
let(:commands) { (1..3).map { instance_double(HttpStub::Configurer::Server::Command) } }
|
14
|
+
|
15
|
+
before(:example) { commands.each { |command| buffered_command_processor.process(command) } }
|
16
|
+
|
17
|
+
it "processes the buffered commands via the command processor" do
|
18
|
+
commands.each { |command| expect(command_processor).to receive(:process).with(command) }
|
19
|
+
|
20
|
+
subject
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "when no commands have been buffered" do
|
26
|
+
|
27
|
+
it "executes without error" do
|
28
|
+
expect { subject }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::CommandProcessor do
|
2
|
+
|
3
|
+
let(:command) { HttpStub::Configurer::Server::Command.new(request: request, description: "performing an operation") }
|
4
|
+
let(:server_base_uri) { "http://localhost:8001" }
|
5
|
+
|
6
|
+
let(:configurer) do
|
7
|
+
double(HttpStub::Configurer, get_base_uri: server_base_uri, get_host: "localhost", get_port: 8001)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:command_processor) { HttpStub::Configurer::Server::CommandProcessor.new(configurer) }
|
11
|
+
|
12
|
+
describe "#process" do
|
13
|
+
|
14
|
+
subject { command_processor.process(command) }
|
15
|
+
|
16
|
+
context "when the server is running" do
|
17
|
+
|
18
|
+
include_context "server integration"
|
19
|
+
|
20
|
+
describe "and the server responds with a 200 response" do
|
21
|
+
|
22
|
+
let(:request) { Net::HTTP::Get.new("/stubs") }
|
23
|
+
|
24
|
+
it "executes without error" do
|
25
|
+
expect { subject }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "and the server responds with a non-200 response" do
|
31
|
+
|
32
|
+
let(:request) { Net::HTTP::Get.new("/causes_error") }
|
33
|
+
|
34
|
+
it "raises an exception that includes the server base URI" do
|
35
|
+
expect { subject }.to raise_error(/#{server_base_uri}/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises an exception that includes the commands description" do
|
39
|
+
expect { subject }.to raise_error(/performing an operation/)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when the server is unavailable" do
|
47
|
+
|
48
|
+
let(:request) { Net::HTTP::Get.new("/does/not/exist") }
|
49
|
+
|
50
|
+
it "raises an exception that includes the server base URI" do
|
51
|
+
expect { subject }.to raise_error(/#{server_base_uri}/)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises an exception that includes the commands description" do
|
55
|
+
expect { subject }.to raise_error(/performing an operation/)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::Command do
|
2
|
+
|
3
|
+
let(:request) { double("HttpRequest") }
|
4
|
+
let(:description) { "Some Description" }
|
5
|
+
let(:args) { { request: request, description: description } }
|
6
|
+
|
7
|
+
let(:command) { HttpStub::Configurer::Server::Command.new(args) }
|
8
|
+
|
9
|
+
describe "#request" do
|
10
|
+
|
11
|
+
it "exposes the provided request" do
|
12
|
+
expect(command.request).to eql(request)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#description" do
|
18
|
+
|
19
|
+
it "exposes the provided description" do
|
20
|
+
expect(command.description).to eql(description)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::DSL do
|
2
|
+
|
3
|
+
let(:server_facade) { instance_double(HttpStub::Configurer::Server::Facade) }
|
4
|
+
|
5
|
+
let(:dsl) { HttpStub::Configurer::Server::DSL.new(server_facade) }
|
6
|
+
|
7
|
+
describe "#has_started!" do
|
8
|
+
|
9
|
+
it "informs the facade that the server has started" do
|
10
|
+
expect(server_facade).to receive(:server_has_started)
|
11
|
+
|
12
|
+
dsl.has_started!
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#build_stub" do
|
18
|
+
|
19
|
+
let(:stub_payload_builder) { instance_double(HttpStub::Configurer::Request::StubPayloadBuilder) }
|
20
|
+
|
21
|
+
before(:example) do
|
22
|
+
allow(HttpStub::Configurer::Request::StubPayloadBuilder).to receive(:new).and_return(stub_payload_builder)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a stub payload builder" do
|
26
|
+
expect(HttpStub::Configurer::Request::StubPayloadBuilder).to receive(:new)
|
27
|
+
|
28
|
+
dsl.build_stub
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when a block is provided" do
|
32
|
+
|
33
|
+
let(:block) { lambda { |_stub| "some block" } }
|
34
|
+
|
35
|
+
subject { dsl.build_stub(&block) }
|
36
|
+
|
37
|
+
it "yields the created builder to the provided block" do
|
38
|
+
expect(block).to receive(:call).with(stub_payload_builder)
|
39
|
+
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the created builder" do
|
44
|
+
expect(subject).to eql(stub_payload_builder)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when a block is not provided" do
|
50
|
+
|
51
|
+
subject { dsl.build_stub }
|
52
|
+
|
53
|
+
it "returns the built stub" do
|
54
|
+
expect(subject).to eql(stub_payload_builder)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#add_stub!" do
|
62
|
+
|
63
|
+
let(:stub_payload) { { stub_payload_key: "stub payload value" } }
|
64
|
+
let(:stub_payload_builder) do
|
65
|
+
instance_double(HttpStub::Configurer::Request::StubPayloadBuilder, build: stub_payload)
|
66
|
+
end
|
67
|
+
let(:stub_request) { instance_double(HttpStub::Configurer::Request::Stub) }
|
68
|
+
|
69
|
+
before(:example) do
|
70
|
+
allow(HttpStub::Configurer::Request::Stub).to receive(:new).and_return(stub_request)
|
71
|
+
allow(server_facade).to receive(:stub_response)
|
72
|
+
end
|
73
|
+
|
74
|
+
shared_examples_for "adding a stub payload" do
|
75
|
+
|
76
|
+
it "builds the stub payload" do
|
77
|
+
expect(stub_payload_builder).to receive(:build).and_return(stub_payload)
|
78
|
+
|
79
|
+
subject
|
80
|
+
end
|
81
|
+
|
82
|
+
it "creates a stub request with the built payload" do
|
83
|
+
expect(HttpStub::Configurer::Request::Stub).to receive(:new).with(stub_payload).and_return(stub_request)
|
84
|
+
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
it "informs the server facade to stub the response" do
|
89
|
+
expect(server_facade).to receive(:stub_response).with(stub_request)
|
90
|
+
|
91
|
+
subject
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when a stub payload builder is provided" do
|
97
|
+
|
98
|
+
subject { dsl.add_stub!(stub_payload_builder) }
|
99
|
+
|
100
|
+
it_behaves_like "adding a stub payload"
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when a stub payload builder is not provided" do
|
105
|
+
|
106
|
+
let(:block) { lambda { |_stub| "some block" } }
|
107
|
+
|
108
|
+
before(:example) do
|
109
|
+
allow(HttpStub::Configurer::Request::StubPayloadBuilder).to receive(:new).and_return(stub_payload_builder)
|
110
|
+
end
|
111
|
+
|
112
|
+
subject { dsl.add_stub!(&block) }
|
113
|
+
|
114
|
+
it "creates a stub payload builder" do
|
115
|
+
expect(HttpStub::Configurer::Request::StubPayloadBuilder).to receive(:new)
|
116
|
+
|
117
|
+
subject
|
118
|
+
end
|
119
|
+
|
120
|
+
it "yields the created builder to the provided block" do
|
121
|
+
expect(block).to receive(:call).with(stub_payload_builder)
|
122
|
+
|
123
|
+
subject
|
124
|
+
end
|
125
|
+
|
126
|
+
it_behaves_like "adding a stub payload"
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#add_activator!" do
|
133
|
+
|
134
|
+
let(:stub_activator_payload) { { activator_payload_key: "activator payload value" } }
|
135
|
+
let(:stub_activator_payload_builder) do
|
136
|
+
instance_double(HttpStub::Configurer::Request::StubActivatorPayloadBuilder, build: stub_activator_payload)
|
137
|
+
end
|
138
|
+
let(:stub_activator_request) { instance_double(HttpStub::Configurer::Request::StubActivator) }
|
139
|
+
|
140
|
+
before(:example) do
|
141
|
+
allow(HttpStub::Configurer::Request::StubActivator).to receive(:new).and_return(stub_activator_request)
|
142
|
+
allow(server_facade).to receive(:stub_activator)
|
143
|
+
end
|
144
|
+
|
145
|
+
let(:block) { lambda { |_activator| "some block" } }
|
146
|
+
|
147
|
+
before(:example) do
|
148
|
+
allow(HttpStub::Configurer::Request::StubActivatorPayloadBuilder).to(
|
149
|
+
receive(:new).and_return(stub_activator_payload_builder)
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
subject { dsl.add_activator!(&block) }
|
154
|
+
|
155
|
+
it "creates a stub activator payload builder" do
|
156
|
+
expect(HttpStub::Configurer::Request::StubActivatorPayloadBuilder).to receive(:new)
|
157
|
+
|
158
|
+
subject
|
159
|
+
end
|
160
|
+
|
161
|
+
it "yields the created builder to the provided block" do
|
162
|
+
expect(block).to receive(:call).with(stub_activator_payload_builder)
|
163
|
+
|
164
|
+
subject
|
165
|
+
end
|
166
|
+
|
167
|
+
it "builds the stub activator payload" do
|
168
|
+
expect(stub_activator_payload_builder).to receive(:build).and_return(stub_activator_payload)
|
169
|
+
|
170
|
+
subject
|
171
|
+
end
|
172
|
+
|
173
|
+
it "creates a stub activator request with the built payload" do
|
174
|
+
expect(HttpStub::Configurer::Request::StubActivator).to(
|
175
|
+
receive(:new).with(stub_activator_payload).and_return(stub_activator_request)
|
176
|
+
)
|
177
|
+
|
178
|
+
subject
|
179
|
+
end
|
180
|
+
|
181
|
+
it "informs the server facade to submit the stub activator request" do
|
182
|
+
expect(server_facade).to receive(:stub_activator).with(stub_activator_request)
|
183
|
+
|
184
|
+
subject
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "#activate!" do
|
190
|
+
|
191
|
+
let(:uri) { "/some/activation/uri" }
|
192
|
+
|
193
|
+
it "delegates to the server facade" do
|
194
|
+
expect(server_facade).to receive(:activate).with(uri)
|
195
|
+
|
196
|
+
dsl.activate!(uri)
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#remember_stubs" do
|
202
|
+
|
203
|
+
it "delegates to the server facade" do
|
204
|
+
expect(server_facade).to receive(:remember_stubs)
|
205
|
+
|
206
|
+
dsl.remember_stubs
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "#recall_stubs!" do
|
212
|
+
|
213
|
+
it "delegates to the server facade" do
|
214
|
+
expect(server_facade).to receive(:recall_stubs)
|
215
|
+
|
216
|
+
dsl.recall_stubs!
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "#clear_stubs!" do
|
222
|
+
|
223
|
+
it "delegates to the server facade" do
|
224
|
+
expect(server_facade).to receive(:clear_stubs)
|
225
|
+
|
226
|
+
dsl.clear_stubs!
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "#clear_activators!" do
|
232
|
+
|
233
|
+
it "delegates to the server facade" do
|
234
|
+
expect(server_facade).to receive(:clear_activators)
|
235
|
+
|
236
|
+
dsl.clear_activators!
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|