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,46 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Session, "when the server is running" do
|
2
|
+
include_context "server integration"
|
3
|
+
|
4
|
+
let(:transactional_session_id) { "http_stub_transactional" }
|
5
|
+
|
6
|
+
let(:response_document) { Nokogiri::HTML(response.body) }
|
7
|
+
|
8
|
+
before(:example) { establish_default_session(transactional_session_id) }
|
9
|
+
|
10
|
+
describe "GET /http_stub" do
|
11
|
+
|
12
|
+
let(:response) { HTTParty.get("#{server_uri}/http_stub") }
|
13
|
+
|
14
|
+
let(:transactional_session_parameter) { "http_stub_session_id=#{transactional_session_id}" }
|
15
|
+
|
16
|
+
it "returns a 200 response code" do
|
17
|
+
expect(response.code).to eql(200)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a response whose body links to the scenarios list for the transactional session" do
|
21
|
+
expect(link_for("scenarios")).to eql("/http_stub/scenarios?#{transactional_session_parameter}")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a response whose body links to the stubs list for the transactional session" do
|
25
|
+
expect(link_for("stubs")).to eql("/http_stub/stubs?#{transactional_session_parameter}")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a response whose body links to the matches list for the transactional session" do
|
29
|
+
expected_matches_link = "/http_stub/stubs/matches?#{transactional_session_parameter}"
|
30
|
+
|
31
|
+
expect(link_for("stub_matches")).to eql(expected_matches_link)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a response whose body links to the misses list for the transactional session" do
|
35
|
+
expected_misses_link = "/http_stub/stubs/misses?#{transactional_session_parameter}"
|
36
|
+
|
37
|
+
expect(link_for("stub_misses")).to eql(expected_misses_link)
|
38
|
+
end
|
39
|
+
|
40
|
+
def link_for(id)
|
41
|
+
response_document.at_css("a##{id}")["href"]
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Session do
|
2
|
+
include_context "http_stub rack application test"
|
3
|
+
|
4
|
+
let(:session_controller) { instance_double(HttpStub::Server::Session::Controller) }
|
5
|
+
|
6
|
+
before(:example) { allow(HttpStub::Server::Session::Controller).to receive(:new).and_return(session_controller) }
|
7
|
+
|
8
|
+
describe "when a request to show the administration landing page is received" do
|
9
|
+
|
10
|
+
subject { get "/http_stub" }
|
11
|
+
|
12
|
+
context "and session support is enabled" do
|
13
|
+
|
14
|
+
include_context "enabled session support"
|
15
|
+
|
16
|
+
let(:found_sessions) { [ HttpStub::Server::SessionFixture.create ] }
|
17
|
+
|
18
|
+
before(:example) { allow(session_controller).to receive(:find_all).and_return(found_sessions) }
|
19
|
+
|
20
|
+
it "responds with a redirect" do
|
21
|
+
subject
|
22
|
+
|
23
|
+
expect(response.status).to eql(302)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "redirects to the page listing all session" do
|
27
|
+
subject
|
28
|
+
|
29
|
+
expect(response.location).to end_with("/http_stub/sessions")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "and session support is disabled" do
|
35
|
+
|
36
|
+
it "responds with a redirect" do
|
37
|
+
subject
|
38
|
+
|
39
|
+
expect(response.status).to eql(302)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "redirects to the transactional session page" do
|
43
|
+
subject
|
44
|
+
|
45
|
+
expect(response.location).to end_with("/http_stub/sessions/transactional")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when a request to list the sessions is received" do
|
53
|
+
include_context "request excludes a session identifier"
|
54
|
+
|
55
|
+
let(:found_sessions) { [ HttpStub::Server::SessionFixture.create ] }
|
56
|
+
|
57
|
+
subject { get "/http_stub/sessions" }
|
58
|
+
|
59
|
+
before(:example) do
|
60
|
+
allow(request).to receive(:session_id).and_return(nil)
|
61
|
+
allow(session_controller).to receive(:find_all).and_return(found_sessions)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "retrieves all sessions via the session controller" do
|
65
|
+
expect(session_controller).to receive(:find_all).and_return(found_sessions)
|
66
|
+
|
67
|
+
subject
|
68
|
+
end
|
69
|
+
|
70
|
+
it "responds with a 200 status code" do
|
71
|
+
subject
|
72
|
+
|
73
|
+
expect(response.status).to eql(200)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "when a request to show a session is received" do
|
79
|
+
include_context "request includes a session identifier"
|
80
|
+
|
81
|
+
let(:found_session) { HttpStub::Server::SessionFixture.create }
|
82
|
+
|
83
|
+
subject { get "/http_stub/sessions" }
|
84
|
+
|
85
|
+
before(:example) { allow(session_controller).to receive(:find).and_return(found_session) }
|
86
|
+
|
87
|
+
it "retrieves the session identified in the request via the stub controller" do
|
88
|
+
expect(session_controller).to receive(:find).with(request, anything).and_return(found_session)
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
it "responds with a 200 status code" do
|
94
|
+
subject
|
95
|
+
|
96
|
+
expect(response.status).to eql(200)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "when a request to show the transactional session is received" do
|
102
|
+
|
103
|
+
let(:transactional_session) { HttpStub::Server::SessionFixture.create }
|
104
|
+
|
105
|
+
subject { get "/http_stub/sessions/transactional" }
|
106
|
+
|
107
|
+
before(:example) { allow(session_controller).to receive(:find_transactional).and_return(transactional_session) }
|
108
|
+
|
109
|
+
it "retrieves the transactional session via the stub controller" do
|
110
|
+
expect(session_controller).to receive(:find_transactional).with(anything).and_return(transactional_session)
|
111
|
+
|
112
|
+
subject
|
113
|
+
end
|
114
|
+
|
115
|
+
it "responds with a 200 status code" do
|
116
|
+
subject
|
117
|
+
|
118
|
+
expect(response.status).to eql(200)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "when a request to mark a session as the default is received" do
|
124
|
+
include_context "request includes a session identifier"
|
125
|
+
|
126
|
+
subject { post "/http_stub/sessions/default" }
|
127
|
+
|
128
|
+
before(:example) { allow(session_controller).to receive(:mark_default) }
|
129
|
+
|
130
|
+
it "retrieves the session identified in the request via the stub controller" do
|
131
|
+
expect(session_controller).to receive(:mark_default).with(request)
|
132
|
+
|
133
|
+
subject
|
134
|
+
end
|
135
|
+
|
136
|
+
it "responds with a 200 status code" do
|
137
|
+
subject
|
138
|
+
|
139
|
+
expect(response.status).to eql(200)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "when a request to delete a session is received" do
|
145
|
+
include_context "request includes a session identifier"
|
146
|
+
|
147
|
+
subject { delete "/http_stub/sessions" }
|
148
|
+
|
149
|
+
before(:example) { allow(session_controller).to receive(:delete) }
|
150
|
+
|
151
|
+
it "deletes the session identified in the request via the stub controller" do
|
152
|
+
expect(session_controller).to receive(:delete).with(request, anything)
|
153
|
+
|
154
|
+
subject
|
155
|
+
end
|
156
|
+
|
157
|
+
it "responds with a 200 status code" do
|
158
|
+
subject
|
159
|
+
|
160
|
+
expect(response.status).to eql(200)
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "when a request to clear the sessions is received" do
|
166
|
+
include_context "request excludes a session identifier"
|
167
|
+
|
168
|
+
subject { delete "/http_stub/sessions" }
|
169
|
+
|
170
|
+
before(:example) { allow(session_controller).to receive(:clear) }
|
171
|
+
|
172
|
+
it "clears the servers sessions via the stub controller" do
|
173
|
+
expect(session_controller).to receive(:clear).with(anything)
|
174
|
+
|
175
|
+
subject
|
176
|
+
end
|
177
|
+
|
178
|
+
it "responds with a 200 status code" do
|
179
|
+
subject
|
180
|
+
|
181
|
+
expect(response.status).to eql(200)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
@@ -1,33 +1,11 @@
|
|
1
|
-
describe HttpStub::Server::Application::
|
1
|
+
describe HttpStub::Server::Application::Routes::Stub, "when the server is running" do
|
2
2
|
include_context "server integration"
|
3
3
|
|
4
|
-
let(:
|
5
|
-
|
6
|
-
describe "GET /http_stub" do
|
7
|
-
|
8
|
-
let(:response) { HTTParty.get("#{server_uri}/http_stub") }
|
9
|
-
|
10
|
-
it "returns a 200 response code" do
|
11
|
-
expect(response.code).to eql(200)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns a response whose body links to the stubs list" do
|
15
|
-
expect(link_for("stubs")).to eql("/http_stub/stubs")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "returns a response whose body links to the scenarios list" do
|
19
|
-
expect(link_for("scenarios")).to eql("/http_stub/scenarios")
|
20
|
-
end
|
4
|
+
let(:transactional_session_id) { "http_stub_transactional" }
|
21
5
|
|
22
|
-
|
23
|
-
expect(link_for("stub_matches")).to eql("/http_stub/stubs/matches")
|
24
|
-
end
|
25
|
-
|
26
|
-
def link_for(id)
|
27
|
-
response_document.at_css("a##{id}")["href"]
|
28
|
-
end
|
6
|
+
let(:response_document) { Nokogiri::HTML(response.body) }
|
29
7
|
|
30
|
-
|
8
|
+
before(:example) { establish_default_session(transactional_session_id) }
|
31
9
|
|
32
10
|
describe "POST /http_stub/stubs" do
|
33
11
|
|
@@ -40,6 +18,8 @@ describe HttpStub::Server::Application::Application, "when the server is running
|
|
40
18
|
)
|
41
19
|
end
|
42
20
|
|
21
|
+
after(:example) { reset_session }
|
22
|
+
|
43
23
|
it "returns a 200 response code" do
|
44
24
|
expect(response.code).to eql(200)
|
45
25
|
end
|
@@ -58,21 +38,17 @@ describe HttpStub::Server::Application::Application, "when the server is running
|
|
58
38
|
end
|
59
39
|
|
60
40
|
describe "and a configurer with multiple scenarios is initialized" do
|
41
|
+
include_context "configurer integration"
|
61
42
|
|
62
|
-
|
63
|
-
configurer = HttpStub::Examples::ConfigurerWithExhaustiveScenarios
|
64
|
-
configurer.stub_server.host = server_host
|
65
|
-
configurer.stub_server.port = server_port
|
66
|
-
configurer.initialize!
|
67
|
-
end
|
43
|
+
let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithExhaustiveScenarios } }
|
68
44
|
|
69
45
|
describe "GET /http_stub/stubs" do
|
70
46
|
|
71
47
|
describe "when multiple stubs are configured" do
|
72
48
|
|
73
|
-
before(:
|
49
|
+
before(:example) do
|
74
50
|
(1..3).each do |i|
|
75
|
-
HTTParty.post("#{server_uri}/http_stub/scenarios/activate", :body => { :
|
51
|
+
HTTParty.post("#{server_uri}/http_stub/scenarios/activate", :body => { name: "Scenario #{i}" })
|
76
52
|
end
|
77
53
|
end
|
78
54
|
|
@@ -219,6 +195,8 @@ describe HttpStub::Server::Application::Application, "when the server is running
|
|
219
195
|
|
220
196
|
let(:response) { HTTParty.get("#{server_uri}/http_stub/scenarios") }
|
221
197
|
|
198
|
+
let(:transactional_session_parameter) { "http_stub_session_id=#{transactional_session_id}" }
|
199
|
+
|
222
200
|
it "returns a response whose body contains the name of each scenario in alphabetical order" do
|
223
201
|
expected_scenario_names = [ "Nested scenario", "Scenario" ].map do |scenario_name_prefix|
|
224
202
|
(1..3).map { |i| "#{scenario_name_prefix} #{i}" }
|
@@ -229,17 +207,17 @@ describe HttpStub::Server::Application::Application, "when the server is running
|
|
229
207
|
expect(scenario_names).to eql(expected_scenario_names)
|
230
208
|
end
|
231
209
|
|
232
|
-
it "returns a response whose body contains links to activate each scenario" do
|
233
|
-
expected_activation_links = [ "/http_stub/scenarios/activate" ] * 6
|
210
|
+
it "returns a response whose body contains links to activate each scenario in the transactional session" do
|
211
|
+
expected_activation_links = [ "/http_stub/scenarios/activate?#{transactional_session_parameter}" ] * 6
|
234
212
|
|
235
213
|
activation_links = response_document.css("a.activate_scenario").map { |link| link["href"] }
|
236
214
|
|
237
215
|
expect(activation_links).to eql(expected_activation_links)
|
238
216
|
end
|
239
217
|
|
240
|
-
it "returns a response whose body contains links to the details of each scenario" do
|
218
|
+
it "returns a response whose body contains links to the details of each scenario for the default session" do
|
241
219
|
expected_detail_links = %w{ Nested+scenario Scenario }.map do |scenario_name_prefix|
|
242
|
-
(1..3).map { |i| "/http_stub/scenarios?name=#{scenario_name_prefix}+#{i}" }
|
220
|
+
(1..3).map { |i| "/http_stub/scenarios?name=#{scenario_name_prefix}+#{i}&#{transactional_session_parameter}" }
|
243
221
|
end.flatten
|
244
222
|
|
245
223
|
detail_links = response_document.css("a.view_scenario").map { |link| link["href"] }
|
@@ -0,0 +1,202 @@
|
|
1
|
+
describe HttpStub::Server::Application::Routes::Stub do
|
2
|
+
include_context "http_stub rack application test"
|
3
|
+
|
4
|
+
let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller) }
|
5
|
+
let(:stub_match_controller) { instance_double(HttpStub::Server::Stub::Match::Controller) }
|
6
|
+
|
7
|
+
before(:example) do
|
8
|
+
allow(HttpStub::Server::Stub::Controller).to receive(:new).and_return(stub_controller)
|
9
|
+
allow(HttpStub::Server::Stub::Match::Controller).to receive(:new).and_return(stub_match_controller)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "when a stub registration request within a session is received" do
|
13
|
+
include_context "request includes a session identifier"
|
14
|
+
|
15
|
+
let(:payload) { { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } }.to_json }
|
16
|
+
|
17
|
+
let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
18
|
+
|
19
|
+
subject { post "/http_stub/stubs" }
|
20
|
+
|
21
|
+
before(:example) do
|
22
|
+
allow(request).to receive(:body).and_return(payload)
|
23
|
+
allow(stub_controller).to receive(:register).and_return(registration_response)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "registers the stub via the stub controller" do
|
27
|
+
expect(stub_controller).to receive(:register).and_return(registration_response)
|
28
|
+
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
|
32
|
+
it "processes the stub 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
|
+
describe "when a request to list the stubs in a session is received" do
|
41
|
+
include_context "request includes a session identifier"
|
42
|
+
|
43
|
+
let(:found_stubs) { [ HttpStub::Server::Stub::Empty::INSTANCE ] }
|
44
|
+
|
45
|
+
subject { get "/http_stub/stubs" }
|
46
|
+
|
47
|
+
it "retrieves the stubs for the current user via the stub controller" do
|
48
|
+
expect(stub_controller).to receive(:find_all).with(request).and_return(found_stubs)
|
49
|
+
|
50
|
+
subject
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "when a request to show a stub in a session is received" do
|
56
|
+
include_context "request includes a session identifier"
|
57
|
+
|
58
|
+
let(:stub_id) { SecureRandom.uuid }
|
59
|
+
|
60
|
+
let(:found_stub) { HttpStub::Server::Stub::Empty::INSTANCE }
|
61
|
+
|
62
|
+
subject { get "/http_stub/stubs/#{stub_id}" }
|
63
|
+
|
64
|
+
before(:example) { allow(stub_controller).to receive(:find).and_return(found_stub) }
|
65
|
+
|
66
|
+
it "retrieves the stub for the current user via the stub controller" do
|
67
|
+
expect(stub_controller).to receive(:find).with(request, anything).and_return(found_stub)
|
68
|
+
|
69
|
+
subject
|
70
|
+
end
|
71
|
+
|
72
|
+
it "responds with a 200 status code" do
|
73
|
+
subject
|
74
|
+
|
75
|
+
expect(response.status).to eql(200)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "when a request to reset the stubs in a session is received" do
|
81
|
+
include_context "request includes a session identifier"
|
82
|
+
|
83
|
+
subject { post "/http_stub/stubs/reset" }
|
84
|
+
|
85
|
+
before(:example) { allow(stub_controller).to receive(:reset) }
|
86
|
+
|
87
|
+
it "resets the stubs in the session via the stub controller" do
|
88
|
+
expect(stub_controller).to receive(:reset).with(request, anything)
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
it "responds with a 200 status code" do
|
94
|
+
subject
|
95
|
+
|
96
|
+
expect(response.status).to eql(200)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "when a request to clear the stubs in a session is received" do
|
102
|
+
include_context "request includes a session identifier"
|
103
|
+
|
104
|
+
subject { delete "/http_stub/stubs" }
|
105
|
+
|
106
|
+
before(:example) { allow(stub_controller).to receive(:clear) }
|
107
|
+
|
108
|
+
it "clears the stubs for the current user via the stub controller" do
|
109
|
+
expect(stub_controller).to receive(:clear).with(request, anything)
|
110
|
+
|
111
|
+
subject
|
112
|
+
end
|
113
|
+
|
114
|
+
it "responds with a 200 status code" do
|
115
|
+
subject
|
116
|
+
|
117
|
+
expect(response.status).to eql(200)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "when a request to list the stub matches in a session is received" do
|
123
|
+
include_context "request includes a session identifier"
|
124
|
+
|
125
|
+
let(:found_matches) { [ HttpStub::Server::Stub::Match::MatchFixture.create ] }
|
126
|
+
|
127
|
+
subject { get "/http_stub/stubs/matches" }
|
128
|
+
|
129
|
+
it "retrieves the matches for the current user via the stub match controller" do
|
130
|
+
expect(stub_match_controller).to receive(:matches).with(request).and_return(found_matches)
|
131
|
+
|
132
|
+
subject
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "when a request to retrieve the last match for an endpoint in a session is received" do
|
138
|
+
include_context "request includes a session identifier"
|
139
|
+
|
140
|
+
let(:uri) { "/some/matched/uri" }
|
141
|
+
let(:method) { "some http method" }
|
142
|
+
let(:last_match_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
143
|
+
|
144
|
+
subject { get "/http_stub/stubs/matches/last" }
|
145
|
+
|
146
|
+
before(:example) do
|
147
|
+
allow(request).to receive(:parameters).and_return(uri: uri, method: method)
|
148
|
+
allow(stub_match_controller).to receive(:last_match).and_return(last_match_response)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "retrieves the last match for the user via the match result controller" do
|
152
|
+
expect(stub_match_controller).to receive(:last_match).with(request, anything)
|
153
|
+
|
154
|
+
subject
|
155
|
+
end
|
156
|
+
|
157
|
+
it "processes the match result controllers response via the response pipeline" do
|
158
|
+
expect(response_pipeline).to receive(:process).with(last_match_response)
|
159
|
+
|
160
|
+
subject
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "when a request to list the stub misses in a session is received" do
|
166
|
+
include_context "request includes a session identifier"
|
167
|
+
|
168
|
+
let(:found_misses) { [ HttpStub::Server::Stub::Match::MissFixture.create ] }
|
169
|
+
|
170
|
+
subject { get "/http_stub/stubs/misses" }
|
171
|
+
|
172
|
+
it "retrieves the misses for the current user via the stub match controller" do
|
173
|
+
expect(stub_match_controller).to receive(:misses).with(request).and_return(found_misses)
|
174
|
+
|
175
|
+
subject
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "when any other request is received" do
|
181
|
+
|
182
|
+
let(:stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
183
|
+
|
184
|
+
subject { get "/some_path" }
|
185
|
+
|
186
|
+
before(:example) { allow(stub_controller).to receive(:match).and_return(stub_response) }
|
187
|
+
|
188
|
+
it "attempts to match the request to a stub response via the stub controller" do
|
189
|
+
expect(stub_controller).to receive(:match).with(request, anything)
|
190
|
+
|
191
|
+
subject
|
192
|
+
end
|
193
|
+
|
194
|
+
it "processes the response via the response pipeline" do
|
195
|
+
expect(response_pipeline).to receive(:process).with(stub_response)
|
196
|
+
|
197
|
+
subject
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|