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
@@ -1,6 +1,6 @@
1
1
  describe HttpStub::Configurer::Request::ControllableValue do
2
2
 
3
- describe ".format" do
3
+ describe "::format" do
4
4
 
5
5
  let(:value) { "some value" }
6
6
 
@@ -23,19 +23,19 @@ describe HttpStub::Configurer::Request::Http::Factory do
23
23
 
24
24
  end
25
25
 
26
- describe "::stub_activator" do
26
+ describe "::scenario" do
27
27
 
28
- let(:model) { instance_double(HttpStub::Configurer::Request::StubActivator) }
28
+ let(:model) { instance_double(HttpStub::Configurer::Request::Scenario) }
29
29
  let(:multipart_request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
30
30
 
31
- subject { HttpStub::Configurer::Request::Http::Factory.stub_activator(model) }
31
+ subject { HttpStub::Configurer::Request::Http::Factory.scenario(model) }
32
32
 
33
33
  before(:example) do
34
34
  allow(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).and_return(multipart_request)
35
35
  end
36
36
 
37
- it "creates a multipart request for the stub activators endpoint with the provided model" do
38
- expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with("/stubs/activators", model)
37
+ it "creates a multipart request for the stub scenarios endpoint with the provided model" do
38
+ expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with("/stubs/scenarios", model)
39
39
 
40
40
  subject
41
41
  end
@@ -46,6 +46,47 @@ describe HttpStub::Configurer::Request::Http::Factory do
46
46
 
47
47
  end
48
48
 
49
+ describe "::activate" do
50
+
51
+ let(:uri) { "some/activate/uri" }
52
+ let(:basic_request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
53
+
54
+ subject { HttpStub::Configurer::Request::Http::Factory.activate(uri) }
55
+
56
+ before(:example) do
57
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(basic_request)
58
+ end
59
+
60
+ context "when the uri is not prefixed with '/'" do
61
+
62
+ let(:uri) { "uri/not/prefixed/with/forward/slash" }
63
+
64
+ it "creates a get request with the uri prefixed with '/'" do
65
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:get).with("/#{uri}")
66
+
67
+ subject
68
+ end
69
+
70
+ end
71
+
72
+ context "when the uri is prefixed with '/'" do
73
+
74
+ let(:uri) { "/uri/prefixed/with/forward/slash" }
75
+
76
+ it "creates a get request with the provided uri" do
77
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:get).with(uri)
78
+
79
+ subject
80
+ end
81
+
82
+ end
83
+
84
+ it "returns the created request" do
85
+ expect(subject).to eql(basic_request)
86
+ end
87
+
88
+ end
89
+
49
90
  describe "::get" do
50
91
 
51
92
  let(:path) { "some/get/path" }
@@ -1,6 +1,6 @@
1
1
  describe HttpStub::Configurer::Request::Omittable do
2
2
 
3
- describe ".format" do
3
+ describe "::format" do
4
4
 
5
5
  context "when the value is a hash" do
6
6
 
@@ -0,0 +1,69 @@
1
+ describe HttpStub::Configurer::Request::Scenario do
2
+
3
+ let(:name) { "some/scenario/name" }
4
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
5
+ let(:triggered_scenario_names) { (1..3).map { |i| "triggered/scenario/name/#{i}" } }
6
+
7
+ let(:scenario) do
8
+ HttpStub::Configurer::Request::Scenario.new(
9
+ name: name, stubs: stubs, triggered_scenario_names: triggered_scenario_names
10
+ )
11
+ end
12
+
13
+ describe "#payload" do
14
+
15
+ let(:stub_payloads) { stubs.each_with_index.map { |_stub, i| { stub_payload_key: "stub payload value #{i}" } } }
16
+
17
+ subject { scenario.payload }
18
+
19
+ before(:example) do
20
+ stubs.zip(stub_payloads).each { |stub, payload| allow(stub).to receive(:payload).and_return(payload) }
21
+ end
22
+
23
+ it "returns a hash containing the scenario's name" do
24
+ expect(subject).to include(name: name)
25
+ end
26
+
27
+ it "returns a hash containing the stub payloads" do
28
+ expect(subject).to include(stubs: stub_payloads)
29
+ end
30
+
31
+ it "returns a hash containing the uris to activate" do
32
+ expect(subject).to include(triggered_scenario_names: triggered_scenario_names)
33
+ end
34
+
35
+ end
36
+
37
+ describe "#response_files" do
38
+
39
+ let(:stub_response_files) do
40
+ stubs.map { (1..3).map { instance_double(HttpStub::Configurer::Request::StubResponseFile) } }
41
+ end
42
+
43
+ subject { scenario.response_files }
44
+
45
+ before(:example) do
46
+ stubs.zip(stub_response_files).each { |stub, files| allow(stub).to receive(:response_files).and_return(files) }
47
+ end
48
+
49
+ it "delegates to the stubs" do
50
+ stubs.zip(stub_response_files).each { |stub, files| expect(stub).to receive(:response_files).and_return(files) }
51
+
52
+ subject
53
+ end
54
+
55
+ it "returns the accummulation of all stub files" do
56
+ expect(subject).to eql(stub_response_files.flatten)
57
+ end
58
+
59
+ end
60
+
61
+ describe "#to_s" do
62
+
63
+ it "returns the scenario's name" do
64
+ expect(scenario.to_s).to eql(name)
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -19,7 +19,7 @@ describe HttpStub::Configurer::Request::Stub do
19
19
  payload: trigger_payload, response_files: trigger_files)
20
20
  end
21
21
  let(:trigger_builders) do
22
- [ instance_double(HttpStub::Configurer::Request::StubBuilder, build: trigger) ]
22
+ [ instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger) ]
23
23
  end
24
24
 
25
25
  end
@@ -35,7 +35,7 @@ describe HttpStub::Configurer::Request::Stub do
35
35
  end
36
36
  let(:trigger_builders) do
37
37
  triggers.map do |trigger|
38
- instance_double(HttpStub::Configurer::Request::StubBuilder, build: trigger)
38
+ instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger)
39
39
  end
40
40
  end
41
41
 
@@ -52,26 +52,26 @@ describe HttpStub::Configurer::Server::Facade do
52
52
 
53
53
  end
54
54
 
55
- describe "#stub_activator" do
55
+ describe "#define_scenario" do
56
56
 
57
57
  let(:model_description) { "some model description" }
58
- let(:model) { instance_double(HttpStub::Configurer::Request::StubActivator, to_s: model_description) }
58
+ let(:model) { instance_double(HttpStub::Configurer::Request::Scenario, to_s: model_description) }
59
59
  let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
60
60
 
61
- subject { facade.stub_activator(model) }
61
+ subject { facade.define_scenario(model) }
62
62
 
63
63
  before(:example) do
64
64
  allow(request_processor).to receive(:submit)
65
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:stub_activator).and_return(request)
65
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:scenario).and_return(request)
66
66
  end
67
67
 
68
- it "creates a stub activator request with the provided model" do
69
- expect(HttpStub::Configurer::Request::Http::Factory).to receive(:stub_activator).with(model)
68
+ it "creates a scenario request with the provided model" do
69
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:scenario).with(model)
70
70
 
71
71
  subject
72
72
  end
73
73
 
74
- it "submits the stub activator request via the request processor" do
74
+ it "submits the scenario request via the request processor" do
75
75
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
76
76
 
77
77
  subject
@@ -79,7 +79,7 @@ describe HttpStub::Configurer::Server::Facade do
79
79
 
80
80
  it "describes the model via its string representation" do
81
81
  expect(request_processor).to(
82
- receive(:submit).with(hash_including(description: "registering activator '#{model_description}'"))
82
+ receive(:submit).with(hash_including(description: "registering scenario '#{model_description}'"))
83
83
  )
84
84
 
85
85
  subject
@@ -95,12 +95,12 @@ describe HttpStub::Configurer::Server::Facade do
95
95
  subject { facade.activate(uri) }
96
96
 
97
97
  before(:example) do
98
- allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(request)
98
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:activate).and_return(request)
99
99
  allow(request_processor).to receive(:submit)
100
100
  end
101
101
 
102
- it "creates a GET request for the uri" do
103
- expect(HttpStub::Configurer::Request::Http::Factory).to receive(:get).with(uri).and_return(request)
102
+ it "creates an activation request for the uri" do
103
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:activate).with(uri).and_return(request)
104
104
 
105
105
  subject
106
106
  end
@@ -212,20 +212,20 @@ describe HttpStub::Configurer::Server::Facade do
212
212
 
213
213
  end
214
214
 
215
- describe "#clear_activators" do
215
+ describe "#clear_scenarios" do
216
216
 
217
217
  let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
218
218
 
219
- subject { facade.clear_activators }
219
+ subject { facade.clear_scenarios }
220
220
 
221
221
  before(:example) do
222
222
  allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
223
223
  allow(request_processor).to receive(:submit)
224
224
  end
225
225
 
226
- it "creates a DELETE request for the /stubs/activators endpoint" do
226
+ it "creates a DELETE request for the /stubs/scenarios endpoint" do
227
227
  expect(HttpStub::Configurer::Request::Http::Factory).to(
228
- receive(:delete).with("/stubs/activators").and_return(request)
228
+ receive(:delete).with("/stubs/scenarios").and_return(request)
229
229
  )
230
230
 
231
231
  subject
@@ -237,8 +237,8 @@ describe HttpStub::Configurer::Server::Facade do
237
237
  subject
238
238
  end
239
239
 
240
- it "describes the request as clearing the server stub activators" do
241
- expect(request_processor).to receive(:submit).with(hash_including(description: "clearing activators"))
240
+ it "describes the request as clearing the server scenarios" do
241
+ expect(request_processor).to receive(:submit).with(hash_including(description: "clearing scenarios"))
242
242
 
243
243
  subject
244
244
  end
@@ -7,7 +7,7 @@ describe HttpStub::Configurer do
7
7
  port "8888"
8
8
  end
9
9
 
10
- describe ".get_base_uri" do
10
+ describe "::get_base_uri" do
11
11
 
12
12
  it "returns a uri that combines the provided host and port" do
13
13
  expect(TestableConfigurer.get_base_uri).to include("some_host:8888")
@@ -32,10 +32,10 @@ describe HttpStub::Server::Application, "when the server is running" do
32
32
 
33
33
  end
34
34
 
35
- describe "and a configurer with multiple stub activators is initialized" do
35
+ describe "and a configurer with multiple scenarios is initialized" do
36
36
 
37
37
  before(:context) do
38
- configurer = HttpStub::Examples::ConfigurerWithClassActivators
38
+ configurer = HttpStub::Examples::ConfigurerWithExhaustiveScenarios
39
39
  configurer.host(server_host)
40
40
  configurer.port(server_port)
41
41
  configurer.initialize!
@@ -70,7 +70,7 @@ describe HttpStub::Server::Application, "when the server is running" do
70
70
  it "returns a response whose body contains the request headers of each stub trigger" do
71
71
  (1..3).each do |stub_number|
72
72
  (1..3).each do |trigger_number|
73
- expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
73
+ expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
74
74
  expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
75
75
  expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
76
76
  end
@@ -86,7 +86,7 @@ describe HttpStub::Server::Application, "when the server is running" do
86
86
  it "returns a response whose body contains the parameters of each stub trigger" do
87
87
  (1..3).each do |stub_number|
88
88
  (1..3).each do |trigger_number|
89
- expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
89
+ expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
90
90
  expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
91
91
  expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
92
92
  end
@@ -107,7 +107,7 @@ describe HttpStub::Server::Application, "when the server is running" do
107
107
 
108
108
  it "returns a response whose body contains the response headers of each stub" do
109
109
  (1..3).each do |stub_number|
110
- expected_header_key = "response_header_#{stub_number}"
110
+ expected_header_key = "response_header_#{stub_number}"
111
111
  expected_header_value = "response_header_value_#{stub_number}"
112
112
  expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
113
113
  end
@@ -116,7 +116,7 @@ describe HttpStub::Server::Application, "when the server is running" do
116
116
  it "returns a response whose body contains the response headers of each stub trigger" do
117
117
  (1..3).each do |stub_number|
118
118
  (1..3).each do |trigger_number|
119
- expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
119
+ expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
120
120
  expected_header_value = "response_header_value_#{stub_number}_trigger_#{trigger_number}"
121
121
  expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
122
122
  end
@@ -139,7 +139,7 @@ describe HttpStub::Server::Application, "when the server is running" do
139
139
  it "returns a response whose body contains the response body of each stub trigger" do
140
140
  (1..3).each do |stub_number|
141
141
  (1..3).each do |trigger_number|
142
- expect(response.body).to match(/Body of activator #{stub_number}_trigger_#{trigger_number}/)
142
+ expect(response.body).to match(/Body of scenario stub #{stub_number}_trigger_#{trigger_number}/)
143
143
  end
144
144
  end
145
145
  end
@@ -158,13 +158,23 @@ describe HttpStub::Server::Application, "when the server is running" do
158
158
 
159
159
  end
160
160
 
161
- describe "GET /stubs/activators" do
161
+ describe "GET /stubs/scenarios" do
162
162
 
163
- let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
163
+ let(:response) { HTTParty.get("#{server_uri}/stubs/scenarios") }
164
164
 
165
- it "returns response whose body contains links to each activator in alphabetical order" do
166
- response_document.css("a.activator").each_with_index do |link, i|
167
- expect(link['href']).to eql("/activator_#{i + 1}")
165
+ it "returns a response whose body contains links to each scenario in alphabetical order" do
166
+ expected_scenario_links = %w{ nested_scenario scenario }.map do |scenario_name_prefix|
167
+ (1..3).map { |i| "/#{scenario_name_prefix}_#{i}" }
168
+ end.flatten
169
+
170
+ scenario_links = response_document.css("a.scenario").map { |link| link['href'] }
171
+
172
+ expect(scenario_links).to eql(expected_scenario_links)
173
+ end
174
+
175
+ it "returns a response whose body contains links to the scenarios triggered by each scenario" do
176
+ response_document.css("a.triggered_scenario").each_with_index do |link, i|
177
+ expect(link['href']).to eql("/nested_scenario_#{i + 1}")
168
178
  end
169
179
  end
170
180
 
@@ -176,7 +186,7 @@ describe HttpStub::Server::Application, "when the server is running" do
176
186
 
177
187
  describe "when multiple stubs are configured" do
178
188
 
179
- before(:context) { (1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") } }
189
+ before(:context) { (1..3).each { |i| HTTParty.get("#{server_uri}/scenario_#{i}") } }
180
190
 
181
191
  let(:response) { HTTParty.get("#{server_uri}/stubs") }
182
192
 
@@ -4,42 +4,42 @@ describe HttpStub::Server::Application do
4
4
  let(:response) { last_response }
5
5
  let(:response_body) { response.body.to_s }
6
6
 
7
- let(:stub_registry) { instance_double(HttpStub::Server::StubRegistry).as_null_object }
8
- let(:stub_activator_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
7
+ let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
8
+ let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
9
9
 
10
- let(:stub_controller) { instance_double(HttpStub::Server::StubController).as_null_object }
11
- let(:stub_activator_controller) { instance_double(HttpStub::Server::StubActivatorController).as_null_object }
10
+ let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller).as_null_object }
11
+ let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller).as_null_object }
12
12
 
13
13
  let(:response_pipeline) { instance_double(HttpStub::Server::ResponsePipeline, process: nil) }
14
14
 
15
15
  let(:app) { HttpStub::Server::Application.new! }
16
16
 
17
17
  before(:example) do
18
- allow(HttpStub::Server::StubRegistry).to receive(:new).and_return(stub_registry)
19
- allow(HttpStub::Server::Registry).to receive(:new).with("stub_activator").and_return(stub_activator_registry)
20
- allow(HttpStub::Server::StubController).to receive(:new).and_return(stub_controller)
21
- allow(HttpStub::Server::StubActivatorController).to receive(:new).and_return(stub_activator_controller)
18
+ allow(HttpStub::Server::Stub::Registry).to receive(:new).and_return(stub_registry)
19
+ allow(HttpStub::Server::Registry).to receive(:new).with("scenario").and_return(scenario_registry)
20
+ allow(HttpStub::Server::Stub::Controller).to receive(:new).and_return(stub_controller)
21
+ allow(HttpStub::Server::Scenario::Controller).to receive(:new).and_return(scenario_controller)
22
22
  allow(HttpStub::Server::ResponsePipeline).to receive(:new).and_return(response_pipeline)
23
23
  end
24
24
 
25
- context "when a stub insertion request is received" do
25
+ context "when a stub registration request is received" do
26
26
 
27
- let(:stub_controller_response) { instance_double(HttpStub::Server::StubResponse::Base) }
27
+ let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
28
28
 
29
29
  subject do
30
30
  post "/stubs", { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } }.to_json
31
31
  end
32
32
 
33
- before(:example) { allow(stub_controller).to receive(:register).and_return(stub_controller_response) }
33
+ before(:example) { allow(stub_controller).to receive(:register).and_return(registration_response) }
34
34
 
35
- it "registers the inserted stub via the controller" do
36
- expect(stub_controller).to receive(:register).and_return(stub_controller_response)
35
+ it "registers the stub via the stub controller" do
36
+ expect(stub_controller).to receive(:register).and_return(registration_response)
37
37
 
38
38
  subject
39
39
  end
40
40
 
41
41
  it "processes the stub controllers response via the response pipeline" do
42
- expect(response_pipeline).to receive(:process).with(stub_controller_response)
42
+ expect(response_pipeline).to receive(:process).with(registration_response)
43
43
 
44
44
  subject
45
45
  end
@@ -100,39 +100,41 @@ describe HttpStub::Server::Application do
100
100
 
101
101
  end
102
102
 
103
- context "when a stub activator insertion request is received" do
103
+ context "when a scenario registration request is received" do
104
104
 
105
- let(:stub_activator_response) { instance_double(HttpStub::Server::StubResponse::Base) }
105
+ let(:registration_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
106
106
 
107
- before(:example) { allow(stub_activator_controller).to receive(:register).and_return(stub_activator_response) }
107
+ before(:example) { allow(scenario_controller).to receive(:register).and_return(registration_response) }
108
108
 
109
109
  subject do
110
- post "/stubs/activators", {
111
- activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
112
- response: { status: 200, body: "Foo" }
113
- }.to_json
110
+ post "/stubs/scenarios",
111
+ {
112
+ uri: "/a_scenario_path",
113
+ stubs: [ { uri: "/a_path", method: "a method", response: { status: 200, body: "Foo" } } ],
114
+ triggered_scenario_names: [ "some/uri/to/activate" ]
115
+ }.to_json
114
116
  end
115
117
 
116
- it "registers the insertion via the stub activator controller" do
117
- expect(stub_activator_controller).to receive(:register).and_return(stub_activator_response)
118
+ it "registers the scenario via the scenario controller" do
119
+ expect(scenario_controller).to receive(:register).and_return(registration_response)
118
120
 
119
121
  subject
120
122
  end
121
123
 
122
- it "processes the stub activators response via the response pipeline" do
123
- expect(response_pipeline).to receive(:process).with(stub_activator_response)
124
+ it "processes the scenarion controllers response via the response pipeline" do
125
+ expect(response_pipeline).to receive(:process).with(registration_response)
124
126
 
125
127
  subject
126
128
  end
127
129
 
128
130
  end
129
131
 
130
- context "when a request to clear the stub activators has been received" do
132
+ context "when a request to clear the scenarios has been received" do
131
133
 
132
- subject { delete "/stubs/activators" }
134
+ subject { delete "/stubs/scenarios" }
133
135
 
134
- it "delegates clearing to the stub activator controller" do
135
- expect(stub_activator_controller).to receive(:clear)
136
+ it "delegates clearing to the scenario controller" do
137
+ expect(scenario_controller).to receive(:clear)
136
138
 
137
139
  subject
138
140
  end
@@ -147,7 +149,7 @@ describe HttpStub::Server::Application do
147
149
 
148
150
  context "when another type of request is received" do
149
151
 
150
- let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base) }
152
+ let(:stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
151
153
 
152
154
  subject { get "/a_path" }
153
155
 
@@ -167,28 +169,28 @@ describe HttpStub::Server::Application do
167
169
 
168
170
  context "and the stub controller does not replay a response" do
169
171
 
170
- let(:stub_activator_response) { double(HttpStub::Server::StubResponse::Base, serve_on: nil) }
172
+ let(:scenario_response) { double(HttpStub::Server::Stub::Response::Base, serve_on: nil) }
171
173
 
172
174
  before(:example) do
173
175
  allow(stub_response).to receive(:empty?).and_return(true)
174
- allow(stub_activator_controller).to receive(:activate).and_return(stub_activator_response)
176
+ allow(scenario_controller).to receive(:activate).and_return(scenario_response)
175
177
  end
176
178
 
177
- context "but the stub activator controller activates a stub" do
179
+ context "but the scenario controller activates a scenario" do
178
180
 
179
- before(:each) { allow(stub_activator_response).to receive(:empty?).and_return(false) }
181
+ before(:each) { allow(scenario_response).to receive(:empty?).and_return(false) }
180
182
 
181
- it "processes the stub activator response via the response pipeline" do
182
- expect(response_pipeline).to receive(:process).with(stub_activator_response)
183
+ it "processes the scenario response via the response pipeline" do
184
+ expect(response_pipeline).to receive(:process).with(scenario_response)
183
185
 
184
186
  subject
185
187
  end
186
188
 
187
189
  end
188
190
 
189
- context "and the stub activator controller does not activate a stub" do
191
+ context "and the scenario controller does not activate a scenario" do
190
192
 
191
- before(:each) { allow(stub_activator_response).to receive(:empty?).and_return(true) }
193
+ before(:each) { allow(scenario_response).to receive(:empty?).and_return(true) }
192
194
 
193
195
  it "processes an error response via the response pipeline" do
194
196
  expect(response_pipeline).to receive(:process).with(HttpStub::Server::Response::ERROR)