http_stub 0.26.0 → 0.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +11 -9
  3. data/lib/http_stub/configurer/dsl/server.rb +3 -10
  4. data/lib/http_stub/configurer/dsl/session.rb +0 -4
  5. data/lib/http_stub/configurer/server/facade.rb +8 -4
  6. data/lib/http_stub/configurer/server/session_facade.rb +0 -7
  7. data/lib/http_stub/server/application/application.rb +2 -1
  8. data/lib/http_stub/server/application/routes/session.rb +0 -5
  9. data/lib/http_stub/server/application/routes/status.rb +37 -0
  10. data/lib/http_stub/server/daemon.rb +3 -3
  11. data/lib/http_stub/server/memory/memory.rb +11 -2
  12. data/lib/http_stub/server/session/controller.rb +0 -4
  13. data/lib/http_stub/server/status/controller.rb +25 -0
  14. data/lib/http_stub/version.rb +1 -1
  15. data/spec/acceptance/configurer_initialization_spec.rb +12 -2
  16. data/spec/acceptance/server_status_spec.rb +37 -0
  17. data/spec/acceptance/stub_miss_list_spec.rb +8 -1
  18. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +4 -22
  19. data/spec/lib/http_stub/configurer/dsl/session_spec.rb +0 -12
  20. data/spec/lib/http_stub/configurer/server/facade_spec.rb +36 -8
  21. data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +0 -51
  22. data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +2 -4
  23. data/spec/lib/http_stub/server/application/routes/session_spec.rb +0 -21
  24. data/spec/lib/http_stub/server/application/routes/status_spec.rb +56 -0
  25. data/spec/lib/http_stub/server/application/routes/stub_integration_spec.rb +2 -4
  26. data/spec/lib/http_stub/server/memory/memory_spec.rb +32 -0
  27. data/spec/lib/http_stub/server/session/controller_spec.rb +0 -12
  28. data/spec/lib/http_stub/server/status/controller_spec.rb +47 -0
  29. data/spec/support/http_stub/server/driver.rb +4 -5
  30. data/spec/support/http_stub/server_integration.rb +9 -4
  31. metadata +527 -519
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 347738836829271815cece8a214373ba88eca832
4
- data.tar.gz: de16a1c9ac5fc32864414c97b320a9564c681df2
3
+ metadata.gz: d74076fbfbad5830130f7c27707249d65108d40f
4
+ data.tar.gz: 749c5d0060cb935728a3dda7d520807d1b2a2d2a
5
5
  SHA512:
6
- metadata.gz: 7bb9b5a27d2528112e775a175bc4827365a81d268acafc283ae6b20b19ae4d9ee677e88e194565519e062dbcc39511a4bdac316be86e734587c205b8d8467829
7
- data.tar.gz: 0554a3a709aa560bb30690d4b9fdc1235cc5e78409068ad97e9a0aa6255bd966bf793401c4f048bce4d76072e735ec78b6b7ba3bbe88a40ce0ab49825500640b
6
+ metadata.gz: 51991b22a7a48eee4c0c52eb897f16fbd5ca4dc44b7ebba32fbf4ff8774bfa32fbe2100718b3820b93a2a037beb6090549bca1c08bf638cb3623d319f7d76d34
7
+ data.tar.gz: 7015ac70615f0b0478c4042313ddb9a16a0d57e7475edbfb071bad2b7d86bd13ba0068f22bd74d4e76548d9ba3d46fb5b72baadeb9ddd539080598511b3fba2a
@@ -30,6 +30,7 @@ require_relative 'http_stub/server/request/sinatra_request'
30
30
  require_relative 'http_stub/server/request/request'
31
31
  require_relative 'http_stub/server/request/factory'
32
32
  require_relative 'http_stub/server/registry'
33
+ require_relative 'http_stub/server/status/controller'
33
34
  require_relative 'http_stub/server/stub/match/omitted_value_matcher'
34
35
  require_relative 'http_stub/server/stub/match/regexp_value_matcher'
35
36
  require_relative 'http_stub/server/stub/match/exact_value_matcher'
@@ -67,13 +68,6 @@ require_relative 'http_stub/server/stub/match/controller'
67
68
  require_relative 'http_stub/server/stub/registry'
68
69
  require_relative 'http_stub/server/stub/controller'
69
70
  require_relative 'http_stub/server/stub'
70
- require_relative 'http_stub/server/scenario/links'
71
- require_relative 'http_stub/server/scenario/trigger'
72
- require_relative 'http_stub/server/scenario/parser'
73
- require_relative 'http_stub/server/scenario/not_found_error'
74
- require_relative 'http_stub/server/scenario/scenario'
75
- require_relative 'http_stub/server/scenario/controller'
76
- require_relative 'http_stub/server/scenario'
77
71
  require_relative 'http_stub/server/session'
78
72
  require_relative 'http_stub/server/session/configuration'
79
73
  require_relative 'http_stub/server/session/identifier_strategy'
@@ -81,6 +75,13 @@ require_relative 'http_stub/server/session/empty'
81
75
  require_relative 'http_stub/server/session/session'
82
76
  require_relative 'http_stub/server/session/registry'
83
77
  require_relative 'http_stub/server/session/controller'
78
+ require_relative 'http_stub/server/scenario/links'
79
+ require_relative 'http_stub/server/scenario/trigger'
80
+ require_relative 'http_stub/server/scenario/parser'
81
+ require_relative 'http_stub/server/scenario/not_found_error'
82
+ require_relative 'http_stub/server/scenario/scenario'
83
+ require_relative 'http_stub/server/scenario/controller'
84
+ require_relative 'http_stub/server/scenario'
84
85
  require_relative 'http_stub/server/memory/memory'
85
86
  require_relative 'http_stub/server/memory/controller'
86
87
  require_relative 'http_stub/server/application/configuration'
@@ -90,11 +91,12 @@ require_relative 'http_stub/server/application/cross_origin_support'
90
91
  require_relative 'http_stub/server/application/session_uri_support'
91
92
  require_relative 'http_stub/server/application/text_formatting_support'
92
93
  require_relative 'http_stub/server/application/response_pipeline'
93
- require_relative 'http_stub/server/application/routes/memory'
94
94
  require_relative 'http_stub/server/application/routes/resource'
95
+ require_relative 'http_stub/server/application/routes/status'
96
+ require_relative 'http_stub/server/application/routes/stub'
95
97
  require_relative 'http_stub/server/application/routes/session'
96
98
  require_relative 'http_stub/server/application/routes/scenario'
97
- require_relative 'http_stub/server/application/routes/stub'
99
+ require_relative 'http_stub/server/application/routes/memory'
98
100
  require_relative 'http_stub/server/application/application'
99
101
  require_relative 'http_stub/server/daemon'
100
102
  require_relative 'http_stub/configurer/request/http/basic'
@@ -28,13 +28,13 @@ module HttpStub
28
28
  end
29
29
 
30
30
  def initialize!
31
- @server_facade.flush_requests
32
- switch_to_transactional_session
31
+ @server_facade.initialize_server
32
+ @default_session = @session_factory.transactional
33
33
  end
34
34
 
35
35
  def has_started!
36
36
  @server_facade.server_has_started
37
- switch_to_transactional_session
37
+ @default_session = @session_factory.transactional
38
38
  end
39
39
 
40
40
  def reset!
@@ -73,13 +73,6 @@ module HttpStub
73
73
  @default_session.clear!
74
74
  end
75
75
 
76
- private
77
-
78
- def switch_to_transactional_session
79
- @session_factory.transactional.mark_as_default!
80
- @default_session = @session_factory.transactional
81
- end
82
-
83
76
  end
84
77
 
85
78
  end
@@ -15,10 +15,6 @@ module HttpStub
15
15
  @default_stub_template = default_stub_template
16
16
  end
17
17
 
18
- def mark_as_default!
19
- @session_facade.mark_as_default
20
- end
21
-
22
18
  def endpoint_template(&block)
23
19
  HttpStub::Configurer::DSL::SessionEndpointTemplate.new(self, @default_stub_template, &block)
24
20
  end
@@ -10,12 +10,16 @@ module HttpStub
10
10
  @request_processor = HttpStub::Configurer::Server::RequestProcessor.new(configuration)
11
11
  end
12
12
 
13
- def server_has_started
14
- @request_processor.disable_buffering!
13
+ def initialize_server
14
+ @request_processor.flush!
15
+ @request_processor.submit(
16
+ request: HttpStub::Configurer::Request::Http::Factory.post("status/initialized"),
17
+ description: "marking server as initialized"
18
+ )
15
19
  end
16
20
 
17
- def flush_requests
18
- @request_processor.flush!
21
+ def server_has_started
22
+ @request_processor.disable_buffering!
19
23
  end
20
24
 
21
25
  def reset
@@ -14,13 +14,6 @@ module HttpStub
14
14
  @session_description = "session '#{session_id}'"
15
15
  end
16
16
 
17
- def mark_as_default
18
- @request_processor.submit(
19
- request: REQUEST_FACTORY.post("sessions/default", http_stub_session_id: @session_id),
20
- description: "marking #{@session_description} as the default"
21
- )
22
- end
23
-
24
17
  def stub_response(stub)
25
18
  @request_processor.submit(
26
19
  request: REQUEST_FACTORY.multipart("stubs", stub, http_stub_session_id: @session_id),
@@ -30,8 +30,9 @@ module HttpStub
30
30
 
31
31
  register HttpStub::Server::Application::CrossOriginSupport
32
32
 
33
- include HttpStub::Server::Application::Routes::Memory
34
33
  include HttpStub::Server::Application::Routes::Resource
34
+ include HttpStub::Server::Application::Routes::Status
35
+ include HttpStub::Server::Application::Routes::Memory
35
36
  include HttpStub::Server::Application::Routes::Scenario
36
37
  include HttpStub::Server::Application::Routes::Session
37
38
  include HttpStub::Server::Application::Routes::Stub
@@ -34,11 +34,6 @@ module HttpStub
34
34
  haml :sessions, {}, sessions: @session_controller.find_all
35
35
  end
36
36
 
37
- post "/default" do
38
- @session_controller.mark_default(http_stub_request)
39
- halt 200, "OK"
40
- end
41
-
42
37
  delete do
43
38
  pass unless http_stub_request.session_id
44
39
  @session_controller.delete(http_stub_request, logger)
@@ -0,0 +1,37 @@
1
+ module HttpStub
2
+ module Server
3
+ module Application
4
+ module Routes
5
+
6
+ module Status
7
+
8
+ def initialize
9
+ super()
10
+ @status_controller = HttpStub::Server::Status::Controller.new(@session_configuration, @server_memory)
11
+ end
12
+
13
+ def self.included(application)
14
+ application.instance_eval do
15
+
16
+ namespace "/http_stub/status" do
17
+
18
+ get do
19
+ halt 200, @status_controller.current
20
+ end
21
+
22
+ post "/initialized" do
23
+ @status_controller.initialized
24
+ halt 200, "OK"
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -16,9 +16,9 @@ module HttpStub
16
16
  end
17
17
 
18
18
  def initialize(args)
19
- @configurer = args[:configurer]
20
- default_args = { host: "localhost" }
21
- default_args = { host: @configurer.stub_server.host, port: @configurer.stub_server.port } if @configurer
19
+ @configurer = args[:configurer]
20
+ default_args = { host: "localhost", ping_uri: "/http_stub/status" }
21
+ default_args.merge!(host: @configurer.stub_server.host, port: @configurer.stub_server.port) if @configurer
22
22
  super(default_args.merge(args))
23
23
  end
24
24
 
@@ -4,18 +4,26 @@ module HttpStub
4
4
 
5
5
  class Memory
6
6
 
7
+ DEFAULT_STATUS = "Started".freeze
8
+ INITIALIZED_STATUS = "Initialized".freeze
9
+
7
10
  SESSION_ID = HttpStub::Server::Session::MEMORY_SESSION_ID
8
11
 
9
- private_constant :SESSION_ID
12
+ private_constant :DEFAULT_STATUS, :INITIALIZED_STATUS, :SESSION_ID
10
13
 
11
- attr_reader :scenarios, :sessions
14
+ attr_reader :status, :scenarios, :sessions
12
15
 
13
16
  def initialize(session_configuration)
17
+ @status = DEFAULT_STATUS
14
18
  @scenarios = HttpStub::Server::Registry.new("scenario")
15
19
  @session = HttpStub::Server::Session::Session.new(SESSION_ID, @scenarios, HttpStub::Server::Session::Empty)
16
20
  @sessions = HttpStub::Server::Session::Registry.new(session_configuration, @scenarios, @session)
17
21
  end
18
22
 
23
+ def initialized!
24
+ @status = INITIALIZED_STATUS
25
+ end
26
+
19
27
  def stubs
20
28
  @session.stubs
21
29
  end
@@ -23,6 +31,7 @@ module HttpStub
23
31
  def reset(logger)
24
32
  @scenarios.clear(logger)
25
33
  @sessions.clear(logger)
34
+ @status = DEFAULT_STATUS
26
35
  end
27
36
 
28
37
  end
@@ -21,10 +21,6 @@ module HttpStub
21
21
  @server_memory.sessions.all
22
22
  end
23
23
 
24
- def mark_default(request)
25
- @session_configuration.default_identifier = request.session_id
26
- end
27
-
28
24
  def delete(request, logger)
29
25
  @server_memory.sessions.delete(request.session_id, logger)
30
26
  end
@@ -0,0 +1,25 @@
1
+ module HttpStub
2
+ module Server
3
+ module Status
4
+
5
+ class Controller
6
+
7
+ def initialize(session_configuration, server_memory)
8
+ @session_configuration = session_configuration
9
+ @server_memory = server_memory
10
+ end
11
+
12
+ def current
13
+ @server_memory.status
14
+ end
15
+
16
+ def initialized
17
+ @server_memory.initialized!
18
+ @session_configuration.default_identifier = HttpStub::Server::Session::TRANSACTIONAL_SESSION_ID
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.26.0".freeze
2
+ VERSION = "0.26.1".freeze
3
3
  end
@@ -105,13 +105,23 @@ describe "Configurer initialization acceptance" do
105
105
  end
106
106
  end
107
107
 
108
- it "registers the stub" do
109
- response = HTTParty.get("#{server_uri}/some_stub_path")
108
+ it "registers the stub in the servers transactional session" do
109
+ response = HTTParty.get("#{server_uri}/some_stub_path", request_session_id_header("http_stub_transactional"))
110
110
 
111
111
  expect(response.code).to eql(200)
112
112
  expect(response.body).to eql("Some stub body")
113
113
  end
114
114
 
115
+ it "does not register the stub in the servers memory session" do
116
+ response = HTTParty.get("#{server_uri}/some_stub_path", request_session_id_header("http_stub_memory"))
117
+
118
+ expect(response.code).to eql(404)
119
+ end
120
+
121
+ end
122
+
123
+ def request_session_id_header(session_id)
124
+ { headers: { "http_stub_session_id" => session_id } }
115
125
  end
116
126
 
117
127
  end
@@ -0,0 +1,37 @@
1
+ describe "Server status acceptance" do
2
+
3
+ describe "GET /http_stub/status" do
4
+
5
+ let(:response) { HTTParty.get("#{server_uri}/http_stub/status") }
6
+
7
+ context "when a server is started without a configurer" do
8
+ include_context "server integration"
9
+
10
+ it "indicates the server has started" do
11
+ expect(response.body).to eql("Started")
12
+ end
13
+
14
+ context "and the server is updated to reflect it is initialized" do
15
+
16
+ before(:example) { HTTParty.post("#{server_uri}/http_stub/status/initialized") }
17
+
18
+ it "indicates the server has been initialized" do
19
+ expect(response.body).to eql("Initialized")
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ context "when a server with a configurer is started" do
27
+ include_context "configurer integration"
28
+
29
+ it "indicates the server has been initialized" do
30
+ expect(response.body).to eql("Initialized")
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -8,6 +8,14 @@ describe "Stub miss list acceptance" do
8
8
 
9
9
  before(:example) { configure_stub_registrator }
10
10
 
11
+ context "when no miss has been registered" do
12
+
13
+ it "returns a response with an empty request list" do
14
+ expect(response.body).to_not include("Request")
15
+ end
16
+
17
+ end
18
+
11
19
  context "when a request has been made that does not match a stub" do
12
20
 
13
21
  before(:example) { stub_registrator.issue_matching_request }
@@ -32,7 +40,6 @@ describe "Stub miss list acceptance" do
32
40
 
33
41
  before(:example) { stub_registrator.register_stub }
34
42
 
35
-
36
43
  include_context "HTML view excluding request details"
37
44
 
38
45
  end
@@ -233,19 +233,10 @@ describe HttpStub::Configurer::DSL::Server do
233
233
 
234
234
  subject { server.initialize! }
235
235
 
236
- before(:example) do
237
- allow(server_facade).to receive(:flush_requests)
238
- allow(transactional_session).to receive(:mark_as_default!)
239
- end
240
-
241
- it "flushes requests held by the server facade" do
242
- expect(server_facade).to receive(:flush_requests)
243
-
244
- subject
245
- end
236
+ before(:example) { allow(server_facade).to receive(:initialize_server) }
246
237
 
247
- it "marks the transactional session as the servers default" do
248
- expect(transactional_session).to receive(:mark_as_default!)
238
+ it "initializes the server via the facade" do
239
+ expect(server_facade).to receive(:initialize_server)
249
240
 
250
241
  subject
251
242
  end
@@ -263,10 +254,7 @@ describe HttpStub::Configurer::DSL::Server do
263
254
 
264
255
  subject { server.has_started! }
265
256
 
266
- before(:example) do
267
- allow(server_facade).to receive(:server_has_started)
268
- allow(transactional_session).to receive(:mark_as_default!)
269
- end
257
+ before(:example) { allow(server_facade).to receive(:server_has_started) }
270
258
 
271
259
  it "informs the facade that the server has started" do
272
260
  expect(server_facade).to receive(:server_has_started)
@@ -274,12 +262,6 @@ describe HttpStub::Configurer::DSL::Server do
274
262
  subject
275
263
  end
276
264
 
277
- it "marks the transactional session as the servers default" do
278
- expect(transactional_session).to receive(:mark_as_default!)
279
-
280
- subject
281
- end
282
-
283
265
  it "causes subsequent session operations to be performed against the transactional session" do
284
266
  subject
285
267
  expect(transactional_session).to receive(:activate!)
@@ -17,18 +17,6 @@ describe HttpStub::Configurer::DSL::Session do
17
17
  session
18
18
  end
19
19
 
20
- describe "#mark_as_default!" do
21
-
22
- subject { session.mark_as_default! }
23
-
24
- it "marks the session as the servers default via the session facade" do
25
- expect(session_facade).to receive(:mark_as_default)
26
-
27
- subject
28
- end
29
-
30
- end
31
-
32
20
  describe "#endpoint_template" do
33
21
 
34
22
  let(:block) { lambda { block_verifier.verify } }