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
@@ -0,0 +1,101 @@
1
+ describe HttpStub::Configurer::Request::Triggers do
2
+
3
+ let(:scenario_names) { (1..3).map { |i| "Some scenario #{i}" } }
4
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
5
+
6
+ let(:triggers) { HttpStub::Configurer::Request::Triggers.new(scenario_names: scenario_names, stubs: stubs) }
7
+
8
+ describe "#response_files" do
9
+
10
+ let(:stubs) do
11
+ response_files_per_stub.map do |response_files|
12
+ instance_double(HttpStub::Configurer::Request::Stub, response_files: response_files)
13
+ end
14
+ end
15
+
16
+ subject { triggers.response_files }
17
+
18
+ context "when many stubs contains response files" do
19
+
20
+ let(:response_files_per_stub) do
21
+ (1..3).map { (1..3).map { HttpStub::Configurer::Request::StubResponseFile } }
22
+ end
23
+
24
+ it "returns all the response files" do
25
+ expect(subject).to eql(response_files_per_stub.flatten)
26
+ end
27
+
28
+ end
29
+
30
+ context "when one stub contains response files" do
31
+
32
+ let(:response_files) { (1..3).map { HttpStub::Configurer::Request::StubResponseFile } }
33
+ let(:response_files_per_stub) { (1..3).map { |i| i % 2 == 0 ? response_files : [] } }
34
+
35
+ it "returns the response files" do
36
+ expect(subject).to eql(response_files)
37
+ end
38
+
39
+ end
40
+
41
+ context "when no stubs contain response files" do
42
+
43
+ let(:response_files_per_stub) { (1..3).map { [] } }
44
+
45
+ it "returns an empty array" do
46
+ expect(subject).to eql([])
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ describe "#payload" do
54
+
55
+ let(:stub_payloads) { stubs.each_with_index.map { |i| "Stub payload #{i}" } }
56
+
57
+ subject { triggers.payload }
58
+
59
+ before(:example) do
60
+ stubs.zip(stub_payloads).each { |stub, payload| allow(stub).to receive(:payload).and_return(payload) }
61
+ end
62
+
63
+ context "when scenario names are provided" do
64
+
65
+ it "has a scenario names entry containing the names" do
66
+ expect(subject).to include(scenario_names: scenario_names)
67
+ end
68
+
69
+ end
70
+
71
+ context "when no scenario names are provided" do
72
+
73
+ let(:scenario_names) { [] }
74
+
75
+ it "has an scenario names entry that is empty" do
76
+ expect(subject).to include(scenario_names: [])
77
+ end
78
+
79
+ end
80
+
81
+ context "when stubs are provided" do
82
+
83
+ it "has a stubs entry containing the payload of the stubs" do
84
+ expect(subject).to include(stubs: stub_payloads)
85
+ end
86
+
87
+ end
88
+
89
+ context "when stub are not provided" do
90
+
91
+ let(:stubs) { [] }
92
+
93
+ it "has a stubs entry that is empty" do
94
+ expect(subject).to include(stubs: [])
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -1,19 +1,20 @@
1
1
  describe HttpStub::Configurer::Server::CommandProcessor do
2
2
 
3
- let(:command) { HttpStub::Configurer::Server::Command.new(request: request, description: "performing an operation") }
4
3
  let(:server_host) { "localhost" }
5
4
  let(:server_port) { 8001 }
6
5
  let(:server_base_uri) { "http://#{server_host}:#{server_port}" }
7
- let(:stub_server) do
8
- instance_double(HttpStub::Configurer::DSL::Server, base_uri: server_base_uri, host: server_host, port: server_port)
6
+ let(:configuration) do
7
+ double(HttpStub::Configurer::Server::Configuration, base_uri: server_base_uri, host: server_host, port: server_port)
9
8
  end
10
9
 
11
- let(:configurer) { double(HttpStub::Configurer, stub_server: stub_server) }
12
-
13
- let(:command_processor) { HttpStub::Configurer::Server::CommandProcessor.new(configurer) }
10
+ let(:command_processor) { HttpStub::Configurer::Server::CommandProcessor.new(configuration) }
14
11
 
15
12
  describe "#process" do
16
13
 
14
+ let(:command) do
15
+ HttpStub::Configurer::Server::Command.new(request: request, description: "performing an operation")
16
+ end
17
+
17
18
  subject { command_processor.process(command) }
18
19
 
19
20
  context "when the server is running" do
@@ -21,7 +22,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
21
22
 
22
23
  describe "and the server responds with a 200 response" do
23
24
 
24
- let(:request) { create_get_request("/http_stub/stubs") }
25
+ let(:request) { create_get_request("stubs") }
25
26
 
26
27
  it "executes without error" do
27
28
  expect { subject }.not_to raise_error
@@ -35,7 +36,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
35
36
 
36
37
  describe "and the server responds with a non-200 response" do
37
38
 
38
- let(:request) { create_get_request("/causes_error") }
39
+ let(:request) { create_get_request("causes_error") }
39
40
 
40
41
  it "raises an exception that includes the server base URI" do
41
42
  expect { subject }.to raise_error(/#{server_base_uri}/)
@@ -53,7 +54,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
53
54
 
54
55
  subject { command_processor.process(command, open_timeout: 1) }
55
56
 
56
- let(:request) { create_get_request("/does/not/exist") }
57
+ let(:request) { create_get_request("does/not/exist") }
57
58
 
58
59
  it "raises an exception that includes the server base URI" do
59
60
  expect { subject }.to raise_error(/#{server_base_uri}/)
@@ -66,7 +67,7 @@ describe HttpStub::Configurer::Server::CommandProcessor do
66
67
  end
67
68
 
68
69
  def create_get_request(path)
69
- HttpStub::Configurer::Request::Http::Basic.new(Net::HTTP::Get.new(path))
70
+ HttpStub::Configurer::Request::Http::Basic.new(method: :get, path: path)
70
71
  end
71
72
 
72
73
  end
@@ -0,0 +1,139 @@
1
+ describe HttpStub::Configurer::Server::Configuration do
2
+
3
+ let(:configuration) { described_class.new }
4
+
5
+ shared_context "a configuration with host and port configured" do
6
+
7
+ before(:example) do
8
+ configuration.host = "some_host"
9
+ configuration.port = 8888
10
+ end
11
+
12
+ end
13
+
14
+ describe "#session_identifier" do
15
+
16
+ let(:session_identifier) { { headers: :some_session_identifier } }
17
+
18
+ subject { configuration.session_identifier }
19
+
20
+ before(:example) { configuration.session_identifier = session_identifier }
21
+
22
+ it "returns any configured value" do
23
+ expect(subject).to eql(session_identifier)
24
+ end
25
+
26
+ end
27
+
28
+ describe "#base_uri" do
29
+
30
+ subject { configuration.base_uri }
31
+
32
+ include_context "a configuration with host and port configured"
33
+
34
+ it "returns a uri that combines any established host and port" do
35
+ expect(subject).to include("some_host:8888")
36
+ end
37
+
38
+ it "returns a uri accessed via http" do
39
+ expect(subject).to match(/^http:\/\//)
40
+ end
41
+
42
+ end
43
+
44
+ describe "#external_base_uri" do
45
+
46
+ subject { configuration.external_base_uri }
47
+
48
+ include_context "a configuration with host and port configured"
49
+
50
+ context "when an external base URI environment variable is established" do
51
+
52
+ let(:external_base_uri) { "http://some/external/base/uri" }
53
+
54
+ before(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = external_base_uri }
55
+ after(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = nil }
56
+
57
+ it "returns the environment variable" do
58
+ expect(subject).to eql(external_base_uri)
59
+ end
60
+
61
+ end
62
+
63
+ context "when an external base URI environment variable is not established" do
64
+
65
+ it "returns the base URI" do
66
+ expect(subject).to eql(configuration.base_uri)
67
+ end
68
+
69
+ end
70
+
71
+ it "returns a uri that combines any established host and port" do
72
+ expect(subject).to include("some_host:8888")
73
+ end
74
+
75
+ it "returns a uri accessed via http" do
76
+ expect(subject).to match(/^http:\/\//)
77
+ end
78
+
79
+ end
80
+
81
+ describe "#enable" do
82
+
83
+ context "when a feature is provided" do
84
+
85
+ let(:feature) { :some_feature }
86
+
87
+ subject { configuration.enable(feature) }
88
+
89
+ it "enables the feature" do
90
+ subject
91
+
92
+ expect(configuration.enabled?(feature)).to be(true)
93
+ end
94
+
95
+ end
96
+
97
+ context "when features are provided" do
98
+
99
+ let(:features) { (1..3).map { |i| "feature_#{i}".to_sym } }
100
+
101
+ subject { configuration.enable(*features) }
102
+
103
+ it "enables the features" do
104
+ subject
105
+
106
+ features.each { |feature| expect(configuration.enabled?(feature)).to be(true) }
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+
113
+ describe "#enabled?" do
114
+
115
+ let(:feature) { :some_feature }
116
+
117
+ subject { configuration.enabled?(feature) }
118
+
119
+ context "when a feature is enabled" do
120
+
121
+ before(:example) { configuration.enable(feature) }
122
+
123
+ it "returns false" do
124
+ expect(subject).to be(true)
125
+ end
126
+
127
+ end
128
+
129
+ context "when a feature is not enabled" do
130
+
131
+ it "returns false" do
132
+ expect(subject).to be(false)
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -1,116 +1,98 @@
1
1
  describe HttpStub::Configurer::Server::Facade do
2
2
 
3
- let(:configurer) { double(HttpStub::Configurer) }
3
+ let(:configuration) { double(HttpStub::Configurer::Server::Configuration) }
4
+
4
5
  let(:request_processor) { instance_double(HttpStub::Configurer::Server::RequestProcessor) }
5
6
 
6
- let(:facade) { HttpStub::Configurer::Server::Facade.new(configurer) }
7
+ let(:facade) { HttpStub::Configurer::Server::Facade.new(configuration) }
7
8
 
8
9
  before(:example) do
9
10
  allow(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).and_return(request_processor)
10
11
  end
11
12
 
12
- describe "constructor" do
13
-
14
- it "creates a request processor with the provided configurer" do
15
- expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configurer)
16
-
17
- facade
18
- end
13
+ it "creates a request processor with the provided configuration" do
14
+ expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configuration)
19
15
 
16
+ facade
20
17
  end
21
18
 
22
- describe "#stub_response" do
23
-
24
- let(:model_description) { "some model description" }
25
- let(:model) { instance_double(HttpStub::Configurer::Request::Stub, to_s: model_description) }
26
- let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
19
+ describe "#server_has_started" do
27
20
 
28
- subject { facade.stub_response(model) }
21
+ subject { facade.server_has_started }
29
22
 
30
- before(:example) do
31
- allow(request_processor).to receive(:submit)
32
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
33
- end
34
-
35
- it "creates a multipart request with the provided model" do
36
- expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(model)
23
+ it "informs the request processor to disable buffering requests" do
24
+ expect(request_processor).to receive(:disable_buffering!)
37
25
 
38
26
  subject
39
27
  end
40
28
 
41
- it "submits the request via the request processor" do
42
- expect(request_processor).to receive(:submit).with(hash_including(request: request))
29
+ end
43
30
 
44
- subject
45
- end
31
+ describe "#flush_requests" do
32
+
33
+ subject { facade.flush_requests }
46
34
 
47
- it "describes the model via its string representation" do
48
- expect(request_processor).to receive(:submit).with(hash_including(description: "stubbing '#{model_description}'"))
35
+ it "informs the request processor to flush it's requests" do
36
+ expect(request_processor).to receive(:flush!)
49
37
 
50
38
  subject
51
39
  end
52
40
 
53
41
  end
54
42
 
55
- describe "#define_scenario" do
43
+ describe "#reset" do
56
44
 
57
- let(:model_description) { "some model description" }
58
- let(:model) { instance_double(HttpStub::Configurer::Request::Scenario, to_s: model_description) }
59
- let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
45
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
60
46
 
61
- subject { facade.define_scenario(model) }
47
+ subject { facade.reset }
62
48
 
63
49
  before(:example) do
50
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
64
51
  allow(request_processor).to receive(:submit)
65
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
66
52
  end
67
53
 
68
- it "creates a multipart request with the provided model" do
69
- expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(model)
54
+ it "creates a DELETE request for the memory endpoint" do
55
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("memory").and_return(request)
70
56
 
71
57
  subject
72
58
  end
73
59
 
74
- it "submits the request via the request processor" do
60
+ it "submits the HTTP Stub request via the request processor" do
75
61
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
76
62
 
77
63
  subject
78
64
  end
79
65
 
80
- it "describes the model via its string representation" do
81
- expect(request_processor).to(
82
- receive(:submit).with(hash_including(description: "registering scenario '#{model_description}'"))
83
- )
66
+ it "describes the request as resetting the server" do
67
+ expect(request_processor).to receive(:submit).with(hash_including(description: "resetting server"))
84
68
 
85
69
  subject
86
70
  end
87
71
 
88
72
  end
89
73
 
90
- describe "#activate" do
74
+ describe "#define_scenario" do
75
+
76
+ let(:scenario_description) { "some scenario description" }
77
+ let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario, to_s: scenario_description) }
91
78
 
92
- let(:scenario_name) { "some/scenario/name" }
93
- let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
79
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
94
80
 
95
- subject { facade.activate(scenario_name) }
81
+ subject { facade.define_scenario(scenario) }
96
82
 
97
83
  before(:example) do
98
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
99
84
  allow(request_processor).to receive(:submit)
85
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).and_return(request)
100
86
  end
101
87
 
102
- it "creates an POST request to activate a scenario" do
103
- expect(HttpStub::Configurer::Request::Http::Factory).to(
104
- receive(:post).with("/http_stub/scenarios/activate", anything).and_return(request)
105
- )
88
+ it "creates a multipart request to the scenarios endpoint" do
89
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with("scenarios", anything)
106
90
 
107
91
  subject
108
92
  end
109
93
 
110
- it "creates a POST request with the scenario name as a parameter" do
111
- expect(HttpStub::Configurer::Request::Http::Factory).to(
112
- receive(:post).with(anything, hash_including(:name => scenario_name)).and_return(request)
113
- )
94
+ it "creates a multipart request with the provided scenario" do
95
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:multipart).with(anything, scenario)
114
96
 
115
97
  subject
116
98
  end
@@ -121,128 +103,89 @@ describe HttpStub::Configurer::Server::Facade do
121
103
  subject
122
104
  end
123
105
 
124
- it "describes the activation request using the provided scenario name" do
125
- expect(request_processor).to receive(:submit).with(hash_including(description: "activating '#{scenario_name}'"))
106
+ it "describes the scenario via its string representation" do
107
+ expect(request_processor).to(
108
+ receive(:submit).with(hash_including(description: "registering scenario '#{scenario_description}'"))
109
+ )
126
110
 
127
111
  subject
128
112
  end
129
113
 
130
114
  end
131
115
 
132
- describe "#remember_stubs" do
116
+ describe "#clear_scenarios" do
133
117
 
134
118
  let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
135
119
 
136
- subject { facade.remember_stubs }
120
+ subject { facade.clear_scenarios }
137
121
 
138
122
  before(:example) do
139
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
123
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
140
124
  allow(request_processor).to receive(:submit)
141
125
  end
142
126
 
143
- it "creates a POST request for the /http_stub/stubs/memory endpoint" do
144
- expect(HttpStub::Configurer::Request::Http::Factory).to(
145
- receive(:post).with("/http_stub/stubs/memory").and_return(request)
146
- )
127
+ it "creates a DELETE request for the scenarios endpoint" do
128
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("scenarios").and_return(request)
147
129
 
148
130
  subject
149
131
  end
150
132
 
151
- it "submits the request via the request processor" do
133
+ it "submits the HTTP Stub request via the request processor" do
152
134
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
153
135
 
154
136
  subject
155
137
  end
156
138
 
157
- it "describes the request as committing the servers stubs to memory" do
158
- expect(request_processor).to receive(:submit).with(hash_including(description: "committing stubs to memory"))
139
+ it "describes the request as clearing the servers scenarios" do
140
+ expect(request_processor).to receive(:submit).with(hash_including(description: "clearing scenarios"))
159
141
 
160
142
  subject
161
143
  end
162
144
 
163
145
  end
164
146
 
165
- describe "#recall_stubs" do
166
-
167
- let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
168
-
169
- subject { facade.recall_stubs }
170
-
171
- before(:example) do
172
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(request)
173
- allow(request_processor).to receive(:submit)
174
- end
147
+ describe "#create_session_facade" do
175
148
 
176
- it "creates a GET request for the /http_stub/stubs/memory endpoint" do
177
- expect(HttpStub::Configurer::Request::Http::Factory).to(
178
- receive(:get).with("/http_stub/stubs/memory").and_return(request)
179
- )
149
+ let(:session_id) { "some session id" }
180
150
 
181
- subject
182
- end
151
+ let(:session_facade) { instance_double(HttpStub::Configurer::Server::SessionFacade) }
183
152
 
184
- it "submits the request via the request processor" do
185
- expect(request_processor).to receive(:submit).with(hash_including(request: request))
153
+ subject { facade.create_session_facade(session_id) }
186
154
 
187
- subject
188
- end
155
+ before(:example) { allow(HttpStub::Configurer::Server::SessionFacade).to receive(:new).and_return(session_facade) }
189
156
 
190
- it "describes the request as recalling the servers stubs in memory" do
191
- expect(request_processor).to receive(:submit).with(hash_including(description: "recalling stubs in memory"))
157
+ it "creates a session facade for the provided session" do
158
+ expect(HttpStub::Configurer::Server::SessionFacade).to receive(:new).with(session_id, anything)
192
159
 
193
160
  subject
194
- end
195
-
196
- end
197
-
198
- describe "#clear_stubs" do
199
161
 
200
- let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
201
-
202
- subject { facade.clear_stubs }
203
-
204
- before(:example) do
205
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
206
- allow(request_processor).to receive(:submit)
207
162
  end
208
163
 
209
- it "creates a DELETE request for the /http_stub/stubs endpoint" do
210
- expect(HttpStub::Configurer::Request::Http::Factory).to(
211
- receive(:delete).with("/http_stub/stubs").and_return(request)
212
- )
164
+ it "creates a session facade that processes requests the server facades request processor" do
165
+ expect(HttpStub::Configurer::Server::SessionFacade).to receive(:new).with(anything, request_processor)
213
166
 
214
167
  subject
215
168
  end
216
169
 
217
- it "submits the request via the request processor" do
218
- expect(request_processor).to receive(:submit).with(hash_including(request: request))
219
-
220
- subject
221
- end
222
-
223
- it "describes the request as clearing the server stubs" do
224
- expect(request_processor).to receive(:submit).with(hash_including(description: "clearing stubs"))
225
-
226
- subject
170
+ it "returns the created session facade" do
171
+ expect(subject).to eql(session_facade)
227
172
  end
228
173
 
229
174
  end
230
175
 
231
- describe "#clear_scenarios" do
176
+ describe "#clear_sessions" do
232
177
 
233
178
  let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
234
179
 
235
- subject { facade.clear_scenarios }
180
+ subject { facade.clear_sessions }
236
181
 
237
182
  before(:example) do
238
183
  allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
239
184
  allow(request_processor).to receive(:submit)
240
185
  end
241
186
 
242
- it "creates a DELETE request for the /http_stub/scenarios endpoint" do
243
- expect(HttpStub::Configurer::Request::Http::Factory).to(
244
- receive(:delete).with("/http_stub/scenarios").and_return(request)
245
- )
187
+ it "creates a DELETE request for the sessions endpoint" do
188
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("sessions").and_return(request)
246
189
 
247
190
  subject
248
191
  end
@@ -253,32 +196,12 @@ describe HttpStub::Configurer::Server::Facade do
253
196
  subject
254
197
  end
255
198
 
256
- it "describes the request as clearing the server scenarios" do
257
- expect(request_processor).to receive(:submit).with(hash_including(description: "clearing scenarios"))
199
+ it "describes the request as clearing the servers sessions" do
200
+ expect(request_processor).to receive(:submit).with(hash_including(description: "clearing sessions"))
258
201
 
259
202
  subject
260
203
  end
261
204
 
262
205
  end
263
206
 
264
- describe "#server_has_started" do
265
-
266
- it "informs the request processor to disable buffering requests" do
267
- expect(request_processor).to receive(:disable_buffering!)
268
-
269
- facade.server_has_started
270
- end
271
-
272
- end
273
-
274
- describe "#flush_requests" do
275
-
276
- it "informs the request processor to flush it's requests" do
277
- expect(request_processor).to receive(:flush!)
278
-
279
- facade.flush_requests
280
- end
281
-
282
- end
283
-
284
207
  end