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,74 @@
|
|
1
|
+
describe HttpStub::Server::Request::Factory do
|
2
|
+
|
3
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
|
4
|
+
let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
|
5
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, sessions: session_registry) }
|
6
|
+
|
7
|
+
let(:session_identifier_strategy) { instance_double(HttpStub::Server::Session::IdentifierStrategy) }
|
8
|
+
|
9
|
+
let(:factory) { described_class.new(session_configuration, server_memory) }
|
10
|
+
|
11
|
+
before(:example) do
|
12
|
+
allow(HttpStub::Server::Session::IdentifierStrategy).to receive(:new).and_return(session_identifier_strategy)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates a session identifier strategy based on the session configuration" do
|
16
|
+
expect(HttpStub::Server::Session::IdentifierStrategy).to receive(:new).with(session_configuration)
|
17
|
+
|
18
|
+
factory
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#create" do
|
22
|
+
|
23
|
+
let(:rack_request) { Rack::RequestFixture.create }
|
24
|
+
let(:sinatra_parameters) { { some_parameter: "some parameter value" } }
|
25
|
+
let(:logger) { instance_double(Logger) }
|
26
|
+
|
27
|
+
let(:discovered_session_id) { "some session id" }
|
28
|
+
let(:sinatra_request) { instance_double(HttpStub::Server::Request::SinatraRequest) }
|
29
|
+
let(:session) { instance_double(HttpStub::Server::Session::Session) }
|
30
|
+
let(:server_request) { instance_double(HttpStub::Server::Request::Request) }
|
31
|
+
|
32
|
+
subject { factory.create(rack_request, sinatra_parameters, logger) }
|
33
|
+
|
34
|
+
before(:example) do
|
35
|
+
allow(HttpStub::Server::Request::SinatraRequest).to receive(:new).and_return(sinatra_request)
|
36
|
+
allow(session_identifier_strategy).to receive(:identifier_for).and_return(discovered_session_id)
|
37
|
+
allow(session_registry).to receive(:find_or_create).and_return(session)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "creates a sinatra request for the rack request and sinatra parameters" do
|
41
|
+
expect(HttpStub::Server::Request::SinatraRequest).to receive(:new).with(rack_request, sinatra_parameters)
|
42
|
+
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
|
46
|
+
it "discovers the session identifier for the sinatra request" do
|
47
|
+
expect(session_identifier_strategy).to receive(:identifier_for).with(sinatra_request)
|
48
|
+
|
49
|
+
subject
|
50
|
+
end
|
51
|
+
|
52
|
+
it "finds or creates the session for the identifier via the servers session registry" do
|
53
|
+
expect(session_registry).to receive(:find_or_create).with(discovered_session_id, logger)
|
54
|
+
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates a http_stub request containing the sinatra request" do
|
59
|
+
expect(HttpStub::Server::Request::Request).to receive(:new).with(sinatra_request, anything, anything)
|
60
|
+
|
61
|
+
subject
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns a http_stub request containing the discovered session id" do
|
65
|
+
expect(subject.session_id).to eql(discovered_session_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns a http_stub request containing the retrieved session" do
|
69
|
+
expect(subject.session).to eql(session)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe HttpStub::Server::Request::Parameters do
|
2
2
|
|
3
|
-
let(:parameter_hash) { {} }
|
3
|
+
let(:parameter_hash) { { "some_parameter_name" => "some parameter value" } }
|
4
4
|
|
5
5
|
let(:parameters) { described_class.new(parameter_hash) }
|
6
6
|
|
@@ -10,17 +10,14 @@ describe HttpStub::Server::Request::Parameters do
|
|
10
10
|
|
11
11
|
describe "::create" do
|
12
12
|
|
13
|
-
|
14
|
-
let(:rack_request) { instance_double(Rack::Request, params: rack_params) }
|
13
|
+
subject { described_class.create(parameter_hash) }
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
it "returns http stub request parameters" do
|
15
|
+
it "returns http_stub request parameters" do
|
19
16
|
expect(subject).to be_an_instance_of(described_class)
|
20
17
|
end
|
21
18
|
|
22
|
-
it "
|
23
|
-
expect(subject).to eql(
|
19
|
+
it "contains the provided parameters" do
|
20
|
+
expect(subject).to eql(parameters)
|
24
21
|
end
|
25
22
|
|
26
23
|
end
|
@@ -1,34 +1,40 @@
|
|
1
1
|
describe HttpStub::Server::Request::Request do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
instance_double(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
let(:sinatra_base_uri) { "http://base_url:8888" }
|
4
|
+
let(:sinatra_uri) { "/rack/path/info" }
|
5
|
+
let(:sinatra_request_method) { "some method" }
|
6
|
+
let(:sinatra_headers) { { "some_header" => "some header value" } }
|
7
|
+
let(:sinatra_parameters) { { "some_parameter" => "some parameter value" } }
|
8
|
+
let(:sinatra_body) { "some request body" }
|
9
|
+
let(:sinatra_request) do
|
10
|
+
instance_double(HttpStub::Server::Request::SinatraRequest, base_uri: sinatra_base_uri,
|
11
|
+
uri: sinatra_uri,
|
12
|
+
method: sinatra_request_method,
|
13
|
+
headers: sinatra_headers,
|
14
|
+
parameters: sinatra_parameters,
|
15
|
+
body: sinatra_body)
|
16
16
|
end
|
17
|
+
let(:session_id) { "some session id" }
|
18
|
+
let(:session) { instance_double(HttpStub::Server::Session::Session) }
|
17
19
|
|
18
|
-
let(:server_request) { described_class.new(
|
20
|
+
let(:server_request) { described_class.new(sinatra_request, session_id, session) }
|
19
21
|
|
20
22
|
describe "#base_uri" do
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
subject { server_request.base_uri }
|
25
|
+
|
26
|
+
it "is the sinatra requests base uri" do
|
27
|
+
expect(subject).to eql(sinatra_base_uri)
|
24
28
|
end
|
25
29
|
|
26
30
|
end
|
27
31
|
|
28
32
|
describe "#uri" do
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
subject { server_request.uri }
|
35
|
+
|
36
|
+
it "is the sinatra requests uri" do
|
37
|
+
expect(subject).to eql(sinatra_uri)
|
32
38
|
end
|
33
39
|
|
34
40
|
end
|
@@ -37,8 +43,8 @@ describe HttpStub::Server::Request::Request do
|
|
37
43
|
|
38
44
|
subject { server_request.method }
|
39
45
|
|
40
|
-
it "is the
|
41
|
-
expect(subject).to eql(
|
46
|
+
it "is the sinatra requests method" do
|
47
|
+
expect(subject).to eql(sinatra_request_method)
|
42
48
|
end
|
43
49
|
|
44
50
|
end
|
@@ -47,72 +53,66 @@ describe HttpStub::Server::Request::Request do
|
|
47
53
|
|
48
54
|
subject { server_request.headers }
|
49
55
|
|
50
|
-
it "
|
51
|
-
expect(
|
56
|
+
it "is the sinatra requests headers" do
|
57
|
+
expect(subject).to eql(sinatra_headers)
|
52
58
|
|
53
59
|
subject
|
54
60
|
end
|
55
61
|
|
56
|
-
it "returns the created http stub request headers" do
|
57
|
-
http_stub_request_headers = instance_double(HttpStub::Server::Request::Headers)
|
58
|
-
allow(HttpStub::Server::Request::Headers).to receive(:create).and_return(http_stub_request_headers)
|
59
|
-
|
60
|
-
expect(subject).to eql(http_stub_request_headers)
|
61
|
-
end
|
62
|
-
|
63
62
|
end
|
64
63
|
|
65
64
|
describe "#parameters" do
|
66
65
|
|
67
66
|
subject { server_request.parameters }
|
68
67
|
|
69
|
-
it "
|
70
|
-
expect(
|
68
|
+
it "is the sinatra requests parameters" do
|
69
|
+
expect(subject).to eql(sinatra_parameters)
|
71
70
|
|
72
71
|
subject
|
73
72
|
end
|
74
73
|
|
75
|
-
it "returns the created http stub request parameters" do
|
76
|
-
http_stub_request_parameters = instance_double(HttpStub::Server::Request::Parameters)
|
77
|
-
allow(HttpStub::Server::Request::Parameters).to receive(:create).and_return(http_stub_request_parameters)
|
78
|
-
|
79
|
-
expect(subject).to eql(http_stub_request_parameters)
|
80
|
-
end
|
81
|
-
|
82
74
|
end
|
83
75
|
|
84
76
|
describe "#body" do
|
85
77
|
|
86
78
|
subject { server_request.body }
|
87
79
|
|
88
|
-
it "is the
|
89
|
-
expect(subject).to eql(
|
80
|
+
it "is the sinatra requests body" do
|
81
|
+
expect(subject).to eql(sinatra_body)
|
90
82
|
end
|
91
83
|
|
92
84
|
end
|
93
85
|
|
94
86
|
describe "#to_json" do
|
95
87
|
|
88
|
+
let(:sinatra_request_json) { "some json" }
|
89
|
+
|
96
90
|
subject { server_request.to_json }
|
97
91
|
|
98
|
-
|
99
|
-
expect(subject).to include_in_json(uri: server_request.uri)
|
100
|
-
end
|
92
|
+
before(:example) { allow(sinatra_request).to receive(:to_json).and_return(sinatra_request_json) }
|
101
93
|
|
102
|
-
it "
|
103
|
-
expect(subject).to
|
94
|
+
it "returns the sinatra requests json representation" do
|
95
|
+
expect(subject).to eql(sinatra_request_json)
|
104
96
|
end
|
105
97
|
|
106
|
-
|
107
|
-
|
108
|
-
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#session_id" do
|
101
|
+
|
102
|
+
subject { server_request.session_id }
|
109
103
|
|
110
|
-
it "
|
111
|
-
expect(subject).to
|
104
|
+
it "is the provided id" do
|
105
|
+
expect(subject).to eql(session_id)
|
112
106
|
end
|
113
107
|
|
114
|
-
|
115
|
-
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#session" do
|
111
|
+
|
112
|
+
subject { server_request.session }
|
113
|
+
|
114
|
+
it "is the provided session" do
|
115
|
+
expect(subject).to eql(session)
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
describe HttpStub::Server::Request::SinatraRequest do
|
2
|
+
|
3
|
+
let(:rack_base_url) { "http://base_url:8888" }
|
4
|
+
let(:rack_path_info) { "/rack/path/info" }
|
5
|
+
let(:rack_request_method) { "some method" }
|
6
|
+
let(:rack_env) { { "some_env_name" => "some env value" } }
|
7
|
+
let(:rack_parameters) { { "rack_parameter_name" => "rack parameter value" } }
|
8
|
+
let(:rack_body_content) { "some request body" }
|
9
|
+
let(:rack_body) { StringIO.new(rack_body_content) }
|
10
|
+
let(:rack_request) do
|
11
|
+
instance_double(Rack::Request, base_url: rack_base_url,
|
12
|
+
path_info: rack_path_info,
|
13
|
+
request_method: rack_request_method,
|
14
|
+
env: rack_env,
|
15
|
+
params: rack_parameters,
|
16
|
+
body: rack_body)
|
17
|
+
end
|
18
|
+
let(:sinatra_parameters) { { "sinatra_parameter_name" => "sinatra parameter value" } }
|
19
|
+
|
20
|
+
let(:sinatra_request) { described_class.new(rack_request, sinatra_parameters) }
|
21
|
+
|
22
|
+
describe "#base_uri" do
|
23
|
+
|
24
|
+
it "is the rack base url" do
|
25
|
+
expect(sinatra_request.base_uri).to eql(rack_base_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#uri" do
|
31
|
+
|
32
|
+
it "is the rack request path information" do
|
33
|
+
expect(sinatra_request.uri).to eql(rack_path_info)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#method" do
|
39
|
+
|
40
|
+
subject { sinatra_request.method }
|
41
|
+
|
42
|
+
it "is the rack request method" do
|
43
|
+
expect(subject).to eql(rack_request_method)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#headers" do
|
49
|
+
|
50
|
+
subject { sinatra_request.headers }
|
51
|
+
|
52
|
+
it "creates http stub request headers from the rack request" do
|
53
|
+
expect(HttpStub::Server::Request::Headers).to receive(:create).with(rack_request)
|
54
|
+
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the created http stub request headers" do
|
59
|
+
http_stub_request_headers = instance_double(HttpStub::Server::Request::Headers)
|
60
|
+
allow(HttpStub::Server::Request::Headers).to receive(:create).and_return(http_stub_request_headers)
|
61
|
+
|
62
|
+
expect(subject).to eql(http_stub_request_headers)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#parameters" do
|
68
|
+
|
69
|
+
subject { sinatra_request.parameters }
|
70
|
+
|
71
|
+
it "creates http stub request parameters from the sinatra parameters" do
|
72
|
+
expect(HttpStub::Server::Request::Parameters).to receive(:create).with(sinatra_parameters)
|
73
|
+
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns the created http stub request parameters" do
|
78
|
+
http_stub_request_parameters = instance_double(HttpStub::Server::Request::Parameters)
|
79
|
+
allow(HttpStub::Server::Request::Parameters).to receive(:create).and_return(http_stub_request_parameters)
|
80
|
+
|
81
|
+
expect(subject).to eql(http_stub_request_parameters)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#body" do
|
87
|
+
|
88
|
+
subject { sinatra_request.body }
|
89
|
+
|
90
|
+
it "is the read rack request body" do
|
91
|
+
expect(subject).to eql(rack_body_content)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "rewinds the Rack body to allow the body to be accessed in future" do
|
95
|
+
expect(rack_body).to receive(:rewind)
|
96
|
+
|
97
|
+
subject
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#to_json" do
|
103
|
+
|
104
|
+
subject { sinatra_request.to_json }
|
105
|
+
|
106
|
+
it "contains the requests uri" do
|
107
|
+
expect(subject).to include_in_json(uri: sinatra_request.uri)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "contains the requests method" do
|
111
|
+
expect(subject).to include_in_json(method: sinatra_request.method)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "contains the requests headers" do
|
115
|
+
expect(subject).to include_in_json(headers: sinatra_request.headers)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "contains the requests parameters" do
|
119
|
+
expect(subject).to include_in_json(parameters: sinatra_request.parameters)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "contains the requests body" do
|
123
|
+
expect(subject).to include_in_json(body: sinatra_request.body)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not contains the session" do
|
127
|
+
expect(subject).to_not include("session")
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -1,27 +1,34 @@
|
|
1
1
|
describe HttpStub::Server::Scenario::Controller do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
5
|
-
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let(:controller) { HttpStub::Server::Scenario::Controller.new(scenario_registry, stub_registry) }
|
14
|
-
|
15
|
-
before(:example) do
|
16
|
-
allow(HttpStub::Server::Scenario::Activator).to receive(:new).and_return(activator)
|
17
|
-
allow(HttpStub::Server::Scenario::Parser).to receive(:parse).and_return(payload)
|
18
|
-
allow(HttpStub::Server::Scenario).to receive(:create).and_return(scenario)
|
3
|
+
let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
4
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, scenarios: scenario_registry) }
|
5
|
+
|
6
|
+
let(:request_uri) { "/some/request/path" }
|
7
|
+
let(:request_parameters) { {} }
|
8
|
+
let(:session) { instance_double(HttpStub::Server::Session::Session) }
|
9
|
+
let(:request) do
|
10
|
+
instance_double(HttpStub::Server::Request::Request, uri: request_uri,
|
11
|
+
parameters: request_parameters,
|
12
|
+
session: session)
|
19
13
|
end
|
14
|
+
let(:logger) { instance_double(Logger) }
|
15
|
+
let(:payload) { HttpStub::ScenarioFixture.new.server_payload }
|
16
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
17
|
+
let(:scenario) { instance_double(HttpStub::Server::Scenario::Scenario, stubs: stubs) }
|
18
|
+
let(:activator) { instance_double(HttpStub::Server::Scenario::Activator).as_null_object }
|
19
|
+
|
20
|
+
let(:controller) { described_class.new(server_memory) }
|
20
21
|
|
21
22
|
describe "#register" do
|
22
23
|
|
23
24
|
subject { controller.register(request, logger) }
|
24
25
|
|
26
|
+
before(:example) do
|
27
|
+
allow(HttpStub::Server::Scenario::Parser).to receive(:parse).and_return(payload)
|
28
|
+
allow(HttpStub::Server::Scenario).to receive(:create).and_return(scenario)
|
29
|
+
allow(scenario_registry).to receive(:add)
|
30
|
+
end
|
31
|
+
|
25
32
|
it "parses the payload from the request" do
|
26
33
|
expect(HttpStub::Server::Scenario::Parser).to receive(:parse).with(request).and_return(payload)
|
27
34
|
|
@@ -34,7 +41,7 @@ describe HttpStub::Server::Scenario::Controller do
|
|
34
41
|
subject
|
35
42
|
end
|
36
43
|
|
37
|
-
it "adds the created scenario to the scenario registry with the provided logger" do
|
44
|
+
it "adds the created scenario to the servers scenario registry with the provided logger" do
|
38
45
|
expect(scenario_registry).to receive(:add).with(scenario, logger)
|
39
46
|
|
40
47
|
subject
|
@@ -46,46 +53,125 @@ describe HttpStub::Server::Scenario::Controller do
|
|
46
53
|
|
47
54
|
end
|
48
55
|
|
49
|
-
describe "#
|
56
|
+
describe "#find" do
|
57
|
+
|
58
|
+
let(:name) { URI.encode_www_form_component("Some scenario name") }
|
59
|
+
let(:request_parameters) { { name: name } }
|
60
|
+
|
61
|
+
subject { controller.find(request, logger) }
|
50
62
|
|
51
|
-
|
63
|
+
before(:example) { allow(scenario_registry).to receive(:find).and_return(scenario) }
|
52
64
|
|
53
|
-
|
65
|
+
it "finds a scenario matching the parameterized name via the registry" do
|
66
|
+
expect(scenario_registry).to receive(:find).with(URI.decode_www_form_component("Some scenario name"), anything)
|
54
67
|
|
55
|
-
|
56
|
-
|
68
|
+
subject
|
69
|
+
end
|
70
|
+
|
71
|
+
it "finds the scenario using the provided logger" do
|
72
|
+
expect(scenario_registry).to receive(:find).with(anything, logger)
|
57
73
|
|
58
74
|
subject
|
59
75
|
end
|
60
76
|
|
61
|
-
|
77
|
+
it "returns the found scenario" do
|
78
|
+
expect(subject).to eql(scenario)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#find_all" do
|
84
|
+
|
85
|
+
let(:scenarios) { (1..3).map { |i| HttpStub::Server::ScenarioFixture.create("#{4 - i}") } }
|
86
|
+
|
87
|
+
subject { controller.find_all }
|
88
|
+
|
89
|
+
before(:example) { allow(scenario_registry).to receive(:all).and_return(scenarios) }
|
90
|
+
|
91
|
+
it "retrieves all scenarios from the servers scenario registry" do
|
92
|
+
expect(scenario_registry).to receive(:all)
|
93
|
+
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns the scenarios sorted by name" do
|
98
|
+
expect(subject).to eql(scenarios.reverse)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#activate" do
|
62
104
|
|
63
|
-
|
105
|
+
subject { controller.activate(request, logger) }
|
64
106
|
|
65
|
-
|
66
|
-
|
107
|
+
context "when a scenario name is provided" do
|
108
|
+
|
109
|
+
let(:scenario_name) { "some scenario name" }
|
110
|
+
let(:request_parameters) { { name: scenario_name } }
|
111
|
+
|
112
|
+
it "delegates to the users session to activate the scenario with the parameterized name" do
|
113
|
+
expect(session).to receive(:activate_scenario!).with(scenario_name, logger)
|
67
114
|
|
68
115
|
subject
|
69
116
|
end
|
70
117
|
|
71
|
-
|
72
|
-
|
118
|
+
describe "when the scenario is not found" do
|
119
|
+
|
120
|
+
before(:example) do
|
121
|
+
allow(session).to(
|
122
|
+
receive(:activate_scenario!).and_raise(HttpStub::Server::Scenario::NotFoundError, scenario_name)
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns a not found response" do
|
127
|
+
expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
|
128
|
+
end
|
129
|
+
|
73
130
|
end
|
74
131
|
|
75
132
|
end
|
76
133
|
|
77
|
-
|
134
|
+
context "when scenario names are provided" do
|
78
135
|
|
79
|
-
|
136
|
+
let(:scenario_names) { (1..3).map { |i| "scenario name #{i}" } }
|
137
|
+
let(:request_parameters) { { names: scenario_names } }
|
80
138
|
|
81
|
-
it "
|
82
|
-
|
139
|
+
it "delegates to the users session to activate the scenarios with the parameterized names" do
|
140
|
+
scenario_names.each do |scenario_name|
|
141
|
+
expect(session).to receive(:activate_scenario!).with(scenario_name, logger)
|
142
|
+
end
|
83
143
|
|
84
144
|
subject
|
85
145
|
end
|
86
146
|
|
87
|
-
|
88
|
-
|
147
|
+
describe "when a scenario is not found" do
|
148
|
+
|
149
|
+
let(:scenario_name_not_found) { scenario_names[1] }
|
150
|
+
|
151
|
+
before(:example) do
|
152
|
+
allow(session).to receive(:activate_scenario!)
|
153
|
+
allow(session).to(
|
154
|
+
receive(:activate_scenario!).with(scenario_name_not_found, anything)
|
155
|
+
.and_raise(HttpStub::Server::Scenario::NotFoundError, scenario_name_not_found)
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns a not found response" do
|
160
|
+
expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "when all scenarios are successfully activated" do
|
168
|
+
|
169
|
+
let(:request_parameters) { { name: "some scenario name" } }
|
170
|
+
|
171
|
+
before(:example) { allow(session).to receive(:activate_scenario!) }
|
172
|
+
|
173
|
+
it "returns an ok response" do
|
174
|
+
expect(subject).to eql(HttpStub::Server::Response::OK)
|
89
175
|
end
|
90
176
|
|
91
177
|
end
|
@@ -96,7 +182,7 @@ describe HttpStub::Server::Scenario::Controller do
|
|
96
182
|
|
97
183
|
subject { controller.clear(logger) }
|
98
184
|
|
99
|
-
it "clears the scenario registry" do
|
185
|
+
it "clears the servers scenario registry" do
|
100
186
|
expect(scenario_registry).to receive(:clear).with(logger)
|
101
187
|
|
102
188
|
subject
|