http_stub 0.15.5 → 0.16.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +37 -27
  3. data/lib/http_stub/configurer.rb +2 -2
  4. data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
  5. data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
  6. data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
  7. data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
  8. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
  9. data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
  10. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
  11. data/lib/http_stub/configurer/request/http/factory.rb +8 -2
  12. data/lib/http_stub/configurer/request/scenario.rb +29 -0
  13. data/lib/http_stub/configurer/server/facade.rb +7 -7
  14. data/lib/http_stub/server/application.rb +21 -14
  15. data/lib/http_stub/server/registry.rb +7 -3
  16. data/lib/http_stub/server/response.rb +3 -3
  17. data/lib/http_stub/server/scenario.rb +12 -0
  18. data/lib/http_stub/server/scenario/activator.rb +25 -0
  19. data/lib/http_stub/server/scenario/controller.rb +36 -0
  20. data/lib/http_stub/server/scenario/instance.rb +36 -0
  21. data/lib/http_stub/server/scenario/request_parser.rb +19 -0
  22. data/lib/http_stub/server/stub.rb +3 -23
  23. data/lib/http_stub/server/stub/controller.rb +30 -0
  24. data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
  25. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
  26. data/lib/http_stub/server/stub/headers.rb +19 -0
  27. data/lib/http_stub/server/stub/instance.rb +31 -0
  28. data/lib/http_stub/server/stub/method.rb +23 -0
  29. data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
  30. data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
  31. data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
  32. data/lib/http_stub/server/stub/registry.rb +31 -0
  33. data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
  34. data/lib/http_stub/server/stub/request_headers.rb +28 -0
  35. data/lib/http_stub/server/stub/request_parameters.rb +23 -0
  36. data/lib/http_stub/server/stub/request_parser.rb +17 -0
  37. data/lib/http_stub/server/stub/response.rb +16 -0
  38. data/lib/http_stub/server/stub/response/base.rb +64 -0
  39. data/lib/http_stub/server/stub/response/file.rb +36 -0
  40. data/lib/http_stub/server/stub/response/text.rb +19 -0
  41. data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
  42. data/lib/http_stub/server/stub/triggers.rb +25 -0
  43. data/lib/http_stub/server/stub/uri.rb +23 -0
  44. data/lib/http_stub/server/views/_scenario.haml +16 -0
  45. data/lib/http_stub/server/views/application.sass +4 -0
  46. data/lib/http_stub/server/views/scenarios.haml +3 -0
  47. data/lib/http_stub/version.rb +1 -1
  48. data/spec/acceptance/activator_spec.rb +81 -0
  49. data/spec/acceptance/configurer_initialization_spec.rb +158 -0
  50. data/spec/acceptance/scenario_spec.rb +91 -0
  51. data/spec/acceptance/stub_control_values_spec.rb +160 -0
  52. data/spec/acceptance/stub_spec.rb +290 -0
  53. data/spec/acceptance/stub_trigger_spec.rb +144 -0
  54. data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
  55. data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
  57. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
  58. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
  59. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
  60. data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
  61. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
  62. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
  63. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
  64. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
  65. data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
  66. data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
  67. data/spec/lib/http_stub/configurer_spec.rb +1 -1
  68. data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
  69. data/spec/lib/http_stub/server/application_spec.rb +40 -38
  70. data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
  71. data/spec/lib/http_stub/server/registry_spec.rb +66 -17
  72. data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
  73. data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
  74. data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
  75. data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
  76. data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
  77. data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
  78. data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
  79. data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
  80. data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
  81. data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
  82. data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
  83. data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
  84. data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
  85. data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
  86. data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
  87. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
  88. data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
  89. data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
  90. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
  91. data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
  92. data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
  93. data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
  94. data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
  95. data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
  96. data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
  97. data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
  98. data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
  99. data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
  100. data/spec/lib/http_stub/server/stub_spec.rb +10 -185
  101. data/spec/spec_helper.rb +10 -5
  102. data/spec/support/configurer_integration.rb +24 -0
  103. data/spec/support/scenario_fixture.rb +33 -0
  104. data/spec/support/stub_fixture.rb +1 -1
  105. metadata +126 -84
  106. data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
  107. data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
  108. data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
  109. data/lib/http_stub/server/exact_value_matcher.rb +0 -13
  110. data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
  111. data/lib/http_stub/server/headers.rb +0 -17
  112. data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
  113. data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
  114. data/lib/http_stub/server/request_header_parser.rb +0 -17
  115. data/lib/http_stub/server/request_parser.rb +0 -29
  116. data/lib/http_stub/server/string_value_matcher.rb +0 -29
  117. data/lib/http_stub/server/stub_activator.rb +0 -30
  118. data/lib/http_stub/server/stub_activator_controller.rb +0 -34
  119. data/lib/http_stub/server/stub_controller.rb +0 -28
  120. data/lib/http_stub/server/stub_headers.rb +0 -24
  121. data/lib/http_stub/server/stub_parameters.rb +0 -21
  122. data/lib/http_stub/server/stub_registry.rb +0 -29
  123. data/lib/http_stub/server/stub_response.rb +0 -14
  124. data/lib/http_stub/server/stub_response/base.rb +0 -62
  125. data/lib/http_stub/server/stub_response/file.rb +0 -34
  126. data/lib/http_stub/server/stub_response/text.rb +0 -17
  127. data/lib/http_stub/server/stub_triggers.rb +0 -23
  128. data/lib/http_stub/server/stub_uri.rb +0 -21
  129. data/lib/http_stub/server/views/stub_activators.haml +0 -6
  130. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
  131. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
  132. data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
  133. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
  134. data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
  135. data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
  136. data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
  137. data/spec/lib/http_stub/server/stub_uri_spec.rb +0 -42
@@ -0,0 +1,144 @@
1
+ describe "Stub trigger acceptance" do
2
+ include_context "configurer integration"
3
+
4
+ let(:configurer) { HttpStub::Examples::ConfigurerWithStubTriggers.new }
5
+
6
+ before(:example) { configurer.class.initialize! }
7
+
8
+ context "when a stub is submitted that contains triggers" do
9
+
10
+ context "with simple response bodies" do
11
+
12
+ let(:triggered_stubs) do
13
+ (1..3).map do |trigger_number|
14
+ stub_server.build_stub do |stub|
15
+ stub.match_requests("/triggered_stub_#{trigger_number}", method: :get)
16
+ stub.respond_with(status: 200 + trigger_number, body: "Triggered stub body #{trigger_number}")
17
+ end
18
+ end
19
+ end
20
+
21
+ before(:example) do
22
+ stub_server.add_stub! do |stub|
23
+ stub.match_requests("/stub_with_triggers", method: :get)
24
+ stub.respond_with(body: "Trigger stub body")
25
+ stub.trigger(triggered_stubs)
26
+ end
27
+ end
28
+
29
+ context "and a request is made matching the stub" do
30
+
31
+ before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/stub_with_triggers") }
32
+
33
+ it "replays the stubbed response" do
34
+ expect(@stub_with_triggers_response.code).to eql(200)
35
+ expect(@stub_with_triggers_response.body).to eql("Trigger stub body")
36
+ end
37
+
38
+ (1..3).each do |trigger_number|
39
+
40
+ context "and then a request matching triggered stub ##{trigger_number} is made" do
41
+
42
+ let(:response) { HTTParty.get("#{server_uri}/triggered_stub_#{trigger_number}") }
43
+
44
+ it "replays the triggered response" do
45
+ expect(response.code).to eql("20#{trigger_number}".to_i)
46
+ expect(response.body).to eql("Triggered stub body #{trigger_number}")
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ context "with a mix of text and file responses" do
58
+
59
+ let(:pdf_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.pdf" }
60
+ let(:pdf_file_trigger) do
61
+ stub_server.build_stub do |stub|
62
+ stub.match_requests("/triggered_stub_pdf_file", method: :get)
63
+ stub.respond_with(
64
+ status: 201,
65
+ headers: { "content-type" => "application/pdf" },
66
+ body: { file: { path: pdf_file_path, name: ::File.basename(pdf_file_path) } }
67
+ )
68
+ end
69
+ end
70
+
71
+ let(:text_body) { "Sample trigger stub body" }
72
+ let(:text_trigger) do
73
+ stub_server.build_stub do |stub|
74
+ stub.match_requests("/triggered_stub_text", method: :get)
75
+ stub.respond_with(status: 202, body: "Sample trigger stub body")
76
+ end
77
+ end
78
+
79
+ let(:txt_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.txt" }
80
+ let(:txt_file_trigger) do
81
+ stub_server.build_stub do |stub|
82
+ stub.match_requests("/triggered_stub_txt_file", method: :get)
83
+ stub.respond_with(
84
+ status: 203,
85
+ headers: { "content-type" => "text/plain" },
86
+ body: { file: { path: txt_file_path, name: ::File.basename(txt_file_path) } }
87
+ )
88
+ end
89
+ end
90
+
91
+ let(:triggered_stubs) { [ pdf_file_trigger, text_trigger, txt_file_trigger ] }
92
+
93
+ before(:example) do
94
+ stub_server.add_stub! do |stub|
95
+ stub.match_requests("/stub_with_triggers", method: :get)
96
+ stub.respond_with(body: "Trigger stub body")
97
+ stub.trigger(triggered_stubs)
98
+ end
99
+ end
100
+
101
+ context "and a request is made matching the stub" do
102
+
103
+ before(:example) { HTTParty.get("#{server_uri}/stub_with_triggers") }
104
+
105
+ context "and then a request matching a triggered stub returning a PDF file is made" do
106
+
107
+ let(:response) { HTTParty.get("#{server_uri}/triggered_stub_pdf_file") }
108
+
109
+ it "replays the triggered response" do
110
+ expect(response.code).to eql(201)
111
+ expect_response_to_contain_file(pdf_file_path)
112
+ end
113
+
114
+ end
115
+
116
+ context "and then a request matching a triggered stub returning texrt is made" do
117
+
118
+ let(:response) { HTTParty.get("#{server_uri}/triggered_stub_text") }
119
+
120
+ it "replays the triggered response" do
121
+ expect(response.code).to eql(202)
122
+ expect(response.body).to eql(text_body)
123
+ end
124
+
125
+ end
126
+
127
+ context "and then a request matching a triggered stub returning a text file is made" do
128
+
129
+ let(:response) { HTTParty.get("#{server_uri}/triggered_stub_txt_file") }
130
+
131
+ it "replays the triggered response" do
132
+ expect(response.code).to eql(203)
133
+ expect(response.parsed_response).to eql(::File.read(txt_file_path))
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -1,4 +1,4 @@
1
- describe HttpStub::Configurer::DeprecatedDSL do
1
+ describe HttpStub::Configurer::DSL::Deprecated do
2
2
 
3
3
  let(:stub_server) { double("StubServer") }
4
4
 
@@ -98,7 +98,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
98
98
 
99
99
  shared_examples_for "a deprecated DSL object" do
100
100
 
101
- [ :recall_stubs!, :clear_stubs!, :clear_activators! ].each do |stub_server_delegate_method|
101
+ [ :recall_stubs!, :clear_stubs! ].each do |stub_server_delegate_method|
102
102
 
103
103
  describe "##{stub_server_delegate_method}" do
104
104
 
@@ -114,8 +114,6 @@ describe HttpStub::Configurer::DeprecatedDSL do
114
114
 
115
115
  describe "#server_has_started!" do
116
116
 
117
- let(:activation_uri) { "http://some/activation/uri" }
118
-
119
117
  it "informs the stub server that it has started" do
120
118
  expect(stub_server).to receive(:has_started!)
121
119
 
@@ -126,7 +124,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
126
124
 
127
125
  describe "#activate!" do
128
126
 
129
- let(:activation_uri) { "http://some/activation/uri" }
127
+ let(:activation_uri) { "/some/activation/uri" }
130
128
 
131
129
  it "delegates to the stub server available to the dsl" do
132
130
  expect(stub_server).to receive(:activate!).with(activation_uri)
@@ -142,7 +140,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
142
140
 
143
141
  include_context "a method stubbing a response"
144
142
 
145
- let(:builder) { instance_double(HttpStub::Configurer::Request::StubBuilder) }
143
+ let(:builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
146
144
 
147
145
  subject { dsl_object.send(method, stub_uri, options) }
148
146
 
@@ -160,11 +158,11 @@ describe HttpStub::Configurer::DeprecatedDSL do
160
158
 
161
159
  describe "#stub_activator" do
162
160
 
163
- let(:activation_uri) { "http://some/activator/uri" }
161
+ let(:activation_uri) { "/some/activation/uri" }
164
162
 
165
163
  include_context "a method stubbing a response"
166
164
 
167
- let(:builder) { instance_double(HttpStub::Configurer::Request::StubActivatorBuilder) }
165
+ let(:builder) { instance_double(HttpStub::Configurer::DSL::StubActivatorBuilder) }
168
166
 
169
167
  subject { dsl_object.stub_activator(activation_uri, stub_uri, options) }
170
168
 
@@ -187,12 +185,22 @@ describe HttpStub::Configurer::DeprecatedDSL do
187
185
 
188
186
  end
189
187
 
188
+ describe "#clear_activators!" do
189
+
190
+ it "informs the stub server to clear scenarios" do
191
+ expect(stub_server).to receive(:clear_scenarios!)
192
+
193
+ dsl_object.clear_activators!
194
+ end
195
+
196
+ end
197
+
190
198
  end
191
199
 
192
200
  context "when included in a class" do
193
201
 
194
- class HttpStub::Configurer::DeprecatedDSLTest
195
- include HttpStub::Configurer::DeprecatedDSL
202
+ class HttpStub::Configurer::DSL::DeprecatedTest
203
+ include HttpStub::Configurer::DSL::Deprecated
196
204
 
197
205
  class << self
198
206
 
@@ -207,8 +215,8 @@ describe HttpStub::Configurer::DeprecatedDSL do
207
215
  describe "the class in which the module was included" do
208
216
 
209
217
  let(:dsl_object) do
210
- HttpStub::Configurer::DeprecatedDSLTest.stub_server = stub_server
211
- HttpStub::Configurer::DeprecatedDSLTest
218
+ HttpStub::Configurer::DSL::DeprecatedTest.stub_server = stub_server
219
+ HttpStub::Configurer::DSL::DeprecatedTest
212
220
  end
213
221
 
214
222
  it_behaves_like "a deprecated DSL object"
@@ -218,7 +226,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
218
226
  describe "an instance of the class in which the module was included" do
219
227
 
220
228
  let(:dsl_object) do
221
- dsl_object = HttpStub::Configurer::DeprecatedDSLTest.new
229
+ dsl_object = HttpStub::Configurer::DSL::DeprecatedTest.new
222
230
  dsl_object.stub_server = stub_server
223
231
  dsl_object
224
232
  end
@@ -1,8 +1,12 @@
1
- describe HttpStub::Configurer::Server::DSL do
1
+ describe HttpStub::Configurer::DSL::Sanctioned do
2
2
 
3
3
  let(:server_facade) { instance_double(HttpStub::Configurer::Server::Facade) }
4
4
 
5
- let(:dsl) { HttpStub::Configurer::Server::DSL.new(server_facade) }
5
+ let(:dsl) { HttpStub::Configurer::DSL::Sanctioned.new(server_facade) }
6
+
7
+ it "produces stub builders" do
8
+ expect(dsl).to be_a(HttpStub::Configurer::DSL::StubBuilderProducer)
9
+ end
6
10
 
7
11
  describe "#has_started!" do
8
12
 
@@ -14,74 +18,10 @@ describe HttpStub::Configurer::Server::DSL do
14
18
 
15
19
  end
16
20
 
17
- describe "#build_stub" do
18
-
19
- let(:stub_builder) { instance_double(HttpStub::Configurer::Request::StubBuilder) }
20
-
21
- before(:example) do
22
- allow(HttpStub::Configurer::Request::StubBuilder).to receive(:new).and_return(stub_builder)
23
- end
24
-
25
- subject { dsl.build_stub }
26
-
27
- context "when response defaults have been established" do
28
-
29
- let(:response_defaults) { { key: "value" } }
30
-
31
- before(:example) { dsl.response_defaults = { key: "value" } }
32
-
33
- it "creates a stub builder containing the response defaults" do
34
- expect(HttpStub::Configurer::Request::StubBuilder).to receive(:new).with(response_defaults)
35
-
36
- subject
37
- end
38
-
39
- end
40
-
41
- context "when no response defaults have been established" do
42
-
43
- it "creates a stub builder with empty response defaults" do
44
- expect(HttpStub::Configurer::Request::StubBuilder).to receive(:new).with({})
45
-
46
- subject
47
- end
48
-
49
- end
50
-
51
- context "when a block is provided" do
52
-
53
- let(:block) { lambda { |_stub| "some block" } }
54
-
55
- subject { dsl.build_stub(&block) }
56
-
57
- it "yields the created builder to the provided block" do
58
- expect(block).to receive(:call).with(stub_builder)
59
-
60
- subject
61
- end
62
-
63
- it "returns the created builder" do
64
- expect(subject).to eql(stub_builder)
65
- end
66
-
67
- end
68
-
69
- context "when a block is not provided" do
70
-
71
- subject { dsl.build_stub }
72
-
73
- it "returns the built stub" do
74
- expect(subject).to eql(stub_builder)
75
- end
76
-
77
- end
78
-
79
- end
80
-
81
21
  describe "#add_stub!" do
82
22
 
83
23
  let(:stub) { instance_double(HttpStub::Configurer::Request::Stub) }
84
- let(:stub_builder) { instance_double(HttpStub::Configurer::Request::StubBuilder, build: stub) }
24
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
85
25
 
86
26
  before(:example) { allow(server_facade).to receive(:stub_response) }
87
27
 
@@ -113,12 +53,12 @@ describe HttpStub::Configurer::Server::DSL do
113
53
 
114
54
  let(:block) { lambda { |_stub| "some block" } }
115
55
 
116
- before(:example) { allow(HttpStub::Configurer::Request::StubBuilder).to receive(:new).and_return(stub_builder) }
56
+ before(:example) { allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder) }
117
57
 
118
58
  subject { dsl.add_stub!(&block) }
119
59
 
120
60
  it "creates a stub builder" do
121
- expect(HttpStub::Configurer::Request::StubBuilder).to receive(:new)
61
+ expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new)
122
62
 
123
63
  subject
124
64
  end
@@ -135,48 +75,85 @@ describe HttpStub::Configurer::Server::DSL do
135
75
 
136
76
  end
137
77
 
138
- describe "#add_stubs!" do
78
+ describe "#add_scenario!" do
139
79
 
140
- context "when multiple stub builders are provided" do
80
+ let(:scenario_name) { "some/scenario/name" }
81
+ let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
82
+ let(:scenario_builder) { instance_double(HttpStub::Configurer::DSL::ScenarioBuilder, build: scenario) }
141
83
 
142
- let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
143
- let(:stub_builders) do
144
- stubs.map { |stub| instance_double(HttpStub::Configurer::Request::StubBuilder, build: stub) }
145
- end
84
+ before(:example) { allow(server_facade).to receive(:define_scenario) }
85
+
86
+ let(:block) { lambda { |_scenario| "some block" } }
87
+
88
+ before(:example) do
89
+ allow(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).and_return(scenario_builder)
90
+ end
91
+
92
+ subject { dsl.add_scenario!(scenario_name, &block) }
93
+
94
+ context "when response defaults have been established" do
95
+
96
+ let(:response_defaults) { { key: "value" } }
97
+
98
+ before(:example) { dsl.response_defaults = { key: "value" } }
146
99
 
147
- subject { dsl.add_stubs!(stub_builders) }
100
+ it "creates a scenario builder containing the response defaults" do
101
+ expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(response_defaults, anything)
148
102
 
149
- before(:example) { allow(server_facade).to receive(:stub_response) }
103
+ subject
104
+ end
150
105
 
151
- it "builds each stub" do
152
- stubs.zip(stub_builders).each { |stub, stub_builder| expect(stub_builder).to receive(:build).and_return(stub) }
106
+ it "creates a scenario builder containing the provided scenario name" do
107
+ expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(anything, scenario_name)
153
108
 
154
109
  subject
155
110
  end
156
111
 
157
- it "informs the server facade of each built stub" do
158
- stubs.each { |stub| expect(server_facade).to receive(:stub_response).with(stub) }
112
+ end
113
+
114
+ context "when no response defaults have been established" do
115
+
116
+ it "creates a scenario builder with empty response defaults" do
117
+ expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with({}, anything)
159
118
 
160
119
  subject
161
120
  end
162
121
 
163
122
  end
164
123
 
124
+ it "yields the created builder to the provided block" do
125
+ expect(block).to receive(:call).with(scenario_builder)
126
+
127
+ subject
128
+ end
129
+
130
+ it "builds the scenario request" do
131
+ expect(scenario_builder).to receive(:build).and_return(scenario)
132
+
133
+ subject
134
+ end
135
+
136
+ it "informs the server facade to submit the scenario request" do
137
+ expect(server_facade).to receive(:define_scenario).with(scenario)
138
+
139
+ subject
140
+ end
141
+
165
142
  end
166
143
 
167
144
  describe "#add_activator!" do
168
145
 
169
- let(:stub_activator) { instance_double(HttpStub::Configurer::Request::StubActivator) }
146
+ let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
170
147
  let(:stub_activator_builder) do
171
- instance_double(HttpStub::Configurer::Request::StubActivatorBuilder, build: stub_activator)
148
+ instance_double(HttpStub::Configurer::DSL::StubActivatorBuilder, build: scenario)
172
149
  end
173
150
 
174
- before(:example) { allow(server_facade).to receive(:stub_activator) }
151
+ before(:example) { allow(server_facade).to receive(:define_scenario) }
175
152
 
176
153
  let(:block) { lambda { |_activator| "some block" } }
177
154
 
178
155
  before(:example) do
179
- allow(HttpStub::Configurer::Request::StubActivatorBuilder).to receive(:new).and_return(stub_activator_builder)
156
+ allow(HttpStub::Configurer::DSL::StubActivatorBuilder).to receive(:new).and_return(stub_activator_builder)
180
157
  end
181
158
 
182
159
  subject { dsl.add_activator!(&block) }
@@ -188,7 +165,7 @@ describe HttpStub::Configurer::Server::DSL do
188
165
  before(:example) { dsl.response_defaults = { key: "value" } }
189
166
 
190
167
  it "creates a stub activator builder containing the response defaults" do
191
- expect(HttpStub::Configurer::Request::StubActivatorBuilder).to receive(:new).with(response_defaults)
168
+ expect(HttpStub::Configurer::DSL::StubActivatorBuilder).to receive(:new).with(response_defaults)
192
169
 
193
170
  subject
194
171
  end
@@ -198,7 +175,7 @@ describe HttpStub::Configurer::Server::DSL do
198
175
  context "when no response defaults have been established" do
199
176
 
200
177
  it "creates a stub activator builder with empty response defaults" do
201
- expect(HttpStub::Configurer::Request::StubActivatorBuilder).to receive(:new).with({})
178
+ expect(HttpStub::Configurer::DSL::StubActivatorBuilder).to receive(:new).with({})
202
179
 
203
180
  subject
204
181
  end
@@ -211,14 +188,14 @@ describe HttpStub::Configurer::Server::DSL do
211
188
  subject
212
189
  end
213
190
 
214
- it "builds the stub activator request" do
215
- expect(stub_activator_builder).to receive(:build).and_return(stub_activator)
191
+ it "builds a scenario request" do
192
+ expect(stub_activator_builder).to receive(:build).and_return(scenario)
216
193
 
217
194
  subject
218
195
  end
219
196
 
220
- it "informs the server facade to submit the stub activator request" do
221
- expect(server_facade).to receive(:stub_activator).with(stub_activator)
197
+ it "informs the server facade to submit the scenario request" do
198
+ expect(server_facade).to receive(:define_scenario).with(scenario)
222
199
 
223
200
  subject
224
201
  end
@@ -227,12 +204,12 @@ describe HttpStub::Configurer::Server::DSL do
227
204
 
228
205
  describe "#activate!" do
229
206
 
230
- let(:uri) { "/some/activation/uri" }
207
+ let(:scenario_name) { "/some/scenario/name" }
231
208
 
232
209
  it "delegates to the server facade" do
233
- expect(server_facade).to receive(:activate).with(uri)
210
+ expect(server_facade).to receive(:activate).with(scenario_name)
234
211
 
235
- dsl.activate!(uri)
212
+ dsl.activate!(scenario_name)
236
213
  end
237
214
 
238
215
  end
@@ -267,12 +244,12 @@ describe HttpStub::Configurer::Server::DSL do
267
244
 
268
245
  end
269
246
 
270
- describe "#clear_activators!" do
247
+ describe "#clear_scenarios!" do
271
248
 
272
249
  it "delegates to the server facade" do
273
- expect(server_facade).to receive(:clear_activators)
250
+ expect(server_facade).to receive(:clear_scenarios)
274
251
 
275
- dsl.clear_activators!
252
+ dsl.clear_scenarios!
276
253
  end
277
254
 
278
255
  end