http_stub 0.25.1 → 0.26.0
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 +32 -9
- data/lib/http_stub/configurer.rb +2 -10
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
- data/lib/http_stub/configurer/dsl/server.rb +32 -43
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
- data/lib/http_stub/configurer/dsl/session.rb +55 -0
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
- data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
- data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
- data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
- data/lib/http_stub/configurer/request/http/basic.rb +9 -3
- data/lib/http_stub/configurer/request/http/factory.rb +7 -16
- data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/configurer/request/triggers.rb +25 -0
- data/lib/http_stub/configurer/server/command_processor.rb +8 -10
- data/lib/http_stub/configurer/server/configuration.rb +33 -0
- data/lib/http_stub/configurer/server/facade.rb +21 -43
- data/lib/http_stub/configurer/server/request_processor.rb +2 -2
- data/lib/http_stub/configurer/server/session_facade.rb +64 -0
- data/lib/http_stub/extensions/core/uri.rb +28 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -0
- data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
- data/lib/http_stub/rake/server_tasks.rb +1 -4
- data/lib/http_stub/server/application/application.rb +17 -98
- data/lib/http_stub/server/application/configuration.rb +38 -0
- data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
- data/lib/http_stub/server/application/request_support.rb +38 -0
- data/lib/http_stub/server/application/response_support.rb +19 -0
- data/lib/http_stub/server/application/routes/memory.rb +37 -0
- data/lib/http_stub/server/application/routes/resource.rb +23 -0
- data/lib/http_stub/server/application/routes/scenario.rb +52 -0
- data/lib/http_stub/server/application/routes/session.rb +65 -0
- data/lib/http_stub/server/application/routes/stub.rb +75 -0
- data/lib/http_stub/server/application/session_uri_support.rb +15 -0
- data/lib/http_stub/server/memory/controller.rb +25 -0
- data/lib/http_stub/server/memory/memory.rb +32 -0
- data/lib/http_stub/server/registry.rb +25 -8
- data/lib/http_stub/server/request/factory.rb +23 -0
- data/lib/http_stub/server/request/parameters.rb +2 -2
- data/lib/http_stub/server/request/request.rb +6 -11
- data/lib/http_stub/server/request/sinatra_request.rb +26 -0
- data/lib/http_stub/server/scenario/controller.rb +16 -11
- data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
- data/lib/http_stub/server/session.rb +14 -0
- data/lib/http_stub/server/session/configuration.rb +32 -0
- data/lib/http_stub/server/session/controller.rb +40 -0
- data/lib/http_stub/server/session/empty.rb +15 -0
- data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
- data/lib/http_stub/server/session/registry.rb +38 -0
- data/lib/http_stub/server/session/session.rb +80 -0
- data/lib/http_stub/server/stub/controller.rb +18 -12
- data/lib/http_stub/server/stub/empty.rb +1 -1
- data/lib/http_stub/server/stub/match/controller.rb +9 -5
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
- data/lib/http_stub/server/stub/registry.rb +6 -13
- data/lib/http_stub/server/stub/triggers.rb +11 -9
- data/lib/http_stub/server/views/_home.haml +2 -0
- data/lib/http_stub/server/views/_post_link_function.haml +26 -0
- data/lib/http_stub/server/views/_session.haml +16 -0
- data/lib/http_stub/server/views/_stub.haml +8 -2
- data/lib/http_stub/server/views/_stubs.haml +4 -0
- data/lib/http_stub/server/views/application.sass +4 -1
- data/lib/http_stub/server/views/layout.haml +1 -0
- data/lib/http_stub/server/views/scenario.haml +4 -3
- data/lib/http_stub/server/views/scenarios.haml +7 -6
- data/lib/http_stub/server/views/session.haml +3 -0
- data/lib/http_stub/server/views/sessions.haml +6 -0
- data/lib/http_stub/server/views/stubs.haml +1 -4
- data/lib/http_stub/server/views/transactional_session.haml +2 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/configurer_initialization_spec.rb +40 -51
- data/spec/acceptance/configurer_part_spec.rb +5 -7
- data/spec/acceptance/cross_origin_support_spec.rb +7 -13
- data/spec/acceptance/endpoint_template_spec.rb +2 -4
- data/spec/acceptance/request_reference_spec.rb +1 -3
- data/spec/acceptance/scenario_spec.rb +7 -9
- data/spec/acceptance/server_defaults_spec.rb +2 -4
- data/spec/acceptance/server_memory_spec.rb +20 -0
- data/spec/acceptance/session_spec.rb +125 -0
- data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
- data/spec/acceptance/stub_control_values_spec.rb +19 -18
- data/spec/acceptance/stub_match_last_spec.rb +0 -4
- data/spec/acceptance/stub_match_list_spec.rb +0 -4
- data/spec/acceptance/stub_miss_list_spec.rb +0 -4
- data/spec/acceptance/stub_spec.rb +11 -11
- data/spec/acceptance/stub_trigger_spec.rb +60 -13
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
- data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
- data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
- data/spec/lib/http_stub/configurer_spec.rb +105 -0
- data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
- data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
- data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
- data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
- data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
- data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
- data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
- data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
- data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
- data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
- data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
- data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
- data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
- data/spec/lib/http_stub/server/registry_spec.rb +153 -34
- data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
- data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
- data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
- data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
- data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
- data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
- data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
- data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
- data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
- data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
- data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
- data/spec/spec_helper.rb +13 -1
- data/spec/support/contain_file.rb +23 -0
- data/spec/support/cross_origin_server/application.rb +1 -1
- data/spec/support/cross_origin_server/index_page.rb +2 -2
- data/spec/support/cross_origin_server/integration.rb +3 -2
- data/spec/support/cross_origin_server/public/index.html +2 -1
- data/spec/support/http_stub/configurer_integration.rb +12 -14
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
- data/spec/support/http_stub/server/driver.rb +56 -0
- data/spec/support/http_stub/server/memory_fixture.rb +17 -0
- data/spec/support/http_stub/server/request_fixture.rb +7 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
- data/spec/support/http_stub/server/session_fixture.rb +27 -0
- data/spec/support/http_stub/server_integration.rb +12 -17
- data/spec/support/http_stub/stub_fixture.rb +19 -6
- data/spec/support/include_in_json.rb +4 -4
- data/spec/support/rack/rack_application_test.rb +9 -0
- data/spec/support/rack/request_fixture.rb +13 -0
- data/spec/support/surpressed_output.rb +10 -0
- metadata +149 -36
- data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
- data/lib/http_stub/server/request.rb +0 -12
- data/lib/http_stub/server/scenario/activator.rb +0 -25
- data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
- data/lib/http_stub/server/views/index.haml +0 -8
- data/spec/acceptance/activator_spec.rb +0 -81
- data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
- data/spec/lib/http_stub/server/request_spec.rb +0 -24
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -0,0 +1,101 @@
|
|
1
|
+
describe HttpStub::Configurer::Request::Triggers do
|
2
|
+
|
3
|
+
let(:scenario_names) { (1..3).map { |i| "Some scenario #{i}" } }
|
4
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
5
|
+
|
6
|
+
let(:triggers) { HttpStub::Configurer::Request::Triggers.new(scenario_names: scenario_names, stubs: stubs) }
|
7
|
+
|
8
|
+
describe "#response_files" do
|
9
|
+
|
10
|
+
let(:stubs) do
|
11
|
+
response_files_per_stub.map do |response_files|
|
12
|
+
instance_double(HttpStub::Configurer::Request::Stub, response_files: response_files)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { triggers.response_files }
|
17
|
+
|
18
|
+
context "when many stubs contains response files" do
|
19
|
+
|
20
|
+
let(:response_files_per_stub) do
|
21
|
+
(1..3).map { (1..3).map { HttpStub::Configurer::Request::StubResponseFile } }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns all the response files" do
|
25
|
+
expect(subject).to eql(response_files_per_stub.flatten)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when one stub contains response files" do
|
31
|
+
|
32
|
+
let(:response_files) { (1..3).map { HttpStub::Configurer::Request::StubResponseFile } }
|
33
|
+
let(:response_files_per_stub) { (1..3).map { |i| i % 2 == 0 ? response_files : [] } }
|
34
|
+
|
35
|
+
it "returns the response files" do
|
36
|
+
expect(subject).to eql(response_files)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when no stubs contain response files" do
|
42
|
+
|
43
|
+
let(:response_files_per_stub) { (1..3).map { [] } }
|
44
|
+
|
45
|
+
it "returns an empty array" do
|
46
|
+
expect(subject).to eql([])
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#payload" do
|
54
|
+
|
55
|
+
let(:stub_payloads) { stubs.each_with_index.map { |i| "Stub payload #{i}" } }
|
56
|
+
|
57
|
+
subject { triggers.payload }
|
58
|
+
|
59
|
+
before(:example) do
|
60
|
+
stubs.zip(stub_payloads).each { |stub, payload| allow(stub).to receive(:payload).and_return(payload) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when scenario names are provided" do
|
64
|
+
|
65
|
+
it "has a scenario names entry containing the names" do
|
66
|
+
expect(subject).to include(scenario_names: scenario_names)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when no scenario names are provided" do
|
72
|
+
|
73
|
+
let(:scenario_names) { [] }
|
74
|
+
|
75
|
+
it "has an scenario names entry that is empty" do
|
76
|
+
expect(subject).to include(scenario_names: [])
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when stubs are provided" do
|
82
|
+
|
83
|
+
it "has a stubs entry containing the payload of the stubs" do
|
84
|
+
expect(subject).to include(stubs: stub_payloads)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when stub are not provided" do
|
90
|
+
|
91
|
+
let(:stubs) { [] }
|
92
|
+
|
93
|
+
it "has a stubs entry that is empty" do
|
94
|
+
expect(subject).to include(stubs: [])
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
describe HttpStub::Configurer::Server::CommandProcessor do
|
2
2
|
|
3
|
-
let(:command) { HttpStub::Configurer::Server::Command.new(request: request, description: "performing an operation") }
|
4
3
|
let(:server_host) { "localhost" }
|
5
4
|
let(:server_port) { 8001 }
|
6
5
|
let(:server_base_uri) { "http://#{server_host}:#{server_port}" }
|
7
|
-
let(:
|
8
|
-
|
6
|
+
let(:configuration) do
|
7
|
+
double(HttpStub::Configurer::Server::Configuration, base_uri: server_base_uri, host: server_host, port: server_port)
|
9
8
|
end
|
10
9
|
|
11
|
-
let(:
|
12
|
-
|
13
|
-
let(:command_processor) { HttpStub::Configurer::Server::CommandProcessor.new(configurer) }
|
10
|
+
let(:command_processor) { HttpStub::Configurer::Server::CommandProcessor.new(configuration) }
|
14
11
|
|
15
12
|
describe "#process" do
|
16
13
|
|
14
|
+
let(:command) do
|
15
|
+
HttpStub::Configurer::Server::Command.new(request: request, description: "performing an operation")
|
16
|
+
end
|
17
|
+
|
17
18
|
subject { command_processor.process(command) }
|
18
19
|
|
19
20
|
context "when the server is running" do
|
@@ -21,7 +22,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
|
|
21
22
|
|
22
23
|
describe "and the server responds with a 200 response" do
|
23
24
|
|
24
|
-
let(:request) { create_get_request("
|
25
|
+
let(:request) { create_get_request("stubs") }
|
25
26
|
|
26
27
|
it "executes without error" do
|
27
28
|
expect { subject }.not_to raise_error
|
@@ -35,7 +36,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
|
|
35
36
|
|
36
37
|
describe "and the server responds with a non-200 response" do
|
37
38
|
|
38
|
-
let(:request) { create_get_request("
|
39
|
+
let(:request) { create_get_request("causes_error") }
|
39
40
|
|
40
41
|
it "raises an exception that includes the server base URI" do
|
41
42
|
expect { subject }.to raise_error(/#{server_base_uri}/)
|
@@ -53,7 +54,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
|
|
53
54
|
|
54
55
|
subject { command_processor.process(command, open_timeout: 1) }
|
55
56
|
|
56
|
-
let(:request) { create_get_request("
|
57
|
+
let(:request) { create_get_request("does/not/exist") }
|
57
58
|
|
58
59
|
it "raises an exception that includes the server base URI" do
|
59
60
|
expect { subject }.to raise_error(/#{server_base_uri}/)
|
@@ -66,7 +67,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def create_get_request(path)
|
69
|
-
HttpStub::Configurer::Request::Http::Basic.new(
|
70
|
+
HttpStub::Configurer::Request::Http::Basic.new(method: :get, path: path)
|
70
71
|
end
|
71
72
|
|
72
73
|
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::Configuration do
|
2
|
+
|
3
|
+
let(:configuration) { described_class.new }
|
4
|
+
|
5
|
+
shared_context "a configuration with host and port configured" do
|
6
|
+
|
7
|
+
before(:example) do
|
8
|
+
configuration.host = "some_host"
|
9
|
+
configuration.port = 8888
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#session_identifier" do
|
15
|
+
|
16
|
+
let(:session_identifier) { { headers: :some_session_identifier } }
|
17
|
+
|
18
|
+
subject { configuration.session_identifier }
|
19
|
+
|
20
|
+
before(:example) { configuration.session_identifier = session_identifier }
|
21
|
+
|
22
|
+
it "returns any configured value" do
|
23
|
+
expect(subject).to eql(session_identifier)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#base_uri" do
|
29
|
+
|
30
|
+
subject { configuration.base_uri }
|
31
|
+
|
32
|
+
include_context "a configuration with host and port configured"
|
33
|
+
|
34
|
+
it "returns a uri that combines any established host and port" do
|
35
|
+
expect(subject).to include("some_host:8888")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a uri accessed via http" do
|
39
|
+
expect(subject).to match(/^http:\/\//)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#external_base_uri" do
|
45
|
+
|
46
|
+
subject { configuration.external_base_uri }
|
47
|
+
|
48
|
+
include_context "a configuration with host and port configured"
|
49
|
+
|
50
|
+
context "when an external base URI environment variable is established" do
|
51
|
+
|
52
|
+
let(:external_base_uri) { "http://some/external/base/uri" }
|
53
|
+
|
54
|
+
before(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = external_base_uri }
|
55
|
+
after(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = nil }
|
56
|
+
|
57
|
+
it "returns the environment variable" do
|
58
|
+
expect(subject).to eql(external_base_uri)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when an external base URI environment variable is not established" do
|
64
|
+
|
65
|
+
it "returns the base URI" do
|
66
|
+
expect(subject).to eql(configuration.base_uri)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns a uri that combines any established host and port" do
|
72
|
+
expect(subject).to include("some_host:8888")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns a uri accessed via http" do
|
76
|
+
expect(subject).to match(/^http:\/\//)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#enable" do
|
82
|
+
|
83
|
+
context "when a feature is provided" do
|
84
|
+
|
85
|
+
let(:feature) { :some_feature }
|
86
|
+
|
87
|
+
subject { configuration.enable(feature) }
|
88
|
+
|
89
|
+
it "enables the feature" do
|
90
|
+
subject
|
91
|
+
|
92
|
+
expect(configuration.enabled?(feature)).to be(true)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when features are provided" do
|
98
|
+
|
99
|
+
let(:features) { (1..3).map { |i| "feature_#{i}".to_sym } }
|
100
|
+
|
101
|
+
subject { configuration.enable(*features) }
|
102
|
+
|
103
|
+
it "enables the features" do
|
104
|
+
subject
|
105
|
+
|
106
|
+
features.each { |feature| expect(configuration.enabled?(feature)).to be(true) }
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#enabled?" do
|
114
|
+
|
115
|
+
let(:feature) { :some_feature }
|
116
|
+
|
117
|
+
subject { configuration.enabled?(feature) }
|
118
|
+
|
119
|
+
context "when a feature is enabled" do
|
120
|
+
|
121
|
+
before(:example) { configuration.enable(feature) }
|
122
|
+
|
123
|
+
it "returns false" do
|
124
|
+
expect(subject).to be(true)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
context "when a feature is not enabled" do
|
130
|
+
|
131
|
+
it "returns false" do
|
132
|
+
expect(subject).to be(false)
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -1,116 +1,98 @@
|
|
1
1
|
describe HttpStub::Configurer::Server::Facade do
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:configuration) { double(HttpStub::Configurer::Server::Configuration) }
|
4
|
+
|
4
5
|
let(:request_processor) { instance_double(HttpStub::Configurer::Server::RequestProcessor) }
|
5
6
|
|
6
|
-
let(:facade) { HttpStub::Configurer::Server::Facade.new(
|
7
|
+
let(:facade) { HttpStub::Configurer::Server::Facade.new(configuration) }
|
7
8
|
|
8
9
|
before(:example) do
|
9
10
|
allow(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).and_return(request_processor)
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
it "creates a request processor with the provided configurer" do
|
15
|
-
expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configurer)
|
16
|
-
|
17
|
-
facade
|
18
|
-
end
|
13
|
+
it "creates a request processor with the provided configuration" do
|
14
|
+
expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configuration)
|
19
15
|
|
16
|
+
facade
|
20
17
|
end
|
21
18
|
|
22
|
-
describe "#
|
23
|
-
|
24
|
-
let(:model_description) { "some model description" }
|
25
|
-
let(:model) { instance_double(HttpStub::Configurer::Request::Stub, to_s: model_description) }
|
26
|
-
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
|
19
|
+
describe "#server_has_started" do
|
27
20
|
|
28
|
-
subject { facade.
|
21
|
+
subject { facade.server_has_started }
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "creates a multipart request with the provided model" do
|
36
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(model)
|
23
|
+
it "informs the request processor to disable buffering requests" do
|
24
|
+
expect(request_processor).to receive(:disable_buffering!)
|
37
25
|
|
38
26
|
subject
|
39
27
|
end
|
40
28
|
|
41
|
-
|
42
|
-
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
29
|
+
end
|
43
30
|
|
44
|
-
|
45
|
-
|
31
|
+
describe "#flush_requests" do
|
32
|
+
|
33
|
+
subject { facade.flush_requests }
|
46
34
|
|
47
|
-
it "
|
48
|
-
expect(request_processor).to receive(:
|
35
|
+
it "informs the request processor to flush it's requests" do
|
36
|
+
expect(request_processor).to receive(:flush!)
|
49
37
|
|
50
38
|
subject
|
51
39
|
end
|
52
40
|
|
53
41
|
end
|
54
42
|
|
55
|
-
describe "#
|
43
|
+
describe "#reset" do
|
56
44
|
|
57
|
-
let(:
|
58
|
-
let(:model) { instance_double(HttpStub::Configurer::Request::Scenario, to_s: model_description) }
|
59
|
-
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
|
45
|
+
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
60
46
|
|
61
|
-
subject { facade.
|
47
|
+
subject { facade.reset }
|
62
48
|
|
63
49
|
before(:example) do
|
50
|
+
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
|
64
51
|
allow(request_processor).to receive(:submit)
|
65
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
|
66
52
|
end
|
67
53
|
|
68
|
-
it "creates a
|
69
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:
|
54
|
+
it "creates a DELETE request for the memory endpoint" do
|
55
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("memory").and_return(request)
|
70
56
|
|
71
57
|
subject
|
72
58
|
end
|
73
59
|
|
74
|
-
it "submits the request via the request processor" do
|
60
|
+
it "submits the HTTP Stub request via the request processor" do
|
75
61
|
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
76
62
|
|
77
63
|
subject
|
78
64
|
end
|
79
65
|
|
80
|
-
it "describes the
|
81
|
-
expect(request_processor).to(
|
82
|
-
receive(:submit).with(hash_including(description: "registering scenario '#{model_description}'"))
|
83
|
-
)
|
66
|
+
it "describes the request as resetting the server" do
|
67
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "resetting server"))
|
84
68
|
|
85
69
|
subject
|
86
70
|
end
|
87
71
|
|
88
72
|
end
|
89
73
|
|
90
|
-
describe "#
|
74
|
+
describe "#define_scenario" do
|
75
|
+
|
76
|
+
let(:scenario_description) { "some scenario description" }
|
77
|
+
let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario, to_s: scenario_description) }
|
91
78
|
|
92
|
-
let(:
|
93
|
-
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
79
|
+
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
|
94
80
|
|
95
|
-
subject { facade.
|
81
|
+
subject { facade.define_scenario(scenario) }
|
96
82
|
|
97
83
|
before(:example) do
|
98
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
|
99
84
|
allow(request_processor).to receive(:submit)
|
85
|
+
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
|
100
86
|
end
|
101
87
|
|
102
|
-
it "creates
|
103
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
104
|
-
receive(:post).with("/http_stub/scenarios/activate", anything).and_return(request)
|
105
|
-
)
|
88
|
+
it "creates a multipart request to the scenarios endpoint" do
|
89
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with("scenarios", anything)
|
106
90
|
|
107
91
|
subject
|
108
92
|
end
|
109
93
|
|
110
|
-
it "creates a
|
111
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
112
|
-
receive(:post).with(anything, hash_including(:name => scenario_name)).and_return(request)
|
113
|
-
)
|
94
|
+
it "creates a multipart request with the provided scenario" do
|
95
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(anything, scenario)
|
114
96
|
|
115
97
|
subject
|
116
98
|
end
|
@@ -121,128 +103,89 @@ describe HttpStub::Configurer::Server::Facade do
|
|
121
103
|
subject
|
122
104
|
end
|
123
105
|
|
124
|
-
it "describes the
|
125
|
-
expect(request_processor).to
|
106
|
+
it "describes the scenario via its string representation" do
|
107
|
+
expect(request_processor).to(
|
108
|
+
receive(:submit).with(hash_including(description: "registering scenario '#{scenario_description}'"))
|
109
|
+
)
|
126
110
|
|
127
111
|
subject
|
128
112
|
end
|
129
113
|
|
130
114
|
end
|
131
115
|
|
132
|
-
describe "#
|
116
|
+
describe "#clear_scenarios" do
|
133
117
|
|
134
118
|
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
135
119
|
|
136
|
-
subject { facade.
|
120
|
+
subject { facade.clear_scenarios }
|
137
121
|
|
138
122
|
before(:example) do
|
139
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:
|
123
|
+
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
|
140
124
|
allow(request_processor).to receive(:submit)
|
141
125
|
end
|
142
126
|
|
143
|
-
it "creates a
|
144
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
145
|
-
receive(:post).with("/http_stub/stubs/memory").and_return(request)
|
146
|
-
)
|
127
|
+
it "creates a DELETE request for the scenarios endpoint" do
|
128
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("scenarios").and_return(request)
|
147
129
|
|
148
130
|
subject
|
149
131
|
end
|
150
132
|
|
151
|
-
it "submits the request via the request processor" do
|
133
|
+
it "submits the HTTP Stub request via the request processor" do
|
152
134
|
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
153
135
|
|
154
136
|
subject
|
155
137
|
end
|
156
138
|
|
157
|
-
it "describes the request as
|
158
|
-
expect(request_processor).to receive(:submit).with(hash_including(description: "
|
139
|
+
it "describes the request as clearing the servers scenarios" do
|
140
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing scenarios"))
|
159
141
|
|
160
142
|
subject
|
161
143
|
end
|
162
144
|
|
163
145
|
end
|
164
146
|
|
165
|
-
describe "#
|
166
|
-
|
167
|
-
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
168
|
-
|
169
|
-
subject { facade.recall_stubs }
|
170
|
-
|
171
|
-
before(:example) do
|
172
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(request)
|
173
|
-
allow(request_processor).to receive(:submit)
|
174
|
-
end
|
147
|
+
describe "#create_session_facade" do
|
175
148
|
|
176
|
-
|
177
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
178
|
-
receive(:get).with("/http_stub/stubs/memory").and_return(request)
|
179
|
-
)
|
149
|
+
let(:session_id) { "some session id" }
|
180
150
|
|
181
|
-
|
182
|
-
end
|
151
|
+
let(:session_facade) { instance_double(HttpStub::Configurer::Server::SessionFacade) }
|
183
152
|
|
184
|
-
|
185
|
-
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
153
|
+
subject { facade.create_session_facade(session_id) }
|
186
154
|
|
187
|
-
|
188
|
-
end
|
155
|
+
before(:example) { allow(HttpStub::Configurer::Server::SessionFacade).to receive(:new).and_return(session_facade) }
|
189
156
|
|
190
|
-
it "
|
191
|
-
expect(
|
157
|
+
it "creates a session facade for the provided session" do
|
158
|
+
expect(HttpStub::Configurer::Server::SessionFacade).to receive(:new).with(session_id, anything)
|
192
159
|
|
193
160
|
subject
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
describe "#clear_stubs" do
|
199
161
|
|
200
|
-
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
201
|
-
|
202
|
-
subject { facade.clear_stubs }
|
203
|
-
|
204
|
-
before(:example) do
|
205
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
|
206
|
-
allow(request_processor).to receive(:submit)
|
207
162
|
end
|
208
163
|
|
209
|
-
it "creates a
|
210
|
-
expect(HttpStub::Configurer::
|
211
|
-
receive(:delete).with("/http_stub/stubs").and_return(request)
|
212
|
-
)
|
164
|
+
it "creates a session facade that processes requests the server facades request processor" do
|
165
|
+
expect(HttpStub::Configurer::Server::SessionFacade).to receive(:new).with(anything, request_processor)
|
213
166
|
|
214
167
|
subject
|
215
168
|
end
|
216
169
|
|
217
|
-
it "
|
218
|
-
expect(
|
219
|
-
|
220
|
-
subject
|
221
|
-
end
|
222
|
-
|
223
|
-
it "describes the request as clearing the server stubs" do
|
224
|
-
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing stubs"))
|
225
|
-
|
226
|
-
subject
|
170
|
+
it "returns the created session facade" do
|
171
|
+
expect(subject).to eql(session_facade)
|
227
172
|
end
|
228
173
|
|
229
174
|
end
|
230
175
|
|
231
|
-
describe "#
|
176
|
+
describe "#clear_sessions" do
|
232
177
|
|
233
178
|
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
234
179
|
|
235
|
-
subject { facade.
|
180
|
+
subject { facade.clear_sessions }
|
236
181
|
|
237
182
|
before(:example) do
|
238
183
|
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
|
239
184
|
allow(request_processor).to receive(:submit)
|
240
185
|
end
|
241
186
|
|
242
|
-
it "creates a DELETE request for the
|
243
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
244
|
-
receive(:delete).with("/http_stub/scenarios").and_return(request)
|
245
|
-
)
|
187
|
+
it "creates a DELETE request for the sessions endpoint" do
|
188
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("sessions").and_return(request)
|
246
189
|
|
247
190
|
subject
|
248
191
|
end
|
@@ -253,32 +196,12 @@ describe HttpStub::Configurer::Server::Facade do
|
|
253
196
|
subject
|
254
197
|
end
|
255
198
|
|
256
|
-
it "describes the request as clearing the
|
257
|
-
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing
|
199
|
+
it "describes the request as clearing the servers sessions" do
|
200
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing sessions"))
|
258
201
|
|
259
202
|
subject
|
260
203
|
end
|
261
204
|
|
262
205
|
end
|
263
206
|
|
264
|
-
describe "#server_has_started" do
|
265
|
-
|
266
|
-
it "informs the request processor to disable buffering requests" do
|
267
|
-
expect(request_processor).to receive(:disable_buffering!)
|
268
|
-
|
269
|
-
facade.server_has_started
|
270
|
-
end
|
271
|
-
|
272
|
-
end
|
273
|
-
|
274
|
-
describe "#flush_requests" do
|
275
|
-
|
276
|
-
it "informs the request processor to flush it's requests" do
|
277
|
-
expect(request_processor).to receive(:flush!)
|
278
|
-
|
279
|
-
facade.flush_requests
|
280
|
-
end
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
207
|
end
|