http_stub 0.22.4 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
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,13 +1,11 @@
1
- describe HttpStub::Server::FormattedHash do
1
+ describe HttpStub::Extensions::Core::Hash::Formatted do
2
+
3
+ let(:testable_class) { Class.new(::Hash).tap { |hash_class| hash_class.send(:include, described_class) } }
2
4
 
3
5
  let(:underlying_hash) { {} }
4
6
  let(:key_value_delimiter) { "=" }
5
7
 
6
- let(:formatted_hash) { described_class.new(underlying_hash, key_value_delimiter) }
7
-
8
- it "is a Hash" do
9
- expect(formatted_hash).to be_a(Hash)
10
- end
8
+ let(:formatted_hash) { testable_class.new(underlying_hash, key_value_delimiter) }
11
9
 
12
10
  describe "#to_s" do
13
11
 
@@ -1,10 +1,14 @@
1
- describe HttpStub::HashWithIndifferentAndInsensitiveAccess do
1
+ describe HttpStub::Extensions::Core::Hash::IndifferentAndInsensitiveAccess do
2
2
 
3
- let(:enhanced_hash) { HttpStub::HashWithIndifferentAndInsensitiveAccess.new(original_hash) }
3
+ let(:testable_class) { Class.new(::Hash).tap { |hash_class| hash_class.send(:include, described_class) } }
4
+
5
+ let(:indifferent_and_insensitive_access_hash) { testable_class.new }
6
+
7
+ before(:example) { indifferent_and_insensitive_access_hash.merge!(original_hash) }
4
8
 
5
9
  describe "#[]" do
6
10
 
7
- subject { enhanced_hash[key] }
11
+ subject { indifferent_and_insensitive_access_hash[key] }
8
12
 
9
13
  context "when the original hash contains symbol keys" do
10
14
 
@@ -90,7 +94,7 @@ describe HttpStub::HashWithIndifferentAndInsensitiveAccess do
90
94
 
91
95
  end
92
96
 
93
- context "when the original hash string keys" do
97
+ context "when the original hash contains string keys" do
94
98
 
95
99
  let(:original_hash) { { "key" => "value", "another_key" => "another value" } }
96
100
 
@@ -0,0 +1,41 @@
1
+ describe HttpStub::Extensions::Core::Hash::WithIndifferentAndInsensitiveAccess do
2
+
3
+ let(:hash_with_indifferent_and_insensitive_access) { described_class.new }
4
+
5
+ it "is a Hash" do
6
+ expect(hash_with_indifferent_and_insensitive_access).to be_a(::Hash)
7
+ end
8
+
9
+ it "has IndifferentAndInsensitiveAccess" do
10
+ expect(hash_with_indifferent_and_insensitive_access).to(
11
+ be_a(HttpStub::Extensions::Core::Hash::IndifferentAndInsensitiveAccess)
12
+ )
13
+ end
14
+
15
+ describe "constructor" do
16
+
17
+ let(:hash_with_indifferent_and_insensitive_access) { described_class.new(existing_hash) }
18
+
19
+ context "when provided an existing hash" do
20
+
21
+ let(:existing_hash) { { key: :value } }
22
+
23
+ it "creates an indifferent and insensitive hash that includes the entries from the provided hash" do
24
+ expect(hash_with_indifferent_and_insensitive_access).to include(existing_hash)
25
+ end
26
+
27
+ end
28
+
29
+ context "when provided nil" do
30
+
31
+ let(:existing_hash) { nil }
32
+
33
+ it "creates an empty indifferent and insensitive hash" do
34
+ expect(hash_with_indifferent_and_insensitive_access.empty?).to be(true)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -1,16 +1,10 @@
1
1
  describe HttpStub::Extensions::Core::Hash do
2
2
 
3
- describe "#downcase_and_underscore_keys" do
3
+ describe "#underscore_keys" do
4
4
 
5
- describe "when the hash contains keys which are strings" do
5
+ subject { hash.underscore_keys }
6
6
 
7
- let(:hash) do
8
- { "lower" => 1, "UPPER" => 2, "MiXeDcAsE" => 3 }
9
- end
10
-
11
- it "downcases the string keys" do
12
- expect(hash.downcase_and_underscore_keys).to eql({ "lower" => 1, "upper" => 2, "mixedcase" => 3 })
13
- end
7
+ describe "when the hash contains keys which are strings" do
14
8
 
15
9
  describe "and keys contain underscores and hyphens" do
16
10
 
@@ -19,9 +13,7 @@ describe HttpStub::Extensions::Core::Hash do
19
13
  end
20
14
 
21
15
  it "downcases the string keys" do
22
- expect(hash.downcase_and_underscore_keys).to eql({ "has_underscore" => 1,
23
- "has_hypen" => 2,
24
- "has_underscore_and_hypen" => 3 })
16
+ expect(subject).to eql({ "has_underscore" => 1, "has_hypen" => 2, "has_underscore_and_hypen" => 3 })
25
17
  end
26
18
 
27
19
  end
@@ -34,120 +26,8 @@ describe HttpStub::Extensions::Core::Hash do
34
26
  { 1 => 2, :symbol => 3, nil => 4 }
35
27
  end
36
28
 
37
- it "does not alter a hash" do
38
- expect(hash.downcase_and_underscore_keys).to eql({ 1 => 2, :symbol => 3, nil => 4 })
39
- end
40
-
41
- end
42
-
43
- end
44
-
45
- describe "#has_hash?" do
46
-
47
- describe "when many elements are provided" do
48
-
49
- let(:hash_parameter) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
50
-
51
- describe "and the hash contains only those elements" do
52
-
53
- let(:hash) { hash_parameter }
54
-
55
- it "returns true" do
56
- expect(hash.has_hash?(hash_parameter)).to be(true)
57
- end
58
-
59
- end
60
-
61
- describe "and the hash contains more than those elements" do
62
-
63
- let(:hash) { hash_parameter.merge("key4" => "value4") }
64
-
65
- it "returns true" do
66
- expect(hash.has_hash?(hash_parameter)).to be(true)
67
- end
68
-
69
- end
70
-
71
- describe "and the hash contains keys that match but values that do not match" do
72
-
73
- let(:hash) { { "key1" => "value1", "key2" => "nonMatchingValue", "key3" => "value3" } }
74
-
75
- it "returns false" do
76
- expect(hash.has_hash?(hash_parameter)).to be(false)
77
- end
78
-
79
- end
80
-
81
- describe "and the hash contains less than those elements" do
82
-
83
- let(:hash) { { "key1" => "value1", "key3" => "value3" } }
84
-
85
- it "returns false" do
86
- expect(hash.has_hash?(hash_parameter)).to be(false)
87
- end
88
-
89
- end
90
-
91
- describe "and the hash contains no elements" do
92
-
93
- let(:hash) { {} }
94
-
95
- it "returns false" do
96
- expect(hash.has_hash?(hash_parameter)).to be(false)
97
- end
98
-
99
- end
100
-
101
- end
102
-
103
- describe "when no elements are provided" do
104
-
105
- let(:hash_parameter) { {} }
106
-
107
- describe "and the hash contains no element" do
108
-
109
- let(:hash) { {} }
110
-
111
- it "returns true" do
112
- expect(hash.has_hash?(hash_parameter)).to be(true)
113
- end
114
-
115
- end
116
-
117
- describe "when the hash contains elements" do
118
-
119
- let(:hash) { { "key" => "value" } }
120
-
121
- it "returns true" do
122
- expect(hash.has_hash?(hash_parameter)).to be(true)
123
- end
124
-
125
- end
126
-
127
- end
128
-
129
- describe "when a nil hash is provided" do
130
-
131
- let(:hash_parameter) { nil }
132
-
133
- describe "and the hash contains no elements" do
134
-
135
- let(:hash) { {} }
136
-
137
- it "returns true" do
138
- expect(hash.has_hash?(hash_parameter)).to be(true)
139
- end
140
-
141
- end
142
-
143
- describe "when the hash contains elements" do
144
-
145
- let(:hash) { { "key" => "value" } }
146
-
147
- it "returns true" do
148
- expect(hash.has_hash?(hash_parameter)).to be(true)
149
- end
150
-
29
+ it "does not alter the hash" do
30
+ expect(subject).to eql({ 1 => 2, :symbol => 3, nil => 4 })
151
31
  end
152
32
 
153
33
  end
@@ -157,18 +37,20 @@ describe HttpStub::Extensions::Core::Hash do
157
37
  describe "#with_indifferent_and_insensitive_access" do
158
38
 
159
39
  let(:hash) { { key: "value" } }
160
- let(:indifferent_and_insensitive_hash) { instance_double(HttpStub::HashWithIndifferentAndInsensitiveAccess) }
40
+ let(:indifferent_and_insensitive_hash) do
41
+ instance_double(HttpStub::Extensions::Core::Hash::WithIndifferentAndInsensitiveAccess)
42
+ end
161
43
 
162
44
  subject { hash.with_indifferent_and_insensitive_access }
163
45
 
164
46
  before(:example) do
165
- allow(HttpStub::HashWithIndifferentAndInsensitiveAccess).to(
47
+ allow(HttpStub::Extensions::Core::Hash::WithIndifferentAndInsensitiveAccess).to(
166
48
  receive(:new).and_return(indifferent_and_insensitive_hash)
167
49
  )
168
50
  end
169
51
 
170
52
  it "creates a hash with indifferent and insensitive access containing the current hash" do
171
- expect(HttpStub::HashWithIndifferentAndInsensitiveAccess).to receive(:new).with(hash)
53
+ expect(HttpStub::Extensions::Core::Hash::WithIndifferentAndInsensitiveAccess).to receive(:new).with(hash)
172
54
 
173
55
  subject
174
56
  end
@@ -285,7 +285,7 @@ describe HttpStub::Server::Application do
285
285
  before(:example) { allow(stub_controller).to receive(:match).and_return(stub_response) }
286
286
 
287
287
  it "attempts to match the request to a stub response via the stub controller" do
288
- expect(stub_controller).to receive(:match).with(an_instance_of(HttpStub::Server::Request), anything)
288
+ expect(stub_controller).to receive(:match).with(an_instance_of(HttpStub::Server::Request::Request), anything)
289
289
 
290
290
  subject
291
291
  end
@@ -5,7 +5,7 @@ describe HttpStub::Server::Stub::PayloadFileConsolidator do
5
5
  describe "::consolidate!" do
6
6
 
7
7
  let(:parameters) { {} }
8
- let(:request) { instance_double(HttpStub::Server::Request, parameters: parameters) }
8
+ let(:request) { instance_double(HttpStub::Server::Request::Request, parameters: parameters) }
9
9
 
10
10
  subject { consolidator.consolidate!(payload, request) }
11
11
 
@@ -0,0 +1,89 @@
1
+ describe HttpStub::Server::Request::Headers do
2
+
3
+ let(:header_hash) { {} }
4
+
5
+ let(:headers) { described_class.new(header_hash) }
6
+
7
+ it "is a hash with indifferent and insensitive access" do
8
+ expect(headers).to be_a(HttpStub::Extensions::Core::Hash::IndifferentAndInsensitiveAccess)
9
+ end
10
+
11
+ describe "::create" do
12
+
13
+ let(:non_header_env_elements) do
14
+ {
15
+ "rack.version" => [1, 3],
16
+ "rack.multithreaded" => true,
17
+ "rack.multiprocess" => false
18
+ }
19
+ end
20
+ let(:env) { non_header_env_elements.merge(header_env_elements) }
21
+ let(:rack_request) { instance_double(Rack::Request, env: env) }
22
+
23
+ subject { described_class.create(rack_request) }
24
+
25
+ describe "when the request contains environment entries in upper case" do
26
+
27
+ let(:header_env_elements) { (1..3).each_with_object({}) { |i, result| result["KEY_#{i}"] = "value#{i}" } }
28
+
29
+ it "returns a hash containing those entries" do
30
+ expect(subject).to eql("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
31
+ end
32
+
33
+ end
34
+
35
+ describe "when the request contains environment entries in upper case prefixed with 'HTTP_'" do
36
+
37
+ let(:header_env_elements) { (1..3).each_with_object({}) { |i, result| result["HTTP_KEY_#{i}"] = "value#{i}" } }
38
+
39
+ it "returns a hash containing those entries with the prefix removed" do
40
+ expect(subject).to include("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
41
+ end
42
+
43
+ end
44
+
45
+ describe "when only has environment entries in lower case" do
46
+
47
+ let(:header_env_elements) { {} }
48
+
49
+ it "returns an empty hash" do
50
+ expect(subject).to eql({})
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ describe "#to_s" do
58
+
59
+ subject { headers.to_s }
60
+
61
+ context "when headers are provided" do
62
+
63
+ let(:header_hash) { (1..3).each_with_object({}) { |i, result| result["KEY_#{i}"] = "VALUE_#{i}" } }
64
+
65
+ it "returns a string with each header name and value separated by ':'" do
66
+ result = subject
67
+
68
+ headers.each { |name, value| expect(result).to match(/#{name}:#{value}/) }
69
+ end
70
+
71
+ it "separates each header with comma for readability" do
72
+ expect(subject).to match(/KEY_\d.VALUE_\d, KEY_\d.VALUE_\d, KEY_\d.VALUE_\d/)
73
+ end
74
+
75
+ end
76
+
77
+ context "when headers are not provided" do
78
+
79
+ let(:header_hash) { {} }
80
+
81
+ it "returns an empty string" do
82
+ expect(subject).to eql("")
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,60 @@
1
+ describe HttpStub::Server::Request::Parameters do
2
+
3
+ let(:parameter_hash) { {} }
4
+
5
+ let(:parameters) { described_class.new(parameter_hash) }
6
+
7
+ it "is a hash with indifferent access" do
8
+ expect(parameters).to be_a(HashWithIndifferentAccess)
9
+ end
10
+
11
+ describe "::create" do
12
+
13
+ let(:rack_params) { { "some_parameter_name" => "some parameter value" } }
14
+ let(:rack_request) { instance_double(Rack::Request, params: rack_params) }
15
+
16
+ subject { described_class.create(rack_request) }
17
+
18
+ it "returns http stub request parameters" do
19
+ expect(subject).to be_an_instance_of(described_class)
20
+ end
21
+
22
+ it "returns parameters containing the rack request parameters" do
23
+ expect(subject).to eql(rack_params)
24
+ end
25
+
26
+ end
27
+
28
+ describe "#to_s" do
29
+
30
+ subject { parameters.to_s }
31
+
32
+ context "when parameters are provided" do
33
+
34
+ let(:parameter_hash) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value#{i}" } }
35
+
36
+ it "returns a string containing each parameter formatted as a conventional request parameter" do
37
+ result = subject
38
+
39
+ parameter_hash.each { |key, value| expect(result).to match(/#{key}=#{value}/) }
40
+ end
41
+
42
+ it "separates each parameter with the conventional request parameter delimiter" do
43
+ expect(subject).to match(/key\d.value\d\&key\d.value\d\&key\d.value\d/)
44
+ end
45
+
46
+ end
47
+
48
+ context "when parameters are not provided" do
49
+
50
+ let(:parameter_hash) { {} }
51
+
52
+ it "returns an empty string" do
53
+ expect(subject).to eql("")
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,84 @@
1
+ describe HttpStub::Server::Request::Request do
2
+
3
+ let(:rack_path_info) { "/rack/path/info" }
4
+ let(:rack_request_method) { "some method" }
5
+ let(:rack_env) { { "some_env_name" => "some env value" } }
6
+ let(:rack_parameters) { { "some_parameter_name" => "some parameter value" } }
7
+ let(:rack_body) { "some request body" }
8
+ let(:rack_request) do
9
+ instance_double(Rack::Request, path_info: rack_path_info,
10
+ request_method: rack_request_method,
11
+ env: rack_env,
12
+ params: rack_parameters,
13
+ body: StringIO.new(rack_body))
14
+ end
15
+
16
+ let(:server_request) { described_class.new(rack_request) }
17
+
18
+ describe "#uri" do
19
+
20
+ it "is the rack request path information" do
21
+ expect(server_request.uri).to eql(rack_path_info)
22
+ end
23
+
24
+ end
25
+
26
+ describe "#method" do
27
+
28
+ subject { server_request.method }
29
+
30
+ it "is the rack request method" do
31
+ expect(subject).to eql(rack_request_method)
32
+ end
33
+
34
+ end
35
+
36
+ describe "#headers" do
37
+
38
+ subject { server_request.headers }
39
+
40
+ it "creates http stub request headers from the rack request" do
41
+ expect(HttpStub::Server::Request::Headers).to receive(:create).with(rack_request)
42
+
43
+ subject
44
+ end
45
+
46
+ it "returns the created http stub request headers" do
47
+ http_stub_request_headers = instance_double(HttpStub::Server::Request::Headers)
48
+ allow(HttpStub::Server::Request::Headers).to receive(:create).and_return(http_stub_request_headers)
49
+
50
+ expect(subject).to eql(http_stub_request_headers)
51
+ end
52
+
53
+ end
54
+
55
+ describe "#parameters" do
56
+
57
+ subject { server_request.parameters }
58
+
59
+ it "creates http stub request parameters from the rack request" do
60
+ expect(HttpStub::Server::Request::Parameters).to receive(:create).with(rack_request)
61
+
62
+ subject
63
+ end
64
+
65
+ it "returns the created http stub request parameters" do
66
+ http_stub_request_parameters = instance_double(HttpStub::Server::Request::Parameters)
67
+ allow(HttpStub::Server::Request::Parameters).to receive(:create).and_return(http_stub_request_parameters)
68
+
69
+ expect(subject).to eql(http_stub_request_parameters)
70
+ end
71
+
72
+ end
73
+
74
+ describe "#body" do
75
+
76
+ subject { server_request.body }
77
+
78
+ it "is the read rack request body" do
79
+ expect(subject).to eql(rack_body)
80
+ end
81
+
82
+ end
83
+
84
+ end