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,167 @@
|
|
1
|
+
describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
2
|
+
|
3
|
+
let(:server) { instance_double(HttpStub::Configurer::DSL::Server) }
|
4
|
+
let(:session_endpoint_template) { instance_double(HttpStub::Configurer::DSL::SessionEndpointTemplate) }
|
5
|
+
let(:active_session) do
|
6
|
+
instance_double(HttpStub::Configurer::DSL::Session, endpoint_template: session_endpoint_template)
|
7
|
+
end
|
8
|
+
let(:initial_block_verifier) { double("BlockVerifier") }
|
9
|
+
let(:block) { lambda { initial_block_verifier.verify } }
|
10
|
+
|
11
|
+
let(:server_endpoint_template) { described_class.new(server, active_session, &block) }
|
12
|
+
|
13
|
+
before(:each) { }
|
14
|
+
|
15
|
+
it "creates a session template in the active session that is initialized with the provided block" do
|
16
|
+
expect(active_session).to receive(:endpoint_template).and_yield
|
17
|
+
expect(initial_block_verifier).to receive(:verify)
|
18
|
+
|
19
|
+
server_endpoint_template
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#match_requests" do
|
23
|
+
|
24
|
+
let(:request_matching_rules) { { uri: "/some/stub/uri", method: :get } }
|
25
|
+
|
26
|
+
subject { server_endpoint_template.match_requests(request_matching_rules) }
|
27
|
+
|
28
|
+
it "delegates to the session template" do
|
29
|
+
expect(session_endpoint_template).to receive(:match_requests).with(request_matching_rules)
|
30
|
+
|
31
|
+
subject
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#schema" do
|
37
|
+
|
38
|
+
let(:type) { :some_schema_type }
|
39
|
+
let(:definition) { "some schema definition" }
|
40
|
+
|
41
|
+
subject { server_endpoint_template.schema(type, definition) }
|
42
|
+
|
43
|
+
it "delegates to the session template" do
|
44
|
+
expect(session_endpoint_template).to receive(:schema).with(type, definition)
|
45
|
+
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns the created schema" do
|
50
|
+
schema = { schema: :some_schema }
|
51
|
+
expect(session_endpoint_template).to receive(:schema).and_return(schema)
|
52
|
+
|
53
|
+
expect(subject).to eql(schema)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#respond_with" do
|
59
|
+
|
60
|
+
let(:response_settings) { { status: 204 } }
|
61
|
+
|
62
|
+
subject { server_endpoint_template.respond_with(response_settings) }
|
63
|
+
|
64
|
+
it "delegates to the session templates" do
|
65
|
+
expect(session_endpoint_template).to receive(:respond_with).with(response_settings)
|
66
|
+
|
67
|
+
subject
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#trigger" do
|
73
|
+
|
74
|
+
let(:trigger_settings) { { scenario: "some scenario name" } }
|
75
|
+
|
76
|
+
subject { server_endpoint_template.trigger(trigger_settings) }
|
77
|
+
|
78
|
+
it "delegates to the session template" do
|
79
|
+
expect(session_endpoint_template).to receive(:trigger).with(trigger_settings)
|
80
|
+
|
81
|
+
subject
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#invoke" do
|
87
|
+
|
88
|
+
let(:block_verifier) { double("BlockVerifier") }
|
89
|
+
let(:block) { lambda { block_verifier.verify } }
|
90
|
+
|
91
|
+
subject { server_endpoint_template.invoke(&block) }
|
92
|
+
|
93
|
+
it "delegates to the session template" do
|
94
|
+
expect(session_endpoint_template).to receive(:invoke).and_yield
|
95
|
+
expect(block_verifier).to receive(:verify)
|
96
|
+
|
97
|
+
subject
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#build_stub" do
|
103
|
+
|
104
|
+
let(:response_overrides) { { status: 201 } }
|
105
|
+
let(:block_verifier) { double("BlockVerifier") }
|
106
|
+
let(:block) { lambda { block_verifier.verify } }
|
107
|
+
|
108
|
+
subject { server_endpoint_template.build_stub(response_overrides, &block) }
|
109
|
+
|
110
|
+
it "delegates to the session template" do
|
111
|
+
expect(session_endpoint_template).to receive(:build_stub).with(response_overrides).and_yield
|
112
|
+
expect(block_verifier).to receive(:verify)
|
113
|
+
|
114
|
+
subject
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#add_stub!" do
|
120
|
+
|
121
|
+
let(:response_overrides) { { status: 201 } }
|
122
|
+
let(:block_verifier) { double("BlockVerifier") }
|
123
|
+
let(:block) { lambda { block_verifier.verify } }
|
124
|
+
|
125
|
+
subject { server_endpoint_template.add_stub!(response_overrides, &block) }
|
126
|
+
|
127
|
+
it "delegates to the session template" do
|
128
|
+
expect(session_endpoint_template).to receive(:add_stub!).with(response_overrides).and_yield
|
129
|
+
expect(block_verifier).to receive(:verify)
|
130
|
+
|
131
|
+
subject
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#add_scenario!" do
|
137
|
+
|
138
|
+
let(:name) { "Some scenario name" }
|
139
|
+
let(:response_overrides) { { status: 201 } }
|
140
|
+
let(:block_verifier) { double("BlockVerifier") }
|
141
|
+
let(:block) { lambda { block_verifier.verify } }
|
142
|
+
|
143
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
144
|
+
|
145
|
+
subject { server_endpoint_template.add_scenario!(name, response_overrides, &block) }
|
146
|
+
|
147
|
+
before(:example) do
|
148
|
+
allow(session_endpoint_template).to receive(:build_stub).and_return(stub_builder)
|
149
|
+
allow(server).to receive(:add_scenario_with_one_stub!)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "builds a stub using any provided response overrides and block" do
|
153
|
+
expect(session_endpoint_template).to receive(:build_stub).with(response_overrides).and_yield
|
154
|
+
expect(block_verifier).to receive(:verify)
|
155
|
+
|
156
|
+
subject
|
157
|
+
end
|
158
|
+
|
159
|
+
it "adds a one stub scenario to the server with the provided name and created stub builder" do
|
160
|
+
expect(server).to receive(:add_scenario_with_one_stub!).with(name, stub_builder)
|
161
|
+
|
162
|
+
subject
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -1,12 +1,49 @@
|
|
1
1
|
describe HttpStub::Configurer::DSL::Server do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
3
|
+
let(:configuration) { instance_double(HttpStub::Configurer::Server::Configuration) }
|
4
|
+
let(:server_facade) { instance_double(HttpStub::Configurer::Server::Facade) }
|
5
|
+
let(:default_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
|
6
|
+
let(:memory_session) { instance_double(HttpStub::Configurer::DSL::Session) }
|
7
|
+
let(:transactional_session) { instance_double(HttpStub::Configurer::DSL::Session) }
|
8
|
+
let(:session_factory) do
|
9
|
+
instance_double(HttpStub::Configurer::DSL::SessionFactory, memory: memory_session,
|
10
|
+
transactional: transactional_session)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:default_session) { memory_session }
|
14
|
+
let(:block_verifier) { double("BlockVerifier") }
|
5
15
|
|
6
|
-
let(:server) {
|
16
|
+
let(:server) { described_class.new }
|
7
17
|
|
8
18
|
before(:example) do
|
9
|
-
allow(HttpStub::Configurer::
|
19
|
+
allow(HttpStub::Configurer::Server::Configuration).to receive(:new).and_return(configuration)
|
20
|
+
allow(HttpStub::Configurer::Server::Facade).to receive(:new).and_return(server_facade)
|
21
|
+
allow(HttpStub::Configurer::DSL::StubBuilderTemplate).to receive(:new).and_return(default_stub_template)
|
22
|
+
allow(HttpStub::Configurer::DSL::SessionFactory).to receive(:new).and_return(session_factory)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a server configuration" do
|
26
|
+
expect(HttpStub::Configurer::Server::Configuration).to receive(:new)
|
27
|
+
|
28
|
+
server
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates a facade to interact with the stub server based on the configuration" do
|
32
|
+
expect(HttpStub::Configurer::Server::Facade).to receive(:new).with(configuration)
|
33
|
+
|
34
|
+
server
|
35
|
+
end
|
36
|
+
|
37
|
+
it "creates a stub builder template to hold the default stub settings for the server" do
|
38
|
+
expect(HttpStub::Configurer::DSL::StubBuilderTemplate).to receive(:new).with(no_args)
|
39
|
+
|
40
|
+
server
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a session factory that creates sessions interacting with the servers facade and stub template" do
|
44
|
+
expect(HttpStub::Configurer::DSL::SessionFactory).to receive(:new).with(server_facade, default_stub_template)
|
45
|
+
|
46
|
+
server
|
10
47
|
end
|
11
48
|
|
12
49
|
shared_context "a server with host and port configured" do
|
@@ -18,121 +55,142 @@ describe HttpStub::Configurer::DSL::Server do
|
|
18
55
|
|
19
56
|
end
|
20
57
|
|
21
|
-
|
22
|
-
|
23
|
-
|
58
|
+
describe "#host" do
|
59
|
+
|
60
|
+
let(:host) { "some_host" }
|
61
|
+
|
62
|
+
subject { server.host }
|
63
|
+
|
64
|
+
it "delegates to the servers configuration" do
|
65
|
+
allow(configuration).to receive(:host).and_return(host)
|
66
|
+
|
67
|
+
expect(subject).to eql(host)
|
68
|
+
end
|
24
69
|
|
25
|
-
it "activates scenarios" do
|
26
|
-
expect(server).to be_a(HttpStub::Configurer::DSL::ScenarioActivator)
|
27
70
|
end
|
28
71
|
|
29
|
-
describe "#
|
72
|
+
describe "#host=" do
|
30
73
|
|
31
|
-
|
74
|
+
let(:host) { "some_host" }
|
32
75
|
|
33
|
-
|
76
|
+
subject { server.host = host }
|
34
77
|
|
35
|
-
it "
|
36
|
-
|
37
|
-
end
|
78
|
+
it "delegates to the servers configuration" do
|
79
|
+
allow(configuration).to receive(:host=).with(host)
|
38
80
|
|
39
|
-
|
40
|
-
expect(subject).to match(/^http:\/\//)
|
81
|
+
subject
|
41
82
|
end
|
42
83
|
|
43
84
|
end
|
44
85
|
|
45
|
-
describe "#
|
86
|
+
describe "#port" do
|
46
87
|
|
47
|
-
|
88
|
+
let(:port) { "8888" }
|
48
89
|
|
49
|
-
|
90
|
+
subject { server.port }
|
50
91
|
|
51
|
-
|
92
|
+
it "delegates to the servers configuration" do
|
93
|
+
allow(configuration).to receive(:port).and_return(port)
|
52
94
|
|
53
|
-
|
95
|
+
expect(subject).to eql(port)
|
96
|
+
end
|
54
97
|
|
55
|
-
|
56
|
-
after(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = nil }
|
98
|
+
end
|
57
99
|
|
58
|
-
|
59
|
-
expect(subject).to eql(external_base_uri)
|
60
|
-
end
|
100
|
+
describe "#port=" do
|
61
101
|
|
62
|
-
|
102
|
+
let(:port) { "8888" }
|
63
103
|
|
64
|
-
|
104
|
+
subject { server.port = port }
|
65
105
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
106
|
+
it "delegates to the servers configuration" do
|
107
|
+
allow(configuration).to receive(:port=).with(port)
|
69
108
|
|
109
|
+
subject
|
70
110
|
end
|
71
111
|
|
72
|
-
|
73
|
-
|
74
|
-
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#base_uri" do
|
115
|
+
|
116
|
+
let(:base_uri) { "some_host:8888" }
|
75
117
|
|
76
|
-
|
77
|
-
|
118
|
+
subject { server.base_uri }
|
119
|
+
|
120
|
+
it "delegates to the servers configuration" do
|
121
|
+
allow(configuration).to receive(:base_uri).and_return(base_uri)
|
122
|
+
|
123
|
+
expect(subject).to eql(base_uri)
|
78
124
|
end
|
79
125
|
|
80
126
|
end
|
81
127
|
|
82
|
-
describe "#
|
128
|
+
describe "#external_base_uri" do
|
83
129
|
|
84
|
-
|
130
|
+
let(:external_base_uri) { "http://some/external/base/uri" }
|
85
131
|
|
86
|
-
|
132
|
+
subject { server.external_base_uri }
|
87
133
|
|
88
|
-
|
134
|
+
it "delegates to the servers configuration" do
|
135
|
+
allow(configuration).to receive(:external_base_uri).and_return(external_base_uri)
|
89
136
|
|
90
|
-
|
91
|
-
|
137
|
+
expect(subject).to eql(external_base_uri)
|
138
|
+
end
|
92
139
|
|
93
|
-
|
94
|
-
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#session_identifier" do
|
143
|
+
|
144
|
+
let(:session_identifier) { { headers: :some_session_identifier } }
|
145
|
+
|
146
|
+
subject { server.session_identifier }
|
95
147
|
|
148
|
+
it "delegates to the servers configuration" do
|
149
|
+
allow(configuration).to receive(:session_identifier).and_return(session_identifier)
|
150
|
+
|
151
|
+
expect(subject).to eql(session_identifier)
|
96
152
|
end
|
97
153
|
|
98
|
-
|
154
|
+
end
|
99
155
|
|
100
|
-
|
156
|
+
describe "#session_identifer=" do
|
101
157
|
|
102
|
-
|
158
|
+
let(:session_identifier) { { headers: :some_session_identifier } }
|
103
159
|
|
104
|
-
|
105
|
-
subject
|
160
|
+
subject { server.session_identifier = session_identifier }
|
106
161
|
|
107
|
-
|
108
|
-
|
162
|
+
it "delegates to the servers configuration" do
|
163
|
+
expect(configuration).to receive(:session_identifier=).with(session_identifier)
|
109
164
|
|
165
|
+
subject
|
110
166
|
end
|
111
167
|
|
112
168
|
end
|
113
169
|
|
114
|
-
describe "#
|
170
|
+
describe "#enable" do
|
115
171
|
|
116
|
-
let(:
|
172
|
+
let(:features) { (1..3).map { |i| "feature_#{i}".to_sym } }
|
117
173
|
|
118
|
-
subject { server.
|
174
|
+
subject { server.enable(*features) }
|
119
175
|
|
120
|
-
|
176
|
+
it "delegates to the sessions configuration" do
|
177
|
+
expect(configuration).to receive(:enable).with(*features)
|
121
178
|
|
122
|
-
|
179
|
+
subject
|
180
|
+
end
|
123
181
|
|
124
|
-
|
125
|
-
expect(subject).to be(true)
|
126
|
-
end
|
182
|
+
end
|
127
183
|
|
128
|
-
|
184
|
+
describe "#enabled?" do
|
185
|
+
|
186
|
+
let(:feature) { :some_feature }
|
129
187
|
|
130
|
-
|
188
|
+
subject { server.enabled?(feature) }
|
131
189
|
|
132
|
-
|
133
|
-
|
134
|
-
end
|
190
|
+
it "delegates to the servers configuration" do
|
191
|
+
expect(configuration).to receive(:enabled?).and_return(true)
|
135
192
|
|
193
|
+
expect(subject).to be(true)
|
136
194
|
end
|
137
195
|
|
138
196
|
end
|
@@ -141,10 +199,12 @@ describe HttpStub::Configurer::DSL::Server do
|
|
141
199
|
|
142
200
|
let(:args) { { request_rule_key: "request rule value" } }
|
143
201
|
|
144
|
-
|
145
|
-
expect(default_stub_builder).to receive(:match_requests).with(args)
|
202
|
+
subject { server.request_defaults = args }
|
146
203
|
|
147
|
-
|
204
|
+
it "establishes request matching rules on the default stub template" do
|
205
|
+
expect(default_stub_template).to receive(:match_requests).with(args)
|
206
|
+
|
207
|
+
subject
|
148
208
|
end
|
149
209
|
|
150
210
|
end
|
@@ -153,82 +213,90 @@ describe HttpStub::Configurer::DSL::Server do
|
|
153
213
|
|
154
214
|
let(:args) { { response_key: "response value" } }
|
155
215
|
|
156
|
-
|
157
|
-
|
216
|
+
subject { server.response_defaults = args }
|
217
|
+
|
218
|
+
it "establishes response values on the default stub template" do
|
219
|
+
expect(default_stub_template).to receive(:respond_with).with(args)
|
158
220
|
|
159
|
-
|
221
|
+
subject
|
160
222
|
end
|
161
223
|
|
162
224
|
end
|
163
225
|
|
164
|
-
|
165
|
-
|
166
|
-
it "informs the facade that the server has started" do
|
167
|
-
expect(server_facade).to receive(:server_has_started)
|
168
|
-
|
169
|
-
server.has_started!
|
170
|
-
end
|
226
|
+
it "causes session operations to be performed against the memory session prior to initialization" do
|
227
|
+
expect(memory_session).to receive(:activate!)
|
171
228
|
|
229
|
+
server.activate!("some scenario name")
|
172
230
|
end
|
173
231
|
|
174
|
-
describe "#
|
232
|
+
describe "#initialize!" do
|
175
233
|
|
176
|
-
|
177
|
-
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
|
234
|
+
subject { server.initialize! }
|
178
235
|
|
179
|
-
before(:example)
|
236
|
+
before(:example) do
|
237
|
+
allow(server_facade).to receive(:flush_requests)
|
238
|
+
allow(transactional_session).to receive(:mark_as_default!)
|
239
|
+
end
|
180
240
|
|
181
|
-
|
241
|
+
it "flushes requests held by the server facade" do
|
242
|
+
expect(server_facade).to receive(:flush_requests)
|
182
243
|
|
183
|
-
|
184
|
-
|
244
|
+
subject
|
245
|
+
end
|
185
246
|
|
186
|
-
|
187
|
-
|
247
|
+
it "marks the transactional session as the servers default" do
|
248
|
+
expect(transactional_session).to receive(:mark_as_default!)
|
188
249
|
|
189
|
-
|
190
|
-
|
250
|
+
subject
|
251
|
+
end
|
191
252
|
|
192
|
-
|
193
|
-
|
253
|
+
it "causes subsequent session operations to be performed against the transactional session" do
|
254
|
+
subject
|
255
|
+
expect(transactional_session).to receive(:activate!)
|
194
256
|
|
257
|
+
server.activate!("some scenario name")
|
195
258
|
end
|
196
259
|
|
197
|
-
|
260
|
+
end
|
198
261
|
|
199
|
-
|
262
|
+
describe "#has_started!" do
|
200
263
|
|
201
|
-
|
264
|
+
subject { server.has_started! }
|
202
265
|
|
266
|
+
before(:example) do
|
267
|
+
allow(server_facade).to receive(:server_has_started)
|
268
|
+
allow(transactional_session).to receive(:mark_as_default!)
|
203
269
|
end
|
204
270
|
|
205
|
-
|
271
|
+
it "informs the facade that the server has started" do
|
272
|
+
expect(server_facade).to receive(:server_has_started)
|
206
273
|
|
207
|
-
|
208
|
-
|
274
|
+
subject
|
275
|
+
end
|
209
276
|
|
210
|
-
|
211
|
-
|
212
|
-
allow(stub_builder).to receive(:invoke)
|
213
|
-
end
|
277
|
+
it "marks the transactional session as the servers default" do
|
278
|
+
expect(transactional_session).to receive(:mark_as_default!)
|
214
279
|
|
215
|
-
subject
|
280
|
+
subject
|
281
|
+
end
|
216
282
|
|
217
|
-
|
218
|
-
|
283
|
+
it "causes subsequent session operations to be performed against the transactional session" do
|
284
|
+
subject
|
285
|
+
expect(transactional_session).to receive(:activate!)
|
219
286
|
|
220
|
-
|
221
|
-
|
287
|
+
server.activate!("some scenario name")
|
288
|
+
end
|
222
289
|
|
223
|
-
|
224
|
-
expect(stub_builder).to receive(:invoke).and_yield
|
225
|
-
expect(block_verifier).to receive(:verify)
|
290
|
+
end
|
226
291
|
|
227
|
-
|
228
|
-
|
292
|
+
describe "#reset!" do
|
293
|
+
|
294
|
+
subject { server.reset! }
|
229
295
|
|
230
|
-
|
296
|
+
it "delegates to the server facade" do
|
297
|
+
expect(server_facade).to receive(:reset)
|
231
298
|
|
299
|
+
subject
|
232
300
|
end
|
233
301
|
|
234
302
|
end
|
@@ -236,27 +304,26 @@ describe HttpStub::Configurer::DSL::Server do
|
|
236
304
|
describe "#add_scenario!" do
|
237
305
|
|
238
306
|
let(:scenario_name) { "some/scenario/name" }
|
307
|
+
let(:block) { lambda { |_scenario| "some block" } }
|
308
|
+
|
239
309
|
let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
|
240
310
|
let(:scenario_builder) { instance_double(HttpStub::Configurer::DSL::ScenarioBuilder, build: scenario) }
|
241
311
|
|
242
|
-
|
243
|
-
|
244
|
-
let(:block) { lambda { |_scenario| "some block" } }
|
312
|
+
subject { server.add_scenario!(scenario_name, &block) }
|
245
313
|
|
246
314
|
before(:example) do
|
247
315
|
allow(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).and_return(scenario_builder)
|
316
|
+
allow(server_facade).to receive(:define_scenario)
|
248
317
|
end
|
249
318
|
|
250
|
-
|
251
|
-
|
252
|
-
it "creates a scenario builder containing the servers default stub builder" do
|
253
|
-
expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(default_stub_builder, anything)
|
319
|
+
it "creates a scenario builder containing the provided scenario name" do
|
320
|
+
expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(scenario_name, anything)
|
254
321
|
|
255
322
|
subject
|
256
323
|
end
|
257
324
|
|
258
|
-
it "creates a scenario builder
|
259
|
-
expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(anything,
|
325
|
+
it "creates a scenario builder extending the servers default stub template" do
|
326
|
+
expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(anything, default_stub_template)
|
260
327
|
|
261
328
|
subject
|
262
329
|
end
|
@@ -281,9 +348,8 @@ describe HttpStub::Configurer::DSL::Server do
|
|
281
348
|
|
282
349
|
describe "#add_scenario_with_one_stub!" do
|
283
350
|
|
284
|
-
let(:scenario_name)
|
285
|
-
let(:
|
286
|
-
let(:block) { lambda { block_verifier.verify } }
|
351
|
+
let(:scenario_name) { "Some scenario name" }
|
352
|
+
let(:block) { lambda { block_verifier.verify } }
|
287
353
|
|
288
354
|
let(:scenario_builder) { instance_double(HttpStub::Configurer::DSL::ScenarioBuilder, add_stub!: nil) }
|
289
355
|
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder, invoke: nil) }
|
@@ -318,8 +384,7 @@ describe HttpStub::Configurer::DSL::Server do
|
|
318
384
|
|
319
385
|
context "when a block is provided" do
|
320
386
|
|
321
|
-
let(:
|
322
|
-
let(:block) { lambda { block_verifier.verify } }
|
387
|
+
let(:block) { lambda { block_verifier.verify } }
|
323
388
|
|
324
389
|
subject { server.add_scenario_with_one_stub!(scenario_name, &block) }
|
325
390
|
|
@@ -338,124 +403,189 @@ describe HttpStub::Configurer::DSL::Server do
|
|
338
403
|
|
339
404
|
describe "#endpoint_template" do
|
340
405
|
|
341
|
-
let(:
|
342
|
-
let(:
|
343
|
-
let(:endpoint_template) { instance_double(HttpStub::Configurer::DSL::EndpointTemplate, invoke: nil) }
|
406
|
+
let(:block) { lambda { block_verifier.verify } }
|
407
|
+
let(:server_endpoint_template) { instance_double(HttpStub::Configurer::DSL::ServerEndpointTemplate) }
|
344
408
|
|
345
409
|
subject { server.endpoint_template(&block) }
|
346
410
|
|
347
411
|
before(:example) do
|
348
|
-
allow(HttpStub::Configurer::DSL::
|
412
|
+
allow(HttpStub::Configurer::DSL::ServerEndpointTemplate).to receive(:new).and_return(server_endpoint_template)
|
349
413
|
end
|
350
414
|
|
351
|
-
it "
|
352
|
-
expect(
|
353
|
-
expect(block_verifier).to receive(:verify)
|
415
|
+
it "creates an endpoint template for the server" do
|
416
|
+
expect(HttpStub::Configurer::DSL::ServerEndpointTemplate).to receive(:new).with(server, anything)
|
354
417
|
|
355
418
|
subject
|
356
419
|
end
|
357
420
|
|
358
|
-
it "creates
|
359
|
-
expect(HttpStub::Configurer::DSL::
|
421
|
+
it "creates an endpoint template using the curently default session" do
|
422
|
+
expect(HttpStub::Configurer::DSL::ServerEndpointTemplate).to receive(:new).with(anything, default_session)
|
423
|
+
|
424
|
+
subject
|
425
|
+
end
|
426
|
+
|
427
|
+
it "creates an endpoint template using any provided block to initialize the template" do
|
428
|
+
allow(HttpStub::Configurer::DSL::ServerEndpointTemplate).to receive(:new).and_yield
|
429
|
+
expect(block_verifier).to receive(:verify)
|
360
430
|
|
361
431
|
subject
|
362
432
|
end
|
363
433
|
|
364
434
|
it "returns the created endpoint template" do
|
365
|
-
expect(subject).to eql(
|
435
|
+
expect(subject).to eql(server_endpoint_template)
|
366
436
|
end
|
367
437
|
|
368
438
|
end
|
369
439
|
|
370
|
-
describe "#
|
440
|
+
describe "#session" do
|
371
441
|
|
372
|
-
let(:
|
373
|
-
let(:stub_activator_builder) do
|
374
|
-
instance_double(HttpStub::Configurer::DSL::StubActivatorBuilder, build: scenario)
|
375
|
-
end
|
442
|
+
let(:session_id) { "some session id" }
|
376
443
|
|
377
|
-
|
444
|
+
let(:session) { instance_double(HttpStub::Configurer::DSL::Session) }
|
378
445
|
|
379
|
-
|
446
|
+
subject { server.session(session_id) }
|
380
447
|
|
381
|
-
before(:example)
|
382
|
-
|
448
|
+
before(:example) { allow(session_factory).to receive(:create).and_return(session) }
|
449
|
+
|
450
|
+
it "creates a DSL for interacting with a session for the provided ID via the session factory" do
|
451
|
+
expect(session_factory).to receive(:create).with(session_id)
|
452
|
+
|
453
|
+
subject
|
454
|
+
end
|
455
|
+
|
456
|
+
it "returns the created session" do
|
457
|
+
expect(subject).to eql(session)
|
383
458
|
end
|
384
459
|
|
385
|
-
|
460
|
+
end
|
461
|
+
|
462
|
+
describe "#activate!" do
|
386
463
|
|
387
|
-
|
388
|
-
|
464
|
+
let(:scenario_name) { "Some scenario name" }
|
465
|
+
|
466
|
+
subject { server.activate!(scenario_name) }
|
467
|
+
|
468
|
+
it "delegates to the default session" do
|
469
|
+
expect(default_session).to receive(:activate!).with(scenario_name)
|
389
470
|
|
390
471
|
subject
|
391
472
|
end
|
392
473
|
|
393
|
-
|
394
|
-
|
474
|
+
end
|
475
|
+
|
476
|
+
describe "#clear_sessions!" do
|
477
|
+
|
478
|
+
subject { server.clear_sessions! }
|
479
|
+
|
480
|
+
it "delegates to the server facade" do
|
481
|
+
expect(server_facade).to receive(:clear_sessions)
|
482
|
+
|
483
|
+
subject
|
395
484
|
end
|
396
485
|
|
397
|
-
|
398
|
-
|
486
|
+
end
|
487
|
+
|
488
|
+
describe "#build_stub" do
|
489
|
+
|
490
|
+
let(:block) { lambda { block_verifier.verify } }
|
491
|
+
|
492
|
+
subject { server.build_stub(&block) }
|
493
|
+
|
494
|
+
it "delegates to the default session" do
|
495
|
+
expect(default_session).to receive(:build_stub)
|
399
496
|
|
400
497
|
subject
|
401
498
|
end
|
402
499
|
|
403
|
-
it "
|
404
|
-
|
500
|
+
it "initializes the built stub using the provided block" do
|
501
|
+
allow(default_session).to receive(:build_stub).and_yield
|
502
|
+
expect(block_verifier).to receive(:verify)
|
405
503
|
|
406
504
|
subject
|
407
505
|
end
|
408
506
|
|
507
|
+
it "returns the built stub" do
|
508
|
+
built_stub = instance_double(HttpStub::Configurer::DSL::StubBuilder)
|
509
|
+
allow(default_session).to receive(:build_stub).and_return(built_stub)
|
510
|
+
|
511
|
+
expect(subject).to eql(built_stub)
|
512
|
+
end
|
513
|
+
|
409
514
|
end
|
410
515
|
|
411
|
-
describe "#
|
516
|
+
describe "#add_stub!" do
|
412
517
|
|
413
|
-
|
518
|
+
context "when a stub builder is provided" do
|
414
519
|
|
415
|
-
|
416
|
-
|
520
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
521
|
+
|
522
|
+
subject { server.add_stub!(stub_builder) }
|
523
|
+
|
524
|
+
it "delegates to the default session" do
|
525
|
+
expect(default_session).to receive(:add_stub!).with(stub_builder)
|
526
|
+
|
527
|
+
subject
|
528
|
+
end
|
417
529
|
|
418
|
-
server.activate!(scenario_name)
|
419
530
|
end
|
420
531
|
|
421
|
-
|
532
|
+
context "when a block is provided" do
|
422
533
|
|
423
|
-
|
534
|
+
let(:block) { lambda { block_verifier.verify } }
|
424
535
|
|
425
|
-
|
426
|
-
|
536
|
+
subject { server.add_stub!(&block) }
|
537
|
+
|
538
|
+
it "delegates to the default session" do
|
539
|
+
expect(default_session).to receive(:add_stub!)
|
540
|
+
|
541
|
+
subject
|
542
|
+
end
|
543
|
+
|
544
|
+
it "supplies the provided block to the session" do
|
545
|
+
allow(default_session).to receive(:add_stub!).and_yield
|
546
|
+
expect(block_verifier).to receive(:verify)
|
547
|
+
|
548
|
+
subject
|
549
|
+
end
|
427
550
|
|
428
|
-
server.remember_stubs
|
429
551
|
end
|
430
552
|
|
431
553
|
end
|
432
554
|
|
433
|
-
describe "#
|
555
|
+
describe "#add_stubs!" do
|
434
556
|
|
435
|
-
|
436
|
-
expect(server_facade).to receive(:recall_stubs)
|
557
|
+
let(:stub_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
|
437
558
|
|
438
|
-
|
559
|
+
subject { server.add_stubs!(stub_builders) }
|
560
|
+
|
561
|
+
it "delegates to the default session" do
|
562
|
+
expect(default_session).to receive(:add_stubs!).with(stub_builders)
|
563
|
+
|
564
|
+
subject
|
439
565
|
end
|
440
566
|
|
441
567
|
end
|
442
568
|
|
443
|
-
describe "#
|
569
|
+
describe "#recall_stubs!" do
|
444
570
|
|
445
|
-
|
446
|
-
expect(server_facade).to receive(:clear_stubs)
|
571
|
+
subject { server.recall_stubs! }
|
447
572
|
|
448
|
-
|
573
|
+
it "resets the default session" do
|
574
|
+
expect(default_session).to receive(:reset!)
|
575
|
+
|
576
|
+
subject
|
449
577
|
end
|
450
578
|
|
451
579
|
end
|
452
580
|
|
453
|
-
describe "#
|
581
|
+
describe "#clear_stubs!" do
|
582
|
+
|
583
|
+
subject { server.clear_stubs! }
|
454
584
|
|
455
|
-
it "delegates to the
|
456
|
-
expect(
|
585
|
+
it "delegates to the default session" do
|
586
|
+
expect(default_session).to receive(:clear!)
|
457
587
|
|
458
|
-
|
588
|
+
subject
|
459
589
|
end
|
460
590
|
|
461
591
|
end
|