http_stub 0.22.4 → 0.23.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +15 -5
  3. data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +19 -0
  4. data/lib/http_stub/configurer/dsl/request_referencer.rb +24 -0
  5. data/lib/http_stub/configurer/dsl/scenario_activator.rb +2 -2
  6. data/lib/http_stub/configurer/dsl/scenario_builder.rb +2 -2
  7. data/lib/http_stub/configurer/dsl/server.rb +4 -4
  8. data/lib/http_stub/configurer/dsl/stub_builder.rb +5 -3
  9. data/lib/http_stub/configurer/request/controllable_value.rb +1 -3
  10. data/lib/http_stub/configurer/request/http/factory.rb +2 -2
  11. data/lib/http_stub/configurer/request/omittable.rb +2 -4
  12. data/lib/http_stub/configurer/request/regexpable.rb +3 -8
  13. data/lib/http_stub/configurer/server/command_processor.rb +5 -7
  14. data/lib/http_stub/configurer/server/facade.rb +2 -4
  15. data/lib/http_stub/extensions/core/hash.rb +4 -11
  16. data/lib/http_stub/extensions/core/hash/formatted.rb +23 -0
  17. data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +24 -0
  18. data/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access.rb +18 -0
  19. data/lib/http_stub/extensions/rack/handler.rb +1 -1
  20. data/lib/http_stub/rake/task_generators.rb +1 -1
  21. data/lib/http_stub/server/application.rb +10 -11
  22. data/lib/http_stub/server/application_helpers.rb +3 -5
  23. data/lib/http_stub/server/daemon.rb +5 -6
  24. data/lib/http_stub/server/request.rb +3 -10
  25. data/lib/http_stub/server/request/headers.rb +25 -0
  26. data/lib/http_stub/server/request/parameters.rb +21 -0
  27. data/lib/http_stub/server/request/request.rb +21 -0
  28. data/lib/http_stub/server/scenario/links.rb +1 -1
  29. data/lib/http_stub/server/stub/controller.rb +1 -1
  30. data/lib/http_stub/server/stub/empty.rb +4 -0
  31. data/lib/http_stub/server/stub/match/hash_matcher.rb +19 -0
  32. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -3
  33. data/lib/http_stub/server/stub/match/rule/body.rb +2 -4
  34. data/lib/http_stub/server/stub/match/rule/headers.rb +5 -11
  35. data/lib/http_stub/server/stub/match/rule/json_body.rb +3 -5
  36. data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
  37. data/lib/http_stub/server/stub/match/rule/parameters.rb +4 -7
  38. data/lib/http_stub/server/stub/match/rule/simple_body.rb +3 -3
  39. data/lib/http_stub/server/stub/match/rule/truthy.rb +27 -0
  40. data/lib/http_stub/server/stub/match/rule/uri.rb +3 -3
  41. data/lib/http_stub/server/stub/match/string_value_matcher.rb +4 -13
  42. data/lib/http_stub/server/stub/response.rb +5 -2
  43. data/lib/http_stub/server/stub/response/attribute/body.rb +32 -0
  44. data/lib/http_stub/server/stub/response/attribute/headers.rb +26 -0
  45. data/lib/http_stub/server/stub/response/attribute/interpolator.rb +26 -0
  46. data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +27 -0
  47. data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +27 -0
  48. data/lib/http_stub/server/stub/response/base.rb +5 -16
  49. data/lib/http_stub/server/stub/response/file.rb +6 -2
  50. data/lib/http_stub/server/stub/response/text.rb +12 -0
  51. data/lib/http_stub/server/stub/stub.rb +4 -0
  52. data/lib/http_stub/version.rb +1 -1
  53. data/spec/acceptance/request_reference_spec.rb +44 -0
  54. data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +37 -0
  55. data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +37 -0
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +14 -14
  57. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +2 -6
  58. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +34 -8
  59. data/spec/lib/http_stub/{server/formatted_hash_spec.rb → extensions/core/hash/formatted_spec.rb} +4 -6
  60. data/spec/lib/http_stub/{hash_with_indifferent_and_insensitive_access_spec.rb → extensions/core/hash/indifferent_and_insensitive_access_spec.rb} +8 -4
  61. data/spec/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access_spec.rb +41 -0
  62. data/spec/lib/http_stub/extensions/core/hash_spec.rb +11 -129
  63. data/spec/lib/http_stub/server/application_spec.rb +1 -1
  64. data/spec/lib/http_stub/server/payload_file_consolidator_spec.rb +1 -1
  65. data/spec/lib/http_stub/server/request/headers_spec.rb +89 -0
  66. data/spec/lib/http_stub/server/request/parameters_spec.rb +60 -0
  67. data/spec/lib/http_stub/server/request/request_spec.rb +84 -0
  68. data/spec/lib/http_stub/server/request_spec.rb +9 -98
  69. data/spec/lib/http_stub/server/response_spec.rb +2 -6
  70. data/spec/lib/http_stub/server/scenario/controller_spec.rb +1 -1
  71. data/spec/lib/http_stub/server/scenario/parser_spec.rb +3 -1
  72. data/spec/lib/http_stub/server/stub/controller_spec.rb +11 -4
  73. data/spec/lib/http_stub/server/stub/empty_spec.rb +10 -0
  74. data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +122 -0
  75. data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +4 -4
  76. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +54 -45
  77. data/spec/lib/http_stub/server/stub/match/rule/json_body_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +19 -17
  79. data/spec/lib/http_stub/server/stub/match/rule/parameters_spec.rb +26 -33
  80. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +16 -25
  81. data/spec/lib/http_stub/server/stub/match/{truthy_matcher_spec.rb → rule/truthy_spec.rb} +3 -5
  82. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +16 -25
  83. data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +2 -12
  84. data/spec/lib/http_stub/server/stub/parser_spec.rb +5 -3
  85. data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +98 -0
  86. data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +57 -0
  87. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +53 -0
  88. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +53 -0
  89. data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +41 -0
  90. data/spec/lib/http_stub/server/stub/response/base_spec.rb +6 -53
  91. data/spec/lib/http_stub/server/stub/response/file_spec.rb +48 -7
  92. data/spec/lib/http_stub/server/stub/response/text_spec.rb +66 -1
  93. data/spec/lib/http_stub/server/stub/stub_spec.rb +25 -4
  94. data/spec/spec_helper.rb +1 -0
  95. data/spec/support/http_stub/server/request_fixture.rb +1 -1
  96. metadata +86 -26
  97. data/lib/http_stub/hash_with_indifferent_and_insensitive_access.rb +0 -18
  98. data/lib/http_stub/server/formatted_hash.rb +0 -18
  99. data/lib/http_stub/server/header_parser.rb +0 -17
  100. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +0 -26
  101. data/lib/http_stub/server/stub/match/truthy_matcher.rb +0 -25
  102. data/spec/lib/http_stub/server/header_parser_spec.rb +0 -51
  103. data/spec/lib/http_stub/server/stub/match/hash_with_string_value_matchers_spec.rb +0 -166
@@ -1,26 +0,0 @@
1
- module HttpStub
2
- module Server
3
- module Stub
4
- module Match
5
-
6
- class HashWithStringValueMatchers < Hash
7
-
8
- def initialize(stub_hash)
9
- stub_hash.each_pair do |key, value|
10
- self[key] = HttpStub::Server::Stub::Match::StringValueMatcher.new(value)
11
- end
12
- end
13
-
14
- def matches?(actual_hash)
15
- !(self.find do |key_and_value_matcher|
16
- key, value_matcher = key_and_value_matcher
17
- !value_matcher.matches?(actual_hash[key])
18
- end)
19
- end
20
-
21
- end
22
-
23
- end
24
- end
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- module HttpStub
2
- module Server
3
- module Stub
4
- module Match
5
-
6
- class TruthyMatcher
7
-
8
- class << self
9
-
10
- def matches?(_request, _logger)
11
- true
12
- end
13
-
14
- def to_s
15
- ""
16
- end
17
-
18
- end
19
-
20
- end
21
-
22
- end
23
- end
24
- end
25
- end
@@ -1,51 +0,0 @@
1
- describe HttpStub::Server::HeaderParser do
2
-
3
- let(:non_header_env_elements) do
4
- {
5
- "rack.version" => [1, 3],
6
- "rack.multithreaded" => true,
7
- "rack.multiprocess" => false
8
- }
9
- end
10
- let(:env) { non_header_env_elements.merge(header_env_elements) }
11
- let(:request) { instance_double(Rack::Request, env: env) }
12
-
13
- let(:header_parser) { described_class }
14
-
15
- describe "::parse" do
16
-
17
- subject { header_parser.parse(request) }
18
-
19
- describe "when the request contains environment entries in upper case" do
20
-
21
- let(:header_env_elements) { { "KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3" } }
22
-
23
- it "returns a hash containing those entries" do
24
- expect(subject).to eql("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
25
- end
26
-
27
- end
28
-
29
- describe "when the request contains environment entries in upper case prefixed with 'HTTP_'" do
30
-
31
- let(:header_env_elements) { { "HTTP_KEY_1" => "value1", "HTTP_KEY_2" => "value2", "HTTP_KEY_3" => "value3" } }
32
-
33
- it "returns a hash containing those entries with the prefix removed" do
34
- expect(subject).to include("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
35
- end
36
-
37
- end
38
-
39
- describe "when only has environment entries in lower case" do
40
-
41
- let(:header_env_elements) { {} }
42
-
43
- it "returns an empty hash" do
44
- expect(subject).to eql({})
45
- end
46
-
47
- end
48
-
49
- end
50
-
51
- end
@@ -1,166 +0,0 @@
1
- describe HttpStub::Server::Stub::Match::HashWithStringValueMatchers do
2
-
3
- let(:stubbed_hash) do
4
- (1..3).reduce({}) do |result, i|
5
- result["key#{i}"] = "value#{i}"
6
- result
7
- end
8
- end
9
-
10
- let(:value_matchers) do
11
- stubbed_hash.values.map do |value|
12
- double(HttpStub::Server::Stub::Match::StringValueMatcher, to_s: value).as_null_object
13
- end
14
- end
15
-
16
- let(:value_matcher_hash) { HttpStub::Server::Stub::Match::HashWithStringValueMatchers.new(stubbed_hash) }
17
-
18
- before(:example) do
19
- value_matchers.each do |value|
20
- allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
21
- end
22
- end
23
-
24
- it "is a hash" do
25
- expect(value_matcher_hash).to be_a(Hash)
26
- end
27
-
28
- describe "constructor" do
29
-
30
- it "creates a value matcher representation of each value in the hash" do
31
- value_matchers.each do |value|
32
- expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(value.to_s).and_return(value)
33
- end
34
-
35
- expect(value_matcher_hash.values).to eql(value_matchers)
36
- end
37
-
38
- end
39
-
40
- describe "#matches?" do
41
-
42
- subject { value_matcher_hash.matches?(provided_hash) }
43
-
44
- context "when the stubbed hash contains multiple entries" do
45
-
46
- context "and the provided hash has the same number of entries" do
47
-
48
- context "and the keys match" do
49
-
50
- let(:provided_hash) do
51
- stubbed_hash.reduce({}) do |result, entry|
52
- result[entry[0]] = "another #{entry[1]}"
53
- result
54
- end
55
- end
56
-
57
- context "and the values match" do
58
-
59
- before(:example) do
60
- value_matchers.each do |value|
61
- allow(value).to receive(:matches?).with("another #{value}").and_return(true)
62
- end
63
- end
64
-
65
- it "returns true" do
66
- expect(subject).to be(true)
67
- end
68
-
69
- end
70
-
71
- context "and a value does not match" do
72
-
73
- before(:example) do
74
- value_matchers.each do |value|
75
- allow(value).to receive(:matches?).with("another #{value}").and_return(true)
76
- end
77
-
78
- non_matching_value = value_matchers[1]
79
- allow(non_matching_value).to receive(:matches?).with("another #{non_matching_value}").and_return(false)
80
- end
81
-
82
- it "returns false" do
83
- expect(subject).to be(false)
84
- end
85
-
86
- end
87
-
88
- end
89
-
90
- context "and a key does not match" do
91
-
92
- let(:provided_hash) { { "key1" => "value1", "differentkey2" => "another value2", "key3" => "value3" } }
93
-
94
- it "determines if the corresponding value matches nil" do
95
- expected_values = [ "value1", nil, "value3" ]
96
- value_matchers.zip(expected_values).each do |value_matcher, expected_value|
97
- allow(value_matcher).to receive(:matches?).with(expected_value)
98
- end
99
-
100
- subject
101
- end
102
-
103
- it "returns the result of evaluating the value matchers" do
104
- value_matchers.each { |value| allow(value).to receive(:matches?).and_return(true) }
105
-
106
- expect(subject).to be(true)
107
- end
108
-
109
- end
110
-
111
- end
112
-
113
- context "and the provided hash contains more entries" do
114
-
115
- let(:provided_hash) do
116
- (1..5).reduce({}) do |result, i|
117
- result["key#{i}"] = "another value#{i}"
118
- result
119
- end
120
- end
121
-
122
- context "and it has matching keys and values" do
123
-
124
- before(:example) do
125
- value_matchers.each { |value| allow(value).to receive(:matches?).with("another #{value}").and_return(true) }
126
- end
127
-
128
- it "returns true" do
129
- expect(subject).to be(true)
130
- end
131
-
132
- end
133
-
134
- end
135
-
136
- end
137
-
138
- context "when the stubbed hash is empty" do
139
-
140
- let(:stubbed_hash) { {} }
141
-
142
- context "and the provided hash is not empty" do
143
-
144
- let(:provided_hash) { { "key" => "value" } }
145
-
146
- it "returns true" do
147
- expect(subject).to be(true)
148
- end
149
-
150
- end
151
-
152
- context "and the provided hash is empty" do
153
-
154
- let(:provided_hash) { {} }
155
-
156
- it "returns true" do
157
- expect(subject).to be(true)
158
- end
159
-
160
- end
161
-
162
- end
163
-
164
- end
165
-
166
- end