evil-client 0.3.3 → 1.0.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 (180) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -11
  3. data/.gitignore +1 -0
  4. data/.rspec +0 -1
  5. data/.rubocop.yml +22 -19
  6. data/.travis.yml +1 -0
  7. data/CHANGELOG.md +251 -6
  8. data/LICENSE.txt +3 -1
  9. data/README.md +47 -81
  10. data/docs/helpers/body.md +93 -0
  11. data/docs/helpers/connection.md +19 -0
  12. data/docs/helpers/headers.md +72 -0
  13. data/docs/helpers/http_method.md +39 -0
  14. data/docs/helpers/let.md +14 -0
  15. data/docs/helpers/logger.md +24 -0
  16. data/docs/helpers/middleware.md +56 -0
  17. data/docs/helpers/operation.md +103 -0
  18. data/docs/helpers/option.md +50 -0
  19. data/docs/helpers/path.md +37 -0
  20. data/docs/helpers/query.md +59 -0
  21. data/docs/helpers/response.md +40 -0
  22. data/docs/helpers/scope.md +121 -0
  23. data/docs/helpers/security.md +102 -0
  24. data/docs/helpers/validate.md +68 -0
  25. data/docs/index.md +70 -78
  26. data/docs/license.md +5 -1
  27. data/docs/rspec.md +96 -0
  28. data/evil-client.gemspec +10 -8
  29. data/lib/evil/client.rb +126 -72
  30. data/lib/evil/client/builder.rb +47 -0
  31. data/lib/evil/client/builder/operation.rb +40 -0
  32. data/lib/evil/client/builder/scope.rb +31 -0
  33. data/lib/evil/client/chaining.rb +17 -0
  34. data/lib/evil/client/connection.rb +60 -20
  35. data/lib/evil/client/container.rb +66 -0
  36. data/lib/evil/client/container/operation.rb +23 -0
  37. data/lib/evil/client/container/scope.rb +28 -0
  38. data/lib/evil/client/exceptions/definition_error.rb +15 -0
  39. data/lib/evil/client/exceptions/name_error.rb +32 -0
  40. data/lib/evil/client/exceptions/response_error.rb +42 -0
  41. data/lib/evil/client/exceptions/type_error.rb +29 -0
  42. data/lib/evil/client/exceptions/validation_error.rb +27 -0
  43. data/lib/evil/client/formatter.rb +49 -0
  44. data/lib/evil/client/formatter/form.rb +45 -0
  45. data/lib/evil/client/formatter/multipart.rb +33 -0
  46. data/lib/evil/client/formatter/part.rb +66 -0
  47. data/lib/evil/client/formatter/text.rb +21 -0
  48. data/lib/evil/client/resolver.rb +84 -0
  49. data/lib/evil/client/resolver/body.rb +22 -0
  50. data/lib/evil/client/resolver/format.rb +30 -0
  51. data/lib/evil/client/resolver/headers.rb +46 -0
  52. data/lib/evil/client/resolver/http_method.rb +34 -0
  53. data/lib/evil/client/resolver/middleware.rb +36 -0
  54. data/lib/evil/client/resolver/query.rb +39 -0
  55. data/lib/evil/client/resolver/request.rb +96 -0
  56. data/lib/evil/client/resolver/response.rb +26 -0
  57. data/lib/evil/client/resolver/security.rb +113 -0
  58. data/lib/evil/client/resolver/uri.rb +35 -0
  59. data/lib/evil/client/rspec.rb +127 -0
  60. data/lib/evil/client/schema.rb +105 -0
  61. data/lib/evil/client/schema/operation.rb +177 -0
  62. data/lib/evil/client/schema/scope.rb +73 -0
  63. data/lib/evil/client/settings.rb +172 -0
  64. data/lib/evil/client/settings/validator.rb +64 -0
  65. data/mkdocs.yml +21 -15
  66. data/spec/features/custom_connection_spec.rb +17 -0
  67. data/spec/features/operation/middleware_spec.rb +50 -0
  68. data/spec/features/operation/options_spec.rb +71 -0
  69. data/spec/features/operation/request_spec.rb +94 -0
  70. data/spec/features/operation/response_spec.rb +48 -0
  71. data/spec/features/scope/options_spec.rb +52 -0
  72. data/spec/fixtures/locales/en.yml +16 -0
  73. data/spec/fixtures/test_client.rb +76 -0
  74. data/spec/spec_helper.rb +18 -6
  75. data/spec/support/fixtures_helper.rb +7 -0
  76. data/spec/unit/builder/operation_spec.rb +90 -0
  77. data/spec/unit/builder/scope_spec.rb +84 -0
  78. data/spec/unit/client_spec.rb +137 -0
  79. data/spec/unit/connection_spec.rb +78 -0
  80. data/spec/unit/container/operation_spec.rb +81 -0
  81. data/spec/unit/container/scope_spec.rb +61 -0
  82. data/spec/unit/container_spec.rb +107 -0
  83. data/spec/unit/exceptions/definition_error_spec.rb +15 -0
  84. data/spec/unit/exceptions/name_error_spec.rb +77 -0
  85. data/spec/unit/exceptions/response_error_spec.rb +22 -0
  86. data/spec/unit/exceptions/type_error_spec.rb +71 -0
  87. data/spec/unit/exceptions/validation_error_spec.rb +13 -0
  88. data/spec/unit/formatter/form_spec.rb +27 -0
  89. data/spec/unit/formatter/multipart_spec.rb +23 -0
  90. data/spec/unit/formatter/part_spec.rb +49 -0
  91. data/spec/unit/formatter/text_spec.rb +37 -0
  92. data/spec/unit/formatter_spec.rb +46 -0
  93. data/spec/unit/resolver/body_spec.rb +65 -0
  94. data/spec/unit/resolver/format_spec.rb +66 -0
  95. data/spec/unit/resolver/headers_spec.rb +93 -0
  96. data/spec/unit/resolver/http_method_spec.rb +67 -0
  97. data/spec/unit/resolver/middleware_spec.rb +83 -0
  98. data/spec/unit/resolver/query_spec.rb +85 -0
  99. data/spec/unit/resolver/request_spec.rb +121 -0
  100. data/spec/unit/resolver/response_spec.rb +64 -0
  101. data/spec/unit/resolver/security_spec.rb +156 -0
  102. data/spec/unit/resolver/uri_spec.rb +117 -0
  103. data/spec/unit/rspec_spec.rb +342 -0
  104. data/spec/unit/schema/operation_spec.rb +309 -0
  105. data/spec/unit/schema/scope_spec.rb +110 -0
  106. data/spec/unit/schema_spec.rb +157 -0
  107. data/spec/unit/settings/validator_spec.rb +128 -0
  108. data/spec/unit/settings_spec.rb +248 -0
  109. metadata +192 -135
  110. data/docs/base_url.md +0 -38
  111. data/docs/documentation.md +0 -9
  112. data/docs/headers.md +0 -59
  113. data/docs/http_method.md +0 -31
  114. data/docs/model.md +0 -173
  115. data/docs/operation.md +0 -0
  116. data/docs/overview.md +0 -0
  117. data/docs/path.md +0 -48
  118. data/docs/query.md +0 -99
  119. data/docs/responses.md +0 -66
  120. data/docs/security.md +0 -102
  121. data/docs/settings.md +0 -32
  122. data/lib/evil/client/connection/net_http.rb +0 -57
  123. data/lib/evil/client/dsl.rb +0 -127
  124. data/lib/evil/client/dsl/base.rb +0 -26
  125. data/lib/evil/client/dsl/files.rb +0 -37
  126. data/lib/evil/client/dsl/headers.rb +0 -16
  127. data/lib/evil/client/dsl/http_method.rb +0 -24
  128. data/lib/evil/client/dsl/operation.rb +0 -91
  129. data/lib/evil/client/dsl/operations.rb +0 -41
  130. data/lib/evil/client/dsl/path.rb +0 -25
  131. data/lib/evil/client/dsl/query.rb +0 -16
  132. data/lib/evil/client/dsl/response.rb +0 -61
  133. data/lib/evil/client/dsl/responses.rb +0 -29
  134. data/lib/evil/client/dsl/scope.rb +0 -27
  135. data/lib/evil/client/dsl/security.rb +0 -57
  136. data/lib/evil/client/dsl/verifier.rb +0 -35
  137. data/lib/evil/client/middleware.rb +0 -81
  138. data/lib/evil/client/middleware/base.rb +0 -11
  139. data/lib/evil/client/middleware/merge_security.rb +0 -20
  140. data/lib/evil/client/middleware/normalize_headers.rb +0 -17
  141. data/lib/evil/client/middleware/stringify_form.rb +0 -40
  142. data/lib/evil/client/middleware/stringify_json.rb +0 -19
  143. data/lib/evil/client/middleware/stringify_multipart.rb +0 -36
  144. data/lib/evil/client/middleware/stringify_multipart/part.rb +0 -36
  145. data/lib/evil/client/middleware/stringify_query.rb +0 -35
  146. data/lib/evil/client/operation.rb +0 -34
  147. data/lib/evil/client/operation/request.rb +0 -26
  148. data/lib/evil/client/operation/response.rb +0 -39
  149. data/lib/evil/client/operation/response_error.rb +0 -13
  150. data/lib/evil/client/operation/unexpected_response_error.rb +0 -19
  151. data/spec/features/instantiation_spec.rb +0 -68
  152. data/spec/features/middleware_spec.rb +0 -79
  153. data/spec/features/operation_with_documentation_spec.rb +0 -41
  154. data/spec/features/operation_with_files_spec.rb +0 -40
  155. data/spec/features/operation_with_form_body_spec.rb +0 -158
  156. data/spec/features/operation_with_headers_spec.rb +0 -99
  157. data/spec/features/operation_with_http_method_spec.rb +0 -45
  158. data/spec/features/operation_with_json_body_spec.rb +0 -156
  159. data/spec/features/operation_with_nested_responses_spec.rb +0 -95
  160. data/spec/features/operation_with_path_spec.rb +0 -47
  161. data/spec/features/operation_with_query_spec.rb +0 -84
  162. data/spec/features/operation_with_security_spec.rb +0 -228
  163. data/spec/features/scoping_spec.rb +0 -48
  164. data/spec/support/test_client.rb +0 -15
  165. data/spec/unit/evil/client/connection/net_http_spec.rb +0 -38
  166. data/spec/unit/evil/client/dsl/files_spec.rb +0 -37
  167. data/spec/unit/evil/client/dsl/operation_spec.rb +0 -374
  168. data/spec/unit/evil/client/dsl/operations_spec.rb +0 -29
  169. data/spec/unit/evil/client/dsl/scope_spec.rb +0 -32
  170. data/spec/unit/evil/client/dsl/security_spec.rb +0 -135
  171. data/spec/unit/evil/client/middleware/merge_security_spec.rb +0 -32
  172. data/spec/unit/evil/client/middleware/normalize_headers_spec.rb +0 -17
  173. data/spec/unit/evil/client/middleware/stringify_form_spec.rb +0 -63
  174. data/spec/unit/evil/client/middleware/stringify_json_spec.rb +0 -61
  175. data/spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb +0 -59
  176. data/spec/unit/evil/client/middleware/stringify_multipart_spec.rb +0 -62
  177. data/spec/unit/evil/client/middleware/stringify_query_spec.rb +0 -40
  178. data/spec/unit/evil/client/middleware_spec.rb +0 -46
  179. data/spec/unit/evil/client/operation/request_spec.rb +0 -49
  180. data/spec/unit/evil/client/operation/response_spec.rb +0 -63
@@ -0,0 +1,309 @@
1
+ RSpec.describe Evil::Client::Schema::Operation do
2
+ let(:client) { class_double Evil::Client, name: "MyApi" }
3
+ let(:parent) { described_class.new client }
4
+ let(:schema) { described_class.new parent, :users }
5
+ let(:block) { -> { "bar" } }
6
+
7
+ it "subclasses the base schema" do
8
+ expect(described_class.superclass).to eq Evil::Client::Schema
9
+ end
10
+
11
+ describe "#leaf?" do
12
+ subject { schema.leaf? }
13
+
14
+ it "returns true" do
15
+ expect(subject).to eq true
16
+ end
17
+ end
18
+
19
+ describe "definitions" do
20
+ subject { schema.definitions }
21
+
22
+ it "is a hash with empty responses" do
23
+ expect(subject).to eq responses: {}
24
+ end
25
+ end
26
+
27
+ describe "#path" do
28
+ context "with block syntax" do
29
+ subject { schema.path(&block) }
30
+
31
+ it "adds block to definitions" do
32
+ expect { subject }
33
+ .to change { schema.definitions[:path] }
34
+ .to block
35
+ end
36
+
37
+ it "returns the schema itself" do
38
+ expect(subject).to eq schema
39
+ end
40
+ end
41
+
42
+ context "with plain syntax" do
43
+ subject { schema.path "foo" }
44
+
45
+ it "wraps value to block and adds it to definitions" do
46
+ expect { subject }
47
+ .to change { schema.definitions[:path]&.call }
48
+ .to "foo"
49
+ end
50
+
51
+ it "returns the schema itself" do
52
+ expect(subject).to eq schema
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#http_method" do
58
+ context "with block syntax" do
59
+ subject { schema.http_method(&block) }
60
+
61
+ it "adds block to definitions" do
62
+ expect { subject }
63
+ .to change { schema.definitions[:http_method] }
64
+ .to block
65
+ end
66
+
67
+ it "returns the schema itself" do
68
+ expect(subject).to eq schema
69
+ end
70
+ end
71
+
72
+ context "with plain syntax" do
73
+ subject { schema.http_method "foo" }
74
+
75
+ it "wraps value to block and adds it to definitions" do
76
+ expect { subject }
77
+ .to change { schema.definitions[:http_method]&.call }
78
+ .to "foo"
79
+ end
80
+
81
+ it "returns the schema itself" do
82
+ expect(subject).to eq schema
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "#format" do
88
+ context "with block syntax" do
89
+ subject { schema.format(&block) }
90
+
91
+ it "adds block to definitions" do
92
+ expect { subject }
93
+ .to change { schema.definitions[:format] }
94
+ .to block
95
+ end
96
+
97
+ it "returns the schema itself" do
98
+ expect(subject).to eq schema
99
+ end
100
+ end
101
+
102
+ context "with plain syntax" do
103
+ subject { schema.format "foo" }
104
+
105
+ it "wraps value to block and adds it to definitions" do
106
+ expect { subject }
107
+ .to change { schema.definitions[:format]&.call }
108
+ .to "foo"
109
+ end
110
+
111
+ it "returns the schema itself" do
112
+ expect(subject).to eq schema
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "#security" do
118
+ context "with block syntax" do
119
+ subject { schema.security(&block) }
120
+
121
+ it "adds block to definitions" do
122
+ expect { subject }
123
+ .to change { schema.definitions[:security] }
124
+ .to block
125
+ end
126
+
127
+ it "returns the schema itself" do
128
+ expect(subject).to eq schema
129
+ end
130
+ end
131
+
132
+ context "with plain syntax" do
133
+ subject { schema.security "foo" => "bar" }
134
+
135
+ it "wraps value to block and adds it to definitions" do
136
+ expect { subject }
137
+ .to change { schema.definitions[:security]&.call }
138
+ .to "foo" => "bar"
139
+ end
140
+
141
+ it "returns the schema itself" do
142
+ expect(subject).to eq schema
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "#headers" do
148
+ context "with block syntax" do
149
+ subject { schema.headers(&block) }
150
+
151
+ it "adds block to definitions" do
152
+ expect { subject }
153
+ .to change { schema.definitions[:headers] }
154
+ .to block
155
+ end
156
+
157
+ it "returns the schema itself" do
158
+ expect(subject).to eq schema
159
+ end
160
+ end
161
+
162
+ context "with plain syntax" do
163
+ subject { schema.headers "foo" => "bar" }
164
+
165
+ it "wraps value to block and adds it to definitions" do
166
+ expect { subject }
167
+ .to change { schema.definitions[:headers]&.call }
168
+ .to "foo" => "bar"
169
+ end
170
+
171
+ it "returns the schema itself" do
172
+ expect(subject).to eq schema
173
+ end
174
+ end
175
+ end
176
+
177
+ describe "#query" do
178
+ context "with block syntax" do
179
+ subject { schema.query(&block) }
180
+
181
+ it "adds block to definitions" do
182
+ expect { subject }
183
+ .to change { schema.definitions[:query] }
184
+ .to block
185
+ end
186
+
187
+ it "returns the schema itself" do
188
+ expect(subject).to eq schema
189
+ end
190
+ end
191
+
192
+ context "with plain syntax" do
193
+ subject { schema.query "foo" => "bar" }
194
+
195
+ it "wraps value to block and adds it to definitions" do
196
+ expect { subject }
197
+ .to change { schema.definitions[:query]&.call }
198
+ .to "foo" => "bar"
199
+ end
200
+
201
+ it "returns the schema itself" do
202
+ expect(subject).to eq schema
203
+ end
204
+ end
205
+ end
206
+
207
+ describe "#body" do
208
+ context "with block syntax" do
209
+ subject { schema.body(&block) }
210
+
211
+ it "adds block to definitions" do
212
+ expect { subject }
213
+ .to change { schema.definitions[:body] }
214
+ .to block
215
+ end
216
+
217
+ it "returns the schema itself" do
218
+ expect(subject).to eq schema
219
+ end
220
+ end
221
+
222
+ context "with plain syntax" do
223
+ subject { schema.body "foo" => "bar" }
224
+
225
+ it "wraps value to block and adds it to definitions" do
226
+ expect { subject }
227
+ .to change { schema.definitions[:body]&.call }
228
+ .to "foo" => "bar"
229
+ end
230
+
231
+ it "returns the schema itself" do
232
+ expect(subject).to eq schema
233
+ end
234
+ end
235
+ end
236
+
237
+ describe "#middleware" do
238
+ context "with block syntax" do
239
+ subject { schema.middleware(&block) }
240
+
241
+ it "adds block to definitions" do
242
+ expect { subject }
243
+ .to change { schema.definitions[:middleware] }
244
+ .to block
245
+ end
246
+
247
+ it "returns the schema itself" do
248
+ expect(subject).to eq schema
249
+ end
250
+ end
251
+
252
+ context "with plain syntax" do
253
+ before { class Test::Foo; end }
254
+ subject { schema.middleware Test::Foo }
255
+
256
+ it "wraps value to block and adds it to definitions" do
257
+ expect { subject }
258
+ .to change { schema.definitions[:middleware]&.call }
259
+ .to Test::Foo
260
+ end
261
+
262
+ it "returns the schema itself" do
263
+ expect(subject).to eq schema
264
+ end
265
+ end
266
+ end
267
+
268
+ describe "#response" do
269
+ context "with a block" do
270
+ subject { schema.response(200, 201, &block) }
271
+
272
+ it "adds block to responses under given keys" do
273
+ expect { subject }
274
+ .to change { schema.definitions[:responses] }
275
+ .to(200 => block, 201 => block)
276
+ end
277
+
278
+ it "returns the schema itself" do
279
+ expect(subject).to eq schema
280
+ end
281
+ end
282
+
283
+ context "without a block" do
284
+ subject { schema.response(200) }
285
+
286
+ it "adds identity block to responses under given keys" do
287
+ subject
288
+
289
+ expect(schema.definitions.dig(:responses, 200).call("Hi")).to eq %w[Hi]
290
+ end
291
+
292
+ it "returns the schema itself" do
293
+ expect(subject).to eq schema
294
+ end
295
+ end
296
+ end
297
+
298
+ describe "#responses" do
299
+ context "with a block" do
300
+ subject { schema.responses(200, 201, &block) }
301
+
302
+ it "is an alias for #response" do
303
+ expect { subject }
304
+ .to change { schema.definitions[:responses] }
305
+ .to(200 => block, 201 => block)
306
+ end
307
+ end
308
+ end
309
+ end
@@ -0,0 +1,110 @@
1
+ RSpec.describe Evil::Client::Schema::Scope do
2
+ let(:client) { class_double Evil::Client, name: "MyApi" }
3
+ let(:parent) { described_class.new client }
4
+ let(:schema) { described_class.new parent, :users }
5
+ let(:block) { proc { def self.foo; :FOO; end } }
6
+ let(:dsl_methods) do
7
+ %i[operations scopes options schema settings inspect logger]
8
+ end
9
+
10
+ it "subclasses the operation schema" do
11
+ expect(described_class.superclass).to eq Evil::Client::Schema::Operation
12
+ end
13
+
14
+ describe "#leaf?" do
15
+ subject { schema.leaf? }
16
+
17
+ it "returns false" do
18
+ expect(subject).to eq false
19
+ end
20
+ end
21
+
22
+ describe "#scopes" do
23
+ subject { schema.scopes }
24
+
25
+ it "returns empty hash by default" do
26
+ expect(subject).to eq({})
27
+ end
28
+ end
29
+
30
+ describe "#scope" do
31
+ subject { schema.scope(:customers, &block) }
32
+
33
+ it "adds named subscope to the scope" do
34
+ subject
35
+ expect(schema.scopes[:customers]).to be_a described_class
36
+ end
37
+
38
+ it "executes the block in context of the new subscope" do
39
+ subject
40
+ expect(schema.scopes[:customers].foo).to eq :FOO
41
+ end
42
+
43
+ it "returns the scope itself" do
44
+ expect(subject).to eq schema
45
+ end
46
+
47
+ context "when name is reserved by DSL" do
48
+ it "raises Evil::Client::NameError" do
49
+ dsl_methods.each do |name|
50
+ expect { schema.scope(name, &block) }
51
+ .to raise_error Evil::Client::NameError
52
+ end
53
+ end
54
+ end
55
+
56
+ context "when there is an operation with the same name" do
57
+ before { schema.operation(:customers) {} }
58
+
59
+ it "raises Evil::Client::TypeError" do
60
+ expect { subject }.to raise_error Evil::Client::TypeError
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#operations" do
66
+ subject { schema.operations }
67
+
68
+ it "returns empty hash by default" do
69
+ expect(subject).to eq({})
70
+ end
71
+ end
72
+
73
+ describe "#operation" do
74
+ subject { schema.operation(:fetch, &block) }
75
+
76
+ it "adds named operation to the scope" do
77
+ subject
78
+ expect(schema.operations[:fetch]).to be_a Evil::Client::Schema::Operation
79
+ end
80
+
81
+ it "executes the block in context of the new operation" do
82
+ subject
83
+ expect(schema.operations[:fetch].foo).to eq :FOO
84
+ end
85
+
86
+ it "returns the scope itself" do
87
+ expect(subject).to eq schema
88
+ end
89
+
90
+ context "when name is reserved by DSL" do
91
+ it "raises Evil::Client::NameError" do
92
+ dsl_methods.each do |name|
93
+ expect { schema.operation(name, &block) }
94
+ .to raise_error Evil::Client::NameError
95
+ end
96
+ end
97
+ end
98
+
99
+ context "when there is an operation with the same name" do
100
+ before { schema.scope(:fetch) {} }
101
+
102
+ it "raises Evil::Client::TypeError" do
103
+ expect { subject }.to raise_error Evil::Client::TypeError
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "#operation" do
109
+ end
110
+ end
@@ -0,0 +1,157 @@
1
+ RSpec.describe Evil::Client::Schema do
2
+ let(:client) { class_double Evil::Client, name: "MyApi" }
3
+ let(:parent) { described_class.new client }
4
+ let(:schema) { described_class.new parent, :users }
5
+
6
+ describe "#client" do
7
+ context "for a root schema" do
8
+ subject { parent.client }
9
+
10
+ it "is taken from initializer" do
11
+ expect(subject).to eq client
12
+ end
13
+ end
14
+
15
+ context "for a subschema" do
16
+ subject { schema.client }
17
+
18
+ it "is taken from parent" do
19
+ expect(subject).to eq client
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#parent" do
25
+ context "for a root schema" do
26
+ subject { parent.parent }
27
+
28
+ it "is absent" do
29
+ expect(subject).to be_nil
30
+ end
31
+ end
32
+
33
+ context "for a subschema" do
34
+ subject { schema.parent }
35
+
36
+ it "is taken from the initializer" do
37
+ expect(subject).to eq parent
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#name" do
43
+ context "for a root schema" do
44
+ subject { parent.name }
45
+
46
+ it "is taken from client" do
47
+ expect(subject).to eq client.name
48
+ end
49
+ end
50
+
51
+ context "for a subschema" do
52
+ subject { schema.name }
53
+
54
+ it "is taken from the initializer" do
55
+ expect(subject).to eq :users
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "#to_s" do
61
+ context "for a root schema" do
62
+ subject { parent.to_s }
63
+
64
+ it "returns the name" do
65
+ expect(subject).to eq "MyApi"
66
+ end
67
+ end
68
+
69
+ context "for a subschema" do
70
+ subject { schema.to_s }
71
+
72
+ it "returns full name" do
73
+ expect(subject).to eq "MyApi.users"
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#to_str" do
79
+ subject { schema.to_str }
80
+
81
+ it "is an alias for #to_s" do
82
+ expect(subject).to eq schema.to_s
83
+ end
84
+ end
85
+
86
+ describe "#inspect" do
87
+ subject { schema.inspect }
88
+
89
+ it "is an alias for #to_s" do
90
+ expect(subject).to eq schema.to_s
91
+ end
92
+ end
93
+
94
+ describe "#settings" do
95
+ context "for a root schema" do
96
+ subject { parent.settings }
97
+
98
+ it "is a subclass of Evil::Client::Settings" do
99
+ expect(subject).to be_a Class
100
+ expect(subject.superclass).to eq Evil::Client::Settings
101
+ end
102
+ end
103
+
104
+ context "for a subschema" do
105
+ subject { schema.settings }
106
+
107
+ it "is a subclass of parent settings" do
108
+ expect(subject).to be_a Class
109
+ expect(subject.superclass).to eq parent.settings
110
+ end
111
+ end
112
+ end
113
+
114
+ describe "#option" do
115
+ before { allow(schema.settings).to receive(:let) }
116
+ subject { schema.option(:user, optional: true) }
117
+
118
+ it "is delegated to settings" do
119
+ expect(schema.settings)
120
+ .to receive(:option).with(:user, nil, optional: true)
121
+
122
+ subject
123
+ end
124
+
125
+ it "returns the schema itself" do
126
+ expect(subject).to eq schema
127
+ end
128
+ end
129
+
130
+ describe "#let" do
131
+ before { allow(schema.settings).to receive(:let) }
132
+ subject { schema.let(:user) {} }
133
+
134
+ it "is delegated to settings" do
135
+ expect(schema.settings).to receive(:let).with(:user)
136
+ subject
137
+ end
138
+
139
+ it "returns the schema itself" do
140
+ expect(subject).to eq schema
141
+ end
142
+ end
143
+
144
+ describe "#validate" do
145
+ before { allow(schema.settings).to receive(:validate) }
146
+ subject { schema.validate(:id_present) {} }
147
+
148
+ it "is delegated to settings" do
149
+ expect(schema.settings).to receive(:validate).with(:id_present)
150
+ subject
151
+ end
152
+
153
+ it "returns the schema itself" do
154
+ expect(subject).to eq schema
155
+ end
156
+ end
157
+ end