fitting 2.18.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -11
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +46 -6
  5. data/fitting.gemspec +1 -1
  6. data/lib/fitting/configuration.rb +12 -6
  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/prefix.rb +20 -41
  17. data/lib/fitting/report/prefixes.rb +7 -8
  18. data/lib/fitting/report/response.rb +0 -3
  19. data/lib/fitting/report/tests.rb +23 -10
  20. data/lib/fitting/storage/responses.rb +5 -9
  21. data/lib/fitting/tests.rb +12 -4
  22. data/lib/fitting/version.rb +1 -1
  23. data/lib/fitting.rb +38 -43
  24. data/lib/tasks/fitting.rake +2 -186
  25. data/lib/tasks/fitting_outgoing.rake +91 -0
  26. metadata +5 -41
  27. data/lib/fitting/configuration/yaml.rb +0 -89
  28. data/lib/fitting/cover/response.rb +0 -37
  29. data/lib/fitting/documentation.rb +0 -56
  30. data/lib/fitting/matchers/response_matcher.rb +0 -88
  31. data/lib/fitting/records/realized_unit.rb +0 -52
  32. data/lib/fitting/records/test_unit/request.rb +0 -98
  33. data/lib/fitting/records/unit/combination.rb +0 -27
  34. data/lib/fitting/records/unit/json_schema.rb +0 -111
  35. data/lib/fitting/records/unit/request.rb +0 -37
  36. data/lib/fitting/records/unit/response.rb +0 -32
  37. data/lib/fitting/request.rb +0 -38
  38. data/lib/fitting/response/fully_validates.rb +0 -34
  39. data/lib/fitting/response.rb +0 -88
  40. data/lib/fitting/statistics/analysis.rb +0 -25
  41. data/lib/fitting/statistics/cover_error.rb +0 -29
  42. data/lib/fitting/statistics/cover_error_enum.rb +0 -29
  43. data/lib/fitting/statistics/cover_error_one_of.rb +0 -29
  44. data/lib/fitting/statistics/great.rb +0 -13
  45. data/lib/fitting/statistics/list.rb +0 -55
  46. data/lib/fitting/statistics/lists.rb +0 -53
  47. data/lib/fitting/statistics/measurement.rb +0 -92
  48. data/lib/fitting/statistics/measurement_cover.rb +0 -92
  49. data/lib/fitting/statistics/measurement_cover_enum.rb +0 -92
  50. data/lib/fitting/statistics/measurement_cover_one_of.rb +0 -92
  51. data/lib/fitting/statistics/not_covered_responses.rb +0 -13
  52. data/lib/fitting/statistics/percent.rb +0 -20
  53. data/lib/fitting/statistics/requests_stats.rb +0 -40
  54. data/lib/fitting/statistics/responses_stats.rb +0 -32
  55. data/lib/fitting/statistics/template.rb +0 -117
  56. data/lib/fitting/statistics/template_cover_error.rb +0 -50
  57. data/lib/fitting/statistics/template_cover_error_enum.rb +0 -50
  58. data/lib/fitting/statistics/template_cover_error_one_of.rb +0 -50
  59. data/lib/fitting/statistics.rb +0 -25
  60. data/lib/fitting/storage/white_list.rb +0 -158
  61. data/lib/fitting/templates/realized_template.rb +0 -49
  62. data/lib/fitting/view/report.html.haml +0 -16
  63. data/lib/fitting/view/style.css +0 -47
@@ -1,29 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class CoverErrorOneOf
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
-
14
- response.json_schemas.map do |json_schema|
15
- json_schema.combinations_with_one_of.map do |combination|
16
- next unless combination.valid_bodies == []
17
-
18
- res += "request method: #{request.method}\nrequest path: #{request.path}\n"\
19
- "response status: #{response.status}\nsource json-schema: #{json_schema.json_schema}\n"\
20
- "combination: #{combination.description}\nnew json-schema: #{combination.json_schema}\n\n"
21
- end
22
- end
23
- end
24
- end
25
- res
26
- end
27
- end
28
- end
29
- end
@@ -1,13 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class Great
4
- def initialize(measurement)
5
- @measurement = measurement
6
- end
7
-
8
- def to_s
9
- return 'All responses are 100% valid! Great job!' if @measurement.cover_responses == @measurement.all_responses
10
- end
11
- end
12
- end
13
- end
@@ -1,55 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class List
4
- def initialize(coverage, max_response_path, depth)
5
- @coverage = coverage
6
- @max_response_path = max_response_path
7
- @depth = depth
8
- end
9
-
10
- def to_s
11
- list_sort.inject([]) do |res, request|
12
- res.push("#{request.method}\t#{request.path}#{responses_stat(request)}")
13
- end.join("\n")
14
- end
15
-
16
- def list_sort
17
- @coverage.sort do |first, second|
18
- first.path.to_s <=> second.path.to_s
19
- end
20
- end
21
-
22
- def responses_stat(request)
23
- tab = "\t" * ((@max_response_path - request.path.to_s.size / 8) + 3)
24
- tab + request.responses.to_a.each_with_object([]) do |response, res|
25
- response_stat(response, res)
26
- end.join(' ')
27
- end
28
-
29
- private
30
-
31
- def response_stat(response, res)
32
- response.json_schemas.map do |json_schema|
33
- json_schema_stat(res, json_schema, response)
34
- end
35
- end
36
-
37
- def json_schema_stat(res, json_schema, response)
38
- case @depth
39
- when 'valid'
40
- if json_schema.bodies == []
41
- res.push("✖ #{response.status}")
42
- else
43
- res.push("✔ #{response.status}")
44
- end
45
- when 'cover'
46
- res.push("#{json_schema.cover}% #{response.status}")
47
- when 'cover_enum'
48
- res.push("#{json_schema.cover_enum}% #{response.status}")
49
- when 'cover_one_of'
50
- res.push("#{json_schema.cover_one_of}% #{response.status}")
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,53 +0,0 @@
1
- require 'fitting/statistics/list'
2
-
3
- module Fitting
4
- class Statistics
5
- class Lists
6
- def initialize(measurement, depth)
7
- @measurement = measurement
8
- @depth = depth
9
- end
10
-
11
- def to_s
12
- [
13
- coverage_fully_stat,
14
- coverage_partially_stat,
15
- coverage_non_stat
16
- ].compact.join("\n\n")
17
- end
18
-
19
- def coverage_fully_stat
20
- if @measurement.coverage_fully == []
21
- nil
22
- else
23
- [
24
- 'Fully conforming requests:',
25
- Fitting::Statistics::List.new(@measurement.coverage_fully, @measurement.max_response_path, @depth).to_s
26
- ].join("\n")
27
- end
28
- end
29
-
30
- def coverage_partially_stat
31
- if @measurement.coverage_partially == []
32
- nil
33
- else
34
- [
35
- 'Partially conforming requests:',
36
- Fitting::Statistics::List.new(@measurement.coverage_partially, @measurement.max_response_path, @depth).to_s
37
- ].join("\n")
38
- end
39
- end
40
-
41
- def coverage_non_stat
42
- if @measurement.coverage_non == []
43
- nil
44
- else
45
- [
46
- 'Non-conforming requests:',
47
- Fitting::Statistics::List.new(@measurement.coverage_non, @measurement.max_response_path, @depth).to_s
48
- ].join("\n")
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,92 +0,0 @@
1
- module Fitting
2
- class Statistics
3
- class Measurement
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.bodies == []
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.bodies == []
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 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