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,3 @@
1
+ %header
2
+ %h2= "Session: #{session.id}"
3
+ = partial :session, locals: { session: session }
@@ -0,0 +1,6 @@
1
+ = partial :home
2
+ %h2 Sessions
3
+ %section
4
+ - sessions.each do |session|
5
+ %a{ href: "/http_stub/sessions?http_stub_session_id=#{session.id}", class: [:session, :link] }= session.id
6
+ %br
@@ -1,6 +1,3 @@
1
1
  %header
2
2
  %h1 Stubs
3
- %section
4
- - stubs.each do |the_stub|
5
- = partial :stub, locals: { the_stub: the_stub }
6
- .header-rule
3
+ = partial :stubs, locals: { stubs: stubs }
@@ -0,0 +1,2 @@
1
+ = partial :home
2
+ = partial :session, locals: { session: session }
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.25.1".freeze
2
+ VERSION = "0.26.0".freeze
3
3
  end
@@ -1,15 +1,11 @@
1
1
  describe "Configurer initialization acceptance" do
2
2
  include_context "configurer integration"
3
3
 
4
- let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
5
-
6
4
  context "when a configurer is initialized" do
7
5
 
8
- before(:example) { configurer.class.initialize! }
9
-
10
- context "that contains a class stub" do
6
+ context "that contains a stub" do
11
7
 
12
- let(:configurer) { HttpStub::Examples::ConfigurerWithTrivialStub.new }
8
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialStub } }
13
9
 
14
10
  it "registers the stub" do
15
11
  response = HTTParty.get("#{server_uri}/a_class_stub")
@@ -18,19 +14,26 @@ describe "Configurer initialization acceptance" do
18
14
  expect(response.body).to eql("Class stub body")
19
15
  end
20
16
 
21
- context "and the stub is overridden" do
17
+ context "and another stub is registered" do
22
18
 
23
19
  before(:example) do
24
- configurer.stub_response!("/a_class_stub", method: :get, response: { body: "Other class stub body" })
20
+ stub_server.add_stub! do |stub|
21
+ stub.match_requests(uri: "/another_stub", method: :get)
22
+ stub.respond_with(body: "Another stub body")
23
+ end
25
24
  end
26
25
 
27
- context "and the configurer is re-initialized" do
26
+ context "and the servers stubs are recalled" do
28
27
 
29
- before(:example) do
30
- configurer.class.initialize!
28
+ before(:example) { stub_server.recall_stubs! }
29
+
30
+ it "removes the stub just registered" do
31
+ response = HTTParty.get("#{server_uri}/another_stub")
32
+
33
+ expect(response.code).to eql(404)
31
34
  end
32
35
 
33
- it "re-establishes the class stub as having priority" do
36
+ it "retains the stub registered during initialization" do
34
37
  response = HTTParty.get("#{server_uri}/a_class_stub")
35
38
 
36
39
  expect(response.code).to eql(201)
@@ -41,40 +44,24 @@ describe "Configurer initialization acceptance" do
41
44
 
42
45
  end
43
46
 
44
- end
45
-
46
- context "and the initializer contains conventional stubs" do
47
-
48
- let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
49
-
50
- it "registers the stub" do
51
- response = HTTParty.get("#{server_uri}/stubbed_during_initialization_path")
52
-
53
- expect(response.code).to eql(200)
54
- expect(response.body).to eql("Stubbed during initialization body")
55
- end
56
-
57
- context "and another stub is registered" do
47
+ context "and the stub is overridden" do
58
48
 
59
49
  before(:example) do
60
- configurer.stub_response!("/another_stub", method: :get, response: { body: "Another stub body" })
50
+ stub_server.add_stub! do |stub|
51
+ stub.match_requests(uri: "/a_class_stub", method: :get)
52
+ stub.respond_with(body: "Other class stub body")
53
+ end
61
54
  end
62
55
 
63
- context "and the servers remembered stubs are recalled" do
64
-
65
- before(:example) { configurer.recall_stubs! }
56
+ context "and the servers stubs are recalled" do
66
57
 
67
- it "removes the stub registered post-initialization" do
68
- response = HTTParty.get("#{server_uri}/another_stub")
69
-
70
- expect(response.code).to eql(404)
71
- end
58
+ before(:example) { stub_server.recall_stubs! }
72
59
 
73
- it "retains the stub registered during initialization" do
74
- response = HTTParty.get("#{server_uri}/stubbed_during_initialization_path")
60
+ it "re-establishes the class stub" do
61
+ response = HTTParty.get("#{server_uri}/a_class_stub")
75
62
 
76
- expect(response.code).to eql(200)
77
- expect(response.body).to eql("Stubbed during initialization body")
63
+ expect(response.code).to eql(201)
64
+ expect(response.body).to eql("Class stub body")
78
65
  end
79
66
 
80
67
  end
@@ -83,9 +70,9 @@ describe "Configurer initialization acceptance" do
83
70
 
84
71
  end
85
72
 
86
- context "and the configurer contains an on initialize callback" do
73
+ context "and the configurer contains an initialize callback" do
87
74
 
88
- let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
75
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithInitializeCallback } }
89
76
 
90
77
  it "executes the callback" do
91
78
  response = HTTParty.get("#{server_uri}/stubbed_on_initialize_path")
@@ -100,20 +87,22 @@ describe "Configurer initialization acceptance" do
100
87
 
101
88
  context "when a configurer is uninitialized" do
102
89
 
90
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialStub, initialize: false } }
91
+
103
92
  context "and the configurer is informed that the server has started" do
104
93
 
105
- before(:example) { configurer.server_has_started! }
94
+ before(:example) { stub_server.has_started! }
106
95
 
107
96
  it "does not initialize the configurer" do
108
- activation_lambda = lambda { configurer.activate!("an_activator") }
109
-
110
- expect(activation_lambda).to raise_error(/error occurred activating 'an_activator'/i)
97
+ expect { stub_server.activate!("an_activator") }.to raise_error(/error occurred activating 'an_activator'/i)
111
98
  end
112
99
 
113
100
  context "and an attempt is made to register a stub" do
114
101
 
115
102
  before(:example) do
116
- configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body" })
103
+ stub_server.add_stub! do
104
+ match_requests(uri: "/some_stub_path", method: :get).respond_with(body: "Some stub body")
105
+ end
117
106
  end
118
107
 
119
108
  it "registers the stub" do
@@ -132,18 +121,18 @@ describe "Configurer initialization acceptance" do
132
121
  context "and an attempt is made to activate a stub" do
133
122
 
134
123
  it "raises an exception indicating an error occurred during activation" do
135
- activation_lambda = lambda { configurer.activate!("an_activator") }
136
-
137
- expect(activation_lambda).to raise_error(/error occurred activating 'an_activator'/i)
124
+ expect { stub_server.activate!("an_activator") }.to raise_error(/error occurred activating 'an_activator'/i)
138
125
  end
139
126
 
140
127
  end
141
128
 
142
129
  end
143
130
 
144
- context "and the configurer contains an on initialize callback" do
131
+ context "and the configurer contains an initialize callback" do
145
132
 
146
- let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
133
+ let(:configurer_specification) do
134
+ { class: HttpStub::Examples::ConfigurerWithInitializeCallback, initialize: false }
135
+ end
147
136
 
148
137
  it "does not execute the callback" do
149
138
  response = HTTParty.get("#{server_uri}/stubbed_on_initialize_path")
@@ -1,11 +1,9 @@
1
1
  describe "Configurer Part acceptance" do
2
2
  include_context "configurer integration"
3
3
 
4
- context "when a configurer contains a part" do
5
-
6
- let(:configurer) { HttpStub::Examples::ConfigurerWithParts.new }
4
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithParts } }
7
5
 
8
- before(:example) { configurer.class.initialize! }
6
+ context "when a configurer contains a part" do
9
7
 
10
8
  context "that contains a configure stub method" do
11
9
 
@@ -17,7 +15,7 @@ describe "Configurer Part acceptance" do
17
15
 
18
16
  end
19
17
 
20
- context "that contains a configure stubs methods" do
18
+ context "that contains a configure stubs method" do
21
19
 
22
20
  let(:response) { issue_request("registered_in_configure_stubs_method") }
23
21
 
@@ -27,7 +25,7 @@ describe "Configurer Part acceptance" do
27
25
 
28
26
  end
29
27
 
30
- context "that contains a configure scenario methods" do
28
+ context "that contains a configure scenario method" do
31
29
 
32
30
  let(:response) { issue_request("registered_in_configure_scenario_method") }
33
31
 
@@ -37,7 +35,7 @@ describe "Configurer Part acceptance" do
37
35
 
38
36
  end
39
37
 
40
- context "that contains a configure scenarios methods" do
38
+ context "that contains a configure scenarios method" do
41
39
 
42
40
  let(:response) { issue_request("registered_in_configure_scenarios_method") }
43
41
 
@@ -7,18 +7,14 @@ describe "Cross origin support acceptance" do
7
7
  context "when a stub server with cross origin support is initialized" do
8
8
  include_context "configurer integration"
9
9
 
10
- def server_name
11
- "cross_origin_stub"
10
+ let(:configurer_specification) do
11
+ { class: HttpStub::Examples::ConfigurerWithCrossOriginSupport, name: :cross_origin_stub, port: 8004 }
12
12
  end
13
13
 
14
- let(:configurer) { HttpStub::Examples::ConfigurerWithCrossOriginSupport.new }
15
-
16
- before(:example) { configurer.class.initialize! }
17
-
18
14
  context "and a browser page rendered by a different server requests a scenario be activated" do
19
15
 
20
16
  before(:example) do
21
- cross_origin_page.load_and_wait_until_available
17
+ cross_origin_page.load_and_wait_until_available(server_port)
22
18
  cross_origin_page.activate_scenario("Get scenario")
23
19
  end
24
20
 
@@ -54,7 +50,7 @@ describe "Cross origin support acceptance" do
54
50
 
55
51
  context "and a scenario configuring OPTIONS request reponses is activated" do
56
52
 
57
- before(:example) { configurer.activate!("Options scenario") }
53
+ before(:example) { stub_server.activate!("Options scenario") }
58
54
 
59
55
  context "and a matching pre-flight request is made" do
60
56
 
@@ -84,14 +80,12 @@ describe "Cross origin support acceptance" do
84
80
  context "when a stub server without cross origin support is initialized" do
85
81
  include_context "configurer integration"
86
82
 
87
- let(:configurer) { HttpStub::Examples::ConfigurerWithTrivialScenarios.new }
88
-
89
- before(:example) { configurer.class.initialize! }
83
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialScenarios } }
90
84
 
91
85
  context "and a browser page rendered by a different server requests a scenario be activated" do
92
86
 
93
87
  before(:example) do
94
- cross_origin_page.load_and_wait_until_available
88
+ cross_origin_page.load_and_wait_until_available(server_port)
95
89
  cross_origin_page.activate_scenario("Get scenario")
96
90
  end
97
91
 
@@ -107,7 +101,7 @@ describe "Cross origin support acceptance" do
107
101
 
108
102
  context "and a scenario is activated" do
109
103
 
110
- before(:example) { configurer.activate!("Scenario 1") }
104
+ before(:example) { stub_server.activate!("Scenario 1") }
111
105
 
112
106
  context "and a matching request is made" do
113
107
 
@@ -1,11 +1,9 @@
1
1
  describe "Endpoint Template acceptance" do
2
- include_context "configurer integration"
3
2
 
4
3
  context "when a configurer contains an endpoint template" do
4
+ include_context "configurer integration"
5
5
 
6
- let(:configurer) { HttpStub::Examples::ConfigurerWithEndpointTemplate.new }
7
-
8
- before(:example) { configurer.class.initialize! }
6
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithEndpointTemplate } }
9
7
 
10
8
  it "does not register a stub when the template is defined" do
11
9
  response = issue_request("template_uri")
@@ -1,9 +1,7 @@
1
1
  describe "Request references in response acceptance" do
2
2
  include_context "configurer integration"
3
3
 
4
- let(:configurer) { HttpStub::Examples::ConfigurerWithRequestReferences.new }
5
-
6
- before(:example) { configurer.class.initialize! }
4
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithRequestReferences } }
7
5
 
8
6
  context "when a request is made matching a stub that references request attributes" do
9
7
 
@@ -1,17 +1,15 @@
1
1
  describe "Scenario acceptance" do
2
- include_context "configurer integration"
3
2
 
4
3
  context "when a configurer that contains scenarios is initialized" do
4
+ include_context "configurer integration"
5
5
 
6
- let(:configurer) { HttpStub::Examples::ConfigurerWithTrivialScenarios.new }
7
-
8
- before(:example) { configurer.class.initialize! }
6
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialScenarios } }
9
7
 
10
8
  context "and a scenario is activated" do
11
9
 
12
10
  context "containing stubs" do
13
11
 
14
- before(:example) { configurer.activate!("Scenario 1") }
12
+ before(:example) { stub_server.activate!("Scenario 1") }
15
13
 
16
14
  (1..3).each do |stub_number|
17
15
 
@@ -32,7 +30,7 @@ describe "Scenario acceptance" do
32
30
 
33
31
  context "containing triggered scenarios" do
34
32
 
35
- before(:example) { configurer.activate!("Activates another scenario") }
33
+ before(:example) { stub_server.activate!("Activates another scenario") }
36
34
 
37
35
  (1..3).each do |stub_number|
38
36
 
@@ -69,9 +67,9 @@ describe "Scenario acceptance" do
69
67
 
70
68
  context "and the response contains a file" do
71
69
 
72
- let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponses.new }
70
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithFileResponses } }
73
71
 
74
- before(:example) { configurer.activate!("Scenario with file") }
72
+ before(:example) { stub_server.activate!("Scenario with file") }
75
73
 
76
74
  context "and the stub request is made" do
77
75
 
@@ -79,7 +77,7 @@ describe "Scenario acceptance" do
79
77
 
80
78
  it "replays the stubbed response" do
81
79
  expect(response.code).to eql(200)
82
- expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
80
+ expect(response).to contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
83
81
  end
84
82
 
85
83
  end
@@ -1,11 +1,9 @@
1
1
  describe "Server defaults acceptance" do
2
- include_context "configurer integration"
3
2
 
4
3
  context "when a configurer defines server defaults" do
4
+ include_context "configurer integration"
5
5
 
6
- let(:configurer) { HttpStub::Examples::ConfigurerWithServerDefaults.new }
7
-
8
- before(:example) { configurer.class.initialize! }
6
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithServerDefaults } }
9
7
 
10
8
  it "matches requests that match the request default rules" do
11
9
  response = issue_matching_request("has_defaults")
@@ -0,0 +1,20 @@
1
+ describe "Server memory acceptance" do
2
+
3
+ context "when a configurer with a stub is initialized" do
4
+ include_context "configurer integration"
5
+
6
+ let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialStub } }
7
+
8
+ describe "GET /http_stub/memory" do
9
+
10
+ let(:response) { HTTParty.get("#{server_uri}/http_stub/memory") }
11
+
12
+ it "lists the stubs registered during initialization" do
13
+ expect(response.body).to include("Class stub body")
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,125 @@
1
+ describe "Session acceptance" do
2
+
3
+ context "when a configurer that has a session support enabled is initialized" do
4
+ include_context "configurer integration"
5
+
6
+ let(:configurer_specification) do
7
+ { class: HttpStub::Examples::ConfigurerWithSessions, name: :session_based_stub, port: 8003 }
8
+ end
9
+
10
+ context "when a stub is added to a session" do
11
+
12
+ let(:stub_session_id) { "some_session" }
13
+ let(:stub_session) { stub_server.session(stub_session_id) }
14
+
15
+ let(:match_response) { HTTParty.get("#{server_uri}/matching_path", request_session_id_header) }
16
+
17
+ before(:example) { stub_session.activate!("Some Scenario") }
18
+
19
+ context "and a matching request is made "do
20
+
21
+ before(:example) { match_response }
22
+
23
+ context "that is issued from the same session" do
24
+
25
+ let(:request_session_id) { stub_session_id }
26
+
27
+ let(:match_list_response) { HTTParty.get("#{server_uri}/http_stub/stubs/matches", request_session_id_header) }
28
+
29
+ it "matches" do
30
+ expect(match_response.code).to eql(200)
31
+ end
32
+
33
+ it "registers a match" do
34
+ expect(match_list_response.body).to include("matching_path")
35
+ end
36
+
37
+ end
38
+
39
+ context "that is issued from another session" do
40
+
41
+ let(:request_session_id) { "another_session" }
42
+
43
+ let(:miss_list_response) { HTTParty.get("#{server_uri}/http_stub/stubs/misses", request_session_id_header) }
44
+
45
+ it "does not match" do
46
+ expect(match_response.code).to eql(404)
47
+ end
48
+
49
+ it "registers a miss" do
50
+ expect(miss_list_response.body).to include("matching_path")
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ context "and the session is reset" do
58
+
59
+ let(:request_session_id) { stub_session_id }
60
+
61
+ before(:example) { stub_session.reset! }
62
+
63
+ context "and a matching request is issued from the same session" do
64
+
65
+ it "does not match" do
66
+ expect(match_response.code).to eql(404)
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ def request_session_id_header
74
+ { headers: { "http_stub_session_id" => request_session_id } }
75
+ end
76
+
77
+ end
78
+
79
+ context "when many sessions have been created" do
80
+
81
+ let(:session_ids) { (1..3).map { |i| "session#{i}"} }
82
+ let(:sessions) { session_ids.map { |session_id| stub_server.session(session_id) } }
83
+
84
+ before(:example) { sessions.each { |session| session.activate!("Some Scenario") } }
85
+
86
+ describe "the administration landing page" do
87
+
88
+ let(:landing_page_response) { HTTParty.get("#{server_uri}/http_stub") }
89
+
90
+ it "lists the sessions" do
91
+ session_ids.each { |session_id| expect(landing_page_response.body).to include(session_id) }
92
+ end
93
+
94
+ it "does not link to stubs" do
95
+ expect(landing_page_response.body).to_not include("/stubs")
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+ context "when a configurer that has a session support disabled is initialized" do
105
+ include_context "configurer integration"
106
+
107
+ let(:configurer_specification) { { class: HttpStub::EmptyConfigurer } }
108
+
109
+ describe "the administration landing page" do
110
+
111
+ let(:landing_page_response) { HTTParty.get("#{server_uri}/http_stub") }
112
+
113
+ it "links to stubs" do
114
+ expect(landing_page_response.body).to include("/stubs")
115
+ end
116
+
117
+ it "does not list sessions" do
118
+ expect(landing_page_response.body).to_not include("/sessions")
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ end