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,59 @@
|
|
1
|
+
describe HttpStub::Server::Application::Configuration do
|
2
|
+
|
3
|
+
let(:configuration) { described_class.new(args) }
|
4
|
+
|
5
|
+
describe "#settings" do
|
6
|
+
|
7
|
+
subject { configuration.settings }
|
8
|
+
|
9
|
+
context "when a configurer is provided" do
|
10
|
+
|
11
|
+
let(:port) { 8888 }
|
12
|
+
let(:session_identifier) { { parameters: :some_session_parameter } }
|
13
|
+
let(:cross_origin_support_flag) { true }
|
14
|
+
let(:stub_server) do
|
15
|
+
instance_double(HttpStub::Configurer::DSL::Server, port: port, session_identifier: session_identifier)
|
16
|
+
end
|
17
|
+
let(:configurer) { double(HttpStub::Configurer, stub_server: stub_server) }
|
18
|
+
let(:args) { { configurer: configurer } }
|
19
|
+
|
20
|
+
before(:example) do
|
21
|
+
allow(stub_server).to receive(:enabled?).with(:cross_origin_support).and_return(cross_origin_support_flag)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has the configurers port" do
|
25
|
+
expect(subject).to include(port: port)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has the configurers session identifier" do
|
29
|
+
expect(subject).to include(session_identifier: session_identifier)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has the configurers cross origin support flag" do
|
33
|
+
expect(subject).to include(cross_origin_support: cross_origin_support_flag)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when a configurer is not provided" do
|
39
|
+
|
40
|
+
let(:port) { 8889 }
|
41
|
+
let(:args) { { port: port } }
|
42
|
+
|
43
|
+
it "has the provided port" do
|
44
|
+
expect(subject).to include(port: port)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has a nil session identifier" do
|
48
|
+
expect(subject).to include(session_identifier: nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has disabled cross origin support" do
|
52
|
+
expect(subject).to include(cross_origin_support: false)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -1,33 +1,36 @@
|
|
1
1
|
describe HttpStub::Server::Application::CrossOriginSupport do
|
2
2
|
include Rack::Test::Methods
|
3
3
|
|
4
|
-
let(:
|
5
|
-
let(:application_headers) do
|
6
|
-
application_header_names.each_with_object({}) { |name, result| result["HTTP_#{name}"] = "#{name} value" }
|
7
|
-
end
|
4
|
+
let(:response) { last_response }
|
8
5
|
|
9
|
-
|
10
|
-
let(:access_control_request_header_names) { (1..3).map { |i| "ACCESS_CONTROL_HEADER_#{i}" } }
|
11
|
-
let(:access_control_request_headers) do
|
12
|
-
{
|
13
|
-
"ACCESS_CONTROL_REQUEST_METHOD" => access_control_request_method,
|
14
|
-
"ACCESS_CONTROL_REQUEST_HEADERS" => access_control_request_header_names.join(",")
|
15
|
-
}
|
16
|
-
end
|
6
|
+
describe "when registered in an application" do
|
17
7
|
|
18
|
-
|
8
|
+
class HttpStub::Server::Application::CrossOriginSupportTestApplication < Sinatra::Base
|
9
|
+
|
10
|
+
def http_stub_request
|
11
|
+
HttpStub::Server::RequestFixture.create(request)
|
12
|
+
end
|
19
13
|
|
20
|
-
|
14
|
+
end
|
21
15
|
|
22
|
-
|
16
|
+
let(:application_header_names) { (1..3).map { |i| "APPLICATION_HEADER_#{i}" } }
|
17
|
+
let(:application_headers) do
|
18
|
+
application_header_names.each_with_object({}) { |name, result| result["HTTP_#{name}"] = "#{name} value" }
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
let(:access_control_request_method) { "PATCH" }
|
22
|
+
let(:access_control_request_header_names) { (1..3).map { |i| "ACCESS_CONTROL_HEADER_#{i}" } }
|
23
|
+
let(:access_control_request_headers) do
|
24
|
+
{
|
25
|
+
"ACCESS_CONTROL_REQUEST_METHOD" => access_control_request_method,
|
26
|
+
"ACCESS_CONTROL_REQUEST_HEADERS" => access_control_request_header_names.join(",")
|
27
|
+
}
|
28
|
+
end
|
27
29
|
|
28
|
-
|
30
|
+
let(:app_class) { HttpStub::Server::Application::CrossOriginSupportTestApplication }
|
31
|
+
let(:app) { app_class.new! }
|
29
32
|
|
30
|
-
before(:example) { app_class.register
|
33
|
+
before(:example) { app_class.register(described_class) }
|
31
34
|
|
32
35
|
shared_examples_for "a request whose response contains access control headers" do
|
33
36
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
describe HttpStub::Server::Application::RequestSupport, "when integrated into a complete Rack application" do
|
2
|
+
|
3
|
+
context "when included in an application" do
|
4
|
+
include_context "rack application test"
|
5
|
+
|
6
|
+
class HttpStub::Server::Application::RequestSupport::IntegrationTestApplication < Sinatra::Base
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@session_configuration = HttpStub::Server::Session::Configuration.new(nil)
|
10
|
+
@server_memory = HttpStub::Server::Memory::Memory.new(@session_configuration)
|
11
|
+
super()
|
12
|
+
end
|
13
|
+
|
14
|
+
include HttpStub::Server::Application::RequestSupport
|
15
|
+
|
16
|
+
get "/accesses_uri" do
|
17
|
+
halt 200, "Request path: #{http_stub_request.uri}"
|
18
|
+
end
|
19
|
+
|
20
|
+
post "/with_body_and_establishes_request_multiple_times" do
|
21
|
+
establish_http_stub_request
|
22
|
+
halt 200, "Request body: #{http_stub_request.body}"
|
23
|
+
end
|
24
|
+
|
25
|
+
post "/without_body" do
|
26
|
+
establish_http_stub_request
|
27
|
+
halt 200
|
28
|
+
end
|
29
|
+
|
30
|
+
any_request_method "/any_request_method_test" do
|
31
|
+
halt 200
|
32
|
+
end
|
33
|
+
|
34
|
+
def logger
|
35
|
+
HttpServerManager::Test::SilentLogger
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:app_class) { HttpStub::Server::Application::RequestSupport::IntegrationTestApplication }
|
41
|
+
let(:app) { app_class.new! }
|
42
|
+
|
43
|
+
describe "#http_stub_request" do
|
44
|
+
|
45
|
+
context "when an action accesses the request" do
|
46
|
+
|
47
|
+
it "retrieves the request attributes successfully" do
|
48
|
+
get "/accesses_uri"
|
49
|
+
|
50
|
+
expect(response.body).to end_with("accesses_uri")
|
51
|
+
end
|
52
|
+
|
53
|
+
context "and the action is a POST with a body that establishes the request multiple times" do
|
54
|
+
|
55
|
+
it "retains any request body provided" do
|
56
|
+
post "/with_body_and_establishes_request_multiple_times", "some body"
|
57
|
+
|
58
|
+
expect(response.body).to end_with("some body")
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "and the action is a POST without a body" do
|
64
|
+
|
65
|
+
it "executes without error" do
|
66
|
+
post "/without_body"
|
67
|
+
|
68
|
+
expect(response.status).to eql(200)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#any_request_method" do
|
78
|
+
|
79
|
+
[ :get, :post, :put, :patch, :delete, :options ].each do |request_method|
|
80
|
+
|
81
|
+
it "handles #{request_method} requests for the provided endpoint" do
|
82
|
+
self.send(request_method, "/any_request_method_test")
|
83
|
+
|
84
|
+
expect(response.status).to eql(200)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
describe HttpStub::Server::Application::RequestSupport do
|
2
|
+
|
3
|
+
context "when included in an application" do
|
4
|
+
include_context "rack application test"
|
5
|
+
|
6
|
+
class HttpStub::Server::Application::RequestSupport::TestApplication < Sinatra::Base
|
7
|
+
include HttpStub::Server::Application::RequestSupport
|
8
|
+
|
9
|
+
def initialize(session_configuration, server_memory)
|
10
|
+
@session_configuration = session_configuration
|
11
|
+
@server_memory = server_memory
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
|
15
|
+
get "/request_support_test" do
|
16
|
+
halt 200
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
|
22
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory) }
|
23
|
+
let(:request_factory) { instance_double(HttpStub::Server::Request::Factory) }
|
24
|
+
|
25
|
+
let(:app_class) { HttpStub::Server::Application::RequestSupport::TestApplication }
|
26
|
+
let(:app) { app_class.new!(session_configuration, server_memory) }
|
27
|
+
|
28
|
+
describe "constructor" do
|
29
|
+
|
30
|
+
subject { app }
|
31
|
+
|
32
|
+
it "creates a factory for creating http_stub using the servers session configuration" do
|
33
|
+
expect(HttpStub::Server::Request::Factory).to receive(:new).with(session_configuration, anything)
|
34
|
+
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a factory for creating http_stub requests based on the servers memory" do
|
39
|
+
expect(HttpStub::Server::Request::Factory).to receive(:new).with(anything, server_memory)
|
40
|
+
|
41
|
+
subject
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when servicing a request" do
|
47
|
+
|
48
|
+
subject { get "/request_support_test" }
|
49
|
+
|
50
|
+
it "creates a http_stub request for rack requests issued" do
|
51
|
+
allow(HttpStub::Server::Request::Factory).to receive(:new).and_return(request_factory)
|
52
|
+
expect(request_factory).to receive(:create).with(a_kind_of(Rack::Request), anything, anything)
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
describe HttpStub::Server::Application::ResponseSupport do
|
2
|
+
|
3
|
+
context "when included in an application" do
|
4
|
+
include_context "rack application test"
|
5
|
+
|
6
|
+
class HttpStub::Server::Application::ResponseSupportTestApplication < Sinatra::Base
|
7
|
+
|
8
|
+
include HttpStub::Server::Application::ResponseSupport
|
9
|
+
|
10
|
+
get "/response_support_test" do
|
11
|
+
halt 200
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:app_class) { HttpStub::Server::Application::ResponseSupportTestApplication }
|
17
|
+
|
18
|
+
it "creates a response pipeline for the application when handling a request" do
|
19
|
+
expect(HttpStub::Server::Application::ResponsePipeline).to receive(:new).with(an_instance_of(app_class))
|
20
|
+
|
21
|
+
issue_a_request
|
22
|
+
end
|
23
|
+
|
24
|
+
def issue_a_request
|
25
|
+
get "/response_support_test"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Memory do
|
2
|
+
include_context "http_stub rack application test"
|
3
|
+
|
4
|
+
let(:memory_controller) { instance_double(HttpStub::Server::Memory::Controller) }
|
5
|
+
|
6
|
+
before(:example) { allow(HttpStub::Server::Memory::Controller).to receive(:new).and_return(memory_controller) }
|
7
|
+
|
8
|
+
context "when a request to show the servers memory is received" do
|
9
|
+
|
10
|
+
subject { get "/http_stub/memory" }
|
11
|
+
|
12
|
+
it "retrieves the servers memorized stub via the memory controller" do
|
13
|
+
memorized_stubs = (1..3).map { HttpStub::Server::Stub::Empty::INSTANCE }
|
14
|
+
expect(memory_controller).to receive(:find_stubs).and_return(memorized_stubs)
|
15
|
+
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when a request to reset the servers memory is received" do
|
22
|
+
|
23
|
+
subject { delete "/http_stub/memory" }
|
24
|
+
|
25
|
+
before(:example) { allow(memory_controller).to receive(:reset) }
|
26
|
+
|
27
|
+
it "resets the servers memory via the memory controller" do
|
28
|
+
expect(memory_controller).to receive(:reset)
|
29
|
+
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
|
33
|
+
it "responds without error" do
|
34
|
+
subject
|
35
|
+
|
36
|
+
expect(response.status).to eql(200)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Resource do
|
2
|
+
include_context "http_stub rack application test"
|
3
|
+
|
4
|
+
context "when a request for the administration pages stylesheet has been received" do
|
5
|
+
|
6
|
+
subject { get "/application.css" }
|
7
|
+
|
8
|
+
it "responds without error" do
|
9
|
+
subject
|
10
|
+
|
11
|
+
expect(response.status).to eql(200)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Scenario do
|
2
|
+
include_context "http_stub rack application test"
|
3
|
+
|
4
|
+
let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller) }
|
5
|
+
|
6
|
+
before(:example) { allow(HttpStub::Server::Scenario::Controller).to receive(:new).and_return(scenario_controller) }
|
7
|
+
|
8
|
+
context "when a scenario registration request is received" do
|
9
|
+
|
10
|
+
let(:payload) do
|
11
|
+
{
|
12
|
+
uri: "/a_scenario_path",
|
13
|
+
stubs: [ { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } } ],
|
14
|
+
triggered_scenario_names: [ "some/uri/to/activate" ]
|
15
|
+
}.to_json
|
16
|
+
end
|
17
|
+
let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
18
|
+
|
19
|
+
before(:example) do
|
20
|
+
allow(request).to receive(:body).and_return(payload)
|
21
|
+
allow(scenario_controller).to receive(:register).and_return(registration_response)
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { post "/http_stub/scenarios" }
|
25
|
+
|
26
|
+
it "registers the scenario via the scenario controller" do
|
27
|
+
expect(scenario_controller).to receive(:register).and_return(registration_response)
|
28
|
+
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
|
32
|
+
it "processes the scenario controllers response via the response pipeline" do
|
33
|
+
expect(response_pipeline).to receive(:process).with(registration_response)
|
34
|
+
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when a request to show a scenario is received" do
|
41
|
+
|
42
|
+
let(:scenario_name) { "Some scenario name" }
|
43
|
+
let(:found_scenario) { HttpStub::Server::ScenarioFixture.create }
|
44
|
+
|
45
|
+
subject { get "/http_stub/scenarios" }
|
46
|
+
|
47
|
+
before(:example) { allow(request).to receive(:parameters).and_return(name: scenario_name) }
|
48
|
+
|
49
|
+
it "retrieves the scenario via the scenario controller" do
|
50
|
+
expect(scenario_controller).to receive(:find).with(request, anything).and_return(found_scenario)
|
51
|
+
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when a request to list the scenarios is received" do
|
58
|
+
|
59
|
+
let(:found_scenarios) { [ HttpStub::Server::ScenarioFixture.create ] }
|
60
|
+
|
61
|
+
subject { get "/http_stub/scenarios" }
|
62
|
+
|
63
|
+
it "retrieves the scenarios via the scenario controller" do
|
64
|
+
expect(scenario_controller).to receive(:find_all).and_return(found_scenarios)
|
65
|
+
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when a request to active scenarios is received" do
|
72
|
+
|
73
|
+
let(:scenario_names) { (1..3).map { |i| "scenario name #{i}" } }
|
74
|
+
let(:activation_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
75
|
+
|
76
|
+
subject { post "/http_stub/scenarios/activate" }
|
77
|
+
|
78
|
+
before(:example) do
|
79
|
+
allow(request).to receive(:parameters).and_return(names: scenario_names)
|
80
|
+
allow(scenario_controller).to receive(:activate).and_return(activation_response)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "activates the scenario via the scenario controller" do
|
84
|
+
expect(scenario_controller).to receive(:activate).with(request, anything).and_return(activation_response)
|
85
|
+
|
86
|
+
subject
|
87
|
+
end
|
88
|
+
|
89
|
+
it "processes the scenario controllers response via the response pipeline" do
|
90
|
+
expect(response_pipeline).to receive(:process).with(activation_response)
|
91
|
+
|
92
|
+
subject
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when a request to clear the scenarios has been received" do
|
98
|
+
|
99
|
+
subject { delete "/http_stub/scenarios" }
|
100
|
+
|
101
|
+
before(:example) { allow(scenario_controller).to receive(:clear) }
|
102
|
+
|
103
|
+
it "delegates clearing to the scenario controller" do
|
104
|
+
expect(scenario_controller).to receive(:clear).with(anything)
|
105
|
+
|
106
|
+
subject
|
107
|
+
end
|
108
|
+
|
109
|
+
it "responds with a 200 status code" do
|
110
|
+
subject
|
111
|
+
|
112
|
+
expect(response.status).to eql(200)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|