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,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
@@ -1,158 +0,0 @@
1
- require 'tomograph'
2
-
3
- module Fitting
4
- module Storage
5
- class WhiteList
6
- def initialize(prefix, white_list, resource_white_list, include_resources, include_actions, resources)
7
- @prefix = prefix
8
- @white_list = white_list
9
- @resource_white_list = resource_white_list
10
- @include_resources = include_resources
11
- @include_actions = include_actions
12
- @resources = resources
13
- @warnings = []
14
- end
15
-
16
- def to_a
17
- return nil if @white_list == nil && @resource_white_list == nil && @include_resources == nil && @include_actions == nil
18
- return @white_list if @white_list
19
- return @white_list = transformation if @resource_white_list
20
-
21
- @white_list = {}
22
- @white_list.merge!(new_transformation) if @include_resources
23
- @white_list.merge!(postnew_transformation) if @include_actions
24
- @white_list
25
- end
26
-
27
- def without_group
28
- return @without_group_list if @without_group_list
29
-
30
- @without_group_list = @resource_white_list.inject([]) do |all_requests, resource|
31
- resource_selection(resource, all_requests)
32
- end.flatten.uniq
33
- puts_warnings
34
- @without_group_list
35
- end
36
-
37
- def resource_selection(resource, all_requests)
38
- if resource[1] == []
39
- find_warnings(resource[0])
40
- requests(@resources[resource[0]], all_requests)
41
- else
42
- requests(resource[1], all_requests)
43
- end
44
- end
45
-
46
- def find_warnings(resource)
47
- return nil if @resources[resource]
48
-
49
- @warnings.push(
50
- "FITTING WARNING: In the documentation there isn't resource from the resource_white_list #{resource}"
51
- )
52
- end
53
-
54
- def puts_warnings
55
- return nil if @warnings == []
56
-
57
- warnings_string = @warnings.join("\n")
58
- puts "\n#{warnings_string}"
59
- end
60
-
61
- def requests(resource, all_requests)
62
- return all_requests unless resource
63
-
64
- resource.map do |request|
65
- all_requests.push(request_hash(request))
66
- end
67
- all_requests
68
- end
69
-
70
- def transformation
71
- result = without_group.group_by { |action| action[:path] }
72
- result.inject({}) do |res, group|
73
- methods = group.last.map { |gr| gr[:method] }
74
- res.merge(group.first => methods)
75
- end
76
- end
77
-
78
- def request_hash(request)
79
- array = request.split(' ')
80
- {
81
- method: array[0],
82
- path: Tomograph::Path.new(array[1]).to_s
83
- }
84
- end
85
-
86
- def new_transformation
87
- @new_resources = {}
88
- @resources.map do |key, value|
89
- @new_resources.merge!(Tomograph::Path.new(key).to_s => value)
90
- end
91
- result = new_without_group.group_by { |action| action[:path] }
92
- result.inject({}) do |res, group|
93
- methods = group.last.map { |gr| gr[:method] }
94
- res.merge(group.first => methods)
95
- end
96
- end
97
-
98
- def new_without_group
99
- return @newwithout_group_list if @newwithout_group_list
100
-
101
- @newwithout_group_list = @include_resources.inject([]) do |all_requests, resource|
102
- if resource[0] == '/'
103
- new_resource_selection(resource, all_requests)
104
- else
105
- new_resource_selection("/#{resource}", all_requests)
106
- end
107
- end.flatten.uniq
108
- puts_warnings
109
- @newwithout_group_list
110
- end
111
-
112
- def new_resource_selection(resource, all_requests)
113
- new_find_warnings(resource)
114
- new_requests(@new_resources[resource], all_requests)
115
- end
116
-
117
- def new_requests(resource, all_requests)
118
- return all_requests unless resource
119
-
120
- resource.map do |request|
121
- all_requests.push(request_hash(request))
122
- end
123
- all_requests
124
- end
125
-
126
- def new_find_warnings(resource)
127
- return nil if @new_resources[resource]
128
-
129
- @warnings.push(
130
- "FITTING WARNING: In the documentation there isn't resource from the resource_white_list #{resource}"
131
- )
132
- end
133
-
134
- def postnew_transformation
135
- result = postnew_without_group.group_by { |action| action[:path] }
136
- result.inject({}) do |res, group|
137
- methods = group.last.map { |gr| gr[:method] }
138
- res.merge(group.first => methods)
139
- end
140
- end
141
-
142
- def postnew_without_group
143
- return @postnewwithout_group_list if @postnewwithout_group_list
144
-
145
- @postnewwithout_group_list = @include_actions.inject([]) do |all_requests, resource|
146
- method, path = resource.split(' ')
147
- if path[0] == '/'
148
- new_requests(["#{method} #{@prefix}#{path}"], all_requests)
149
- else
150
- new_requests(["#{method} #{@prefix}/#{path}"], all_requests)
151
- end
152
- end.flatten.uniq
153
- puts_warnings
154
- @postnewwithout_group_list
155
- end
156
- end
157
- end
158
- end
@@ -1,49 +0,0 @@
1
- module Fitting
2
- class Templates
3
- class RealizedTemplate
4
- def initialize(realized_unit)
5
- @realized_unit = realized_unit
6
- end
7
-
8
- def to_s
9
- res = ''
10
- res += "1. Find request method and path:\n"
11
- @realized_unit.test_file_paths.each do |key, requests|
12
- all_good = requests.all?(&:documented?)
13
- res += "file: #{key} #{all_good ? '✔' : '✖'}\n"
14
- end
15
- res += "\n2. Find response status code:\n"
16
- @realized_unit.test_file_paths.each do |key, requests|
17
- all_good = requests.all?(&:response_documented?)
18
- res += "file: #{key} #{all_good ? '✔' : '✖'}\n"
19
- end
20
- res += "\n3. Find response json-schemas:\n"
21
- @realized_unit.test_file_paths.each do |key, requests|
22
- all_good = requests.all?(&:response_json_schemas?)
23
- res += "file: #{key} #{all_good ? '✔' : '✖'}\n"
24
- end
25
- res += "\n4. Check valid json-schemas:\n"
26
- @realized_unit.test_file_paths.each do |key, requests|
27
- all_good = requests.all?(&:valid_json_schemas?)
28
- res += "path: #{key} #{all_good ? '✔' : '✖'}\n"
29
- next if all_good
30
-
31
- requests.map do |request|
32
- next if request.valid_json_schemas?
33
-
34
- res += " full path: #{request.test_path} ✖\n"
35
- res += " request.method #{request.method}\n"
36
- res += " request.path #{request.path}\n"
37
- res += " request.response.status #{request.response.status}\n"
38
- res += " request.response.body #{request.response.body}\n\n"
39
- request.invalid_json_schemas.map do |schema|
40
- res += " json_schemas: #{schema[:json_schema]}\n"
41
- res += " fully_validate: #{schema[:fully_validate]}\n\n"
42
- end
43
- end
44
- end
45
- res
46
- end
47
- end
48
- end
49
- end
@@ -1,16 +0,0 @@
1
- !!! 5
2
- %html
3
- %head
4
- %title= Time.now
5
- %meta{charset: "utf-8"}
6
- %body
7
- - @to_hash.each do |key, value|
8
- %details
9
- %summary{class: "collapse #{value['type']}"}
10
- = "#{key} #{value['cover']}"
11
- %div{class: 'group'}
12
- %div{class: 'section'}
13
- %div
14
- %b main json-schema
15
- %xmp
16
- = value['json_schema']
@@ -1,47 +0,0 @@
1
- summary {
2
- margin: 10px;
3
- }
4
-
5
- summary:hover {
6
- background: #e1e1e1;
7
- }
8
-
9
- .passed {
10
- color: green;
11
- }
12
-
13
- .failed {
14
- color: red;
15
- }
16
-
17
- .pending {
18
- color: orange;
19
- }
20
-
21
- .collapse {
22
- cursor: pointer;
23
- display: block;
24
- background: white;
25
- }
26
-
27
- .collapse + input {
28
- display: none; /* hide the checkboxes */
29
- }
30
-
31
- .collapse + input + div {
32
- display: none;
33
- }
34
-
35
- .collapse + input:checked + div {
36
- display: block;
37
- }
38
-
39
- .section {
40
- padding-top: 10px;
41
- }
42
-
43
- .group {
44
- border: 1px solid black;
45
- margin: 5px 0px;
46
- padding: 0px 5px;
47
- }