http_stub 0.19.1 → 0.20.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 (114) hide show
  1. checksums.yaml +13 -5
  2. data/lib/http_stub.rb +26 -21
  3. data/lib/http_stub/configurer/server/command_processor.rb +1 -0
  4. data/lib/http_stub/server/application.rb +24 -46
  5. data/lib/http_stub/server/formatted_hash.rb +18 -0
  6. data/lib/http_stub/server/header_parser.rb +17 -0
  7. data/lib/http_stub/server/registry.rb +9 -9
  8. data/lib/http_stub/server/request.rb +19 -0
  9. data/lib/http_stub/server/request_pipeline.rb +27 -0
  10. data/lib/http_stub/server/response.rb +7 -3
  11. data/lib/http_stub/server/scenario.rb +1 -1
  12. data/lib/http_stub/server/scenario/activator.rb +4 -4
  13. data/lib/http_stub/server/scenario/controller.rb +8 -8
  14. data/lib/http_stub/server/scenario/{request_parser.rb → parser.rb} +2 -2
  15. data/lib/http_stub/server/scenario/{instance.rb → scenario.rb} +2 -2
  16. data/lib/http_stub/server/stub.rb +1 -1
  17. data/lib/http_stub/server/stub/controller.rb +8 -8
  18. data/lib/http_stub/server/stub/empty.rb +34 -0
  19. data/lib/http_stub/server/stub/match/exact_value_matcher.rb +17 -0
  20. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +26 -0
  21. data/lib/http_stub/server/stub/match/match.rb +20 -0
  22. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +23 -0
  23. data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +18 -0
  24. data/lib/http_stub/server/stub/match/rule/body.rb +49 -0
  25. data/lib/http_stub/server/stub/match/rule/headers.rb +31 -0
  26. data/lib/http_stub/server/stub/match/rule/json_body.rb +39 -0
  27. data/lib/http_stub/server/stub/match/rule/method.rb +27 -0
  28. data/lib/http_stub/server/stub/match/rule/parameters.rb +27 -0
  29. data/lib/http_stub/server/stub/match/rule/simple_body.rb +27 -0
  30. data/lib/http_stub/server/stub/match/rule/uri.rb +27 -0
  31. data/lib/http_stub/server/stub/match/string_value_matcher.rb +33 -0
  32. data/lib/http_stub/server/stub/match/truthy_matcher.rb +25 -0
  33. data/lib/http_stub/server/stub/{request_parser.rb → parser.rb} +2 -2
  34. data/lib/http_stub/server/stub/payload_file_consolidator.rb +1 -1
  35. data/lib/http_stub/server/stub/registry.rb +16 -8
  36. data/lib/http_stub/server/stub/response/base.rb +2 -2
  37. data/lib/http_stub/server/stub/stub.rb +44 -0
  38. data/lib/http_stub/server/stub/triggers.rb +2 -2
  39. data/lib/http_stub/server/views/_match.haml +20 -0
  40. data/lib/http_stub/server/views/matches.haml +3 -0
  41. data/lib/http_stub/server/views/stub.haml +1 -0
  42. data/lib/http_stub/version.rb +1 -1
  43. data/spec/acceptance/stub_control_values_spec.rb +6 -3
  44. data/spec/acceptance/stub_match_spec.rb +142 -0
  45. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +4 -0
  46. data/spec/lib/http_stub/server/application_integration_spec.rb +17 -18
  47. data/spec/lib/http_stub/server/application_spec.rb +81 -53
  48. data/spec/lib/http_stub/server/formatted_hash_spec.rb +54 -0
  49. data/spec/lib/http_stub/server/{stub/request_header_parser_spec.rb → header_parser_spec.rb} +9 -9
  50. data/spec/lib/http_stub/server/{request_file_consolidator_spec.rb → payload_file_consolidator_spec.rb} +4 -4
  51. data/spec/lib/http_stub/server/registry_spec.rb +13 -14
  52. data/spec/lib/http_stub/server/request_pipeline_spec.rb +80 -0
  53. data/spec/lib/http_stub/server/request_spec.rb +113 -0
  54. data/spec/lib/http_stub/server/response_spec.rb +46 -12
  55. data/spec/lib/http_stub/server/scenario/activator_spec.rb +18 -18
  56. data/spec/lib/http_stub/server/scenario/controller_spec.rb +18 -15
  57. data/spec/lib/http_stub/server/scenario/{request_parser_spec.rb → parser_spec.rb} +8 -8
  58. data/spec/lib/http_stub/server/scenario/{instance_spec.rb → scenario_spec.rb} +7 -5
  59. data/spec/lib/http_stub/server/scenario_spec.rb +3 -3
  60. data/spec/lib/http_stub/server/stub/controller_spec.rb +29 -14
  61. data/spec/lib/http_stub/server/stub/empty_spec.rb +68 -0
  62. data/spec/lib/http_stub/server/stub/{exact_value_matcher_spec.rb → match/exact_value_matcher_spec.rb} +2 -2
  63. data/spec/lib/http_stub/server/stub/{hash_with_string_value_matchers_spec.rb → match/hash_with_string_value_matchers_spec.rb} +27 -19
  64. data/spec/lib/http_stub/server/stub/match/match_spec.rb +40 -0
  65. data/spec/lib/http_stub/server/stub/{omitted_value_matcher_spec.rb → match/omitted_value_matcher_spec.rb} +2 -2
  66. data/spec/lib/http_stub/server/stub/{regexp_value_matcher_spec.rb → match/regexp_value_matcher_spec.rb} +2 -2
  67. data/spec/lib/http_stub/server/stub/{request_body_spec.rb → match/rule/body_spec.rb} +12 -12
  68. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +90 -0
  69. data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb} +9 -10
  70. data/spec/lib/http_stub/server/stub/{method_spec.rb → match/rule/method_spec.rb} +6 -5
  71. data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb} +16 -10
  72. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +46 -0
  73. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +46 -0
  74. data/spec/lib/http_stub/server/stub/{string_value_matcher_spec.rb → match/string_value_matcher_spec.rb} +30 -26
  75. data/spec/lib/http_stub/server/stub/match/truthy_matcher_spec.rb +24 -0
  76. data/spec/lib/http_stub/server/stub/{request_parser_spec.rb → parser_spec.rb} +7 -7
  77. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/registry_spec.rb +114 -43
  79. data/spec/lib/http_stub/server/stub/response/base_spec.rb +8 -2
  80. data/spec/lib/http_stub/server/stub/stub_spec.rb +294 -0
  81. data/spec/lib/http_stub/server/stub/triggers_spec.rb +4 -4
  82. data/spec/lib/http_stub/server/stub_spec.rb +3 -3
  83. data/spec/spec_helper.rb +7 -3
  84. data/spec/support/configurer_integration.rb +1 -0
  85. data/spec/support/http_stub/empty_configurer.rb +7 -0
  86. data/spec/support/{scenario_fixture.rb → http_stub/scenario_fixture.rb} +0 -0
  87. data/spec/support/http_stub/server/request_fixture.rb +25 -0
  88. data/spec/support/http_stub/server/scenario/scenario_fixture.rb +15 -0
  89. data/spec/support/http_stub/server/stub/match/match_fixture.rb +17 -0
  90. data/spec/support/{stub_fixture.rb → http_stub/stub_fixture.rb} +0 -0
  91. data/spec/support/server_integration.rb +1 -0
  92. metadata +315 -290
  93. data/lib/http_stub/server/stub/exact_value_matcher.rb +0 -15
  94. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +0 -22
  95. data/lib/http_stub/server/stub/headers.rb +0 -19
  96. data/lib/http_stub/server/stub/instance.rb +0 -32
  97. data/lib/http_stub/server/stub/json_request_body.rb +0 -35
  98. data/lib/http_stub/server/stub/method.rb +0 -23
  99. data/lib/http_stub/server/stub/omitted_value_matcher.rb +0 -21
  100. data/lib/http_stub/server/stub/regexp_value_matcher.rb +0 -16
  101. data/lib/http_stub/server/stub/request_body.rb +0 -44
  102. data/lib/http_stub/server/stub/request_header_parser.rb +0 -19
  103. data/lib/http_stub/server/stub/request_headers.rb +0 -28
  104. data/lib/http_stub/server/stub/request_parameters.rb +0 -23
  105. data/lib/http_stub/server/stub/simple_request_body.rb +0 -23
  106. data/lib/http_stub/server/stub/string_value_matcher.rb +0 -31
  107. data/lib/http_stub/server/stub/truthy_request_matcher.rb +0 -23
  108. data/lib/http_stub/server/stub/uri.rb +0 -23
  109. data/spec/lib/http_stub/server/stub/headers_spec.rb +0 -51
  110. data/spec/lib/http_stub/server/stub/instance_spec.rb +0 -235
  111. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +0 -68
  112. data/spec/lib/http_stub/server/stub/simple_request_body_spec.rb +0 -43
  113. data/spec/lib/http_stub/server/stub/truthy_request_matcher_spec.rb +0 -23
  114. data/spec/lib/http_stub/server/stub/uri_spec.rb +0 -43
@@ -0,0 +1,113 @@
1
+ describe HttpStub::Server::Request do
2
+
3
+ let(:rack_path_info) { "/rack/path/info" }
4
+ let(:rack_request_method) { "some method" }
5
+ let(:rack_parameters) { { "parameter_key" => "parameter value" } }
6
+ let(:rack_body) { "some request body" }
7
+ let(:rack_request) do
8
+ instance_double(Rack::Request, path_info: rack_path_info,
9
+ request_method: rack_request_method,
10
+ params: rack_parameters,
11
+ body: StringIO.new(rack_body))
12
+ end
13
+
14
+ let(:server_request) { described_class.new(rack_request) }
15
+
16
+ before(:example) do
17
+ allow(HttpStub::Server::HeaderParser).to receive(:parse).and_return({})
18
+ allow(HttpStub::Server::FormattedHash).to receive(:new)
19
+ end
20
+
21
+ describe "#uri" do
22
+
23
+ it "is the rack request path information" do
24
+ expect(server_request.uri).to eql(rack_path_info)
25
+ end
26
+
27
+ end
28
+
29
+ describe "#method" do
30
+
31
+ subject { server_request.method }
32
+
33
+ it "is the rack request method" do
34
+ expect(subject).to eql(rack_request_method)
35
+ end
36
+
37
+ end
38
+
39
+ describe "#headers" do
40
+
41
+ let(:parsed_headers) { { "parsed_header_key" => "parsed header value" } }
42
+ let(:formatted_hash) { instance_double(HttpStub::Server::FormattedHash) }
43
+
44
+ subject { server_request.headers }
45
+
46
+ before(:example) do
47
+ allow(HttpStub::Server::HeaderParser).to receive(:parse).and_return(parsed_headers)
48
+ allow(HttpStub::Server::FormattedHash).to receive(:new).with(parsed_headers, anything).and_return(formatted_hash)
49
+ end
50
+
51
+ it "parses the headers from the rack request via the header parser" do
52
+ expect(HttpStub::Server::HeaderParser).to receive(:parse).with(rack_request)
53
+
54
+ subject
55
+ end
56
+
57
+ it "creates a formatted hash containing the parsed headers" do
58
+ expect(HttpStub::Server::FormattedHash).to receive(:new).with(parsed_headers, anything)
59
+
60
+ subject
61
+ end
62
+
63
+ it "creates a formatted hash formatted by a ':' request value delimiter" do
64
+ expect(HttpStub::Server::FormattedHash).to receive(:new).with(anything, ":")
65
+
66
+ subject
67
+ end
68
+
69
+ it "is the formattted hash" do
70
+ expect(subject).to eql(formatted_hash)
71
+ end
72
+
73
+ end
74
+
75
+ describe "#parameters" do
76
+
77
+ let(:formatted_hash) { instance_double(HttpStub::Server::FormattedHash) }
78
+
79
+ subject { server_request.parameters }
80
+
81
+ before(:example) do
82
+ allow(HttpStub::Server::FormattedHash).to receive(:new).with(rack_parameters, anything).and_return(formatted_hash)
83
+ end
84
+
85
+ it "creates a formatted hash containing the rack request parameters" do
86
+ expect(HttpStub::Server::FormattedHash).to receive(:new).with(rack_parameters, anything)
87
+
88
+ subject
89
+ end
90
+
91
+ it "creates a formatted hash with a '=' request value delimiter" do
92
+ expect(HttpStub::Server::FormattedHash).to receive(:new).with(anything, "=")
93
+
94
+ subject
95
+ end
96
+
97
+ it "is the formatted hash" do
98
+ expect(subject).to eql(formatted_hash)
99
+ end
100
+
101
+ end
102
+
103
+ describe "#body" do
104
+
105
+ subject { server_request.body }
106
+
107
+ it "is the read rack request body" do
108
+ expect(subject).to eql(rack_body)
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -1,39 +1,73 @@
1
1
  describe HttpStub::Server::Response do
2
2
 
3
- describe "::SUCCESS" do
4
-
5
- let(:response) { HttpStub::Server::Response::SUCCESS }
3
+ shared_examples_for "a success response" do
6
4
 
7
5
  it "has a status of 200" do
8
- expect(response.status).to eql(200)
6
+ expect(subject.status).to eql(200)
9
7
  end
10
8
 
11
9
  it "has a body containing OK to visually indicate success to those interacting via a browser" do
12
- expect(response.body).to match(/OK/)
10
+ expect(subject.body).to match(/OK/)
11
+ end
12
+
13
+ end
14
+
15
+ describe "::success" do
16
+
17
+ subject { HttpStub::Server::Response::success }
18
+
19
+ it_behaves_like "a success response"
20
+
21
+ context "when headers are provided" do
22
+
23
+ let(:headers) { { "response_header_key" => "response header value" } }
24
+
25
+ subject { HttpStub::Server::Response::success(headers) }
26
+
27
+ it "established the headers" do
28
+ expect(subject.headers).to eql(headers)
29
+ end
30
+
13
31
  end
14
32
 
15
33
  end
16
34
 
17
- describe "::ERROR" do
35
+ describe "::SUCCESS" do
36
+
37
+ subject { HttpStub::Server::Response::SUCCESS }
38
+
39
+ it_behaves_like "a success response"
40
+
41
+ end
42
+
43
+ describe "::NOT_FOUND" do
18
44
 
19
- let(:response) { HttpStub::Server::Response::ERROR }
45
+ subject { HttpStub::Server::Response::NOT_FOUND }
20
46
 
21
47
  it "has a status of 404" do
22
- expect(response.status).to eql(404)
48
+ expect(subject.status).to eql(404)
23
49
  end
24
50
 
25
- it "has a body containing ERROR to visually indicate the error to those interacting via a browser" do
26
- expect(response.body).to match(/ERROR/)
51
+ it "has a body containing NOT FOUND to visually indicate the response to those interacting via a browser" do
52
+ expect(subject.body).to match(/NOT FOUND/)
27
53
  end
28
54
 
29
55
  end
30
56
 
31
57
  describe "::EMPTY" do
32
58
 
33
- let(:response) { HttpStub::Server::Response::EMPTY }
59
+ subject { HttpStub::Server::Response::EMPTY }
60
+
61
+ it "has a status of 200" do
62
+ expect(subject.status).to eql(200)
63
+ end
64
+
65
+ it "has no body" do
66
+ expect(subject.body).to be(nil)
67
+ end
34
68
 
35
69
  it "is empty" do
36
- expect(response.empty?).to be(true)
70
+ expect(subject).to be_empty
37
71
  end
38
72
 
39
73
  end
@@ -1,25 +1,25 @@
1
1
  describe HttpStub::Server::Scenario::Activator do
2
2
 
3
- let(:request) { instance_double(Rack::Request) }
4
- let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Instance) } }
3
+ let(:logger) { instance_double(Logger) }
4
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
5
5
  let(:triggered_scenario_names) { [] }
6
- let(:scenario) do
6
+ let(:scenario) do
7
7
  instance_double(
8
- HttpStub::Server::Scenario::Instance, stubs: stubs, triggered_scenario_names: triggered_scenario_names
8
+ HttpStub::Server::Scenario::Scenario, stubs: stubs, triggered_scenario_names: triggered_scenario_names
9
9
  )
10
10
  end
11
- let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
12
- let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
13
- let(:activator_class) { HttpStub::Server::Scenario::Activator }
11
+ let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
12
+ let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
13
+ let(:activator_class) { HttpStub::Server::Scenario::Activator }
14
14
 
15
15
  let(:activator) { activator_class.new(scenario_registry, stub_registry) }
16
16
 
17
17
  describe "#activate" do
18
18
 
19
- subject { activator.activate(scenario, request) }
19
+ subject { activator.activate(scenario, logger) }
20
20
 
21
- it "adds the scenario's stubs to the stub registry with the provided request" do
22
- expect(stub_registry).to receive(:concat).with(stubs, request)
21
+ it "adds the scenario's stubs to the stub registry with the provided logger" do
22
+ expect(stub_registry).to receive(:concat).with(stubs, logger)
23
23
 
24
24
  subject
25
25
  end
@@ -29,14 +29,14 @@ describe HttpStub::Server::Scenario::Activator do
29
29
  let(:triggered_scenario_names) { (1..3).map { |i| "triggered_scenario_name/#{i}" } }
30
30
  let(:triggered_scenarios) do
31
31
  triggered_scenario_names.map do
32
- instance_double(HttpStub::Server::Scenario::Instance, stubs: [], triggered_scenario_names: [])
32
+ instance_double(HttpStub::Server::Scenario::Scenario, stubs: [], triggered_scenario_names: [])
33
33
  end
34
34
  end
35
35
 
36
36
  before(:each) do
37
37
  triggered_scenario_names.zip(triggered_scenarios).each do |triggered_scenario_name, triggered_scenario|
38
38
  allow(scenario_registry).to(
39
- receive(:find).with(hash_including(criteria: triggered_scenario_name)).and_return(triggered_scenario)
39
+ receive(:find).with(triggered_scenario_name, anything).and_return(triggered_scenario)
40
40
  )
41
41
  end
42
42
  end
@@ -44,7 +44,7 @@ describe HttpStub::Server::Scenario::Activator do
44
44
  it "finds each triggered scenario in the scenario registry" do
45
45
  triggered_scenario_names.zip(triggered_scenarios).each do |triggered_scenario_name, triggered_scenario|
46
46
  expect(scenario_registry).to(
47
- receive(:find).with(criteria: triggered_scenario_name, request: request).and_return(triggered_scenario)
47
+ receive(:find).with(triggered_scenario_name, logger).and_return(triggered_scenario)
48
48
  )
49
49
  end
50
50
 
@@ -62,8 +62,8 @@ describe HttpStub::Server::Scenario::Activator do
62
62
  @activate_args = []
63
63
  end
64
64
 
65
- def activate(scenario, request)
66
- @activate_args << [ scenario, request ]
65
+ def activate(scenario, logger)
66
+ @activate_args << [ scenario, logger ]
67
67
  super
68
68
  end
69
69
 
@@ -72,8 +72,8 @@ describe HttpStub::Server::Scenario::Activator do
72
72
  let(:activator_class) { HttpStub::Server::Scenario::ActivatorRetainingActivateArgs }
73
73
 
74
74
  it "activates the scenario's" do
75
- expected_activate_args = triggered_scenarios.reduce([ [ scenario, request ] ]) do |result, triggered_scenario|
76
- result << [ triggered_scenario, request ]
75
+ expected_activate_args = triggered_scenarios.reduce([ [ scenario, logger ] ]) do |result, triggered_scenario|
76
+ result << [ triggered_scenario, logger ]
77
77
  end
78
78
 
79
79
  subject
@@ -89,7 +89,7 @@ describe HttpStub::Server::Scenario::Activator do
89
89
 
90
90
  before(:example) do
91
91
  allow(scenario_registry).to(
92
- receive(:find).with(hash_including(criteria: scenario_name_not_found)).and_return(nil)
92
+ receive(:find).with(scenario_name_not_found, anything).and_return(nil)
93
93
  )
94
94
  end
95
95
 
@@ -1,10 +1,11 @@
1
1
  describe HttpStub::Server::Scenario::Controller do
2
2
 
3
- let(:request_path_info) { "/some/request/path" }
4
- let(:request) { instance_double(Rack::Request, path_info: request_path_info) }
3
+ let(:request_uri) { "/some/request/path" }
4
+ let(:request) { instance_double(HttpStub::Server::Request, uri: request_uri) }
5
+ let(:logger) { instance_double(Logger) }
5
6
  let(:payload) { HttpStub::ScenarioFixture.new.server_payload }
6
- let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Instance) } }
7
- let(:scenario) { instance_double(HttpStub::Server::Scenario::Instance, stubs: stubs) }
7
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
8
+ let(:scenario) { instance_double(HttpStub::Server::Scenario::Scenario, stubs: stubs) }
8
9
  let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
9
10
  let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
10
11
  let(:activator) { instance_double(HttpStub::Server::Scenario::Activator).as_null_object }
@@ -13,16 +14,16 @@ describe HttpStub::Server::Scenario::Controller do
13
14
 
14
15
  before(:example) do
15
16
  allow(HttpStub::Server::Scenario::Activator).to receive(:new).and_return(activator)
16
- allow(HttpStub::Server::Scenario::RequestParser).to receive(:parse).and_return(payload)
17
+ allow(HttpStub::Server::Scenario::Parser).to receive(:parse).and_return(payload)
17
18
  allow(HttpStub::Server::Scenario).to receive(:create).and_return(scenario)
18
19
  end
19
20
 
20
21
  describe "#register" do
21
22
 
22
- subject { controller.register(request) }
23
+ subject { controller.register(request, logger) }
23
24
 
24
25
  it "parses the payload from the request" do
25
- expect(HttpStub::Server::Scenario::RequestParser).to receive(:parse).with(request).and_return(payload)
26
+ expect(HttpStub::Server::Scenario::Parser).to receive(:parse).with(request).and_return(payload)
26
27
 
27
28
  subject
28
29
  end
@@ -33,8 +34,8 @@ describe HttpStub::Server::Scenario::Controller do
33
34
  subject
34
35
  end
35
36
 
36
- it "adds the created scenario to the scenario registry with the provided request" do
37
- expect(scenario_registry).to receive(:add).with(scenario, request)
37
+ it "adds the created scenario to the scenario registry with the provided logger" do
38
+ expect(scenario_registry).to receive(:add).with(scenario, logger)
38
39
 
39
40
  subject
40
41
  end
@@ -47,20 +48,20 @@ describe HttpStub::Server::Scenario::Controller do
47
48
 
48
49
  describe "#activate" do
49
50
 
50
- subject { controller.activate(request) }
51
+ subject { controller.activate(request, logger) }
51
52
 
52
53
  it "finds a scenario whose name matches the request path omitting the '/' prefix" do
53
- expect(scenario_registry).to receive(:find).with(criteria: "some/request/path", request: request)
54
+ expect(scenario_registry).to receive(:find).with("some/request/path", logger)
54
55
 
55
56
  subject
56
57
  end
57
58
 
58
- describe "when a scenario is found that satisfies the request" do
59
+ describe "when a scenario is found that matches the request" do
59
60
 
60
61
  before(:example) { allow(scenario_registry).to receive(:find).and_return(scenario) }
61
62
 
62
63
  it "activates the scenario via the activator" do
63
- expect(activator).to receive(:activate).with(scenario, request)
64
+ expect(activator).to receive(:activate).with(scenario, logger)
64
65
 
65
66
  subject
66
67
  end
@@ -91,10 +92,12 @@ describe HttpStub::Server::Scenario::Controller do
91
92
 
92
93
  describe "#clear" do
93
94
 
95
+ subject { controller.clear(logger) }
96
+
94
97
  it "clears the scenario registry" do
95
- expect(scenario_registry).to receive(:clear).with(request)
98
+ expect(scenario_registry).to receive(:clear).with(logger)
96
99
 
97
- controller.clear(request)
100
+ subject
98
101
  end
99
102
 
100
103
  end
@@ -1,20 +1,20 @@
1
- describe HttpStub::Server::Scenario::RequestParser do
1
+ describe HttpStub::Server::Scenario::Parser do
2
2
 
3
- let(:request_parser) { described_class }
3
+ let(:parser) { described_class }
4
4
 
5
5
  describe "::parse" do
6
6
 
7
- let(:params) { {} }
8
- let(:body_hash) { {} }
9
- let(:request) { instance_double(Rack::Request, params: params, body: StringIO.new(body_hash.to_json)) }
7
+ let(:parameters) { {} }
8
+ let(:body_hash) { {} }
9
+ let(:request) { instance_double(HttpStub::Server::Request, parameters: parameters, body: body_hash.to_json) }
10
10
 
11
- subject { request_parser.parse(request) }
11
+ subject { parser.parse(request) }
12
12
 
13
13
  context "when the request contains many stubs" do
14
14
 
15
15
  let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(3).server_payload }
16
16
  let(:stub_payloads) { payload["stubs"] }
17
- let(:params) { { "payload" => payload.to_json } }
17
+ let(:parameters) { { "payload" => payload.to_json } }
18
18
 
19
19
  it "consolidates any files into each stub payload" do
20
20
  stub_payloads.each do |stub_payload|
@@ -38,7 +38,7 @@ describe HttpStub::Server::Scenario::RequestParser do
38
38
 
39
39
  let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(1).server_payload }
40
40
  let(:stub_payload) { payload["stubs"].first }
41
- let(:params) { { "payload" => payload.to_json } }
41
+ let(:parameters) { { "payload" => payload.to_json } }
42
42
 
43
43
  it "consolidates any file into the stub payload" do
44
44
  expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, request)
@@ -1,8 +1,8 @@
1
- describe HttpStub::Server::Scenario::Instance do
1
+ describe HttpStub::Server::Scenario::Scenario do
2
2
 
3
3
  let(:name) { "some_scenario_name" }
4
4
  let(:number_of_stubs) { 3 }
5
- let(:stubs) { (1..number_of_stubs).map { instance_double(HttpStub::Server::Stub::Instance) } }
5
+ let(:stubs) { (1..number_of_stubs).map { instance_double(HttpStub::Server::Stub::Stub) } }
6
6
  let(:triggered_scenario_names) { (1..3).map { |i| "triggered/scenario/name/#{i}" } }
7
7
  let(:args) do
8
8
  HttpStub::ScenarioFixture.new.with_name!(name).
@@ -11,7 +11,7 @@ describe HttpStub::Server::Scenario::Instance do
11
11
  server_payload
12
12
  end
13
13
 
14
- let(:scenario) { HttpStub::Server::Scenario::Instance.new(args) }
14
+ let(:scenario) { HttpStub::Server::Scenario::Scenario.new(args) }
15
15
 
16
16
  before(:example) { allow(HttpStub::Server::Stub).to receive(:create).and_return(*stubs) }
17
17
 
@@ -43,9 +43,11 @@ describe HttpStub::Server::Scenario::Instance do
43
43
 
44
44
  end
45
45
 
46
- describe "#satisfies?" do
46
+ describe "#matches?" do
47
47
 
48
- subject { scenario.satisfies?(other_name) }
48
+ let(:logger) { instance_double(Logger) }
49
+
50
+ subject { scenario.matches?(other_name, logger) }
49
51
 
50
52
  describe "when the scenario's name exactly matches the provided name" do
51
53
 
@@ -7,14 +7,14 @@ describe HttpStub::Server::Scenario do
7
7
  subject { HttpStub::Server::Scenario.create(args) }
8
8
 
9
9
  it "creates a scenario instance with the provided arguments" do
10
- expect(HttpStub::Server::Scenario::Instance).to receive(:new).with(args)
10
+ expect(HttpStub::Server::Scenario::Scenario).to receive(:new).with(args)
11
11
 
12
12
  subject
13
13
  end
14
14
 
15
15
  it "returns the created scenario" do
16
- scenario = instance_double(HttpStub::Server::Scenario::Instance)
17
- allow(HttpStub::Server::Scenario::Instance).to receive(:new).and_return(scenario)
16
+ scenario = instance_double(HttpStub::Server::Scenario::Scenario)
17
+ allow(HttpStub::Server::Scenario::Scenario).to receive(:new).and_return(scenario)
18
18
 
19
19
  expect(subject).to eql(scenario)
20
20
  end