fitting 2.18.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -11
  3. data/CHANGELOG.md +21 -0
  4. data/README.md +46 -6
  5. data/fitting.gemspec +3 -1
  6. data/lib/fitting/configuration.rb +11 -41
  7. data/lib/fitting/cover/json_schema.rb +4 -2
  8. data/lib/fitting/cover/json_schema_enum.rb +4 -2
  9. data/lib/fitting/cover/json_schema_one_of.rb +4 -2
  10. data/lib/fitting/railtie.rb +1 -0
  11. data/lib/fitting/records/documented/request.rb +1 -15
  12. data/lib/fitting/records/spherical/requests.rb +1 -1
  13. data/lib/fitting/records/tested/request.rb +11 -11
  14. data/lib/fitting/records/tested/response.rb +4 -4
  15. data/lib/fitting/report/actions.rb +4 -0
  16. data/lib/fitting/report/combinations.rb +1 -1
  17. data/lib/fitting/report/console.rb +35 -15
  18. data/lib/fitting/report/prefix.rb +20 -41
  19. data/lib/fitting/report/prefixes.rb +7 -8
  20. data/lib/fitting/report/response.rb +0 -3
  21. data/lib/fitting/report/tests.rb +23 -10
  22. data/lib/fitting/storage/responses.rb +5 -9
  23. data/lib/fitting/tests.rb +12 -4
  24. data/lib/fitting/version.rb +1 -1
  25. data/lib/fitting.rb +38 -43
  26. data/lib/tasks/fitting.rake +3 -186
  27. data/lib/tasks/fitting_outgoing.rake +91 -0
  28. metadata +28 -45
  29. data/lib/fitting/configuration/legacy.rb +0 -61
  30. data/lib/fitting/configuration/yaml.rb +0 -89
  31. data/lib/fitting/cover/response.rb +0 -37
  32. data/lib/fitting/documentation.rb +0 -56
  33. data/lib/fitting/matchers/response_matcher.rb +0 -96
  34. data/lib/fitting/records/realized_unit.rb +0 -52
  35. data/lib/fitting/records/test_unit/request.rb +0 -98
  36. data/lib/fitting/records/unit/combination.rb +0 -27
  37. data/lib/fitting/records/unit/json_schema.rb +0 -111
  38. data/lib/fitting/records/unit/request.rb +0 -37
  39. data/lib/fitting/records/unit/response.rb +0 -32
  40. data/lib/fitting/request.rb +0 -38
  41. data/lib/fitting/response/fully_validates.rb +0 -34
  42. data/lib/fitting/response.rb +0 -88
  43. data/lib/fitting/statistics/analysis.rb +0 -25
  44. data/lib/fitting/statistics/cover_error.rb +0 -29
  45. data/lib/fitting/statistics/cover_error_enum.rb +0 -29
  46. data/lib/fitting/statistics/cover_error_one_of.rb +0 -29
  47. data/lib/fitting/statistics/great.rb +0 -13
  48. data/lib/fitting/statistics/list.rb +0 -55
  49. data/lib/fitting/statistics/lists.rb +0 -53
  50. data/lib/fitting/statistics/measurement.rb +0 -92
  51. data/lib/fitting/statistics/measurement_cover.rb +0 -92
  52. data/lib/fitting/statistics/measurement_cover_enum.rb +0 -92
  53. data/lib/fitting/statistics/measurement_cover_one_of.rb +0 -92
  54. data/lib/fitting/statistics/not_covered_responses.rb +0 -13
  55. data/lib/fitting/statistics/percent.rb +0 -20
  56. data/lib/fitting/statistics/requests_stats.rb +0 -40
  57. data/lib/fitting/statistics/responses_stats.rb +0 -32
  58. data/lib/fitting/statistics/template.rb +0 -117
  59. data/lib/fitting/statistics/template_cover_error.rb +0 -50
  60. data/lib/fitting/statistics/template_cover_error_enum.rb +0 -50
  61. data/lib/fitting/statistics/template_cover_error_one_of.rb +0 -50
  62. data/lib/fitting/statistics.rb +0 -25
  63. data/lib/fitting/storage/white_list.rb +0 -158
  64. data/lib/fitting/templates/realized_template.rb +0 -49
  65. data/lib/fitting/view/report.html.haml +0 -16
  66. data/lib/fitting/view/style.css +0 -47
@@ -1,92 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class MeasurementCover
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 != 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 != 100
85
- @not_cover += 1
86
- else
87
- @cover += 1
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,92 +0,0 @@
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
@@ -1,92 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class MeasurementCoverOneOf
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_one_of != 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_one_of != 100
85
- @not_cover += 1
86
- else
87
- @cover += 1
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,13 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class NotCoveredResponses
4
- def initialize(measurement)
5
- @measurement = measurement
6
- end
7
-
8
- def to_s
9
- "#{@measurement.not_covered_responses.join("\n")}\n"
10
- end
11
- end
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class Percent
4
- def initialize(divider, dividend)
5
- @divider = divider
6
- @dividend = dividend
7
- end
8
-
9
- def to_f
10
- return 0.to_f if @divider.zero?
11
-
12
- (@dividend.to_f / @divider * 100.0).round(2)
13
- end
14
-
15
- def to_s
16
- "#{@dividend} (#{to_f}% of #{@divider})"
17
- end
18
- end
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- require 'fitting/statistics/percent'
2
-
3
- module Fitting
4
- class Statistics
5
- class RequestsStats
6
- def initialize(measurement)
7
- @measurement = measurement
8
- end
9
-
10
- def to_s
11
- @to_s ||= [
12
- "API requests with fully implemented responses: #{fully}.",
13
- "API requests with partially implemented responses: #{partially}.",
14
- "API requests with no implemented responses: #{non}."
15
- ].join("\n")
16
- end
17
-
18
- def fully
19
- @fully ||= Fitting::Statistics::Percent.new(
20
- @measurement.requests.size,
21
- @measurement.coverage_fully.size
22
- )
23
- end
24
-
25
- def partially
26
- @partially ||= Fitting::Statistics::Percent.new(
27
- @measurement.requests.size,
28
- @measurement.coverage_partially.size
29
- )
30
- end
31
-
32
- def non
33
- @non ||= Fitting::Statistics::Percent.new(
34
- @measurement.requests.size,
35
- @measurement.coverage_non.size
36
- )
37
- end
38
- end
39
- end
40
- end
@@ -1,32 +0,0 @@
1
- require 'fitting/statistics/percent'
2
-
3
- module Fitting
4
- class Statistics
5
- class ResponsesStats
6
- def initialize(measurement)
7
- @measurement = measurement
8
- end
9
-
10
- def to_s
11
- @to_s ||= [
12
- "API responses conforming to the blueprint: #{cover}.",
13
- "API responses with validation errors or untested: #{not_cover}."
14
- ].join("\n")
15
- end
16
-
17
- def cover
18
- @cover ||= Fitting::Statistics::Percent.new(
19
- @measurement.all_responses,
20
- @measurement.cover_responses
21
- )
22
- end
23
-
24
- def not_cover
25
- @not_cover ||= Fitting::Statistics::Percent.new(
26
- @measurement.all_responses,
27
- @measurement.not_cover_responses
28
- )
29
- end
30
- end
31
- end
32
- end
@@ -1,117 +0,0 @@
1
- require 'fitting/statistics/not_covered_responses'
2
- require 'fitting/statistics/analysis'
3
- require 'fitting/statistics/measurement'
4
- require 'fitting/statistics/measurement_cover'
5
- require 'fitting/statistics/measurement_cover_enum'
6
- require 'fitting/statistics/measurement_cover_one_of'
7
- require 'fitting/records/unit/request'
8
- require 'fitting/storage/white_list'
9
- require 'fitting/records/documented/request'
10
-
11
- module Fitting
12
- class Statistics
13
- class Template
14
- def initialize(tested_requests, config, depth = 'valid')
15
- @tested_requests = tested_requests
16
- @config = config
17
- @depth = depth
18
- end
19
-
20
- def save
21
- File.open(@config.stats_path, 'w') { |file| file.write(stats) }
22
- File.open(@config.not_covered_path, 'w') { |file| file.write(not_covered) }
23
- end
24
-
25
- def stats
26
- if @config.white_list.present? || @config.resource_white_list.present? || @config.include_resources.present?
27
- [
28
- ['[Black list]', black_statistics].join("\n"),
29
- ['[White list]', white_statistics].join("\n"),
30
- ''
31
- ].join("\n\n")
32
- else
33
- [white_statistics, "\n\n"].join
34
- end
35
- end
36
-
37
- def not_covered
38
- Fitting::Statistics::NotCoveredResponses.new(white_measurement).to_s
39
- end
40
-
41
- def white_statistics
42
- @white_statistics ||= Fitting::Statistics::Analysis.new(white_measurement, @depth)
43
- end
44
-
45
- def black_statistics
46
- @black_statistics ||= Fitting::Statistics::Analysis.new(black_measurement, @depth)
47
- end
48
-
49
- def white_measurement
50
- @white_measurement ||=
51
- case @depth
52
- when 'valid'
53
- Fitting::Statistics::Measurement.new(white_unit)
54
- when 'cover'
55
- Fitting::Statistics::MeasurementCover.new(white_unit)
56
- when 'cover_enum'
57
- Fitting::Statistics::MeasurementCoverEnum.new(white_unit)
58
- when 'cover_one_of'
59
- Fitting::Statistics::MeasurementCoverOneOf.new(white_unit)
60
- end
61
- end
62
-
63
- def black_measurement
64
- @black_measurement ||=
65
- case @depth
66
- when 'valid'
67
- Fitting::Statistics::Measurement.new(black_unit)
68
- when 'cover'
69
- Fitting::Statistics::MeasurementCover.new(black_unit)
70
- when 'cover_enum'
71
- Fitting::Statistics::MeasurementCoverEnum.new(black_unit)
72
- when 'cover_one_of'
73
- Fitting::Statistics::MeasurementCoverOneOf.new(black_unit)
74
- end
75
- end
76
-
77
- def white_unit
78
- @white_unit_requests ||= documented_requests_white.inject([]) do |res, documented_request|
79
- res.push(Fitting::Records::Unit::Request.new(documented_request, @tested_requests))
80
- end
81
- end
82
-
83
- def black_unit
84
- @black_unit_requests ||= documented_requests_black.inject([]) do |res, documented_request|
85
- res.push(Fitting::Records::Unit::Request.new(documented_request, @tested_requests))
86
- end
87
- end
88
-
89
- def documented_requests_white
90
- @documented_requests_white ||= documented.find_all(&:white)
91
- end
92
-
93
- def documented_requests_black
94
- @documented_requests_black ||= documented.find_all do |request|
95
- !request.white
96
- end
97
- end
98
-
99
- def documented
100
- @documented_requests ||= @config.tomogram.to_a.inject([]) do |res, tomogram_request|
101
- res.push(Fitting::Records::Documented::Request.new(tomogram_request, white_list.to_a))
102
- end
103
- end
104
-
105
- def white_list
106
- @white_list ||= Fitting::Storage::WhiteList.new(
107
- @config.prefix,
108
- @config.white_list,
109
- @config.resource_white_list,
110
- @config.include_resources,
111
- @config.include_actions,
112
- @config.tomogram.to_resources
113
- )
114
- end
115
- end
116
- end
117
- end
@@ -1,50 +0,0 @@
1
- require 'fitting/statistics/cover_error'
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 TemplateCoverError
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::CoverError.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,50 +0,0 @@
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,50 +0,0 @@
1
- require 'fitting/statistics/cover_error_one_of'
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 TemplateCoverErrorOneOf
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::CoverErrorOneOf.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,25 +0,0 @@
1
- require 'fitting/statistics/template'
2
-
3
- module Fitting
4
- class Statistics
5
- def initialize(tested_requests)
6
- @tested_requests = tested_requests
7
- end
8
-
9
- def save
10
- make_dir('fitting')
11
- if Fitting.configuration.is_a?(Array)
12
- Fitting.configuration.each do |config|
13
- make_dir("fitting/#{config.title}")
14
- Fitting::Statistics::Template.new(@tested_requests, config).save
15
- end
16
- else
17
- Fitting::Statistics::Template.new(@tested_requests, Fitting.configuration).save
18
- end
19
- end
20
-
21
- def make_dir(dir_name)
22
- FileUtils.mkdir_p(dir_name)
23
- end
24
- end
25
- end