fitting 2.7.2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84283dbea86e6b51feff80746c42083581d41062
4
- data.tar.gz: 2e7bfe061b7da0572fec39b8dda02ce9cd0a1a64
3
+ metadata.gz: e2cacd061443e2b01a8632268f720ded08dffce1
4
+ data.tar.gz: 1d0237514578651a2376ae63b47b8ca6433a3a9c
5
5
  SHA512:
6
- metadata.gz: c507b40654e438c1123080328253b112803de9e407c3134eee4d321d25e43cca9e3966e96d7d48f6a51b17faec3be252b5468230fff8ffeaf7cea2af17050114
7
- data.tar.gz: 67e50590a29a8ece5903df6db5c263d787f19a647a7fba1631ec354e404c665036070ce7cf0aad76b0be3b7fc2fcfd0e141a84b97165b79a570ebf7336bf11ee
6
+ metadata.gz: a23cd2b021cfc20b7fa23a02cc97446e27a99714bb0069cfd4b08303a2011daca9e59fab7f38cc98476fd7b447df8389d9247806e451b2277d7f6a8dd6d0208f
7
+ data.tar.gz: d10e832b45a744eabf84cdbdbe0f213bd901f80bce104e6639d391d83d1123df4f95426a64cda0c28706210eac6c6e2100d031696413c6bbc23fcd536202cb94
@@ -0,0 +1 @@
1
+ 2.2.0
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ### 2.8.0 - 2018-10-13
4
+
5
+ * features
6
+ * Add m size (for cover enum in json-schema) in rake tasks fitting:documentation_responses, fitting:documentation_responses_error
7
+
3
8
  ### 2.7.2 - 2018-09-08
4
9
 
5
10
  * fixes
data/README.md CHANGED
@@ -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:
@@ -149,6 +149,11 @@ 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,10 @@ 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
+ ### tomogram_json_path
177
+
178
+ Path to Tomogram documentation pre-parsed with [tomograph](https://github.com/funbox/tomograph) and saved to a JSON file.
179
+
171
180
  ### strict
172
181
 
173
182
  Default `false`. If `true` then all properties are condisidered to have `"required": true` and all objects `"additionalProperties": false`.
@@ -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
@@ -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
- comb,
34
- bodies
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
@@ -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 metohd: #{request.method}\nrequest path: #{request.path}\n"\
17
+ "response staus: #{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
- else
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
- else
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
- else
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
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '2.7.2'.freeze
2
+ VERSION = '2.8.0'.freeze
3
3
  end
@@ -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 s'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitting
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.8.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: 2018-09-07 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -195,6 +195,7 @@ extra_rdoc_files: []
195
195
  files:
196
196
  - ".gitignore"
197
197
  - ".rubocop.yml"
198
+ - ".ruby-version"
198
199
  - ".travis.yml"
199
200
  - CHANGELOG.md
200
201
  - CODE_OF_CONDUCT.md
@@ -211,6 +212,7 @@ files:
211
212
  - lib/fitting/configuration/yaml.rb
212
213
  - lib/fitting/cover.rb
213
214
  - lib/fitting/cover/json_schema.rb
215
+ - lib/fitting/cover/json_schema_enum.rb
214
216
  - lib/fitting/cover/response.rb
215
217
  - lib/fitting/documentation.rb
216
218
  - lib/fitting/matchers/response_matcher.rb
@@ -233,17 +235,20 @@ files:
233
235
  - lib/fitting/statistics.rb
234
236
  - lib/fitting/statistics/analysis.rb
235
237
  - lib/fitting/statistics/cover_error.rb
238
+ - lib/fitting/statistics/cover_error_enum.rb
236
239
  - lib/fitting/statistics/great.rb
237
240
  - lib/fitting/statistics/list.rb
238
241
  - lib/fitting/statistics/lists.rb
239
242
  - lib/fitting/statistics/measurement.rb
240
243
  - lib/fitting/statistics/measurement_cover.rb
244
+ - lib/fitting/statistics/measurement_cover_enum.rb
241
245
  - lib/fitting/statistics/not_covered_responses.rb
242
246
  - lib/fitting/statistics/percent.rb
243
247
  - lib/fitting/statistics/requests_stats.rb
244
248
  - lib/fitting/statistics/responses_stats.rb
245
249
  - lib/fitting/statistics/template.rb
246
250
  - lib/fitting/statistics/template_cover_error.rb
251
+ - lib/fitting/statistics/template_cover_error_enum.rb
247
252
  - lib/fitting/storage/responses.rb
248
253
  - lib/fitting/storage/white_list.rb
249
254
  - lib/fitting/templates/realized_template.rb