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,126 @@
1
+ describe HttpStub::Server::Scenario::Instance do
2
+
3
+ let(:name) { "some_scenario_name" }
4
+ let(:number_of_stubs) { 3 }
5
+ let(:stubs) { (1..number_of_stubs).map { instance_double(HttpStub::Server::Stub::Instance) } }
6
+ let(:triggered_scenario_names) { (1..3).map { |i| "triggered/scenario/name/#{i}" } }
7
+ let(:args) do
8
+ HttpStub::ScenarioFixture.new.with_name!(name).
9
+ with_stubs!(number_of_stubs).
10
+ with_triggered_scenario_names!(triggered_scenario_names).
11
+ server_payload
12
+ end
13
+
14
+ let(:scenario) { HttpStub::Server::Scenario::Instance.new(args) }
15
+
16
+ before(:example) { allow(HttpStub::Server::Stub).to receive(:create).and_return(*stubs) }
17
+
18
+ describe "#constructor" do
19
+
20
+ context "when many stub payloads are provided" do
21
+
22
+ let(:number_of_stubs) { 3 }
23
+
24
+ it "creates an underlying stub for each stub payload provided" do
25
+ args["stubs"].each { |stub_args| expect(HttpStub::Server::Stub).to receive(:create).with(stub_args) }
26
+
27
+ scenario
28
+ end
29
+
30
+ end
31
+
32
+ context "when one stub payload is provided" do
33
+
34
+ let(:number_of_stubs) { 1 }
35
+
36
+ it "creates an underlying stub for each stub payload provided" do
37
+ expect(HttpStub::Server::Stub).to receive(:create).with(args["stubs"].first)
38
+
39
+ scenario
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe "#satisfies?" do
47
+
48
+ subject { scenario.satisfies?(other_name) }
49
+
50
+ describe "when the scenario's name exactly matches the provided name" do
51
+
52
+ let(:other_name) { name }
53
+
54
+ it "returns true" do
55
+ expect(subject).to be(true)
56
+ end
57
+
58
+ end
59
+
60
+ describe "when the scenario's name is a substring of the provided name" do
61
+
62
+ let(:other_name) { "#{name}_with_additional_context" }
63
+
64
+ it "returns false" do
65
+ expect(subject).to be(false)
66
+ end
67
+
68
+ end
69
+
70
+ describe "when the scenario's name is completely different to the provided name" do
71
+
72
+ let(:other_name) { "completely_different_scenario_name" }
73
+
74
+ it "returns false" do
75
+ expect(subject).to be(false)
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ describe "#uri" do
83
+
84
+ it "returns the scenario's name with '/' prefixed" do
85
+ expect(scenario.uri).to eql("/#{name}")
86
+ end
87
+
88
+ end
89
+
90
+ describe "#stubs" do
91
+
92
+ it "returns the HttpStub::Server::Stub's constructed from the scenario's arguments" do
93
+ expect(scenario.stubs).to eql(stubs)
94
+ end
95
+
96
+ end
97
+
98
+ describe "#triggered_scenario_names" do
99
+
100
+ it "returns the value provided in the payload" do
101
+ expect(scenario.triggered_scenario_names).to eql(triggered_scenario_names)
102
+ end
103
+
104
+ end
105
+
106
+ describe "#triggered_scenarios" do
107
+
108
+ it "returns an array containing the triggered scenario names and uris" do
109
+ expected_details = triggered_scenario_names.reduce([]) { |result, name| result << [name, "/#{name}"] }
110
+
111
+ expect(scenario.triggered_scenarios).to eql(expected_details)
112
+ end
113
+
114
+ end
115
+
116
+ describe "#to_s" do
117
+
118
+ it "returns the string representation of the activation arguments" do
119
+ expect(args).to receive(:to_s).and_return("scenario string representation")
120
+
121
+ expect(scenario.to_s).to eql("scenario string representation")
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,59 @@
1
+ describe HttpStub::Server::Scenario::RequestParser do
2
+
3
+ let(:request_parser) { described_class }
4
+
5
+ describe "::parse" do
6
+
7
+ let(:params) { {} }
8
+ let(:body_hash) { {} }
9
+ let(:request) { instance_double(Rack::Request, params: params, body: StringIO.new(body_hash.to_json)) }
10
+
11
+ subject { request_parser.parse(request) }
12
+
13
+ context "when the request contains many stubs" do
14
+
15
+ let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(3).server_payload }
16
+ let(:stub_payloads) { payload["stubs"] }
17
+ let(:params) { { "payload" => payload.to_json } }
18
+
19
+ it "consolidates any files into each stub payload" do
20
+ stub_payloads.each do |stub_payload|
21
+ expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, request)
22
+ end
23
+
24
+ subject
25
+ end
26
+
27
+ it "consolidates any files in each stub payload" do
28
+ stub_payloads.each_with_index.each do |stub_payload|
29
+ allow(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, anything)
30
+ end
31
+
32
+ expect(subject).to eql(payload)
33
+ end
34
+
35
+ end
36
+
37
+ context "when the request contains one stub" do
38
+
39
+ let(:payload) { HttpStub::ScenarioFixture.new.with_stubs!(1).server_payload }
40
+ let(:stub_payload) { payload["stubs"].first }
41
+ let(:params) { { "payload" => payload.to_json } }
42
+
43
+ it "consolidates any file into the stub payload" do
44
+ expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, request)
45
+
46
+ subject
47
+ end
48
+
49
+ it "consolidates any file in the stub payload" do
50
+ allow(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(stub_payload, anything)
51
+
52
+ expect(subject).to eql(payload)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,24 @@
1
+ describe HttpStub::Server::Scenario do
2
+
3
+ let(:args) { HttpStub::ScenarioFixture.new.server_payload }
4
+
5
+ describe "::create" do
6
+
7
+ subject { HttpStub::Server::Scenario.create(args) }
8
+
9
+ it "creates a scenario instance with the provided arguments" do
10
+ expect(HttpStub::Server::Scenario::Instance).to receive(:new).with(args)
11
+
12
+ subject
13
+ end
14
+
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)
18
+
19
+ expect(subject).to eql(scenario)
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -1,16 +1,16 @@
1
- describe HttpStub::Server::StubController do
1
+ describe HttpStub::Server::Stub::Controller do
2
2
 
3
- let(:request) { instance_double(Rack::Request) }
4
- let(:payload) { HttpStub::StubFixture.new.server_payload }
5
- let(:response) { instance_double(HttpStub::Server::StubResponse::Base) }
6
- let(:the_stub) { instance_double(HttpStub::Server::Stub, response: response) }
7
- let(:registry) { instance_double(HttpStub::Server::StubRegistry).as_null_object }
3
+ let(:request) { instance_double(Rack::Request) }
4
+ let(:payload) { HttpStub::StubFixture.new.server_payload }
5
+ let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
6
+ let(:the_stub) { instance_double(HttpStub::Server::Stub::Instance, response: response) }
7
+ let(:registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
8
8
 
9
- let(:controller) { HttpStub::Server::StubController.new(registry) }
9
+ let(:controller) { HttpStub::Server::Stub::Controller.new(registry) }
10
10
 
11
11
  before(:example) do
12
- allow(HttpStub::Server::RequestParser).to receive(:parse).and_return(payload)
13
- allow(HttpStub::Server::Stub).to receive(:new).and_return(the_stub)
12
+ allow(HttpStub::Server::Stub::RequestParser).to receive(:parse).and_return(payload)
13
+ allow(HttpStub::Server::Stub).to receive(:create).and_return(the_stub)
14
14
  end
15
15
 
16
16
  describe "#register" do
@@ -18,13 +18,13 @@ describe HttpStub::Server::StubController do
18
18
  subject { controller.register(request) }
19
19
 
20
20
  it "parses the payload from the request" do
21
- expect(HttpStub::Server::RequestParser).to receive(:parse).with(request).and_return(payload)
21
+ expect(HttpStub::Server::Stub::RequestParser).to receive(:parse).with(request).and_return(payload)
22
22
 
23
23
  subject
24
24
  end
25
25
 
26
26
  it "creates a stub with the parsed payload" do
27
- expect(HttpStub::Server::Stub).to receive(:new).with(payload).and_return(the_stub)
27
+ expect(HttpStub::Server::Stub).to receive(:create).with(payload).and_return(the_stub)
28
28
 
29
29
  subject
30
30
  end
@@ -45,9 +45,7 @@ describe HttpStub::Server::StubController do
45
45
 
46
46
  describe "when a stub has been registered that should be replayed for the request" do
47
47
 
48
- before(:example) do
49
- allow(registry).to receive(:find_for).with(request).and_return(the_stub)
50
- end
48
+ before(:example) { allow(registry).to receive(:find_for).with(request).and_return(the_stub) }
51
49
 
52
50
  it "returns the stubs response" do
53
51
  expect(the_stub).to receive(:response).and_return(response)
@@ -59,9 +57,7 @@ describe HttpStub::Server::StubController do
59
57
 
60
58
  describe "when no stub should be replayed for the request" do
61
59
 
62
- before(:example) do
63
- allow(registry).to receive(:find_for).with(request).and_return(nil)
64
- end
60
+ before(:example) { allow(registry).to receive(:find_for).with(request).and_return(nil) }
65
61
 
66
62
  it "returns an empty response" do
67
63
  expect(controller.replay(request)).to eql(HttpStub::Server::Response::EMPTY)
@@ -1,6 +1,6 @@
1
- describe HttpStub::Server::ExactValueMatcher do
1
+ describe HttpStub::Server::Stub::ExactValueMatcher do
2
2
 
3
- describe ".match?" do
3
+ describe "::match?" do
4
4
 
5
5
  let(:stub_value) { "some stub value" }
6
6
 
@@ -25,7 +25,7 @@ describe HttpStub::Server::ExactValueMatcher do
25
25
  end
26
26
 
27
27
  def perform_match
28
- HttpStub::Server::ExactValueMatcher.match?(stub_value, actual_value)
28
+ HttpStub::Server::Stub::ExactValueMatcher.match?(stub_value, actual_value)
29
29
  end
30
30
 
31
31
  end
@@ -1,4 +1,4 @@
1
- describe HttpStub::Server::HashWithStringValueMatchers do
1
+ describe HttpStub::Server::Stub::HashWithStringValueMatchers do
2
2
 
3
3
  let(:stubbed_hash) do
4
4
  (1..3).reduce({}) do |result, i|
@@ -8,13 +8,15 @@ describe HttpStub::Server::HashWithStringValueMatchers do
8
8
  end
9
9
 
10
10
  let(:value_matchers) do
11
- stubbed_hash.values.map { |value| double(HttpStub::Server::StringValueMatcher, to_s: value).as_null_object }
11
+ stubbed_hash.values.map { |value| double(HttpStub::Server::Stub::StringValueMatcher, to_s: value).as_null_object }
12
12
  end
13
13
 
14
- let(:value_matcher_hash) { HttpStub::Server::HashWithStringValueMatchers.new(stubbed_hash) }
14
+ let(:value_matcher_hash) { HttpStub::Server::Stub::HashWithStringValueMatchers.new(stubbed_hash) }
15
15
 
16
16
  before(:example) do
17
- value_matchers.each { |value| allow(HttpStub::Server::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value) }
17
+ value_matchers.each do |value|
18
+ allow(HttpStub::Server::Stub::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
19
+ end
18
20
  end
19
21
 
20
22
  it "is a hash" do
@@ -25,7 +27,7 @@ describe HttpStub::Server::HashWithStringValueMatchers do
25
27
 
26
28
  it "creates a value matcher representation of each value in the hash" do
27
29
  value_matchers.each do |value|
28
- expect(HttpStub::Server::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
30
+ expect(HttpStub::Server::Stub::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
29
31
  end
30
32
 
31
33
  expect(value_matcher_hash.values).to eql(value_matchers)
@@ -1,8 +1,8 @@
1
- describe HttpStub::Server::Headers do
1
+ describe HttpStub::Server::Stub::Headers do
2
2
 
3
3
  let(:header_hash) { {} }
4
4
 
5
- let(:headers) { HttpStub::Server::Headers.new(header_hash) }
5
+ let(:headers) { HttpStub::Server::Stub::Headers.new(header_hash) }
6
6
 
7
7
  it "is a Hash" do
8
8
  expect(headers).to be_a(Hash)
@@ -0,0 +1,201 @@
1
+ describe HttpStub::Server::Stub::Instance do
2
+
3
+ let(:request_header_payload) do
4
+ {
5
+ "header1" => "header_value1",
6
+ "header2" => "header_value2",
7
+ "header3" => "header_value3"
8
+ }
9
+ end
10
+ let(:request_parameter_payload) do
11
+ {
12
+ "param1" => "param_value1",
13
+ "param2" => "param_value2",
14
+ "param3" => "param_value3"
15
+ }
16
+ end
17
+ let(:request_method_payload) { "get" }
18
+ let(:trigger_payload) do
19
+ {
20
+ "uri" => "/a_triggered_path",
21
+ "method" => "post",
22
+ "headers" => { "triggered_header" => "triggered_header_value" },
23
+ "parameters" => { "triggered_parameter" => "triggered_parameter_value" },
24
+ "response" => {
25
+ "status" => 203,
26
+ "body" => "Triggered body"
27
+ }
28
+ }
29
+ end
30
+ let(:stub_payload) do
31
+ {
32
+ "uri" => "/a_path",
33
+ "method" => stub_method,
34
+ "headers" => request_header_payload,
35
+ "parameters" => request_parameter_payload,
36
+ "response" => {
37
+ "status" => 201,
38
+ "body" => "Some body"
39
+ },
40
+ "triggers" => [ trigger_payload ]
41
+ }
42
+ end
43
+ let(:stub_method) { instance_double(HttpStub::Server::Stub::Method, match?: true) }
44
+ let(:uri) { instance_double(HttpStub::Server::Stub::Uri, match?: true) }
45
+ let(:request_headers) { instance_double(HttpStub::Server::Stub::RequestHeaders, match?: true) }
46
+ let(:request_parameters) { instance_double(HttpStub::Server::Stub::RequestParameters, match?: true) }
47
+ let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
48
+ let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers) }
49
+
50
+ let(:the_stub) { HttpStub::Server::Stub::Instance.new(stub_payload) }
51
+
52
+ before(:example) do
53
+ allow(HttpStub::Server::Stub::Method).to receive(:new).and_return(stub_method)
54
+ allow(HttpStub::Server::Stub::Uri).to receive(:new).and_return(uri)
55
+ allow(HttpStub::Server::Stub::RequestHeaders).to receive(:new).and_return(request_headers)
56
+ allow(HttpStub::Server::Stub::RequestParameters).to receive(:new).and_return(request_parameters)
57
+ allow(HttpStub::Server::Stub::Response).to receive(:create).and_return(response)
58
+ allow(HttpStub::Server::Stub::Triggers).to receive(:new).and_return(triggers)
59
+ end
60
+
61
+ describe "#satisfies?" do
62
+
63
+ let(:request_method) { request_method_payload }
64
+ let(:request_uri) { "/a_request_uri" }
65
+ let(:request) { instance_double(Rack::Request, :request_method => request_method_payload) }
66
+
67
+ describe "when the request uri matches" do
68
+
69
+ before(:example) { allow(uri).to receive(:match?).with(request).and_return(true) }
70
+
71
+ describe "and the request method matches" do
72
+
73
+ describe "and a header match is configured" do
74
+
75
+ describe "that matches" do
76
+
77
+ before(:example) { allow(request_headers).to receive(:match?).with(request).and_return(true) }
78
+
79
+ describe "and a parameter match is configured" do
80
+
81
+ describe "that matches" do
82
+
83
+ before(:example) { allow(request_parameters).to receive(:match?).with(request).and_return(true) }
84
+
85
+ it "returns true" do
86
+ expect(the_stub.satisfies?(request)).to be_truthy
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ describe "when the request method does not match" do
102
+
103
+ before(:example) { allow(stub_method).to receive(:match?).with(request).and_return(false) }
104
+
105
+ it "returns false" do
106
+ expect(the_stub.satisfies?(request)).to be(false)
107
+ end
108
+
109
+ end
110
+
111
+ describe "when the request uri does not match" do
112
+
113
+ before(:example) { allow(uri).to receive(:match?).with(request).and_return(false) }
114
+
115
+ it "returns false" do
116
+ expect(the_stub.satisfies?(request)).to be(false)
117
+ end
118
+
119
+ end
120
+
121
+ describe "when the headers do not match" do
122
+
123
+ before(:example) { allow(request_headers).to receive(:match?).with(request).and_return(false) }
124
+
125
+ it "returns false" do
126
+ expect(the_stub.satisfies?(request)).to be(false)
127
+ end
128
+
129
+ end
130
+
131
+ describe "when the parameters do not match" do
132
+
133
+ before(:example) { allow(request_parameters).to receive(:match?).with(request).and_return(false) }
134
+
135
+ it "returns false" do
136
+ expect(the_stub.satisfies?(request)).to be(false)
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+
143
+ describe "#method" do
144
+
145
+ it "returns the method model encapsulating the method provided in the request body" do
146
+ expect(the_stub.method).to eql(stub_method)
147
+ end
148
+
149
+ end
150
+
151
+ describe "#uri" do
152
+
153
+ it "returns the rui model encapsulating the uri provided in the request body" do
154
+ expect(the_stub.uri).to eql(uri)
155
+ end
156
+
157
+ end
158
+
159
+ describe "#headers" do
160
+
161
+ it "returns the headers model encapsulating the headers provided in the request body" do
162
+ expect(the_stub.headers).to eql(request_headers)
163
+ end
164
+
165
+ end
166
+
167
+ describe "#parameters" do
168
+
169
+ it "returns the parameters model encapsulating the parameters provided in the request body" do
170
+ expect(the_stub.parameters).to eql(request_parameters)
171
+ end
172
+
173
+ end
174
+
175
+ describe "#response" do
176
+
177
+ it "exposes the response model encapsulating the response provided in the request body" do
178
+ expect(the_stub.response).to eql(response)
179
+ end
180
+
181
+ end
182
+
183
+ describe "#triggers" do
184
+
185
+ it "returns the triggers model encapsulating the triggers provided in the request body" do
186
+ expect(the_stub.triggers).to eql(triggers)
187
+ end
188
+
189
+ end
190
+
191
+ describe "#to_s" do
192
+
193
+ it "returns a string representation of the stub arguments" do
194
+ expect(stub_payload).to receive(:to_s).and_return("stub arguments string")
195
+
196
+ expect(the_stub.to_s).to eql("stub arguments string")
197
+ end
198
+
199
+ end
200
+
201
+ end