http_stub 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +5 -13
  2. data/lib/http_stub.rb +2 -1
  3. data/lib/http_stub/configurer/dsl/scenario_builder.rb +4 -4
  4. data/lib/http_stub/configurer/request/http/factory.rb +2 -2
  5. data/lib/http_stub/configurer/server/facade.rb +19 -9
  6. data/lib/http_stub/server/application.rb +22 -12
  7. data/lib/http_stub/server/{views → public}/favicon.ico +0 -0
  8. data/lib/http_stub/server/public/jquery-2.2.1.min.js +4 -0
  9. data/lib/http_stub/server/scenario/activator.rb +3 -3
  10. data/lib/http_stub/server/scenario/controller.rb +3 -3
  11. data/lib/http_stub/server/scenario/links.rb +22 -0
  12. data/lib/http_stub/server/scenario/scenario.rb +14 -11
  13. data/lib/http_stub/server/scenario/trigger.rb +18 -0
  14. data/lib/http_stub/server/stub/controller.rb +1 -1
  15. data/lib/http_stub/server/stub/registry.rb +2 -2
  16. data/lib/http_stub/server/views/_activate_scenario.haml +10 -0
  17. data/lib/http_stub/server/views/application.sass +4 -0
  18. data/lib/http_stub/server/views/index.haml +6 -0
  19. data/lib/http_stub/server/views/layout.haml +3 -2
  20. data/lib/http_stub/server/views/matches.haml +1 -0
  21. data/lib/http_stub/server/views/{_scenario.haml → scenario.haml} +4 -3
  22. data/lib/http_stub/server/views/scenarios.haml +10 -3
  23. data/lib/http_stub/server/views/stubs.haml +1 -0
  24. data/lib/http_stub/version.rb +1 -1
  25. data/spec/acceptance/endpoint_template_spec.rb +2 -2
  26. data/spec/acceptance/scenario_spec.rb +3 -3
  27. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +24 -4
  28. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +2 -2
  29. data/spec/lib/http_stub/configurer/server/facade_spec.rb +18 -8
  30. data/spec/lib/http_stub/server/application_integration_spec.rb +270 -111
  31. data/spec/lib/http_stub/server/application_spec.rb +81 -15
  32. data/spec/lib/http_stub/server/scenario/activator_spec.rb +8 -3
  33. data/spec/lib/http_stub/server/scenario/controller_spec.rb +9 -7
  34. data/spec/lib/http_stub/server/scenario/links_spec.rb +41 -0
  35. data/spec/lib/http_stub/server/scenario/scenario_spec.rb +72 -30
  36. data/spec/lib/http_stub/server/scenario/trigger_spec.rb +36 -0
  37. data/spec/lib/http_stub/server/stub/controller_spec.rb +2 -2
  38. data/spec/lib/http_stub/server/stub/registry_spec.rb +23 -9
  39. data/spec/spec_helper.rb +1 -1
  40. data/spec/support/http_stub/scenario_fixture.rb +3 -3
  41. metadata +334 -342
  42. data/lib/http_stub/server/request_pipeline.rb +0 -27
  43. data/spec/lib/http_stub/server/request_pipeline_spec.rb +0 -80
@@ -1,27 +0,0 @@
1
- module HttpStub
2
- module Server
3
-
4
- class RequestPipeline
5
-
6
- def initialize(stub_controller, scenario_controller, match_registry)
7
- @stub_controller = stub_controller
8
- @scenario_controller = scenario_controller
9
- @match_registry = match_registry
10
- end
11
-
12
- def process(request, logger)
13
- response = @stub_controller.replay(request, logger)
14
- response = @scenario_controller.activate(request, logger) if response.empty?
15
- response.empty? ? process_unmatched(request, logger) : response
16
- end
17
-
18
- private
19
-
20
- def process_unmatched(request, logger)
21
- @match_registry.add(HttpStub::Server::Stub::Match::Match.new(nil, request), logger)
22
- HttpStub::Server::Response::NOT_FOUND
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,80 +0,0 @@
1
- describe HttpStub::Server::RequestPipeline do
2
-
3
- let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller).as_null_object }
4
- let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller).as_null_object }
5
- let(:match_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
6
-
7
- let(:request_pipeline) { described_class.new(stub_controller, scenario_controller, match_registry) }
8
-
9
- describe "#process" do
10
-
11
- let(:request) { instance_double(HttpStub::Server::Request) }
12
- let(:logger) { instance_double(Logger) }
13
-
14
- let(:stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
15
-
16
- subject { request_pipeline.process(request, logger) }
17
-
18
- before(:example) { allow(stub_controller).to receive(:replay).and_return(stub_response) }
19
-
20
- context "when the stub controller replays a response" do
21
-
22
- before(:example) { allow(stub_response).to receive(:empty?).and_return(false) }
23
-
24
- it "returns the replayed response" do
25
- expect(subject).to eql(stub_response)
26
- end
27
-
28
- end
29
-
30
- context "when the stub controller does not replay a response" do
31
-
32
- let(:scenario_response) { double(HttpStub::Server::Stub::Response::Base, serve_on: nil) }
33
-
34
- before(:example) do
35
- allow(stub_response).to receive(:empty?).and_return(true)
36
- allow(scenario_controller).to receive(:activate).and_return(scenario_response)
37
- end
38
-
39
- context "but the scenario controller activates a scenario" do
40
-
41
- before(:each) { allow(scenario_response).to receive(:empty?).and_return(false) }
42
-
43
- it "returns the scenario response" do
44
- expect(subject).to eql(scenario_response)
45
- end
46
-
47
- end
48
-
49
- context "and the scenario controller does not activate a scenario" do
50
-
51
- let(:stub_match) { instance_double(HttpStub::Server::Stub::Match::Match) }
52
-
53
- before(:each) do
54
- allow(HttpStub::Server::Stub::Match::Match).to receive(:new).and_return(stub_match)
55
- allow(scenario_response).to receive(:empty?).and_return(true)
56
- end
57
-
58
- it "creates a match with no stub to indicate their was no match" do
59
- expect(HttpStub::Server::Stub::Match::Match).to receive(:new).with(nil, request)
60
-
61
- subject
62
- end
63
-
64
- it "registers the created match in the match registry" do
65
- expect(match_registry).to receive(:add).with(stub_match, logger)
66
-
67
- subject
68
- end
69
-
70
- it "returns a not found response" do
71
- expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
72
- end
73
-
74
- end
75
-
76
- end
77
-
78
- end
79
-
80
- end