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,150 @@
1
+ describe HttpStub::Configurer::DSL::SessionEndpointTemplate do
2
+
3
+ let(:session) { instance_double(HttpStub::Configurer::DSL::Session) }
4
+ let(:default_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
5
+ let(:initial_block_verifier) { double("BlockVerifier") }
6
+ let(:block) { lambda { initial_block_verifier.verify } }
7
+
8
+ let(:session_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
9
+
10
+ let(:session_endpoint_template) { described_class.new(session, default_stub_template, &block) }
11
+
12
+ before(:each) do
13
+ allow(HttpStub::Configurer::DSL::StubBuilderTemplate).to receive(:new).and_return(session_stub_template)
14
+ end
15
+
16
+ it "creates a stub template that extends the default template and is initialized with the provided block" do
17
+ expect(HttpStub::Configurer::DSL::StubBuilderTemplate).to receive(:new).with(default_stub_template).and_yield
18
+ expect(initial_block_verifier).to receive(:verify)
19
+
20
+ session_endpoint_template
21
+ end
22
+
23
+ describe "#match_requests" do
24
+
25
+ let(:request_matching_rules) { { uri: "/some/stub/uri", method: :get } }
26
+
27
+ subject { session_endpoint_template.match_requests(request_matching_rules) }
28
+
29
+ it "delegates to the sessions stub template" do
30
+ expect(session_stub_template).to receive(:match_requests).with(request_matching_rules)
31
+
32
+ subject
33
+ end
34
+
35
+ end
36
+
37
+ describe "#schema" do
38
+
39
+ let(:type) { :some_schema_type }
40
+ let(:definition) { "some schema definition" }
41
+
42
+ subject { session_endpoint_template.schema(type, definition) }
43
+
44
+ it "delegates to the sessions stub template" do
45
+ expect(session_stub_template).to receive(:schema).with(type, definition)
46
+
47
+ subject
48
+ end
49
+
50
+ it "returns the created schema" do
51
+ schema = { schema: :some_schema }
52
+ expect(session_stub_template).to receive(:schema).and_return(schema)
53
+
54
+ expect(subject).to eql(schema)
55
+ end
56
+
57
+ end
58
+
59
+ describe "#respond_with" do
60
+
61
+ let(:response_settings) { { status: 204 } }
62
+
63
+ subject { session_endpoint_template.respond_with(response_settings) }
64
+
65
+ it "delegates to the sessions stub template" do
66
+ expect(session_stub_template).to receive(:respond_with).with(response_settings)
67
+
68
+ subject
69
+ end
70
+
71
+ end
72
+
73
+ describe "#trigger" do
74
+
75
+ let(:trigger_settings) { { scenario: "some scenario name" } }
76
+
77
+ subject { session_endpoint_template.trigger(trigger_settings) }
78
+
79
+ it "delegates to the sessions stub template" do
80
+ expect(session_stub_template).to receive(:trigger).with(trigger_settings)
81
+
82
+ subject
83
+ end
84
+
85
+ end
86
+
87
+ describe "#invoke" do
88
+
89
+ let(:block_verifier) { double("BlockVerifier") }
90
+ let(:block) { lambda { block_verifier.verify } }
91
+
92
+ subject { session_endpoint_template.invoke(&block) }
93
+
94
+ it "delegates to the sessions stub template" do
95
+ expect(session_stub_template).to receive(:invoke).and_yield
96
+ expect(block_verifier).to receive(:verify)
97
+
98
+ subject
99
+ end
100
+
101
+ end
102
+
103
+ describe "#build_stub" do
104
+
105
+ let(:response_overrides) { { status: 201 } }
106
+ let(:block_verifier) { double("BlockVerifier") }
107
+ let(:block) { lambda { block_verifier.verify } }
108
+
109
+ subject { session_endpoint_template.build_stub(response_overrides, &block) }
110
+
111
+ it "delegates to the sessions stub template" do
112
+ expect(session_stub_template).to receive(:build_stub).with(response_overrides).and_yield
113
+ expect(block_verifier).to receive(:verify)
114
+
115
+ subject
116
+ end
117
+
118
+ end
119
+
120
+ describe "#add_stub!" do
121
+
122
+ let(:response_overrides) { { status: 201 } }
123
+ let(:block_verifier) { double("BlockVerifier") }
124
+ let(:block) { lambda { block_verifier.verify } }
125
+
126
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
127
+
128
+ subject { session_endpoint_template.add_stub!(response_overrides, &block) }
129
+
130
+ before(:example) do
131
+ allow(session_stub_template).to receive(:build_stub).and_return(stub_builder)
132
+ allow(session).to receive(:add_stub!)
133
+ end
134
+
135
+ it "builds a stub using any provided response overrides and block" do
136
+ expect(session_stub_template).to receive(:build_stub).with(response_overrides).and_yield
137
+ expect(block_verifier).to receive(:verify)
138
+
139
+ subject
140
+ end
141
+
142
+ it "adds a stub to the session with the provided name and created stub builder" do
143
+ expect(session).to receive(:add_stub!).with(stub_builder)
144
+
145
+ subject
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,97 @@
1
+ describe HttpStub::Configurer::DSL::SessionFactory do
2
+
3
+ let(:server_facade) { instance_double(HttpStub::Configurer::Server::Facade) }
4
+ let(:default_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
5
+
6
+ let(:session) { instance_double(HttpStub::Configurer::DSL::Session) }
7
+
8
+ let(:session_factory) { described_class.new(server_facade, default_stub_template) }
9
+
10
+ describe "#create" do
11
+
12
+ let(:id) { "some_session_id" }
13
+
14
+ subject { create_session }
15
+
16
+ it "creates a session with the provided ID" do
17
+ expect(HttpStub::Configurer::DSL::Session).to receive(:new).with(id, anything, anything)
18
+
19
+ subject
20
+ end
21
+
22
+ it "creates a session uses the stubs server facade" do
23
+ expect(HttpStub::Configurer::DSL::Session).to receive(:new).with(anything, server_facade, anything)
24
+
25
+ subject
26
+ end
27
+
28
+ it "creates a session uses the stubs default stub template" do
29
+ expect(HttpStub::Configurer::DSL::Session).to receive(:new).with(anything, anything, default_stub_template)
30
+
31
+ subject
32
+ end
33
+
34
+ it "returns the created session" do
35
+ allow(HttpStub::Configurer::DSL::Session).to receive(:new).and_return(session)
36
+
37
+ expect(subject).to eql(session)
38
+
39
+ end
40
+
41
+ context "when a session has been created" do
42
+
43
+ before(:example) do
44
+ allow(HttpStub::Configurer::DSL::Session).to receive(:new).and_return(session).once
45
+
46
+ create_session
47
+ end
48
+
49
+ it "returns the same session when a session with the same ID is created" do
50
+ expect(subject).to be(session)
51
+ end
52
+
53
+ end
54
+
55
+ def create_session
56
+ session_factory.create(id)
57
+ end
58
+
59
+ end
60
+
61
+ describe "#memory" do
62
+
63
+ subject { session_factory.memory }
64
+
65
+ it "creates a session whose ID is an internal memory identifier" do
66
+ expect(session_factory).to receive(:create).with("http_stub_memory")
67
+
68
+ subject
69
+ end
70
+
71
+ it "returns the created session" do
72
+ allow(session_factory).to receive(:create).and_return(session)
73
+
74
+ expect(subject).to eql(session)
75
+ end
76
+
77
+ end
78
+
79
+ describe "#transactional" do
80
+
81
+ subject { session_factory.transactional }
82
+
83
+ it "creates a session whose ID is an internal transactional space identifier" do
84
+ expect(session_factory).to receive(:create).with("http_stub_transactional")
85
+
86
+ subject
87
+ end
88
+
89
+ it "returns the created session" do
90
+ allow(session_factory).to receive(:create).and_return(session)
91
+
92
+ expect(subject).to eql(session)
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,222 @@
1
+ describe HttpStub::Configurer::DSL::Session do
2
+
3
+ let(:id) { "some_session_id" }
4
+ let(:session_facade) { instance_double(HttpStub::Configurer::Server::SessionFacade) }
5
+ let(:server_facade) do
6
+ instance_double(HttpStub::Configurer::Server::Facade, create_session_facade: session_facade)
7
+ end
8
+ let(:default_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
9
+
10
+ let(:block_verifier) { double("BlockVerifier") }
11
+
12
+ let(:session) { described_class.new(id, server_facade, default_stub_template) }
13
+
14
+ it "creates a facade the session uses to interact with the stub server" do
15
+ expect(server_facade).to receive(:create_session_facade).with(id)
16
+
17
+ session
18
+ end
19
+
20
+ describe "#mark_as_default!" do
21
+
22
+ subject { session.mark_as_default! }
23
+
24
+ it "marks the session as the servers default via the session facade" do
25
+ expect(session_facade).to receive(:mark_as_default)
26
+
27
+ subject
28
+ end
29
+
30
+ end
31
+
32
+ describe "#endpoint_template" do
33
+
34
+ let(:block) { lambda { block_verifier.verify } }
35
+ let(:session_endpoint_template) { instance_double(HttpStub::Configurer::DSL::SessionEndpointTemplate) }
36
+
37
+ subject { session.endpoint_template(&block) }
38
+
39
+ before(:example) do
40
+ allow(HttpStub::Configurer::DSL::SessionEndpointTemplate).to receive(:new).and_return(session_endpoint_template)
41
+ end
42
+
43
+ it "creates an endpoint template for the session" do
44
+ expect(HttpStub::Configurer::DSL::SessionEndpointTemplate).to receive(:new).with(session, anything)
45
+
46
+ subject
47
+ end
48
+
49
+ it "creates an endpoint template that extends the default stub template" do
50
+ expect(HttpStub::Configurer::DSL::SessionEndpointTemplate).to receive(:new).with(anything, default_stub_template)
51
+
52
+ subject
53
+ end
54
+
55
+ it "creates an endpoint template using any provided block to initialize the template" do
56
+ allow(HttpStub::Configurer::DSL::SessionEndpointTemplate).to receive(:new).and_yield
57
+ expect(block_verifier).to receive(:verify)
58
+
59
+ subject
60
+ end
61
+
62
+ it "returns the created endpoint template" do
63
+ expect(subject).to eql(session_endpoint_template)
64
+ end
65
+
66
+ end
67
+
68
+ describe "#activate!" do
69
+
70
+ let(:scenario_names) { (1..3).map { |i| "Scenario name #{i}" } }
71
+
72
+ subject { session.activate!(*scenario_names) }
73
+
74
+ it "delegates to the session facade in order to activate the scenarios" do
75
+ expect(session_facade).to receive(:activate).with(scenario_names)
76
+
77
+ subject
78
+ end
79
+
80
+ end
81
+
82
+ describe "#build_stub" do
83
+
84
+ let(:block) { lambda { block_verifier.verify } }
85
+
86
+ subject { session.build_stub(&block) }
87
+
88
+ it "delegates to the servers default stub template" do
89
+ expect(default_stub_template).to receive(:build_stub)
90
+
91
+ subject
92
+ end
93
+
94
+ it "initializes the built stub using the provided block" do
95
+ allow(default_stub_template).to receive(:build_stub).and_yield
96
+ expect(block_verifier).to receive(:verify)
97
+
98
+ subject
99
+ end
100
+
101
+ it "returns the built stub" do
102
+ built_stub = instance_double(HttpStub::Configurer::DSL::StubBuilder)
103
+ allow(default_stub_template).to receive(:build_stub).and_return(built_stub)
104
+
105
+ expect(subject).to eql(built_stub)
106
+ end
107
+
108
+ end
109
+
110
+ describe "#add_stub!" do
111
+
112
+ let(:built_stub) { instance_double(HttpStub::Configurer::Request::Stub) }
113
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder, build: built_stub) }
114
+
115
+ before(:example) { allow(session_facade).to receive(:stub_response) }
116
+
117
+ context "when a stub builder is provided" do
118
+
119
+ subject { session.add_stub!(stub_builder) }
120
+
121
+ it "builds a stub from the provided builder" do
122
+ expect(stub_builder).to receive(:build)
123
+
124
+ subject
125
+ end
126
+
127
+ it "registers the built stub via the session facade" do
128
+ expect(session_facade).to receive(:stub_response).with(built_stub)
129
+
130
+ subject
131
+ end
132
+
133
+ end
134
+
135
+ context "when a block is provided" do
136
+
137
+ let(:block) { lambda { block_verifier.verify } }
138
+
139
+ subject { session.add_stub!(&block) }
140
+
141
+ before(:example) { allow(default_stub_template).to receive(:build_stub).and_return(stub_builder) }
142
+
143
+ it "creates a stub builder via the servers default stub template" do
144
+ expect(default_stub_template).to receive(:build_stub)
145
+
146
+ subject
147
+ end
148
+
149
+ it "supplies the provided block when creating the stub builder" do
150
+ allow(default_stub_template).to receive(:build_stub).and_return(stub_builder).and_yield
151
+ expect(block_verifier).to receive(:verify)
152
+
153
+ subject
154
+ end
155
+
156
+ it "builds a stub from the created builder" do
157
+ expect(stub_builder).to receive(:build)
158
+
159
+ subject
160
+ end
161
+
162
+ it "registers the built stub via the session facade" do
163
+ expect(session_facade).to receive(:stub_response).with(built_stub)
164
+
165
+ subject
166
+ end
167
+
168
+ end
169
+
170
+ end
171
+
172
+ describe "#add_stubs!" do
173
+
174
+ let(:stub_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
175
+
176
+ subject { session.add_stubs!(stub_builders) }
177
+
178
+ it "adds each provided stub" do
179
+ stub_builders.each { |stub_builder| allow(session).to receive(:add_stub!).with(stub_builder) }
180
+
181
+ subject
182
+ end
183
+
184
+ end
185
+
186
+ describe "#reset!" do
187
+
188
+ subject { session.reset! }
189
+
190
+ it "resets the sessions stubs via the session facade" do
191
+ expect(session_facade).to receive(:reset_stubs)
192
+
193
+ subject
194
+ end
195
+
196
+ end
197
+
198
+ describe "#clear!" do
199
+
200
+ subject { session.clear! }
201
+
202
+ it "clears the sessions stubs via the session facade" do
203
+ expect(session_facade).to receive(:clear_stubs)
204
+
205
+ subject
206
+ end
207
+
208
+ end
209
+
210
+ describe "#delete!" do
211
+
212
+ subject { session.delete! }
213
+
214
+ it "deletes the session via the session facade" do
215
+ expect(session_facade).to receive(:delete)
216
+
217
+ subject
218
+ end
219
+
220
+ end
221
+
222
+ end