http_stub 0.25.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +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,75 @@
|
|
1
|
+
describe HttpStub::Extensions::Core::URI do
|
2
|
+
|
3
|
+
it "patches ::URI" do
|
4
|
+
expect(::URI.included_modules).to include(described_class)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "::add_parameters" do
|
8
|
+
|
9
|
+
let(:original_parameters) { {} }
|
10
|
+
let(:arg_parameters) { {} }
|
11
|
+
let(:uri) do
|
12
|
+
uri = URI.parse("https://some-host:8888/some/path")
|
13
|
+
uri.query = "#{URI.encode_www_form(original_parameters)}"
|
14
|
+
uri.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { ::URI.add_parameters(uri, arg_parameters) }
|
18
|
+
|
19
|
+
it "preserves the uri's host, port and path" do
|
20
|
+
expect(subject).to start_with("https://some-host:8888/some/path")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when the uri has parameters" do
|
24
|
+
|
25
|
+
let(:original_parameters) { (1..3).each_with_object({}) { |i, hash| hash["parameter_#{i}"] = "value #{i}" } }
|
26
|
+
|
27
|
+
context "and parameters are to be replaced" do
|
28
|
+
|
29
|
+
let(:arg_parameters) { { "parameter_2" => "updated value 2", "parameter_3" => "updated value 3" } }
|
30
|
+
|
31
|
+
it "replaces the parameters" do
|
32
|
+
expect(effective_parameters).to include(arg_parameters)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "retains other parameters" do
|
36
|
+
expect(effective_parameters).to include("parameter_1" => "value 1")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "and other parameters are to be added" do
|
42
|
+
|
43
|
+
let(:arg_parameters) do
|
44
|
+
(1..3).each_with_object({}) { |i, hash| hash["another_parameter_#{i}"] = "another value #{i}" }
|
45
|
+
end
|
46
|
+
|
47
|
+
it "adds the parameter" do
|
48
|
+
expect(effective_parameters).to include(arg_parameters)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "retains other parameters" do
|
52
|
+
expect(effective_parameters).to include(original_parameters)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the uri does not have parameters" do
|
60
|
+
|
61
|
+
let(:arg_parameters) { (1..3).each_with_object({}) { |i, hash| hash["parameter_#{i}"] = "value #{i}" } }
|
62
|
+
|
63
|
+
it "adds the parameters" do
|
64
|
+
expect(effective_parameters).to include(arg_parameters)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def effective_parameters
|
70
|
+
URI.decode_www_form(URI.parse(subject).query).to_h
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe HttpStub::Extensions::Rack::Handler do
|
2
2
|
|
3
3
|
it "patches Rack::Handler" do
|
4
|
-
expect(::Rack::Handler.included_modules).to include(
|
4
|
+
expect(::Rack::Handler.included_modules).to include(described_class)
|
5
5
|
end
|
6
6
|
|
7
7
|
context "when mixed in to a module" do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
describe "Sinatra::Namespace loading customisations" do
|
2
|
+
include Rake::DSL
|
3
|
+
include_context "rack application test"
|
4
|
+
|
5
|
+
class HttpStub::Extensions::SinatraNamespaceTestApplication < Sinatra::Base
|
6
|
+
|
7
|
+
register Sinatra::Namespace
|
8
|
+
|
9
|
+
namespace "/sinatra_namespace_extension" do
|
10
|
+
|
11
|
+
get do
|
12
|
+
halt 200
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:app_class) { HttpStub::Extensions::SinatraNamespaceTestApplication }
|
20
|
+
|
21
|
+
it "preserves Rake's namespace" do
|
22
|
+
rake_namespace = namespace(:some_rake_namespace) {}
|
23
|
+
expect(rake_namespace).to be_an_instance_of(Rake::NameSpace)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "scopes Sinatra's namespace to be available to those extending Sinatra::Namespace" do
|
27
|
+
issue_a_request
|
28
|
+
|
29
|
+
expect(response.status).to eql(200)
|
30
|
+
end
|
31
|
+
|
32
|
+
def issue_a_request
|
33
|
+
get "/sinatra_namespace_extension"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -2,6 +2,7 @@ describe HttpStub::Rake::ServerTasks do
|
|
2
2
|
include Rake::DSL
|
3
3
|
|
4
4
|
shared_context "verification of generated tasks" do
|
5
|
+
include_context "surpressed output"
|
5
6
|
|
6
7
|
before(:example) { HttpStub::Rake::ServerTasks.new(task_args) }
|
7
8
|
|
@@ -12,7 +13,7 @@ describe HttpStub::Rake::ServerTasks do
|
|
12
13
|
context "when invoked" do
|
13
14
|
|
14
15
|
before(:example) do
|
15
|
-
Thread.new { task.invoke("--
|
16
|
+
Thread.new { task.invoke("--silent") }
|
16
17
|
wait_until_server_has_started
|
17
18
|
end
|
18
19
|
|
@@ -48,7 +49,7 @@ describe HttpStub::Rake::ServerTasks do
|
|
48
49
|
|
49
50
|
context "when a configurer is provided" do
|
50
51
|
|
51
|
-
let(:port) {
|
52
|
+
let(:port) { 8005 }
|
52
53
|
let(:configurer) do
|
53
54
|
Class.new.tap do |configurer|
|
54
55
|
configurer.send(:include, HttpStub::Configurer)
|
@@ -64,7 +65,7 @@ describe HttpStub::Rake::ServerTasks do
|
|
64
65
|
|
65
66
|
context "when a port is provided" do
|
66
67
|
|
67
|
-
let(:port) {
|
68
|
+
let(:port) { 8006 }
|
68
69
|
let(:task_args) { { name: :test_server_with_port, port: port } }
|
69
70
|
|
70
71
|
include_context "verification of generated tasks"
|
@@ -9,25 +9,30 @@ describe HttpStub::Rake::ServerTasks do
|
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
|
-
let(:server_name)
|
13
|
-
let(:default_args)
|
14
|
-
let(:
|
15
|
-
let(:
|
12
|
+
let(:server_name) { "server_tasks_test_#{HttpStub::Rake::ServerTasksTestCounter.next}".to_sym }
|
13
|
+
let(:default_args) { { port: 8001, name: server_name } }
|
14
|
+
let(:additional_args) { {} }
|
15
|
+
let(:args) { default_args.merge(additional_args) }
|
16
|
+
let(:configurer) { double(HttpStub::Configurer).as_null_object }
|
16
17
|
|
17
|
-
before(:example) { HttpStub::Rake::ServerTasks.new(
|
18
|
+
before(:example) { HttpStub::Rake::ServerTasks.new(args) }
|
18
19
|
|
19
20
|
describe "the configure task" do
|
20
21
|
|
21
|
-
|
22
|
+
let(:task) { Rake::Task["#{server_name}:configure"] }
|
22
23
|
|
23
|
-
|
24
|
+
context "when executed" do
|
24
25
|
|
25
|
-
|
26
|
+
subject { task.execute }
|
27
|
+
|
28
|
+
context "with a configurer" do
|
29
|
+
|
30
|
+
let(:additional_args) { { configurer: configurer } }
|
26
31
|
|
27
32
|
it "initializes the provided configurer" do
|
28
33
|
expect(configurer).to receive(:initialize!)
|
29
34
|
|
30
|
-
|
35
|
+
subject
|
31
36
|
end
|
32
37
|
|
33
38
|
end
|
@@ -37,7 +42,39 @@ describe HttpStub::Rake::ServerTasks do
|
|
37
42
|
context "when a configurer is not provided" do
|
38
43
|
|
39
44
|
it "does not generate a task" do
|
40
|
-
expect {
|
45
|
+
expect { task }.to raise_error(/Don't know how to build task/)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "the start foreground task" do
|
53
|
+
|
54
|
+
let(:application) { HttpStub::Server::Application::Application }
|
55
|
+
|
56
|
+
let(:task) { Rake::Task["#{server_name}:start:foreground"] }
|
57
|
+
|
58
|
+
context "when executed" do
|
59
|
+
|
60
|
+
subject { task.execute }
|
61
|
+
|
62
|
+
before(:example) do
|
63
|
+
allow(HttpStub::Server::Application::Application).to receive(:configure)
|
64
|
+
allow(HttpStub::Server::Application::Application).to receive(:run!)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "configures the application using the tasks arguments" do
|
68
|
+
expect(application).to receive(:configure).with(args)
|
69
|
+
|
70
|
+
subject
|
71
|
+
end
|
72
|
+
|
73
|
+
it "runs the configured application" do
|
74
|
+
expect(application).to receive(:configure).ordered
|
75
|
+
expect(application).to receive(:run!).ordered
|
76
|
+
|
77
|
+
subject
|
41
78
|
end
|
42
79
|
|
43
80
|
end
|
@@ -1,353 +1,96 @@
|
|
1
1
|
describe HttpStub::Server::Application::Application do
|
2
|
-
|
2
|
+
include_context "http_stub rack application test"
|
3
3
|
|
4
|
-
|
5
|
-
let(:response_body) { response.body.to_s }
|
4
|
+
describe "::configure" do
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller) }
|
13
|
-
let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller) }
|
14
|
-
let(:stub_match_controller) { instance_double(HttpStub::Server::Stub::Match::Controller) }
|
15
|
-
|
16
|
-
let(:response_pipeline) { instance_double(HttpStub::Server::Application::ResponsePipeline, process: nil) }
|
17
|
-
|
18
|
-
let(:app) { HttpStub::Server::Application::Application.new! }
|
19
|
-
|
20
|
-
before(:example) do
|
21
|
-
allow(HttpStub::Server::Registry).to receive(:new).with("scenario").and_return(scenario_registry)
|
22
|
-
allow(HttpStub::Server::Stub::Registry).to receive(:new).and_return(stub_registry)
|
23
|
-
allow(HttpStub::Server::Registry).to receive(:new).with("stub match").and_return(stub_match_registry)
|
24
|
-
allow(HttpStub::Server::Registry).to receive(:new).with("stub miss").and_return(stub_miss_registry)
|
25
|
-
allow(HttpStub::Server::Scenario::Controller).to receive(:new).and_return(scenario_controller)
|
26
|
-
allow(HttpStub::Server::Stub::Controller).to receive(:new).and_return(stub_controller)
|
27
|
-
allow(HttpStub::Server::Stub::Match::Controller).to receive(:new).and_return(stub_match_controller)
|
28
|
-
allow(HttpStub::Server::Application::ResponsePipeline).to receive(:new).and_return(response_pipeline)
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when the diagnostics landing page is retrieved" do
|
32
|
-
|
33
|
-
subject { get "/http_stub" }
|
34
|
-
|
35
|
-
it "responds without error" do
|
36
|
-
subject
|
37
|
-
|
38
|
-
expect(response.status).to eql(200)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when a stub registration request is received" do
|
44
|
-
|
45
|
-
let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
46
|
-
|
47
|
-
subject do
|
48
|
-
post "/http_stub/stubs", { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } }.to_json
|
49
|
-
end
|
50
|
-
|
51
|
-
before(:example) { allow(stub_controller).to receive(:register).and_return(registration_response) }
|
52
|
-
|
53
|
-
it "registers the stub via the stub controller" do
|
54
|
-
expect(stub_controller).to receive(:register).and_return(registration_response)
|
55
|
-
|
56
|
-
subject
|
57
|
-
end
|
58
|
-
|
59
|
-
it "processes the stub controllers response via the response pipeline" do
|
60
|
-
expect(response_pipeline).to receive(:process).with(registration_response)
|
61
|
-
|
62
|
-
subject
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when a request to list the stubs is received" do
|
68
|
-
|
69
|
-
let(:found_stubs) { [ HttpStub::Server::Stub::Empty::INSTANCE ] }
|
70
|
-
|
71
|
-
subject { get "/http_stub/stubs" }
|
72
|
-
|
73
|
-
it "retrieves the stubs from the registry" do
|
74
|
-
expect(stub_registry).to receive(:all).and_return(found_stubs)
|
75
|
-
|
76
|
-
subject
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when a request to show a stub is received" do
|
82
|
-
|
83
|
-
let(:stub_id) { SecureRandom.uuid }
|
84
|
-
let(:found_stub) { HttpStub::Server::Stub::Empty::INSTANCE }
|
85
|
-
|
86
|
-
subject { get "/http_stub/stubs/#{stub_id}" }
|
87
|
-
|
88
|
-
it "retrieves the stub from the registry" do
|
89
|
-
expect(stub_registry).to receive(:find).with(stub_id, anything).and_return(found_stub)
|
90
|
-
|
91
|
-
subject
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when a request to clear the stubs is received" do
|
97
|
-
|
98
|
-
subject { delete "/http_stub/stubs" }
|
99
|
-
|
100
|
-
before(:example) { allow(stub_controller).to receive(:clear) }
|
101
|
-
|
102
|
-
it "delegates clearing to the stub controller" do
|
103
|
-
expect(stub_controller).to receive(:clear)
|
104
|
-
|
105
|
-
subject
|
106
|
-
end
|
107
|
-
|
108
|
-
it "responds with a 200 status code" do
|
109
|
-
subject
|
110
|
-
|
111
|
-
expect(response.status).to eql(200)
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
context "when a request to commit the stubs to memory is received" do
|
117
|
-
|
118
|
-
subject { post "/http_stub/stubs/memory" }
|
119
|
-
|
120
|
-
before(:example) { allow(stub_registry).to receive(:remember) }
|
121
|
-
|
122
|
-
it "remembers the stubs in the stub registry" do
|
123
|
-
expect(stub_registry).to receive(:remember)
|
124
|
-
|
125
|
-
subject
|
126
|
-
end
|
127
|
-
|
128
|
-
it "responds with a 200 status code" do
|
129
|
-
subject
|
130
|
-
|
131
|
-
expect(response.status).to eql(200)
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when a request to recall the stubs in memory is received" do
|
137
|
-
|
138
|
-
subject { get "/http_stub/stubs/memory" }
|
139
|
-
|
140
|
-
before(:example) { allow(stub_registry).to receive(:recall) }
|
141
|
-
|
142
|
-
it "recalls the stubs remembered by the stub registry" do
|
143
|
-
expect(stub_registry).to receive(:recall)
|
144
|
-
|
145
|
-
subject
|
146
|
-
end
|
147
|
-
|
148
|
-
it "responds with a 200 status code" do
|
149
|
-
subject
|
150
|
-
|
151
|
-
expect(response.status).to eql(200)
|
6
|
+
let(:args) { { some_argument_key: "some argument value" } }
|
7
|
+
let(:configured_settings) { { setting_1: "value 1", setting_2: "value 2", setting_3: "value 3" } }
|
8
|
+
let(:configuration) do
|
9
|
+
instance_double(HttpStub::Server::Application::Configuration, settings: configured_settings)
|
152
10
|
end
|
153
11
|
|
154
|
-
|
155
|
-
|
156
|
-
context "when a request to list the stub matches is received" do
|
157
|
-
|
158
|
-
let(:found_matches) { [ HttpStub::Server::Stub::Match::MatchFixture.create ] }
|
12
|
+
subject { described_class.configure(args) }
|
159
13
|
|
160
|
-
|
14
|
+
before(:example) { allow(HttpStub::Server::Application::Configuration).to receive(:new).and_return(configuration) }
|
161
15
|
|
162
|
-
it "
|
163
|
-
expect(
|
16
|
+
it "creates application configuration encapsulating the arguments" do
|
17
|
+
expect(HttpStub::Server::Application::Configuration).to receive(:new).with(args).and_return(configuration)
|
164
18
|
|
165
19
|
subject
|
166
20
|
end
|
167
21
|
|
168
|
-
|
169
|
-
|
170
|
-
context "when a request to retrieve the last match for an endpoint is received" do
|
171
|
-
|
172
|
-
let(:uri) { "/some/matched/uri" }
|
173
|
-
let(:method) { "some http method" }
|
174
|
-
let(:last_match_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
175
|
-
|
176
|
-
subject { get "/http_stub/stubs/matches/last", "uri" => uri, "method" => method }
|
177
|
-
|
178
|
-
before(:example) { allow(stub_match_controller).to receive(:find_last).and_return(last_match_response) }
|
179
|
-
|
180
|
-
it "retrieves the last match from the match result registry for the provided request" do
|
181
|
-
expect(stub_match_controller).to(
|
182
|
-
receive(:find_last).with(an_instance_of(HttpStub::Server::Request::Request), anything)
|
183
|
-
)
|
184
|
-
|
22
|
+
it "establishes the configured settings on the application" do
|
185
23
|
subject
|
186
|
-
end
|
187
24
|
|
188
|
-
|
189
|
-
expect(response_pipeline).to receive(:process).with(last_match_response)
|
190
|
-
|
191
|
-
subject
|
25
|
+
configured_settings.each { |name, value| expect(described_class.settings.send(name)).to eql(value) }
|
192
26
|
end
|
193
27
|
|
194
28
|
end
|
195
29
|
|
196
|
-
|
197
|
-
|
198
|
-
let(:found_misses) { [ HttpStub::Server::Stub::Match::MissFixture.create ] }
|
199
|
-
|
200
|
-
subject { get "/http_stub/stubs/misses" }
|
201
|
-
|
202
|
-
it "retrieves the misses from the miss registry" do
|
203
|
-
expect(stub_miss_registry).to receive(:all).and_return(found_misses)
|
204
|
-
|
205
|
-
subject
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
|
210
|
-
context "when a scenario registration request is received" do
|
211
|
-
|
212
|
-
let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
213
|
-
|
214
|
-
before(:example) { allow(scenario_controller).to receive(:register).and_return(registration_response) }
|
215
|
-
|
216
|
-
subject do
|
217
|
-
post "/http_stub/scenarios",
|
218
|
-
{
|
219
|
-
uri: "/a_scenario_path",
|
220
|
-
stubs: [ { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } } ],
|
221
|
-
triggered_scenario_names: [ "some/uri/to/activate" ]
|
222
|
-
}.to_json
|
223
|
-
end
|
224
|
-
|
225
|
-
it "registers the scenario via the scenario controller" do
|
226
|
-
expect(scenario_controller).to receive(:register).and_return(registration_response)
|
227
|
-
|
228
|
-
subject
|
229
|
-
end
|
230
|
-
|
231
|
-
it "processes the scenario controllers response via the response pipeline" do
|
232
|
-
expect(response_pipeline).to receive(:process).with(registration_response)
|
233
|
-
|
234
|
-
subject
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
context "when a request to show a scenario is received" do
|
240
|
-
|
241
|
-
let(:scenario_name) { "Some scenario name" }
|
242
|
-
let(:found_scenario) { HttpStub::Server::Scenario::ScenarioFixture.create }
|
243
|
-
|
244
|
-
subject { get "/http_stub/scenarios?#{URI.encode_www_form(:name => scenario_name)}" }
|
245
|
-
|
246
|
-
it "retrieves the scenario from the scenario registry" do
|
247
|
-
expect(scenario_registry).to receive(:find).with(scenario_name, anything).and_return(found_scenario)
|
248
|
-
|
249
|
-
subject
|
250
|
-
end
|
251
|
-
|
30
|
+
it "disables all standard HTTP security measures to allow stubs full control of responses" do
|
31
|
+
expect(app.settings.protection).to eql(false)
|
252
32
|
end
|
253
33
|
|
254
|
-
|
255
|
-
|
256
|
-
let(:found_scenarios) { [ HttpStub::Server::Scenario::ScenarioFixture.create ] }
|
257
|
-
|
258
|
-
subject { get "/http_stub/scenarios" }
|
259
|
-
|
260
|
-
it "retrieves the stubs from the registry" do
|
261
|
-
expect(scenario_registry).to receive(:all).and_return(found_scenarios)
|
262
|
-
|
263
|
-
subject
|
264
|
-
end
|
265
|
-
|
34
|
+
it "disables cross origin support by default" do
|
35
|
+
expect(app.settings.cross_origin_support).to eql(false)
|
266
36
|
end
|
267
37
|
|
268
|
-
|
38
|
+
describe "the session configuration" do
|
269
39
|
|
270
|
-
let(:
|
271
|
-
let(:activation_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
40
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration).as_null_object }
|
272
41
|
|
273
|
-
|
42
|
+
context "when a session identifier is set" do
|
274
43
|
|
275
|
-
|
44
|
+
include_context "enabled session support"
|
276
45
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
subject
|
281
|
-
end
|
46
|
+
it "is created on startup with the session identifier" do
|
47
|
+
expect(HttpStub::Server::Session::Configuration).to receive(:new).with(session_identifier)
|
282
48
|
|
283
|
-
|
284
|
-
|
49
|
+
app
|
50
|
+
end
|
285
51
|
|
286
|
-
subject
|
287
52
|
end
|
288
53
|
|
289
|
-
|
290
|
-
|
291
|
-
context "when a request to clear the scenarios has been received" do
|
292
|
-
|
293
|
-
subject { delete "/http_stub/scenarios" }
|
54
|
+
context "when a session identifier is not configured" do
|
294
55
|
|
295
|
-
|
56
|
+
it "is created on startup with a nil session identifier" do
|
57
|
+
expect(HttpStub::Server::Session::Configuration).to receive(:new).with(nil)
|
296
58
|
|
297
|
-
|
298
|
-
|
59
|
+
app
|
60
|
+
end
|
299
61
|
|
300
|
-
subject
|
301
|
-
end
|
302
|
-
|
303
|
-
it "responds with a 200 status code" do
|
304
|
-
subject
|
305
|
-
|
306
|
-
expect(response.status).to eql(200)
|
307
62
|
end
|
308
63
|
|
309
|
-
|
310
|
-
|
311
|
-
context "when a request for the diagnostic pages stylesheet has been received" do
|
312
|
-
|
313
|
-
subject { get "/application.css" }
|
314
|
-
|
315
|
-
it "responds without error" do
|
316
|
-
subject
|
64
|
+
it "is reused on all requests" do
|
65
|
+
expect(HttpStub::Server::Session::Configuration).to receive(:new).once
|
317
66
|
|
318
|
-
|
67
|
+
issue_a_request
|
68
|
+
issue_a_request
|
319
69
|
end
|
320
70
|
|
321
71
|
end
|
322
72
|
|
323
|
-
|
73
|
+
describe "the memory" do
|
324
74
|
|
325
|
-
let(:
|
75
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory).as_null_object }
|
326
76
|
|
327
|
-
|
77
|
+
it "is created on startup" do
|
78
|
+
expect(HttpStub::Server::Memory::Memory).to receive(:new).and_return(server_memory)
|
328
79
|
|
329
|
-
|
330
|
-
|
331
|
-
it "attempts to match the request to a stub response via the stub controller" do
|
332
|
-
expect(stub_controller).to receive(:match).with(an_instance_of(HttpStub::Server::Request::Request), anything)
|
333
|
-
|
334
|
-
subject
|
80
|
+
app
|
335
81
|
end
|
336
82
|
|
337
|
-
it "
|
338
|
-
expect(
|
83
|
+
it "is reused on all requests" do
|
84
|
+
expect(HttpStub::Server::Memory::Memory).to receive(:new).once.and_return(server_memory)
|
339
85
|
|
340
|
-
|
86
|
+
issue_a_request
|
87
|
+
issue_a_request
|
341
88
|
end
|
342
89
|
|
343
90
|
end
|
344
91
|
|
345
|
-
|
346
|
-
|
347
|
-
end
|
348
|
-
|
349
|
-
it "disables cross origin support by default" do
|
350
|
-
expect(app.settings.cross_origin_support).to eql(false)
|
92
|
+
def issue_a_request
|
93
|
+
get "/application.css"
|
351
94
|
end
|
352
95
|
|
353
96
|
end
|