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.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +32 -9
  3. data/lib/http_stub/configurer.rb +2 -10
  4. data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
  5. data/lib/http_stub/configurer/dsl/server.rb +32 -43
  6. data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
  7. data/lib/http_stub/configurer/dsl/session.rb +55 -0
  8. data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
  9. data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
  10. data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
  11. data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
  12. data/lib/http_stub/configurer/request/http/basic.rb +9 -3
  13. data/lib/http_stub/configurer/request/http/factory.rb +7 -16
  14. data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
  15. data/lib/http_stub/configurer/request/stub.rb +3 -3
  16. data/lib/http_stub/configurer/request/triggers.rb +25 -0
  17. data/lib/http_stub/configurer/server/command_processor.rb +8 -10
  18. data/lib/http_stub/configurer/server/configuration.rb +33 -0
  19. data/lib/http_stub/configurer/server/facade.rb +21 -43
  20. data/lib/http_stub/configurer/server/request_processor.rb +2 -2
  21. data/lib/http_stub/configurer/server/session_facade.rb +64 -0
  22. data/lib/http_stub/extensions/core/uri.rb +28 -0
  23. data/lib/http_stub/extensions/rack/handler.rb +1 -0
  24. data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
  25. data/lib/http_stub/rake/server_tasks.rb +1 -4
  26. data/lib/http_stub/server/application/application.rb +17 -98
  27. data/lib/http_stub/server/application/configuration.rb +38 -0
  28. data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
  29. data/lib/http_stub/server/application/request_support.rb +38 -0
  30. data/lib/http_stub/server/application/response_support.rb +19 -0
  31. data/lib/http_stub/server/application/routes/memory.rb +37 -0
  32. data/lib/http_stub/server/application/routes/resource.rb +23 -0
  33. data/lib/http_stub/server/application/routes/scenario.rb +52 -0
  34. data/lib/http_stub/server/application/routes/session.rb +65 -0
  35. data/lib/http_stub/server/application/routes/stub.rb +75 -0
  36. data/lib/http_stub/server/application/session_uri_support.rb +15 -0
  37. data/lib/http_stub/server/memory/controller.rb +25 -0
  38. data/lib/http_stub/server/memory/memory.rb +32 -0
  39. data/lib/http_stub/server/registry.rb +25 -8
  40. data/lib/http_stub/server/request/factory.rb +23 -0
  41. data/lib/http_stub/server/request/parameters.rb +2 -2
  42. data/lib/http_stub/server/request/request.rb +6 -11
  43. data/lib/http_stub/server/request/sinatra_request.rb +26 -0
  44. data/lib/http_stub/server/scenario/controller.rb +16 -11
  45. data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
  46. data/lib/http_stub/server/session.rb +14 -0
  47. data/lib/http_stub/server/session/configuration.rb +32 -0
  48. data/lib/http_stub/server/session/controller.rb +40 -0
  49. data/lib/http_stub/server/session/empty.rb +15 -0
  50. data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
  51. data/lib/http_stub/server/session/registry.rb +38 -0
  52. data/lib/http_stub/server/session/session.rb +80 -0
  53. data/lib/http_stub/server/stub/controller.rb +18 -12
  54. data/lib/http_stub/server/stub/empty.rb +1 -1
  55. data/lib/http_stub/server/stub/match/controller.rb +9 -5
  56. data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
  57. data/lib/http_stub/server/stub/registry.rb +6 -13
  58. data/lib/http_stub/server/stub/triggers.rb +11 -9
  59. data/lib/http_stub/server/views/_home.haml +2 -0
  60. data/lib/http_stub/server/views/_post_link_function.haml +26 -0
  61. data/lib/http_stub/server/views/_session.haml +16 -0
  62. data/lib/http_stub/server/views/_stub.haml +8 -2
  63. data/lib/http_stub/server/views/_stubs.haml +4 -0
  64. data/lib/http_stub/server/views/application.sass +4 -1
  65. data/lib/http_stub/server/views/layout.haml +1 -0
  66. data/lib/http_stub/server/views/scenario.haml +4 -3
  67. data/lib/http_stub/server/views/scenarios.haml +7 -6
  68. data/lib/http_stub/server/views/session.haml +3 -0
  69. data/lib/http_stub/server/views/sessions.haml +6 -0
  70. data/lib/http_stub/server/views/stubs.haml +1 -4
  71. data/lib/http_stub/server/views/transactional_session.haml +2 -0
  72. data/lib/http_stub/version.rb +1 -1
  73. data/spec/acceptance/configurer_initialization_spec.rb +40 -51
  74. data/spec/acceptance/configurer_part_spec.rb +5 -7
  75. data/spec/acceptance/cross_origin_support_spec.rb +7 -13
  76. data/spec/acceptance/endpoint_template_spec.rb +2 -4
  77. data/spec/acceptance/request_reference_spec.rb +1 -3
  78. data/spec/acceptance/scenario_spec.rb +7 -9
  79. data/spec/acceptance/server_defaults_spec.rb +2 -4
  80. data/spec/acceptance/server_memory_spec.rb +20 -0
  81. data/spec/acceptance/session_spec.rb +125 -0
  82. data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
  83. data/spec/acceptance/stub_control_values_spec.rb +19 -18
  84. data/spec/acceptance/stub_match_last_spec.rb +0 -4
  85. data/spec/acceptance/stub_match_list_spec.rb +0 -4
  86. data/spec/acceptance/stub_miss_list_spec.rb +0 -4
  87. data/spec/acceptance/stub_spec.rb +11 -11
  88. data/spec/acceptance/stub_trigger_spec.rb +60 -13
  89. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
  90. data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
  91. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
  92. data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
  93. data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
  94. data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
  95. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
  96. data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
  97. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
  98. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
  99. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
  100. data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
  101. data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
  102. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
  103. data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
  104. data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
  105. data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
  106. data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
  107. data/spec/lib/http_stub/configurer_spec.rb +105 -0
  108. data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
  109. data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
  110. data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
  111. data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
  112. data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
  113. data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
  114. data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
  115. data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
  116. data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
  117. data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
  118. data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
  119. data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
  120. data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
  121. data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
  122. data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
  123. data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
  124. data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
  125. data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
  126. data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
  127. data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
  128. data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
  129. data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
  130. data/spec/lib/http_stub/server/registry_spec.rb +153 -34
  131. data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
  132. data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
  133. data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
  134. data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
  135. data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
  136. data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
  137. data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
  138. data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
  139. data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
  140. data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
  141. data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
  142. data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
  143. data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
  144. data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
  145. data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
  146. data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
  147. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
  148. data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
  149. data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
  150. data/spec/spec_helper.rb +13 -1
  151. data/spec/support/contain_file.rb +23 -0
  152. data/spec/support/cross_origin_server/application.rb +1 -1
  153. data/spec/support/cross_origin_server/index_page.rb +2 -2
  154. data/spec/support/cross_origin_server/integration.rb +3 -2
  155. data/spec/support/cross_origin_server/public/index.html +2 -1
  156. data/spec/support/http_stub/configurer_integration.rb +12 -14
  157. data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
  158. data/spec/support/http_stub/server/driver.rb +56 -0
  159. data/spec/support/http_stub/server/memory_fixture.rb +17 -0
  160. data/spec/support/http_stub/server/request_fixture.rb +7 -6
  161. data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
  162. data/spec/support/http_stub/server/session_fixture.rb +27 -0
  163. data/spec/support/http_stub/server_integration.rb +12 -17
  164. data/spec/support/http_stub/stub_fixture.rb +19 -6
  165. data/spec/support/include_in_json.rb +4 -4
  166. data/spec/support/rack/rack_application_test.rb +9 -0
  167. data/spec/support/rack/request_fixture.rb +13 -0
  168. data/spec/support/surpressed_output.rb +10 -0
  169. metadata +149 -36
  170. data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
  171. data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
  172. data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
  173. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
  174. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
  175. data/lib/http_stub/server/request.rb +0 -12
  176. data/lib/http_stub/server/scenario/activator.rb +0 -25
  177. data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
  178. data/lib/http_stub/server/views/index.haml +0 -8
  179. data/spec/acceptance/activator_spec.rb +0 -81
  180. data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
  181. data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
  182. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
  183. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
  184. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
  185. data/spec/lib/http_stub/server/request_spec.rb +0 -24
  186. data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
  187. data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
data/spec/spec_helper.rb CHANGED
@@ -34,15 +34,23 @@ module HttpStub
34
34
  end
35
35
 
36
36
  require_relative 'support/include_in_json'
37
+ require_relative 'support/contain_file'
38
+ require_relative 'support/surpressed_output'
39
+ require_relative 'support/rack/request_fixture'
40
+ require_relative 'support/rack/rack_application_test'
37
41
  require_relative 'support/cross_origin_server/integration'
38
42
  require_relative 'support/cross_origin_server/index_page'
39
43
  require_relative 'support/http_stub/server/request_fixture'
40
- require_relative 'support/http_stub/server/scenario/scenario_fixture'
44
+ require_relative 'support/http_stub/server/session_fixture'
45
+ require_relative 'support/http_stub/server/scenario_fixture'
46
+ require_relative 'support/http_stub/server/memory_fixture'
41
47
  require_relative 'support/http_stub/server/stub/match/match_fixture'
42
48
  require_relative 'support/http_stub/server/stub/match/miss_fixture'
43
49
  require_relative 'support/http_stub/stub_fixture'
44
50
  require_relative 'support/http_stub/scenario_fixture'
51
+ require_relative 'support/http_stub/server/application/http_stub_rack_application_test'
45
52
  require_relative 'support/http_stub/empty_configurer'
53
+ require_relative 'support/http_stub/server/driver'
46
54
  require_relative 'support/http_stub/server_integration'
47
55
  require_relative 'support/http_stub/configurer_integration'
48
56
  require_relative 'support/http_stub/stub_registrator'
@@ -50,3 +58,7 @@ require_relative 'support/html_helpers'
50
58
  require_relative 'support/http_stub/html_view_including_request_details'
51
59
  require_relative 'support/http_stub/html_view_excluding_request_details'
52
60
  require_relative 'support/browser_integration'
61
+
62
+ RSpec.configure do |config|
63
+ config.after(:suite) { HttpStub::Server::Driver.all.each(&:stop) }
64
+ end
@@ -0,0 +1,23 @@
1
+ RSpec::Matchers.define :contain_file do |expected_path|
2
+
3
+ match do |actual_response|
4
+ actual_file = Tempfile.new(File.basename(expected_path)).tap do |file|
5
+ file.write(actual_response.parsed_response)
6
+ file.flush
7
+ end
8
+ FileUtils.compare_file(expected_path, actual_file.path)
9
+ end
10
+
11
+ description do
12
+ "to contain contents of #{expected_path}"
13
+ end
14
+
15
+ failure_message do
16
+ "expected the response to contain the contents of #{expected_path}"
17
+ end
18
+
19
+ failure_message_when_negated do
20
+ "expected the response to not contain the contents of #{expected_path}"
21
+ end
22
+
23
+ end
@@ -1,5 +1,5 @@
1
1
  require 'sinatra'
2
2
 
3
- set :port, 8005
3
+ set :port, 8007
4
4
 
5
5
  set :root, File.dirname(__FILE__)
@@ -6,8 +6,8 @@ module CrossOriginServer
6
6
  @browser = browser
7
7
  end
8
8
 
9
- def load_and_wait_until_available
10
- @browser.navigate.to("http://localhost:8005/index.html")
9
+ def load_and_wait_until_available(stub_port)
10
+ @browser.navigate.to("http://localhost:8007/index.html?stubPort=#{stub_port}")
11
11
  ::Wait.until!(description: "cross origin test page has loaded") { @browser.find_element(id: "scenario_name") }
12
12
  end
13
13
 
@@ -1,7 +1,8 @@
1
1
  shared_context "cross origin server integration" do
2
2
 
3
3
  before(:context) do
4
- @cross_origin_server_pid = Process.spawn("ruby #{File.dirname(__FILE__)}/application.rb")
4
+ @cross_origin_server_pid = Process.spawn("ruby #{File.dirname(__FILE__)}/application.rb", out: "/dev/null",
5
+ err: "/dev/null")
5
6
  ::Wait.until!(description: "cross origin server started") do
6
7
  Net::HTTP.get_response(cross_origin_server_host, "/", cross_origin_server_port)
7
8
  end
@@ -14,7 +15,7 @@ shared_context "cross origin server integration" do
14
15
  end
15
16
 
16
17
  def cross_origin_server_port
17
- 8005
18
+ 8007
18
19
  end
19
20
 
20
21
  def cross_origin_server_uri
@@ -4,7 +4,8 @@
4
4
 
5
5
  function activateScenario() {
6
6
  var request = new XMLHttpRequest();
7
- request.open("POST", "http://localhost:8001/http_stub/scenarios/activate", false);
7
+ var stubPort = document.URL.match(/stubPort=(.+)$/)[1];
8
+ request.open("POST", "http://localhost:" + stubPort + "/http_stub/scenarios/activate", false);
8
9
  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
9
10
 
10
11
  var result = "Failed";
@@ -1,26 +1,24 @@
1
1
  shared_context "configurer integration" do
2
2
  include_context "server integration"
3
3
 
4
- let(:configurer) { HttpStub::EmptyConfigurer }
5
- let(:stub_server) { configurer.stub_server }
4
+ let(:configurer_specification) { {} }
5
+ let(:effective_configurer_specification) do
6
+ { class: HttpStub::EmptyConfigurer, initialize: true }.merge(configurer_specification)
7
+ end
8
+
9
+ let(:server_specification) { effective_configurer_specification.slice(:name, :port) }
10
+
11
+ let(:configurer) { effective_configurer_specification[:class] }
12
+ let(:stub_server) { configurer.stub_server }
13
+
6
14
  let(:stub_registrator) { HttpStub::StubRegistrator.new(stub_server) }
7
15
 
8
16
  before(:example) do
9
17
  stub_server.host = server_host
10
18
  stub_server.port = server_port
19
+ configurer.initialize! if effective_configurer_specification[:initialize]
11
20
  end
12
21
 
13
- after(:example) do
14
- stub_server.clear_stubs!
15
- stub_server.clear_scenarios!
16
- end
17
-
18
- def expect_response_to_contain_file(path)
19
- response_file = Tempfile.new(File.basename(path)).tap do |file|
20
- file.write(response.parsed_response)
21
- file.flush
22
- end
23
- expect(FileUtils.compare_file(path, response_file.path)).to be(true)
24
- end
22
+ after(:example) { stub_server.reset! }
25
23
 
26
24
  end
@@ -0,0 +1,47 @@
1
+ shared_context "http_stub rack application test" do
2
+ include_context "rack application test"
3
+
4
+ let(:response) { last_response }
5
+ let(:response_body) { response.body.to_s }
6
+
7
+ let(:request) { HttpStub::Server::RequestFixture.create }
8
+ let(:request_factory) { instance_double(HttpStub::Server::Request::Factory, create: request) }
9
+
10
+ let(:response_pipeline) { instance_double(HttpStub::Server::Application::ResponsePipeline, process: nil) }
11
+
12
+ let(:app_class) { HttpStub::Server::Application::Application }
13
+ let(:app) { app_class.new! }
14
+
15
+ before(:example) do
16
+ allow(HttpStub::Server::Request::Factory).to receive(:new).and_return(request_factory)
17
+ allow(HttpStub::Server::Application::ResponsePipeline).to receive(:new).and_return(response_pipeline)
18
+ end
19
+
20
+ shared_context "enabled session support" do
21
+
22
+ let(:session_identifier) { { header: :some_session_identifier } }
23
+
24
+ before(:example) do
25
+ @original_session_identifier = app_class.settings.session_identifier
26
+ app_class.set :session_identifier, session_identifier
27
+ end
28
+
29
+ after(:example) { app_class.set :session_identifier, @original_session_identifier }
30
+
31
+ end
32
+
33
+ shared_context "request excludes a session identifier" do
34
+
35
+ before(:example) { allow(request).to receive(:session_id).and_return(nil) }
36
+
37
+ end
38
+
39
+ shared_context "request includes a session identifier" do
40
+
41
+ let(:session_id) { SecureRandom.uuid }
42
+
43
+ before(:example) { allow(request).to receive(:session_id).and_return(session_id) }
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,56 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class Driver
5
+
6
+ DRIVERS = {}
7
+
8
+ private_constant :DRIVERS
9
+
10
+ attr_reader :default_session_id, :host, :port, :uri
11
+
12
+ class << self
13
+
14
+ def find_or_create(specification)
15
+ resolved_specification = { name: "example_server", port: 8001 }.merge(specification)
16
+ DRIVERS[resolved_specification] ||= self.new(resolved_specification)
17
+ end
18
+
19
+ def all
20
+ DRIVERS.values
21
+ end
22
+
23
+ end
24
+
25
+ def initialize(specification)
26
+ @name = specification[:name]
27
+ @host = "localhost"
28
+ @port = specification[:port]
29
+ @uri = "http://#{@host}:#{@port}"
30
+ end
31
+
32
+ def start
33
+ return if @pid
34
+ @pid = Process.spawn("rake #{@name}:start:foreground", out: "/dev/null", err: "/dev/null")
35
+ ::Wait.until!(description: "http stub server #{@name} started") do
36
+ Net::HTTP.get_response(@host, "/", @port)
37
+ end
38
+ end
39
+
40
+ def default_session_id=(session_id)
41
+ @default_session_id = session_id
42
+ HTTParty.post("#{@uri}/http_stub/sessions/default", body: { http_stub_session_id: session_id })
43
+ end
44
+
45
+ def reset_session
46
+ HTTParty.post("#{@uri}/http_stub/stubs/reset", body: { http_stub_session_id: @default_session_id })
47
+ end
48
+
49
+ def stop
50
+ Process.kill(9, @pid)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class MemoryFixture
5
+
6
+ class << self
7
+
8
+ def create(session_configuration=HttpStub::Server::Session::Configuration.new(nil))
9
+ HttpStub::Server::Memory::Memory.new(session_configuration)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -5,16 +5,17 @@ module HttpStub
5
5
 
6
6
  class << self
7
7
 
8
- def create
9
- HttpStub::Server::Request.create(create_rack_request)
8
+ def create(rack_request=Rack::RequestFixture.create)
9
+ request_factory.create(rack_request, rack_request.params, HttpServerManager::Test::SilentLogger)
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def create_rack_request
15
- Rack::Request.new("PATH_INFO" => "/some/path/info",
16
- "REQUEST_METHOD" => "GET",
17
- "rack.input" => StringIO.new)
14
+ def request_factory
15
+ @session_configuration ||= HttpStub::Server::Session::Configuration.new(nil)
16
+ @request_factory ||= HttpStub::Server::Request::Factory.new(
17
+ @session_configuration, HttpStub::Server::MemoryFixture.create(@session_configuration)
18
+ )
18
19
  end
19
20
 
20
21
  end
@@ -0,0 +1,13 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class ScenarioFixture
5
+
6
+ def self.create(name="empty")
7
+ HttpStub::Server::Scenario::Scenario.new("name" => name, "stubs" => [], "triggered_scenario_names" => [])
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class SessionFixture
5
+
6
+ class << self
7
+
8
+ def create(id=SecureRandom.uuid)
9
+ HttpStub::Server::Session::Session.new(id, scenario_registry, HttpStub::Server::Session::Empty)
10
+ end
11
+
12
+ def memory
13
+ self.create(HttpStub::Server::Session::MEMORY_SESSION_ID)
14
+ end
15
+
16
+ private
17
+
18
+ def scenario_registry
19
+ @scenario_registry ||= HttpStub::Server::Registry.new("scenario")
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -2,29 +2,24 @@ shared_context "server integration" do
2
2
  include Rack::Utils
3
3
  include HtmlHelpers
4
4
 
5
- before(:context) do
6
- @server_pid = Process.spawn("rake #{server_name}:start:foreground --trace")
7
- ::Wait.until!(description: "http stub server #{server_name} started") do
8
- Net::HTTP.get_response(server_host, "/", server_port)
9
- end
10
- end
11
-
12
- after(:context) { Process.kill(9, @server_pid) }
5
+ let(:server_specification) { {} }
6
+ let(:server_driver) { HttpStub::Server::Driver.find_or_create(server_specification) }
7
+ let(:server_host) { server_driver.host }
8
+ let(:server_port) { server_driver.port }
9
+ let(:server_uri) { server_driver.uri }
13
10
 
14
- def server_name
15
- "example_server"
16
- end
11
+ before(:example) { server_driver.start }
17
12
 
18
- def server_host
19
- "localhost"
13
+ def default_session_id
14
+ server_driver.default_session_id
20
15
  end
21
16
 
22
- def server_port
23
- 8001
17
+ def establish_default_session(session_id)
18
+ server_driver.default_session_id = session_id
24
19
  end
25
20
 
26
- def server_uri
27
- "http://#{server_host}:#{server_port}"
21
+ def reset_session
22
+ server_driver.reset_session
28
23
  end
29
24
 
30
25
  end
@@ -2,7 +2,7 @@ module HttpStub
2
2
 
3
3
  class StubFixture
4
4
 
5
- attr_reader :id, :request, :response
5
+ attr_reader :id, :request, :response, :triggers
6
6
 
7
7
  class Part
8
8
 
@@ -54,7 +54,10 @@ module HttpStub
54
54
  body: "body #{@id}",
55
55
  delay_in_seconds: 8
56
56
  )
57
- @trigger_fixtures = []
57
+ @triggers = {
58
+ scenario_names: [],
59
+ stub_fixtures: []
60
+ }
58
61
  end
59
62
 
60
63
  def request=(options)
@@ -78,15 +81,22 @@ module HttpStub
78
81
  name: "payload_#{@id}_file.name" } })
79
82
  end
80
83
 
81
- def with_triggers!(triggers)
82
- self.tap { @trigger_fixtures.concat(triggers) }
84
+ def with_triggered_scenarios!(scenario_names)
85
+ self.tap { @triggers[:scenario_names].concat(scenario_names) }
86
+ end
87
+
88
+ def with_triggered_stubs!(stubs)
89
+ self.tap { @triggers[:stub_fixtures].concat(stubs) }
83
90
  end
84
91
 
85
92
  def configurer_payload
86
93
  {
87
94
  request: @request.symbolized,
88
95
  response: @response.symbolized,
89
- triggers: @trigger_fixtures.map(&:configurer_payload)
96
+ triggers: {
97
+ scenario_names: @triggers[:scenario_names],
98
+ stubs: @triggers[:stub_fixtures].map(&:configurer_payload)
99
+ }
90
100
  }
91
101
  end
92
102
 
@@ -99,7 +109,10 @@ module HttpStub
99
109
  "headers" => @request.headers,
100
110
  "parameters" => @request.parameters,
101
111
  "response" => @response.stringified,
102
- "triggers" => @trigger_fixtures.map(&:server_payload)
112
+ "triggers" => {
113
+ "scenario_names" => @triggers[:scenario_names],
114
+ "stubs" => @triggers[:stub_fixtures].map(&:server_payload)
115
+ }
103
116
  }
104
117
  end
105
118
 
@@ -4,6 +4,10 @@ RSpec::Matchers.define :include_in_json do |expected_hash|
4
4
  actual_json.include?(expected_hash.to_json[1..-2])
5
5
  end
6
6
 
7
+ description do
8
+ "include JSON"
9
+ end
10
+
7
11
  failure_message do |actual_json|
8
12
  "expected the JSON #{actual_json} to include #{expected_hash.to_json}"
9
13
  end
@@ -12,8 +16,4 @@ RSpec::Matchers.define :include_in_json do |expected_hash|
12
16
  "expected the JSON #{actual_json} to exclude #{expected_hash.to_json}"
13
17
  end
14
18
 
15
- description do
16
- "include JSON"
17
- end
18
-
19
19
  end