fitting 2.16.1 → 2.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -3
- data/CHANGELOG.md +20 -0
- data/README.md +28 -4
- data/fitting.gemspec +9 -9
- data/images/example.png +0 -0
- data/images/example2.png +0 -0
- data/images/logo.png +0 -0
- data/lib/fitting/configuration/yaml.rb +13 -13
- data/lib/fitting/configuration.rb +3 -39
- data/lib/fitting/cover/json_schema.rb +3 -2
- data/lib/fitting/cover/json_schema_enum.rb +1 -1
- data/lib/fitting/cover/json_schema_one_of.rb +1 -1
- data/lib/fitting/cover/response.rb +1 -5
- data/lib/fitting/documentation.rb +0 -2
- data/lib/fitting/matchers/response_matcher.rb +2 -9
- data/lib/fitting/records/documented/request.rb +1 -0
- data/lib/fitting/records/realized_unit.rb +13 -15
- data/lib/fitting/records/spherical/request.rb +1 -1
- data/lib/fitting/records/spherical/requests.rb +2 -1
- data/lib/fitting/records/spherical/response.rb +2 -2
- data/lib/fitting/records/test_unit/request.rb +4 -0
- data/lib/fitting/records/tested/request.rb +4 -4
- data/lib/fitting/records/unit/combination.rb +5 -6
- data/lib/fitting/records/unit/json_schema.rb +38 -33
- data/lib/fitting/records/unit/request.rb +1 -0
- data/lib/fitting/records/unit/response.rb +1 -0
- data/lib/fitting/report/action.rb +6 -9
- data/lib/fitting/report/actions.rb +7 -5
- data/lib/fitting/report/combination.rb +1 -15
- data/lib/fitting/report/combinations.rb +4 -5
- data/lib/fitting/report/console.rb +1 -0
- data/lib/fitting/report/prefix.rb +42 -51
- data/lib/fitting/report/prefixes.rb +3 -3
- data/lib/fitting/report/response.rb +17 -18
- data/lib/fitting/report/responses.rb +9 -8
- data/lib/fitting/report/test.rb +9 -11
- data/lib/fitting/report/tests.rb +10 -13
- data/lib/fitting/request.rb +0 -1
- data/lib/fitting/response.rb +4 -3
- data/lib/fitting/statistics/cover_error.rb +2 -0
- data/lib/fitting/statistics/cover_error_enum.rb +2 -0
- data/lib/fitting/statistics/cover_error_one_of.rb +2 -0
- data/lib/fitting/statistics/list.rb +5 -4
- data/lib/fitting/statistics/not_covered_responses.rb +1 -1
- data/lib/fitting/statistics/percent.rb +2 -1
- data/lib/fitting/statistics/template.rb +10 -8
- data/lib/fitting/storage/responses.rb +2 -2
- data/lib/fitting/storage/white_list.rb +7 -0
- data/lib/fitting/templates/realized_template.rb +2 -0
- data/lib/fitting/tests.rb +1 -1
- data/lib/fitting/version.rb +1 -1
- data/lib/fitting.rb +9 -6
- data/lib/tasks/fitting.rake +62 -54
- data/lib/templates/bomboniere/package-lock.json +82 -67
- data/lib/templates/bomboniere/src/components/HelloWorld.vue +3 -0
- metadata +27 -53
- data/example.png +0 -0
- data/example2.png +0 -0
- data/lib/fitting/configuration/legacy.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4939d5e53f11ac3b5f28fa3088b20acefd5613b3c7ea8b075917ce9fa5703acd
|
4
|
+
data.tar.gz: 694aadc94e89341395c72cf1f26baeb065f7e10f6d0a7e305f4190ddc3e50d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7f9bfe0f22b4110e304e80daf8f843d6eba3bdf32598767b6da1e294ff83867593402eaaaa9665649162789aa3485f64ee3af066688dec0af0e96edb52caf8
|
7
|
+
data.tar.gz: 4ebe7ebf8d3f629b66f0378016fbd99a42d9d9907e911fe754732cb0c25761ebfe16cb095b4b76d11f24261b1f5213a6800e433998f225fd20b6bf9d7c0974e6
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.6
|
3
3
|
|
4
|
-
|
5
|
-
Max:
|
4
|
+
Layout/LineLength:
|
5
|
+
Max: 130
|
6
6
|
|
7
7
|
Style/Documentation:
|
8
8
|
Enabled: false
|
@@ -18,3 +18,34 @@ Style/CaseEquality:
|
|
18
18
|
|
19
19
|
Style/NilComparison:
|
20
20
|
Enabled: false
|
21
|
+
|
22
|
+
Naming/MemoizedInstanceVariableName:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Lint/UnreachableCode:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 50
|
30
|
+
|
31
|
+
# FIXME
|
32
|
+
Metrics/AbcSize:
|
33
|
+
Max: 50
|
34
|
+
|
35
|
+
Metrics/PerceivedComplexity:
|
36
|
+
Max: 20
|
37
|
+
|
38
|
+
Metrics/CyclomaticComplexity:
|
39
|
+
Max: 20
|
40
|
+
|
41
|
+
Metrics/ParameterLists:
|
42
|
+
Max: 7
|
43
|
+
|
44
|
+
Metrics/ClassLength:
|
45
|
+
Max: 150
|
46
|
+
|
47
|
+
Lint/UselessAssignment:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/ZeroLengthPredicate:
|
51
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
### 2.18.2 - 2021-11-09
|
4
|
+
|
5
|
+
* patch
|
6
|
+
* remove legacy [#123](https://github.com/funbox/fitting/issues/123)
|
7
|
+
|
8
|
+
### 2.18.1 - 2021-10-12
|
9
|
+
|
10
|
+
* patch
|
11
|
+
* fix bugs and refactoring
|
12
|
+
|
13
|
+
### 2.18.0 - 2021-09-29
|
14
|
+
|
15
|
+
* patch
|
16
|
+
* remove multi_json [#119](https://github.com/funbox/fitting/issues/119)
|
17
|
+
|
18
|
+
### 2.17.0 - 2021-09-20
|
19
|
+
|
20
|
+
* features
|
21
|
+
* display tests_without_responses details on the main page [#115](https://github.com/funbox/fitting/issues/115)
|
22
|
+
|
3
23
|
### 2.16.1 - 2021-02-10
|
4
24
|
* patch
|
5
25
|
* make prefix optional [#98](https://github.com/funbox/fitting/issues/98)
|
data/README.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# Fitting
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
<img align="right" width="192" height="192"
|
4
|
+
alt="Optimizt avatar: OK sign with Mona Lisa picture between the fingers"
|
5
|
+
src="./images/logo.png">
|
6
|
+
|
7
|
+
There are such ways of describing the API documentation as API Blueprint, Swagger and OpenAPI. And using the tests already writed for your code, you can reuse them to find out the documentation coverage.
|
8
|
+
This makes it easy to find out how much the documentation matches the implementation.
|
9
|
+
|
10
|
+
* Cool if you already have a project with tests and documentation, you can check how good everything is and fix microbags.
|
11
|
+
|
12
|
+
* If are you going developing API and write documentation for it, this tool will help you document-driven development easily create high-quality write API documentation and API.
|
13
|
+
|
14
|
+
* Also, if you have an undocumented API, this is an easy way to describe it.
|
15
|
+
|
16
|
+
![exmaple](images/example.png)
|
4
17
|
|
5
18
|
## Installation
|
6
19
|
Add this line to your application's Gemfile:
|
@@ -119,11 +132,11 @@ tests_without_responses: 43
|
|
119
132
|
|
120
133
|
And task will create HTML (`fitting/index.html`) reports.
|
121
134
|
|
122
|
-
![exmaple](example.png)
|
135
|
+
![exmaple](images/example.png)
|
123
136
|
|
124
137
|
More information on action coverage
|
125
138
|
|
126
|
-
![exmaple2](example2.png)
|
139
|
+
![exmaple2](images/example2.png)
|
127
140
|
|
128
141
|
## prefix name
|
129
142
|
|
@@ -134,6 +147,17 @@ prefixes:
|
|
134
147
|
- openapi2_json_path: doc.json
|
135
148
|
```
|
136
149
|
|
150
|
+
## prefix skip
|
151
|
+
|
152
|
+
It is not necessary to immediately describe each prefix in detail, you can only specify its name and skip it until you are ready to documented it
|
153
|
+
```yaml
|
154
|
+
prefixes:
|
155
|
+
- name: /api/v1
|
156
|
+
openapi2_json_path: doc.json
|
157
|
+
- name: /api/v3
|
158
|
+
skip: true
|
159
|
+
```
|
160
|
+
|
137
161
|
## Contributing
|
138
162
|
|
139
163
|
Bug reports and pull requests are welcome on GitHub at [github.com/funbox/fitting](https://github.com/funbox/fitting).
|
data/fitting.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'fitting/version'
|
4
4
|
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['d.efimov']
|
9
9
|
spec.email = ['d.efimov@fun-box.ru']
|
10
10
|
|
11
|
-
spec.summary = 'Coverage API Blueprint, Swagger and OpenAPI with
|
12
|
-
spec.description = 'Coverage API Blueprint, Swagger and OpenAPI with
|
11
|
+
spec.summary = 'Coverage API Blueprint, Swagger and OpenAPI with RSpec'
|
12
|
+
spec.description = 'Coverage API Blueprint, Swagger and OpenAPI with RSpec for easily make high-quality API and documenatiton'
|
13
13
|
spec.homepage = 'https://github.com/funbox/fitting'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,13 +18,13 @@ 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.required_ruby_version = '>= 2.6.0'
|
21
22
|
spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
|
22
|
-
spec.add_runtime_dependency 'multi_json', '~> 1.11'
|
23
23
|
spec.add_runtime_dependency 'tomograph', '~> 3.1', '>= 3.1.0'
|
24
24
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
|
-
spec.add_development_dependency 'byebug', '~>
|
26
|
-
spec.add_development_dependency 'rake', '>=
|
27
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
28
|
-
spec.add_development_dependency 'rubocop', '~>
|
29
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
25
|
+
spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
|
26
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 1.22.0'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.21'
|
30
30
|
end
|
data/images/example.png
ADDED
Binary file
|
data/images/example2.png
ADDED
Binary file
|
data/images/logo.png
ADDED
Binary file
|
@@ -39,24 +39,24 @@ module Fitting
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def tomogram
|
42
|
-
@tomogram ||= if
|
42
|
+
@tomogram ||= if crafter_yaml_path || crafter_apib_path
|
43
43
|
Tomograph::Tomogram.new(
|
44
|
-
prefix:
|
45
|
-
crafter_apib_path:
|
46
|
-
crafter_yaml_path:
|
44
|
+
prefix: prefix,
|
45
|
+
crafter_apib_path: crafter_apib_path,
|
46
|
+
crafter_yaml_path: crafter_yaml_path
|
47
47
|
)
|
48
|
-
elsif
|
48
|
+
elsif drafter_4_apib_path || drafter_4_yaml_path
|
49
49
|
Tomograph::Tomogram.new(
|
50
|
-
prefix:
|
51
|
-
drafter_4_apib_path:
|
52
|
-
drafter_4_yaml_path:
|
50
|
+
prefix: prefix,
|
51
|
+
drafter_4_apib_path: drafter_4_apib_path,
|
52
|
+
drafter_4_yaml_path: drafter_4_yaml_path
|
53
53
|
)
|
54
54
|
else
|
55
55
|
Tomograph::Tomogram.new(
|
56
|
-
prefix:
|
57
|
-
apib_path:
|
58
|
-
drafter_yaml_path:
|
59
|
-
tomogram_json_path:
|
56
|
+
prefix: prefix,
|
57
|
+
apib_path: apib_path,
|
58
|
+
drafter_yaml_path: drafter_yaml_path,
|
59
|
+
tomogram_json_path: tomogram_json_path
|
60
60
|
)
|
61
61
|
end
|
62
62
|
end
|
@@ -80,7 +80,7 @@ module Fitting
|
|
80
80
|
private
|
81
81
|
|
82
82
|
def default
|
83
|
-
@strict ||= false if
|
83
|
+
@strict ||= false if strict.nil?
|
84
84
|
@prefix ||= ''
|
85
85
|
@ignore_list ||= []
|
86
86
|
end
|
@@ -1,47 +1,11 @@
|
|
1
1
|
require 'fitting/configuration/yaml'
|
2
|
-
require 'fitting/configuration/legacy'
|
3
2
|
require 'yaml'
|
4
3
|
|
5
4
|
module Fitting
|
6
5
|
class Configuration
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
one_yaml
|
11
|
-
elsif more_than_one_yaml?
|
12
|
-
more_than_one_yaml
|
13
|
-
else
|
14
|
-
legacy
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def one_yaml?
|
19
|
-
File.file?('.fitting.yml')
|
20
|
-
end
|
21
|
-
|
22
|
-
def more_than_one_yaml?
|
23
|
-
!Dir['fitting/*.yml'].empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
def one_yaml
|
27
|
-
yaml = YAML.safe_load(File.read('.fitting.yml'))
|
28
|
-
Fitting::Configuration::Yaml.new(yaml)
|
29
|
-
end
|
30
|
-
|
31
|
-
def more_than_one_yaml
|
32
|
-
files.map do |file|
|
33
|
-
yaml = YAML.safe_load(File.read(file))
|
34
|
-
Fitting::Configuration::Yaml.new(yaml, file[8..-5])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def legacy
|
39
|
-
Fitting::Configuration::Legacy.new
|
40
|
-
end
|
41
|
-
|
42
|
-
def files
|
43
|
-
Dir['fitting/*.yml']
|
44
|
-
end
|
6
|
+
def self.craft
|
7
|
+
yaml = YAML.safe_load(File.read('.fitting.yml'))
|
8
|
+
Fitting::Configuration::Yaml.new(yaml)
|
45
9
|
end
|
46
10
|
end
|
47
11
|
end
|
@@ -15,17 +15,18 @@ module Fitting
|
|
15
15
|
|
16
16
|
def inception(json_schema, combinations)
|
17
17
|
json_schema.each do |key, value|
|
18
|
-
if key == 'properties'
|
18
|
+
if (key == 'properties') && (json_schema['required'] != value.keys)
|
19
19
|
schema = json_schema.dup
|
20
20
|
one_of = schema.delete('required') || []
|
21
21
|
schema['properties'].each_key do |property|
|
22
22
|
next if one_of.include?(property)
|
23
|
+
|
23
24
|
combinations.push([schema.merge('required' => one_of + [property]), "required.#{property}"])
|
24
25
|
end
|
25
26
|
elsif value.is_a?(Hash)
|
26
27
|
com = inception(value, [])
|
27
28
|
com.each do |combination|
|
28
|
-
combination[0] = { key => value.merge(combination[0])}
|
29
|
+
combination[0] = { key => value.merge(combination[0]) }
|
29
30
|
combination[1] = "#{key}.#{combination[1]}"
|
30
31
|
end
|
31
32
|
combinations += com
|
@@ -24,7 +24,7 @@ module Fitting
|
|
24
24
|
elsif value.is_a?(Hash)
|
25
25
|
com = inception(value, [])
|
26
26
|
com.each do |combination|
|
27
|
-
combination[0] = { key => value.merge(combination[0])}
|
27
|
+
combination[0] = { key => value.merge(combination[0]) }
|
28
28
|
combination[1] = "#{key}.#{combination[1]}"
|
29
29
|
end
|
30
30
|
combinations += com
|
@@ -24,7 +24,7 @@ module Fitting
|
|
24
24
|
elsif value.is_a?(Hash)
|
25
25
|
com = inception(value, [])
|
26
26
|
com.each do |combination|
|
27
|
-
combination[0] = { key => value.merge(combination[0])}
|
27
|
+
combination[0] = { key => value.merge(combination[0]) }
|
28
28
|
combination[1] = "#{key}.#{combination[1]}"
|
29
29
|
end
|
30
30
|
combinations += com
|
@@ -39,7 +39,8 @@ module Fitting
|
|
39
39
|
if response.within_prefix?(config.prefix)
|
40
40
|
@response = response
|
41
41
|
return true if @response.ignored?(config.ignore_list)
|
42
|
-
|
42
|
+
|
43
|
+
@response.fully_validates.valid?
|
43
44
|
else
|
44
45
|
true
|
45
46
|
end
|
@@ -83,13 +84,5 @@ module Fitting
|
|
83
84
|
@response.strict_fully_validates.valid?
|
84
85
|
end
|
85
86
|
end
|
86
|
-
|
87
|
-
def match_schema
|
88
|
-
Response.new
|
89
|
-
end
|
90
|
-
|
91
|
-
def strictly_match_schema
|
92
|
-
StrictResponse.new
|
93
|
-
end
|
94
87
|
end
|
95
88
|
end
|
@@ -9,27 +9,25 @@ module Fitting
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def fully_covered?
|
12
|
+
all_good_documented = false
|
13
|
+
all_good_response_documented = false
|
14
|
+
all_good_response_json_schemas = false
|
15
|
+
all_good_valid_json_schemas = false
|
16
|
+
|
12
17
|
test_file_paths.each do |_key, requests|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
all_good = requests.all?(&:response_documented?)
|
18
|
-
return false unless all_good
|
19
|
-
end
|
20
|
-
test_file_paths.each do |_key, requests|
|
21
|
-
all_good = requests.all?(&:response_json_schemas?)
|
22
|
-
return false unless all_good
|
23
|
-
end
|
24
|
-
test_file_paths.each do |_key, requests|
|
25
|
-
all_good = requests.all?(&:valid_json_schemas?)
|
26
|
-
return false unless all_good
|
18
|
+
all_good_documented = requests.all?(&:documented?)
|
19
|
+
all_good_response_documented = requests.all?(&:response_documented?)
|
20
|
+
all_good_response_json_schemas = requests.all?(&:response_json_schemas?)
|
21
|
+
all_good_valid_json_schemas = requests.all?(&:valid_json_schemas?)
|
27
22
|
end
|
28
|
-
|
23
|
+
|
24
|
+
all_good_documented && all_good_response_documented &&
|
25
|
+
all_good_response_json_schemas && all_good_valid_json_schemas
|
29
26
|
end
|
30
27
|
|
31
28
|
def test_file_paths
|
32
29
|
return @test_file_paths if @test_file_paths
|
30
|
+
|
33
31
|
@test_file_paths = {}
|
34
32
|
white_unit.map do |request|
|
35
33
|
@test_file_paths[request.test_file_path] ||= []
|
@@ -10,11 +10,12 @@ module Fitting
|
|
10
10
|
|
11
11
|
array = []
|
12
12
|
Dir['fitting_tests/*.json'].each do |file|
|
13
|
-
array += JSON.
|
13
|
+
array += JSON.parse(File.read(file))
|
14
14
|
end
|
15
15
|
@to_a = array.inject([]) do |res, tested_request|
|
16
16
|
request = Fitting::Records::Spherical::Request.load(tested_request)
|
17
17
|
next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
|
18
|
+
|
18
19
|
res.push(request)
|
19
20
|
end
|
20
21
|
end
|
@@ -14,7 +14,7 @@ module Fitting
|
|
14
14
|
def to_hash
|
15
15
|
{
|
16
16
|
status: status,
|
17
|
-
body: JSON.
|
17
|
+
body: JSON.parse(body)
|
18
18
|
}
|
19
19
|
rescue JSON::ParserError
|
20
20
|
{
|
@@ -23,7 +23,7 @@ module Fitting
|
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
26
|
-
def to_json
|
26
|
+
def to_json(*_args)
|
27
27
|
JSON.dump(to_hash)
|
28
28
|
end
|
29
29
|
|
@@ -37,6 +37,7 @@ module Fitting
|
|
37
37
|
@documented_requests ||= @all_documented_requests.inject([]) do |res, documented_request|
|
38
38
|
next res unless @tested_request.method == documented_request.method &&
|
39
39
|
documented_request.path.match(@tested_request.path.to_s)
|
40
|
+
|
40
41
|
res.push(documented_request)
|
41
42
|
end
|
42
43
|
end
|
@@ -49,6 +50,7 @@ module Fitting
|
|
49
50
|
@documented_responses ||= documented_requests.inject([]) do |res, documented_request|
|
50
51
|
documented_request.responses.map do |documented_response|
|
51
52
|
next unless documented_response['status'] == response.status.to_s
|
53
|
+
|
52
54
|
res.push(documented_response)
|
53
55
|
end
|
54
56
|
end.flatten.compact
|
@@ -71,6 +73,7 @@ module Fitting
|
|
71
73
|
def valid_json_schemas
|
72
74
|
@valid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
|
73
75
|
next res unless JSON::Validator.validate(json_schema, response.body)
|
76
|
+
|
74
77
|
res.push(json_schema)
|
75
78
|
end.flatten
|
76
79
|
end
|
@@ -78,6 +81,7 @@ module Fitting
|
|
78
81
|
def invalid_json_schemas
|
79
82
|
@invalid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
|
80
83
|
next res if JSON::Validator.validate(json_schema, response.body)
|
84
|
+
|
81
85
|
res.push(
|
82
86
|
json_schema: json_schema,
|
83
87
|
fully_validate: JSON::Validator.fully_validate(json_schema, response.body)
|
@@ -6,9 +6,9 @@ module Fitting
|
|
6
6
|
class Records
|
7
7
|
class Tested
|
8
8
|
class Request
|
9
|
-
def initialize(env_response,
|
9
|
+
def initialize(env_response, metadata)
|
10
10
|
@env_response = env_response
|
11
|
-
@
|
11
|
+
@metadata = metadata
|
12
12
|
end
|
13
13
|
|
14
14
|
def method
|
@@ -28,11 +28,11 @@ module Fitting
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_path
|
31
|
-
@test_path ||= @
|
31
|
+
@test_path ||= @metadata.fetch(:location)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_file_path
|
35
|
-
@test_file_path ||=
|
35
|
+
@test_file_path ||= @metadata.fetch(:file_path)
|
36
36
|
end
|
37
37
|
|
38
38
|
def to_spherical
|
@@ -14,12 +14,11 @@ module Fitting
|
|
14
14
|
|
15
15
|
def valid_bodies
|
16
16
|
@valid_bodies ||= @bodies.inject([]) do |res, tested_body|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
17
|
+
next res unless JSON::Validator.validate(@json_schema, tested_body)
|
18
|
+
|
19
|
+
res.push(tested_body)
|
20
|
+
rescue JSON::Schema::UriError
|
21
|
+
res.push(tested_body)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -17,50 +17,55 @@ module Fitting
|
|
17
17
|
|
18
18
|
def bodies
|
19
19
|
@bodies ||= @tested_bodies.inject([]) do |res, tested_body|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
20
|
+
next res unless JSON::Validator.validate(@json_schema, tested_body)
|
21
|
+
|
22
|
+
res.push(tested_body)
|
23
|
+
rescue JSON::Schema::UriError
|
24
|
+
res.push(tested_body)
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
def combinations
|
30
29
|
return @combinations if @combinations
|
30
|
+
|
31
31
|
@combinations = []
|
32
32
|
cover_json_schema = Fitting::Cover::JSONSchema.new(@json_schema)
|
33
33
|
cover_json_schema.combi.map do |comb|
|
34
34
|
@combinations.push(Fitting::Records::Unit::Combination.new(
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
comb,
|
36
|
+
bodies
|
37
|
+
))
|
38
38
|
end
|
39
39
|
@combinations
|
40
40
|
end
|
41
41
|
|
42
42
|
def combinations_with_enum
|
43
43
|
return @combinations_with_enum if @combinations_with_enum
|
44
|
+
|
44
45
|
@combinations_with_enum = []
|
45
|
-
qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
|
46
|
+
qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
|
47
|
+
Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi
|
46
48
|
qwe.map do |comb|
|
47
49
|
@combinations_with_enum.push(Fitting::Records::Unit::Combination.new(
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
comb,
|
51
|
+
bodies
|
52
|
+
))
|
51
53
|
end
|
52
54
|
@combinations_with_enum
|
53
55
|
end
|
54
56
|
|
55
57
|
def combinations_with_one_of
|
56
58
|
return @combinations_with_one_of if @combinations_with_one_of
|
59
|
+
|
57
60
|
@combinations_with_one_of = []
|
58
|
-
qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
|
61
|
+
qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
|
62
|
+
Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi +
|
63
|
+
Fitting::Cover::JSONSchemaOneOf.new(@json_schema).combi
|
59
64
|
qwe.map do |comb|
|
60
65
|
@combinations_with_one_of.push(Fitting::Records::Unit::Combination.new(
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
comb,
|
67
|
+
bodies
|
68
|
+
))
|
64
69
|
end
|
65
70
|
@combinations_with_one_of
|
66
71
|
end
|
@@ -79,26 +84,26 @@ module Fitting
|
|
79
84
|
|
80
85
|
def cover_enum
|
81
86
|
@cover_enum ||= if bodies == []
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
0
|
88
|
+
else
|
89
|
+
count = 0
|
90
|
+
combinations_with_enum.map do |combination|
|
91
|
+
count += 1 unless combination.valid_bodies == []
|
92
|
+
end
|
93
|
+
(count + 1) * 100 / (combinations_with_enum.size + 1)
|
94
|
+
end
|
90
95
|
end
|
91
96
|
|
92
97
|
def cover_one_of
|
93
98
|
@cover_one_of ||= if bodies == []
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
0
|
100
|
+
else
|
101
|
+
count = 0
|
102
|
+
combinations_with_one_of.map do |combination|
|
103
|
+
count += 1 unless combination.valid_bodies == []
|
104
|
+
end
|
105
|
+
(count + 1) * 100 / (combinations_with_one_of.size + 1)
|
106
|
+
end
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|