fitting 2.13.1 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +1 -1
  3. data/.ruby-version +1 -1
  4. data/.tool-versions +1 -1
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +23 -0
  7. data/README.md +127 -84
  8. data/lib/fitting/records/spherical/requests.rb +3 -1
  9. data/lib/fitting/report/action.rb +53 -0
  10. data/lib/fitting/report/actions.rb +55 -0
  11. data/lib/fitting/report/combination.rb +37 -0
  12. data/lib/fitting/report/combinations.rb +47 -0
  13. data/lib/fitting/report/console.rb +41 -0
  14. data/lib/fitting/report/prefix.rb +53 -0
  15. data/lib/fitting/report/prefixes.rb +44 -0
  16. data/lib/fitting/report/response.rb +71 -0
  17. data/lib/fitting/report/responses.rb +48 -0
  18. data/lib/fitting/report/test.rb +61 -0
  19. data/lib/fitting/report/tests.rb +62 -0
  20. data/lib/fitting/tests.rb +0 -1
  21. data/lib/fitting/version.rb +1 -1
  22. data/lib/tasks/fitting.rake +65 -31
  23. data/lib/templates/bomboniere/.gitignore +21 -0
  24. data/lib/templates/bomboniere/.tool-versions +1 -0
  25. data/lib/templates/bomboniere/README.md +19 -0
  26. data/lib/templates/bomboniere/dist/css/app.62e086ac.css +1 -0
  27. data/lib/templates/bomboniere/dist/css/chunk-vendors.ec5f6c3f.css +1 -0
  28. data/lib/templates/bomboniere/dist/favicon.ico +0 -0
  29. data/lib/templates/bomboniere/dist/index.html +1 -0
  30. data/lib/templates/bomboniere/dist/js/app.4356d509.js +2 -0
  31. data/lib/templates/bomboniere/dist/js/app.4356d509.js.map +1 -0
  32. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js +13 -0
  33. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js.map +1 -0
  34. data/lib/templates/bomboniere/package-lock.json +9263 -0
  35. data/lib/templates/bomboniere/package.json +25 -0
  36. data/lib/templates/bomboniere/public/favicon.ico +0 -0
  37. data/lib/templates/bomboniere/public/index.html +17 -0
  38. data/lib/templates/bomboniere/src/App.vue +102 -0
  39. data/lib/templates/bomboniere/src/assets/logo.png +0 -0
  40. data/lib/templates/bomboniere/src/components/HelloWorld.vue +188 -0
  41. data/lib/templates/bomboniere/src/main.js +10 -0
  42. data/lib/templates/bomboniere/src/router/index.js +31 -0
  43. data/lib/templates/bomboniere/src/views/About.vue +5 -0
  44. data/lib/templates/bomboniere/src/views/Action.vue +154 -0
  45. data/lib/templates/bomboniere/src/views/Home.vue +17 -0
  46. data/lib/templates/bomboniere/vue.config.js +3 -0
  47. metadata +38 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 483a7f1462b7204b2dbeb31d372ad2526783c775
4
- data.tar.gz: eef485bd208b70fbe0fd10e350e3bda9e82ac084
2
+ SHA256:
3
+ metadata.gz: 036f174c7154d494520197fefae664cf6086fb47feaad76f091d25f194016ce8
4
+ data.tar.gz: 339e5f12a4a85e86f10bb112bdf23231d9f0af5bbc6a2fba0145f344a37802da
5
5
  SHA512:
6
- metadata.gz: 16b2442c467a9a507262b721fe4d0528af989ae7ab9a7f8f703d740ca692aedf97c47c7cb8eec180955ade9b151c85948af723ca301dcdb73c56cf9b06e14250
7
- data.tar.gz: 2e42661f2d0a13f794cb6c808ea5b4d6e3b7fbc8d2ae368c4948a2cfc69a7e8a398333cc8de76a3e70cc6db63bceea03f4df76b14acdc6757dc53107fc883400
6
+ metadata.gz: dde3886c4f56bcab60b00f91f0a3c129676f430b2c3c5c3687a08fe28c207474e3076d21780e8f9adb2a2c6f6e0bc02f490a4101d77394ed2d92ec5f9687f9cd
7
+ data.tar.gz: f2d6bc93bed0cfe10d0fadb3bb528e837cb4b9867e479991e2f71f772f961113a937c9559903435b55b64d3c2993a275872b804f31fb09c077d252db7d9fb8b2
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.3
3
3
 
4
4
  Metrics/LineLength:
5
5
  Max: 120
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
@@ -1 +1 @@
1
- ruby 2.2.0
1
+ ruby 2.3.0
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
3
+ - 2.3
4
4
  before_install: gem install bundler -v 1.12
@@ -1,5 +1,28 @@
1
1
  # Change log
2
2
 
3
+ ### 2.14.0 - 2020-09-18
4
+
5
+ * features
6
+ * save tests for all prefixes [#35](https://github.com/funbox/fitting/issues/35)
7
+ * prefix checking [#37](https://github.com/funbox/fitting/issues/37)
8
+ * html view for prefix checking [#39](https://github.com/funbox/fitting/issues/39)
9
+ * add actions join in new html report [#41](https://github.com/funbox/fitting/issues/41)
10
+ * add responses join in new report [#43](https://github.com/funbox/fitting/issues/43)
11
+ * add combinations join in new report [#47](https://github.com/funbox/fitting/issues/47)
12
+ * add action page [#49](https://github.com/funbox/fitting/issues/49)
13
+ * show more information in new report [#51](https://github.com/funbox/fitting/issues/51)
14
+ * add accordion for prefixes [#55](https://github.com/funbox/fitting/issues/55)
15
+ * move json-schemas to separate files [#57](https://github.com/funbox/fitting/issues/57)
16
+ * add method for tests without actions [#61](https://github.com/funbox/fitting/issues/61)
17
+ * show tests without responses [#63](https://github.com/funbox/fitting/issues/63)
18
+ * add console output for new report [#69](https://github.com/funbox/fitting/issues/69)
19
+ * check test in new console [#71](https://github.com/funbox/fitting/issues/71)
20
+ * fixes
21
+ * fix vulnerability CVE-2020-7660 [#53](https://github.com/funbox/fitting/issues/53)
22
+ * fix cover if response without combinations [#59](https://github.com/funbox/fitting/issues/59)
23
+ * fix cover if combinations without tests [#66](https://github.com/funbox/fitting/issues/66)
24
+ * do not check tests without combinations [#73](https://github.com/funbox/fitting/issues/73)
25
+
3
26
  ### 2.13.1 - 2020-04-17
4
27
 
5
28
  * fixes
data/README.md CHANGED
@@ -1,42 +1,42 @@
1
1
  # Fitting
2
2
 
3
- <a href="https://funbox.ru">
4
- <img src="https://funbox.ru/badges/sponsored_by_funbox_compact.svg" alt="Sponsored by FunBox" width=250 />
5
- </a>
6
-
7
3
  [![Gem Version](https://badge.fury.io/rb/fitting.svg)](https://badge.fury.io/rb/fitting)
8
4
  [![Build Status](https://travis-ci.org/funbox/fitting.svg?branch=master)](https://travis-ci.org/funbox/fitting)
9
5
 
10
6
  This gem will help you implement your API in strict accordance to the documentation in [API Blueprint](https://apiblueprint.org/) format.
11
- To do this, when you run your RSpec tests on controllers, it automatically searches for the corresponding json-schemas in the documentation and then validates responses with them.
7
+ To do this, when you run your RSpec tests on controllers, it automatically searches for the corresponding JSON-schemas in the documentation and then validates responses with them.
12
8
 
13
9
  ## Installation
14
10
 
15
11
  First you need to install [drafter](https://github.com/apiaryio/drafter).
16
12
 
17
- Second add this line to your application's Gemfile:
13
+ Then add this line to your application's Gemfile:
18
14
 
19
15
  ```ruby
20
16
  gem 'fitting'
21
17
  ```
22
18
 
23
- And then execute:
19
+ After that execute:
24
20
 
25
- $ bundle
21
+ ```bash
22
+ $ bundle
23
+ ```
26
24
 
27
- Or install it yourself as:
25
+ Or install the gem by yourself:
28
26
 
29
- $ gem install fitting
27
+ ```bash
28
+ $ gem install fitting
29
+ ```
30
30
 
31
31
  ## Usage
32
32
 
33
- In your `.fitting.yml`:
33
+ Add this to your `.fitting.yml`:
34
34
 
35
35
  ```yaml
36
36
  apib_path: /path/to/doc.apib
37
37
  ```
38
38
 
39
- In your `spec_helper.rb`:
39
+ And this to your `spec_helper.rb`:
40
40
 
41
41
  ```ruby
42
42
  require 'fitting'
@@ -44,11 +44,11 @@ require 'fitting'
44
44
  Fitting.save_test_data
45
45
  ```
46
46
 
47
- The files will be created in ./fitting_tests/ path
47
+ The result files will be created in `./fitting_tests/` folder.
48
48
 
49
- Example:
49
+ Output example:
50
50
 
51
- ```
51
+ ```json
52
52
  [
53
53
  {
54
54
  "method": "GET",
@@ -75,30 +75,45 @@ Example:
75
75
  },
76
76
  "title": "/spec/controllers/api/v1/books_controller_spec.rb:22",
77
77
  "group": "/spec/controllers/api/v1/books_controller_spec.rb"
78
- },
79
- ...
78
+ }
79
+ ]
80
80
  ```
81
81
 
82
+ ## Documentation coverage
83
+
84
+ To match routes and validate JSON-schemas run:
82
85
 
83
- ## Check documentation cover
86
+ ```bash
87
+ rake fitting:documentation_responses[report_size]
88
+ ```
84
89
 
85
- ### xs size
90
+ There are four types (or `report_size`) of reports available:
91
+
92
+ - `xs` — the smallest report;
93
+ - `s` — includes coverage for `required` fields;
94
+ - `m` — includes coverage for `required` and `enum` fields;
95
+ - `l` — includes coverage for `required`, `enum` and `oneOf` fields.
86
96
 
87
- For match routes and valid json-schemas run
97
+ E.g. for `xs` size:
88
98
 
89
- for bash
90
- ```
99
+ ```bash
91
100
  rake fitting:documentation_responses[xs]
92
101
  ```
93
102
 
94
- for zsh
95
- ```
103
+ **Note**: In zsh you should add quotes around the task:
104
+
105
+ ```bash
96
106
  rake 'fitting:documentation_responses[xs]'
97
107
  ```
98
108
 
99
- You will get statistics:
109
+ Also you can use `documentation_responses_error` to get more detailed errors description.
110
+ Check the examples below.
100
111
 
101
- ```
112
+ ### Examples
113
+
114
+ `xs` size:
115
+
116
+ ```text
102
117
  Fully conforming requests:
103
118
  DELETE /api/v1/book ✔ 200 ✔ 201 ✔ 404
104
119
  DELETE /api/v1/book/{id} ✔ 200 ✔ 201 ✔ 404
@@ -122,11 +137,9 @@ API responses conforming to the blueprint: 16 (64.00% of 25).
122
137
  API responses with validation errors or untested: 9 (36.00% of 25).
123
138
  ```
124
139
 
125
- ### s size
126
-
127
- In addition to the previous comand, you will learn the coverage(required) json-schemas with task `rake fitting:documentation_responses[s]`
140
+ `s` size:
128
141
 
129
- ```
142
+ ```text
130
143
  Fully conforming requests:
131
144
  DELETE /api/v1/book 100% 200 100% 201 100% 404
132
145
  DELETE /api/v1/book/{id} 100% 200 100% 201 100% 404
@@ -150,7 +163,7 @@ API responses conforming to the blueprint: 16 (64.00% of 25).
150
163
  API responses with validation errors or untested: 9 (36.00% of 25).
151
164
  ```
152
165
 
153
- For details `rake fitting:documentation_responses_error[s]`
166
+ `documentation_responses_error[s]` example:
154
167
 
155
168
  ```
156
169
  request method: GET
@@ -161,68 +174,79 @@ combination: ["required", "pages"]
161
174
  new json-schema: {"$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>"object", ...}
162
175
  ```
163
176
 
164
- ### m size
177
+ ### Experimental report
165
178
 
166
- In addition to the previous comand, you will learn the coverage(enum) json-schemas with task `rake fitting:documentation_responses[m]`
167
- For details `rake fitting:documentation_responses_error[m]`
179
+ This report will be available and properly documented in the next major update, but you already can try it by running:
168
180
 
169
- ### l size
181
+ ```bash
182
+ bundle e rake fitting:report
183
+ ```
170
184
 
171
- In addition to the previous comand, you will learn the coverage(oneOf) json-schemas with task `rake fitting:documentation_responses[l]`
172
- For details `rake fitting:documentation_responses_error[l]`
185
+ Using this you can document API prefixes.
186
+ The task will create JSON (`fitting/report.json`) and HTML (`fitting/index.html`) reports.
173
187
 
174
- ## Check tests cover
188
+ ## Tests coverage
175
189
 
176
- ### xs size
190
+ Only `xs` size is available for tests coverage:
177
191
 
178
- `rake fitting:tests_responses[xs]`
192
+ ```bash
193
+ rake fitting:tests_responses[xs]
194
+ ```
179
195
 
180
196
  ## Config
181
197
 
182
- You can specify the settings either in a yaml file `.fitting.yml` or in config.
183
- If your project uses several prefixes, for each one you need to create a separate yaml file in the folder `fitting` (`fitting/*.yml`).
198
+ You can specify the settings either in a YAML file `.fitting.yml` or in a config.
199
+ If your project uses several prefixes, for each one you should create a separate YAML file in the folder `fitting` (`fitting/*.yml`).
200
+
201
+ All the available config options are described below.
184
202
 
185
- ### apib_path
203
+ ### `apib_path`
186
204
 
187
- Path to API Blueprint v3 documentation. There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
205
+ Path to API Blueprint v3 documentation.
206
+ There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
188
207
 
189
- ### drafter_yaml_path
208
+ ### `drafter_yaml_path`
190
209
 
191
- Path to API Blueprint v3 documentation pre-parsed with `drafter` and saved to a YAML file.
210
+ Path to API Blueprint v3 documentation, pre-parsed with `drafter` and saved to a YAML file.
192
211
 
193
- ### drafter_4_apib_path
212
+ ### `drafter_4_apib_path`
194
213
 
195
- Path to API Blueprint v4 documentation. There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
214
+ Path to API Blueprint v4 documentation.
215
+ There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
196
216
 
197
- ### drafter_4_yaml_path
217
+ ### `drafter_4_yaml_path`
198
218
 
199
- Path to API Blueprint v4 documentation pre-parsed with `drafter` and saved to a YAML file.
219
+ Path to API Blueprint v4 documentation, pre-parsed with `drafter` and saved to a YAML file.
200
220
 
201
- ### crafter_apib_path
221
+ ### `crafter_apib_path`
202
222
 
203
223
  Path to API Blueprint v4 documentation.
204
224
 
205
- ### crafter_yaml_path
225
+ ### `crafter_yaml_path`
206
226
 
207
- Path to API Blueprint v4 documentation pre-parsed with `crafter` and saved to a YAML file.
227
+ Path to API Blueprint v4 documentation, pre-parsed with `crafter` and saved to a YAML file.
208
228
 
209
- ### tomogram_json_path
229
+ ### `tomogram_json_path`
210
230
 
211
- Path to Tomogram documentation pre-parsed with [tomograph](https://github.com/funbox/tomograph) and saved to a JSON file.
231
+ Path to Tomogram documentation, pre-parsed with [tomograph](https://github.com/funbox/tomograph) and saved to a JSON file.
212
232
 
213
- ### strict
233
+ ### `strict`
214
234
 
215
- Default `false`. If `true` then all properties are condisidered to have `"required": true` and all objects `"additionalProperties": false`.
235
+ Default: `false`
216
236
 
217
- ### prefix
237
+ When `true` all properties are considered to have `"required": true` and all objects are considered to have `"additionalProperties": false`.
218
238
 
219
- Prefix of API requests. Example: `'/api'`. Validation will not be performed if the request path does not start with a prefix.
239
+ ### `prefix`
220
240
 
221
- ### white_list
241
+ Prefix for API requests. E.g. `'/api'`. Validation will not be performed if the request path does not start with a prefix.
222
242
 
223
- Default: all paths. This is an array of paths that are mandatory for implementation.
224
- This list does not affect the work of the matcher.
225
- This list is only for the report in the console.
243
+ ### `white_list`
244
+
245
+ Default: all paths
246
+
247
+ This is an array of paths that are mandatory for implementation.
248
+ The list does not affect the work of the matcher.
249
+ It's used for the CLI report only.
226
250
 
227
251
  ```yaml
228
252
  white_list:
@@ -237,13 +261,15 @@ white_list:
237
261
  /sessions: []
238
262
  ```
239
263
 
240
- Empty array `[]` means all methods.
264
+ Empty array (`[]`) means all methods.
241
265
 
242
- ### resource_white_list
266
+ ### `resource_white_list`
243
267
 
244
- Default: all resources. This is an array of resources that are mandatory for implementation.
245
- This list does not affect the work of the matcher.
246
- This list is only for the report in the console.
268
+ Default: all resources
269
+
270
+ This is an array of resources that are mandatory for implementation.
271
+ The list does not affect the work of the matcher.
272
+ It's used for the CLI report only.
247
273
 
248
274
  ```yaml
249
275
  resource_white_list:
@@ -257,31 +283,35 @@ resource_white_list:
257
283
  /sessions: []
258
284
  ```
259
285
 
260
- Empty array `[]` means all methods.
286
+ Empty array (`[]`) means all methods.
287
+
288
+ ### `json_schema_cover`
289
+
290
+ Default: false
261
291
 
262
- ### json_schema_cover
292
+ JSON-schema covering becomes mandatory.
293
+ However, if you don't use `Fitting.statistics` you can call `responses.statistics.cover_save`.
263
294
 
264
- Default: false. Json-schema covering becomes mandatory.
265
- Or you can call `responses.statistics.cover_save` if you don't use call `Fitting.statistics`.
295
+ ### `include_resources`
266
296
 
267
- ### include_resources
297
+ Default: all resources (but only when `include_resources` and `include_actions` are not defined)
268
298
 
269
- Default: all resources if `include_resources` and `include_actions` is not used.
270
299
  This is an array of resources that are mandatory for implementation.
271
- This list does not affect the work of the matcher.
272
- This list is only for the report in the console.
300
+ The list does not affect the work of the matcher.
301
+ It's used for the CLI report only.
273
302
 
274
303
  ```yaml
275
304
  include_resources:
276
305
  - /sessions
277
306
  ```
278
307
 
279
- ### include_actions
308
+ ### `include_actions`
309
+
310
+ Default: all paths (but only when `include_resources` and `include_actions` are not defined)
280
311
 
281
- Default: all paths if `include_resources` and `include_actions` is not used.
282
312
  This is an array of paths that are mandatory for implementation.
283
- This list does not affect the work of the matcher.
284
- This list is only for the report in the console.
313
+ The list does not affect the work of the matcher.
314
+ It's used for the CLI report only.
285
315
 
286
316
  ```yaml
287
317
  include_actions:
@@ -292,9 +322,9 @@ include_actions:
292
322
  - GET /users/{id}/employees
293
323
  ```
294
324
 
295
- ### ignore_list
325
+ ### `ignore_list`
296
326
 
297
- You can use ignore list for omit checks with matchers.
327
+ You can use ignore list to omit checks with matchers.
298
328
 
299
329
  ```yaml
300
330
  ignore_list:
@@ -302,12 +332,25 @@ ignore_list:
302
332
  - %r{/api/v1/comments}
303
333
  ```
304
334
 
305
- It works only for match_schema (NOT FOR strictly_match_schema)
335
+ It works only for `match_schema` and **not** for `strictly_match_schema`.
336
+
337
+ ### `prefixes`
338
+
339
+ Example:
340
+
341
+ ```yaml
342
+ prefixes:
343
+ - name: /api/v1
344
+ - name: /api/v2
345
+ ```
306
346
 
307
347
  ## Contributing
308
348
 
309
- Bug reports and pull requests are welcome on GitHub at https://github.com/funbox/fitting. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
349
+ Bug reports and pull requests are welcome on GitHub at [github.com/funbox/fitting](https://github.com/funbox/fitting).
350
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
310
351
 
311
352
  ## License
312
353
 
313
354
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
355
+
356
+ [![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)
@@ -13,7 +13,9 @@ module Fitting
13
13
  array += JSON.load(File.read(file))
14
14
  end
15
15
  @to_a = array.inject([]) do |res, tested_request|
16
- res.push(Fitting::Records::Spherical::Request.load(tested_request))
16
+ request = Fitting::Records::Spherical::Request.load(tested_request)
17
+ next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
18
+ res.push(request)
17
19
  end
18
20
  end
19
21
  end
@@ -0,0 +1,53 @@
1
+ require 'fitting/report/responses'
2
+
3
+ module Fitting
4
+ module Report
5
+ class Action
6
+ def initialize(action)
7
+ @action = action
8
+ @tests = Fitting::Report::Tests.new([])
9
+ @responses = Fitting::Report::Responses.new(@action.responses)
10
+ end
11
+
12
+ def method
13
+ @action.method
14
+ end
15
+
16
+ def path
17
+ @action.path.to_s
18
+ end
19
+
20
+ def responses
21
+ @responses
22
+ end
23
+
24
+ def add_test(test)
25
+ @tests.push(test)
26
+ end
27
+
28
+ def path_match(find_path)
29
+ regexp =~ find_path
30
+ end
31
+
32
+ def regexp
33
+ return @regexp if @regexp
34
+
35
+ str = Regexp.escape(path)
36
+ str = str.gsub(/\\{\w+\\}/, '[^&=\/]+')
37
+ str = "\\A#{str}\\z"
38
+ @regexp = Regexp.new(str)
39
+ end
40
+
41
+ def tests
42
+ @tests
43
+ end
44
+
45
+ def details
46
+ {
47
+ tests_without_responses: @tests.without_responses,
48
+ responses_details: @responses.to_a.map { |r| {method: r.status, tests_size: r.tests.size, json_schema: r.id, combinations: r.details} }
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end