fitting 2.7.2 → 2.10.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +28 -0
- data/README.md +17 -4
- data/fitting.gemspec +1 -2
- data/lib/fitting.rb +2 -0
- data/lib/fitting/configuration/legacy.rb +12 -5
- data/lib/fitting/configuration/yaml.rb +17 -6
- data/lib/fitting/cover/json_schema_enum.rb +88 -0
- data/lib/fitting/records/spherical/requests.rb +4 -1
- data/lib/fitting/records/unit/json_schema.rb +28 -2
- data/lib/fitting/statistics/cover_error.rb +2 -2
- data/lib/fitting/statistics/cover_error_enum.rb +27 -0
- data/lib/fitting/statistics/list.rb +3 -1
- data/lib/fitting/statistics/measurement_cover_enum.rb +92 -0
- data/lib/fitting/statistics/template.rb +7 -2
- data/lib/fitting/statistics/template_cover_error_enum.rb +50 -0
- data/lib/fitting/tests.rb +3 -1
- data/lib/fitting/version.rb +1 -1
- data/lib/tasks/fitting.rake +21 -2
- metadata +11 -21
- data/lib/fitting/cover.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a58b7be52158cd26f8ae3fd7454cbc89512610
|
4
|
+
data.tar.gz: cb6bb15b054e2ec15e6262d16e3c697932d81640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffb5323b7ab335ad9f2ad966c7bfd2249b9388dcc9d434f35eff2f7626ba97ce3a5ac5f6bf386041840f7db397fe8c596ae52c95406e584120558865340a8742
|
7
|
+
data.tar.gz: 8db3c993339889701401ec962e0576f31ea746cbec06e3c5f326fe07487527cec79d36a20a7de0c5949418ebf2e2aaee5b9c269e03446a740530a0006535d51e
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
### 2.10.0 - 2019-09-05
|
4
|
+
|
5
|
+
* features
|
6
|
+
* add crafter_yaml_path
|
7
|
+
|
8
|
+
### 2.9.1 - 2019-07-15
|
9
|
+
|
10
|
+
* fixes
|
11
|
+
* Improve gemspec
|
12
|
+
* Delete experimental code with haml
|
13
|
+
|
14
|
+
### 2.9.0 - 2019-07-15
|
15
|
+
|
16
|
+
* features
|
17
|
+
* Delete old spec json
|
18
|
+
* fixes
|
19
|
+
* Improve gemspec
|
20
|
+
|
21
|
+
### 2.8.1 - 2018-12-18
|
22
|
+
|
23
|
+
* features
|
24
|
+
* Add support for [parallel_tests](https://github.com/grosser/parallel_tests)
|
25
|
+
|
26
|
+
### 2.8.0 - 2018-10-13
|
27
|
+
|
28
|
+
* features
|
29
|
+
* Add m size (for cover enum in json-schema) in rake tasks fitting:documentation_responses, fitting:documentation_responses_error
|
30
|
+
|
3
31
|
### 2.7.2 - 2018-09-08
|
4
32
|
|
5
33
|
* fixes
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ require 'fitting'
|
|
42
42
|
Fitting.save_test_data
|
43
43
|
```
|
44
44
|
|
45
|
-
The
|
45
|
+
The files will be created in ./fitting_tests/ path
|
46
46
|
|
47
47
|
Example:
|
48
48
|
|
@@ -112,7 +112,7 @@ API responses with validation errors or untested: 9 (36.00% of 25).
|
|
112
112
|
|
113
113
|
### s size
|
114
114
|
|
115
|
-
In addition to the previous comand, you will learn the coverage json-schemas with task `rake fitting:documentation_responses[s]`
|
115
|
+
In addition to the previous comand, you will learn the coverage(required) json-schemas with task `rake fitting:documentation_responses[s]`
|
116
116
|
|
117
117
|
```
|
118
118
|
Fully conforming requests:
|
@@ -141,14 +141,19 @@ API responses with validation errors or untested: 9 (36.00% of 25).
|
|
141
141
|
For details `rake fitting:documentation_responses_error[s]`
|
142
142
|
|
143
143
|
```
|
144
|
-
request
|
144
|
+
request method: GET
|
145
145
|
request path: /api/v1/book
|
146
|
-
response
|
146
|
+
response status: 200
|
147
147
|
source json-schema: {"$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>"object", ...}
|
148
148
|
combination: ["required", "pages"]
|
149
149
|
new json-schema: {"$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>"object", ...}
|
150
150
|
```
|
151
151
|
|
152
|
+
### m size
|
153
|
+
|
154
|
+
In addition to the previous comand, you will learn the coverage(enum) json-schemas with task `rake fitting:documentation_responses[m]`
|
155
|
+
For details `rake fitting:documentation_responses_error[m]`
|
156
|
+
|
152
157
|
## Check tests cover
|
153
158
|
|
154
159
|
### xs size
|
@@ -168,6 +173,14 @@ Path to API Blueprint documentation. There must be an installed [drafter](https:
|
|
168
173
|
|
169
174
|
Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
|
170
175
|
|
176
|
+
### crafter_yaml_path
|
177
|
+
|
178
|
+
Path to API Blueprint documentation pre-parsed with `crafter` and saved to a YAML file.
|
179
|
+
|
180
|
+
### tomogram_json_path
|
181
|
+
|
182
|
+
Path to Tomogram documentation pre-parsed with [tomograph](https://github.com/funbox/tomograph) and saved to a JSON file.
|
183
|
+
|
171
184
|
### strict
|
172
185
|
|
173
186
|
Default `false`. If `true` then all properties are condisidered to have `"required": true` and all objects `"additionalProperties": false`.
|
data/fitting.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'haml'
|
22
21
|
spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
|
23
|
-
spec.add_runtime_dependency 'multi_json'
|
22
|
+
spec.add_runtime_dependency 'multi_json', '~> 1.11'
|
24
23
|
spec.add_runtime_dependency 'tomograph', '~> 2.0', '>= 2.2.0'
|
25
24
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
25
|
spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
|
data/lib/fitting.rb
CHANGED
@@ -32,6 +32,8 @@ module Fitting
|
|
32
32
|
def save_test_data
|
33
33
|
responses = Fitting::Storage::Responses.new
|
34
34
|
|
35
|
+
FileUtils.rm_r Dir.glob("fitting_tests/*"), :force => true
|
36
|
+
|
35
37
|
RSpec.configure do |config|
|
36
38
|
config.after(:each, type: :controller) do
|
37
39
|
responses.add(response, inspect)
|
@@ -20,11 +20,18 @@ module Fitting
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def tomogram
|
23
|
-
@tomogram ||=
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
@tomogram ||= if @crafter_yaml_path
|
24
|
+
Tomograph::Tomogram.new(
|
25
|
+
prefix: @prefix,
|
26
|
+
apib_path: @apib_path,
|
27
|
+
crafter_yaml_path: @crafter_yaml_path
|
28
|
+
)
|
29
|
+
else Tomograph::Tomogram.new(
|
30
|
+
prefix: @prefix,
|
31
|
+
apib_path: @apib_path,
|
32
|
+
drafter_yaml_path: @drafter_yaml_path
|
33
|
+
)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def title
|
@@ -6,6 +6,7 @@ module Fitting
|
|
6
6
|
attr_reader :title
|
7
7
|
attr_accessor :apib_path,
|
8
8
|
:drafter_yaml_path,
|
9
|
+
:crafter_yaml_path,
|
9
10
|
:tomogram_json_path,
|
10
11
|
:strict,
|
11
12
|
:prefix,
|
@@ -18,6 +19,7 @@ module Fitting
|
|
18
19
|
def initialize(yaml, title = 'fitting')
|
19
20
|
@apib_path = yaml['apib_path']
|
20
21
|
@drafter_yaml_path = yaml['drafter_yaml_path']
|
22
|
+
@crafter_yaml_path = yaml['crafter_yaml_path']
|
21
23
|
@tomogram_json_path = yaml['tomogram_json_path']
|
22
24
|
@strict = yaml['strict']
|
23
25
|
@prefix = yaml['prefix']
|
@@ -31,12 +33,21 @@ module Fitting
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def tomogram
|
34
|
-
@tomogram ||=
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
@tomogram ||= if @crafter_yaml_path
|
37
|
+
Tomograph::Tomogram.new(
|
38
|
+
prefix: @prefix,
|
39
|
+
apib_path: @apib_path,
|
40
|
+
crafter_yaml_path: @crafter_yaml_path,
|
41
|
+
tomogram_json_path: @tomogram_json_path
|
42
|
+
)
|
43
|
+
else
|
44
|
+
Tomograph::Tomogram.new(
|
45
|
+
prefix: @prefix,
|
46
|
+
apib_path: @apib_path,
|
47
|
+
drafter_yaml_path: @drafter_yaml_path,
|
48
|
+
tomogram_json_path: @tomogram_json_path
|
49
|
+
)
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
53
|
def stats_path
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Fitting
|
2
|
+
class Cover
|
3
|
+
class JSONSchemaEnum
|
4
|
+
def initialize(json_schema)
|
5
|
+
@json_schema = json_schema
|
6
|
+
end
|
7
|
+
|
8
|
+
def combi
|
9
|
+
return @combinations if @combinations
|
10
|
+
@combinations = []
|
11
|
+
|
12
|
+
return @combinations unless @json_schema['properties']
|
13
|
+
@combinations = new_super_each(@json_schema['properties'], { 'properties' => nil }, @json_schema, @combinations, 'properties')
|
14
|
+
|
15
|
+
@combinations
|
16
|
+
end
|
17
|
+
|
18
|
+
def new_super_each(json_schema, old_keys_hash, lol_schema, combinations, old_key)
|
19
|
+
json_schema.each do |key, value|
|
20
|
+
next unless value.is_a?(Hash)
|
21
|
+
|
22
|
+
new_keys_hash = clone_hash(old_keys_hash)
|
23
|
+
add_super_key(new_keys_hash, key)
|
24
|
+
|
25
|
+
combinations = new_super_each(value, new_keys_hash, lol_schema, combinations, [old_key, key].compact.join('.'))
|
26
|
+
|
27
|
+
qwe = new_enum(value)
|
28
|
+
qwe.map do |asd|
|
29
|
+
new_json_shema = clone_hash(lol_schema)
|
30
|
+
super_merge(new_keys_hash, asd[0], new_json_shema)
|
31
|
+
combinations.push([new_json_shema, [asd[1][0], [old_key, key, asd[1][1]].compact.join('.')]])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
combinations
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_super_key(vbn, new_key)
|
38
|
+
vbn.each do |key, value|
|
39
|
+
if value
|
40
|
+
add_super_key(value, new_key)
|
41
|
+
else
|
42
|
+
vbn[key] = { new_key => nil }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def super_merge(vbn, asd, old_json_schema)
|
48
|
+
vbn.each do |key, value|
|
49
|
+
if value
|
50
|
+
super_merge(value, asd, old_json_schema[key])
|
51
|
+
else
|
52
|
+
old_json_schema[key].merge!(asd)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
old_json_schema
|
56
|
+
end
|
57
|
+
|
58
|
+
def clone_hash(old_json_schema)
|
59
|
+
new_json_schema = {}
|
60
|
+
old_json_schema.each do |key, value|
|
61
|
+
if value.is_a?(Hash)
|
62
|
+
new_json_schema.merge!(key => clone_hash(value))
|
63
|
+
elsif value
|
64
|
+
new_json_schema.merge!(key => value.clone)
|
65
|
+
else
|
66
|
+
new_json_schema.merge!(key => nil)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
new_json_schema
|
70
|
+
end
|
71
|
+
|
72
|
+
def new_enum(json_schema)
|
73
|
+
res = []
|
74
|
+
new_keys(json_schema).map do |new_key|
|
75
|
+
new_json_shema = json_schema.dup
|
76
|
+
new_json_shema['enum'] = [new_key]
|
77
|
+
res.push([new_json_shema, ['enum', new_key]])
|
78
|
+
end
|
79
|
+
res
|
80
|
+
end
|
81
|
+
|
82
|
+
def new_keys(json_schema)
|
83
|
+
return [] unless json_schema['enum']
|
84
|
+
json_schema['enum']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -8,7 +8,10 @@ module Fitting
|
|
8
8
|
def to_a
|
9
9
|
return @to_a if @to_a
|
10
10
|
|
11
|
-
array =
|
11
|
+
array = []
|
12
|
+
Dir['fitting_tests/*.json'].each do |file|
|
13
|
+
array += JSON.load(File.read(file))
|
14
|
+
end
|
12
15
|
@to_a = array.inject([]) do |res, tested_request|
|
13
16
|
res.push(Fitting::Records::Spherical::Request.load(tested_request))
|
14
17
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json-schema'
|
2
2
|
require 'fitting/cover/json_schema'
|
3
|
+
require 'fitting/cover/json_schema_enum'
|
3
4
|
require 'fitting/records/unit/combination'
|
4
5
|
|
5
6
|
module Fitting
|
@@ -30,13 +31,26 @@ module Fitting
|
|
30
31
|
cover_json_schema = Fitting::Cover::JSONSchema.new(@json_schema)
|
31
32
|
cover_json_schema.combi.map do |comb|
|
32
33
|
@combinations.push(Fitting::Records::Unit::Combination.new(
|
33
|
-
|
34
|
-
|
34
|
+
comb,
|
35
|
+
bodies
|
35
36
|
))
|
36
37
|
end
|
37
38
|
@combinations
|
38
39
|
end
|
39
40
|
|
41
|
+
def combinations_with_enum
|
42
|
+
return @combinations_with_enum if @combinations_with_enum
|
43
|
+
@combinations_with_enum = []
|
44
|
+
qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi
|
45
|
+
qwe.map do |comb|
|
46
|
+
@combinations_with_enum.push(Fitting::Records::Unit::Combination.new(
|
47
|
+
comb,
|
48
|
+
bodies
|
49
|
+
))
|
50
|
+
end
|
51
|
+
@combinations_with_enum
|
52
|
+
end
|
53
|
+
|
40
54
|
def cover
|
41
55
|
@cover ||= if bodies == []
|
42
56
|
0
|
@@ -48,6 +62,18 @@ module Fitting
|
|
48
62
|
(count + 1) * 100 / (combinations.size + 1)
|
49
63
|
end
|
50
64
|
end
|
65
|
+
|
66
|
+
def cover_enum
|
67
|
+
@cover_enum ||= if bodies == []
|
68
|
+
0
|
69
|
+
else
|
70
|
+
count = 0
|
71
|
+
combinations_with_enum.map do |combination|
|
72
|
+
count += 1 unless combination.valid_bodies == []
|
73
|
+
end
|
74
|
+
(count + 1) * 100 / (combinations_with_enum.size + 1)
|
75
|
+
end
|
76
|
+
end
|
51
77
|
end
|
52
78
|
end
|
53
79
|
end
|
@@ -13,8 +13,8 @@ module Fitting
|
|
13
13
|
response.json_schemas.map do |json_schema|
|
14
14
|
json_schema.combinations.map do |combination|
|
15
15
|
next unless combination.valid_bodies == []
|
16
|
-
res += "request
|
17
|
-
"response
|
16
|
+
res += "request method: #{request.method}\nrequest path: #{request.path}\n"\
|
17
|
+
"response status: #{response.status}\nsource json-schema: #{json_schema.json_schema}\n"\
|
18
18
|
"combination: #{combination.description}\nnew json-schema: #{combination.json_schema}\n\n"
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fitting
|
2
|
+
class Statistics
|
3
|
+
class CoverErrorEnum
|
4
|
+
def initialize(request_unit)
|
5
|
+
@request_unit = request_unit
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
res = ''
|
10
|
+
@request_unit.map do |request|
|
11
|
+
request.responses.map do |response|
|
12
|
+
next unless response.tested_bodies != []
|
13
|
+
response.json_schemas.map do |json_schema|
|
14
|
+
json_schema.combinations_with_enum.map do |combination|
|
15
|
+
next unless combination.valid_bodies == []
|
16
|
+
res += "request method: #{request.method}\nrequest path: #{request.path}\n"\
|
17
|
+
"response status: #{response.status}\nsource json-schema: #{json_schema.json_schema}\n"\
|
18
|
+
"combination: #{combination.description}\nnew json-schema: #{combination.json_schema}\n\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -41,8 +41,10 @@ module Fitting
|
|
41
41
|
else
|
42
42
|
res.push("✔ #{response.status}")
|
43
43
|
end
|
44
|
-
|
44
|
+
elsif @depth == 'cover'
|
45
45
|
res.push("#{json_schema.cover}% #{response.status}")
|
46
|
+
elsif @depth == 'cover_enum'
|
47
|
+
res.push("#{json_schema.cover_enum}% #{response.status}")
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Fitting
|
2
|
+
class Statistics
|
3
|
+
class MeasurementCoverEnum
|
4
|
+
attr_reader :requests, :all_responses, :cover_responses, :not_cover_responses, :max_response_path,
|
5
|
+
:coverage_fully, :coverage_non, :coverage_partially, :not_covered_responses
|
6
|
+
|
7
|
+
def initialize(requests)
|
8
|
+
@requests = requests
|
9
|
+
@all_responses = 0
|
10
|
+
@cover_responses = 0
|
11
|
+
@not_cover_responses = 0
|
12
|
+
@max_response_path = 0
|
13
|
+
@coverage_fully = []
|
14
|
+
@coverage_non = []
|
15
|
+
@coverage_partially = []
|
16
|
+
@not_covered_responses = []
|
17
|
+
check_responses
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_responses
|
21
|
+
return if @ready
|
22
|
+
|
23
|
+
@requests.map do |request|
|
24
|
+
chech_request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
@ready = true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def chech_request(request)
|
33
|
+
check_cover(request)
|
34
|
+
coverage_push(request)
|
35
|
+
|
36
|
+
@max_response_path = request.path.to_s.size / 8 if request.path.to_s.size / 8 > @max_response_path
|
37
|
+
request.responses.map do |response|
|
38
|
+
check_response(response, request)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_response(response, request)
|
43
|
+
json_schema_index = 0
|
44
|
+
response.json_schemas.map do |json_schema|
|
45
|
+
json_schema_index = check_json_schema(json_schema, request, response, json_schema_index)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_json_schema(json_schema, request, response, json_schema_index)
|
50
|
+
if json_schema.cover_enum != 100
|
51
|
+
@not_cover_responses += 1
|
52
|
+
@not_covered_responses.push("#{request.method}\t#{request.path} #{response.status} #{json_schema_index}")
|
53
|
+
else
|
54
|
+
@cover_responses += 1
|
55
|
+
end
|
56
|
+
@all_responses += 1
|
57
|
+
json_schema_index + 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def coverage_push(request)
|
61
|
+
if @all == @cover
|
62
|
+
@coverage_fully.push(request)
|
63
|
+
elsif @all == @not_cover
|
64
|
+
@coverage_non.push(request)
|
65
|
+
else
|
66
|
+
@coverage_partially.push(request)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_cover(request)
|
71
|
+
@all = 0
|
72
|
+
@cover = 0
|
73
|
+
@not_cover = 0
|
74
|
+
|
75
|
+
request.responses.map do |response|
|
76
|
+
response.json_schemas.map do |json_schema|
|
77
|
+
count_cover(json_schema)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def count_cover(json_schema)
|
83
|
+
@all += 1
|
84
|
+
if json_schema.cover_enum != 100
|
85
|
+
@not_cover += 1
|
86
|
+
else
|
87
|
+
@cover += 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -2,6 +2,7 @@ require 'fitting/statistics/not_covered_responses'
|
|
2
2
|
require 'fitting/statistics/analysis'
|
3
3
|
require 'fitting/statistics/measurement'
|
4
4
|
require 'fitting/statistics/measurement_cover'
|
5
|
+
require 'fitting/statistics/measurement_cover_enum'
|
5
6
|
require 'fitting/records/unit/request'
|
6
7
|
require 'fitting/storage/white_list'
|
7
8
|
require 'fitting/records/documented/request'
|
@@ -48,8 +49,10 @@ module Fitting
|
|
48
49
|
@white_measurement ||=
|
49
50
|
if @depth == 'valid'
|
50
51
|
Fitting::Statistics::Measurement.new(white_unit)
|
51
|
-
|
52
|
+
elsif @depth == 'cover'
|
52
53
|
Fitting::Statistics::MeasurementCover.new(white_unit)
|
54
|
+
elsif @depth == 'cover_enum'
|
55
|
+
Fitting::Statistics::MeasurementCoverEnum.new(white_unit)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
@@ -57,8 +60,10 @@ module Fitting
|
|
57
60
|
@black_measurement ||=
|
58
61
|
if @depth == 'valid'
|
59
62
|
Fitting::Statistics::Measurement.new(black_unit)
|
60
|
-
|
63
|
+
elsif @depth == 'cover'
|
61
64
|
Fitting::Statistics::MeasurementCover.new(black_unit)
|
65
|
+
elsif @depth == 'cover_enum'
|
66
|
+
Fitting::Statistics::MeasurementCoverEnum.new(black_unit)
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'fitting/statistics/cover_error_enum'
|
2
|
+
require 'fitting/records/unit/request'
|
3
|
+
require 'fitting/storage/white_list'
|
4
|
+
require 'fitting/records/documented/request'
|
5
|
+
|
6
|
+
module Fitting
|
7
|
+
class Statistics
|
8
|
+
class TemplateCoverErrorEnum
|
9
|
+
def initialize(tested_requests, config)
|
10
|
+
@tested_requests = tested_requests
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def stats
|
15
|
+
"#{white_statistics}\n\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
def white_statistics
|
19
|
+
@white_statistics ||= Fitting::Statistics::CoverErrorEnum.new(white_unit)
|
20
|
+
end
|
21
|
+
|
22
|
+
def white_unit
|
23
|
+
@white_unit_requests ||= documented_requests_white.inject([]) do |res, documented_request|
|
24
|
+
res.push(Fitting::Records::Unit::Request.new(documented_request, @tested_requests))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def documented_requests_white
|
29
|
+
@documented_requests_white ||= documented.find_all(&:white)
|
30
|
+
end
|
31
|
+
|
32
|
+
def documented
|
33
|
+
@documented_requests ||= @config.tomogram.to_a.inject([]) do |res, tomogram_request|
|
34
|
+
res.push(Fitting::Records::Documented::Request.new(tomogram_request, white_list.to_a))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def white_list
|
39
|
+
@white_list ||= Fitting::Storage::WhiteList.new(
|
40
|
+
@config.prefix,
|
41
|
+
@config.white_list,
|
42
|
+
@config.resource_white_list,
|
43
|
+
@config.include_resources,
|
44
|
+
@config.include_actions,
|
45
|
+
@config.tomogram.to_resources
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/fitting/tests.rb
CHANGED
@@ -7,12 +7,14 @@ module Fitting
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def save
|
10
|
+
make_dir('fitting_tests')
|
10
11
|
array = @tested_requests.inject([]) do |res, request|
|
11
12
|
next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
|
12
13
|
res.push(request.to_spherical.to_hash)
|
13
14
|
end
|
14
15
|
json = JSON.dump(array)
|
15
|
-
|
16
|
+
|
17
|
+
File.open("fitting_tests/test#{ENV["TEST_ENV_NUMBER"]}.json", 'w') { |file| file.write(json) }
|
16
18
|
end
|
17
19
|
|
18
20
|
def make_dir(dir_name)
|
data/lib/fitting/version.rb
CHANGED
data/lib/tasks/fitting.rake
CHANGED
@@ -3,6 +3,7 @@ require 'fitting/configuration'
|
|
3
3
|
require 'fitting/records/realized_unit'
|
4
4
|
require 'fitting/templates/realized_template'
|
5
5
|
require 'fitting/statistics/template_cover_error'
|
6
|
+
require 'fitting/statistics/template_cover_error_enum'
|
6
7
|
|
7
8
|
namespace :fitting do
|
8
9
|
desc 'Fitting documentation'
|
@@ -40,12 +41,24 @@ namespace :fitting do
|
|
40
41
|
)
|
41
42
|
puts documented_unit.stats
|
42
43
|
|
44
|
+
unless documented_unit.not_covered == "\n"
|
45
|
+
puts 'Not all responses from the whitelist are covered!'
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
elsif args.size == 'm'
|
49
|
+
documented_unit = Fitting::Statistics::Template.new(
|
50
|
+
Fitting::Records::Spherical::Requests.new,
|
51
|
+
Fitting.configuration,
|
52
|
+
'cover_enum'
|
53
|
+
)
|
54
|
+
puts documented_unit.stats
|
55
|
+
|
43
56
|
unless documented_unit.not_covered == "\n"
|
44
57
|
puts 'Not all responses from the whitelist are covered!'
|
45
58
|
exit 1
|
46
59
|
end
|
47
60
|
else
|
48
|
-
puts 'need key xs or
|
61
|
+
puts 'need key xs, s or m'
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
@@ -57,8 +70,14 @@ namespace :fitting do
|
|
57
70
|
Fitting.configuration
|
58
71
|
)
|
59
72
|
puts documented_unit.stats
|
73
|
+
elsif args.size == 'm'
|
74
|
+
documented_unit = Fitting::Statistics::TemplateCoverErrorEnum.new(
|
75
|
+
Fitting::Records::Spherical::Requests.new,
|
76
|
+
Fitting.configuration
|
77
|
+
)
|
78
|
+
puts documented_unit.stats
|
60
79
|
else
|
61
|
-
puts 'need key s'
|
80
|
+
puts 'need key s or m'
|
62
81
|
end
|
63
82
|
end
|
64
83
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- d.efimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: haml
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: json-schema
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,16 +34,16 @@ dependencies:
|
|
48
34
|
name: multi_json
|
49
35
|
requirement: !ruby/object:Gem::Requirement
|
50
36
|
requirements:
|
51
|
-
- - "
|
37
|
+
- - "~>"
|
52
38
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
39
|
+
version: '1.11'
|
54
40
|
type: :runtime
|
55
41
|
prerelease: false
|
56
42
|
version_requirements: !ruby/object:Gem::Requirement
|
57
43
|
requirements:
|
58
|
-
- - "
|
44
|
+
- - "~>"
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
46
|
+
version: '1.11'
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: tomograph
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,6 +181,7 @@ extra_rdoc_files: []
|
|
195
181
|
files:
|
196
182
|
- ".gitignore"
|
197
183
|
- ".rubocop.yml"
|
184
|
+
- ".ruby-version"
|
198
185
|
- ".travis.yml"
|
199
186
|
- CHANGELOG.md
|
200
187
|
- CODE_OF_CONDUCT.md
|
@@ -209,8 +196,8 @@ files:
|
|
209
196
|
- lib/fitting/configuration.rb
|
210
197
|
- lib/fitting/configuration/legacy.rb
|
211
198
|
- lib/fitting/configuration/yaml.rb
|
212
|
-
- lib/fitting/cover.rb
|
213
199
|
- lib/fitting/cover/json_schema.rb
|
200
|
+
- lib/fitting/cover/json_schema_enum.rb
|
214
201
|
- lib/fitting/cover/response.rb
|
215
202
|
- lib/fitting/documentation.rb
|
216
203
|
- lib/fitting/matchers/response_matcher.rb
|
@@ -233,17 +220,20 @@ files:
|
|
233
220
|
- lib/fitting/statistics.rb
|
234
221
|
- lib/fitting/statistics/analysis.rb
|
235
222
|
- lib/fitting/statistics/cover_error.rb
|
223
|
+
- lib/fitting/statistics/cover_error_enum.rb
|
236
224
|
- lib/fitting/statistics/great.rb
|
237
225
|
- lib/fitting/statistics/list.rb
|
238
226
|
- lib/fitting/statistics/lists.rb
|
239
227
|
- lib/fitting/statistics/measurement.rb
|
240
228
|
- lib/fitting/statistics/measurement_cover.rb
|
229
|
+
- lib/fitting/statistics/measurement_cover_enum.rb
|
241
230
|
- lib/fitting/statistics/not_covered_responses.rb
|
242
231
|
- lib/fitting/statistics/percent.rb
|
243
232
|
- lib/fitting/statistics/requests_stats.rb
|
244
233
|
- lib/fitting/statistics/responses_stats.rb
|
245
234
|
- lib/fitting/statistics/template.rb
|
246
235
|
- lib/fitting/statistics/template_cover_error.rb
|
236
|
+
- lib/fitting/statistics/template_cover_error_enum.rb
|
247
237
|
- lib/fitting/storage/responses.rb
|
248
238
|
- lib/fitting/storage/white_list.rb
|
249
239
|
- lib/fitting/templates/realized_template.rb
|
data/lib/fitting/cover.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'fitting/cover/response'
|
2
|
-
require 'haml'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Fitting
|
6
|
-
class Cover
|
7
|
-
def initialize(all_responses, coverage)
|
8
|
-
@all_responses = all_responses
|
9
|
-
@coverage = coverage
|
10
|
-
@list = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_hash
|
14
|
-
return @list unless @list == {}
|
15
|
-
@all_responses.each_with_object({}) do |response, res|
|
16
|
-
next res unless response.documented?
|
17
|
-
if res.key?(response.route)
|
18
|
-
res[response.route].update(response)
|
19
|
-
else
|
20
|
-
res[response.route] = Fitting::Cover::Response.new(response)
|
21
|
-
end
|
22
|
-
end.map do |key, value|
|
23
|
-
@list[key] = value.to_hash
|
24
|
-
end
|
25
|
-
@list
|
26
|
-
end
|
27
|
-
|
28
|
-
def template
|
29
|
-
return @template if @template
|
30
|
-
@template = {}
|
31
|
-
to_hash.each do |key, value|
|
32
|
-
@template[key] = value
|
33
|
-
@template[key]['cover'] = 100.0
|
34
|
-
if value['flags'] == []
|
35
|
-
@template[key]['type'] = 'passed'
|
36
|
-
else
|
37
|
-
flag_true = value['flags'].find_all { |flag| flag == true }
|
38
|
-
flag_false = value['flags'].find_all { |flag| flag == false }
|
39
|
-
if flag_false.empty?
|
40
|
-
@template[key]['type'] = 'passed'
|
41
|
-
else
|
42
|
-
@template[key]['cover'] = if flag_true.empty?
|
43
|
-
0.0
|
44
|
-
else
|
45
|
-
flag_false.size / flag_true.size
|
46
|
-
end
|
47
|
-
@template[key]['type'] = 'failed'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
@template[key]['json_schema'] = JSON.pretty_generate(value['json_schemas'].last)
|
51
|
-
end
|
52
|
-
@template
|
53
|
-
end
|
54
|
-
|
55
|
-
def save
|
56
|
-
to_hash
|
57
|
-
contents = File.read(File.expand_path('../view/report.html.haml', __FILE__))
|
58
|
-
html = "<style>\n#{File.read(File.expand_path('../view/style.css', __FILE__))}\n</style>\n"
|
59
|
-
html += Haml::Engine.new(contents).render(
|
60
|
-
Object.new,
|
61
|
-
:@to_hash => template
|
62
|
-
)
|
63
|
-
html
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|