fitting 2.11.0 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +1 -1
  4. data/.ruby-version +1 -1
  5. data/.tool-versions +1 -0
  6. data/.travis.yml +1 -1
  7. data/CHANGELOG.md +47 -0
  8. data/README.md +136 -76
  9. data/fitting.gemspec +1 -1
  10. data/lib/fitting.rb +5 -0
  11. data/lib/fitting/cover/json_schema.rb +21 -80
  12. data/lib/fitting/cover/json_schema_enum.rb +20 -70
  13. data/lib/fitting/cover/json_schema_one_of.rb +38 -0
  14. data/lib/fitting/records/spherical/requests.rb +3 -1
  15. data/lib/fitting/records/unit/json_schema.rb +26 -0
  16. data/lib/fitting/report/action.rb +53 -0
  17. data/lib/fitting/report/actions.rb +55 -0
  18. data/lib/fitting/report/combination.rb +37 -0
  19. data/lib/fitting/report/combinations.rb +47 -0
  20. data/lib/fitting/report/console.rb +41 -0
  21. data/lib/fitting/report/prefix.rb +53 -0
  22. data/lib/fitting/report/prefixes.rb +44 -0
  23. data/lib/fitting/report/response.rb +71 -0
  24. data/lib/fitting/report/responses.rb +48 -0
  25. data/lib/fitting/report/test.rb +61 -0
  26. data/lib/fitting/report/tests.rb +62 -0
  27. data/lib/fitting/statistics/cover_error_one_of.rb +27 -0
  28. data/lib/fitting/statistics/list.rb +2 -0
  29. data/lib/fitting/statistics/measurement_cover_one_of.rb +92 -0
  30. data/lib/fitting/statistics/template.rb +5 -0
  31. data/lib/fitting/statistics/template_cover_error_one_of.rb +50 -0
  32. data/lib/fitting/tests.rb +0 -1
  33. data/lib/fitting/version.rb +1 -1
  34. data/lib/tasks/fitting.rake +150 -2
  35. data/lib/templates/bomboniere/.gitignore +21 -0
  36. data/lib/templates/bomboniere/.tool-versions +1 -0
  37. data/lib/templates/bomboniere/README.md +19 -0
  38. data/lib/templates/bomboniere/dist/css/app.62e086ac.css +1 -0
  39. data/lib/templates/bomboniere/dist/css/chunk-vendors.ec5f6c3f.css +1 -0
  40. data/lib/templates/bomboniere/dist/favicon.ico +0 -0
  41. data/lib/templates/bomboniere/dist/index.html +1 -0
  42. data/lib/templates/bomboniere/dist/js/app.4356d509.js +2 -0
  43. data/lib/templates/bomboniere/dist/js/app.4356d509.js.map +1 -0
  44. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js +13 -0
  45. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js.map +1 -0
  46. data/lib/templates/bomboniere/package-lock.json +9263 -0
  47. data/lib/templates/bomboniere/package.json +25 -0
  48. data/lib/templates/bomboniere/public/favicon.ico +0 -0
  49. data/lib/templates/bomboniere/public/index.html +17 -0
  50. data/lib/templates/bomboniere/src/App.vue +102 -0
  51. data/lib/templates/bomboniere/src/assets/logo.png +0 -0
  52. data/lib/templates/bomboniere/src/components/HelloWorld.vue +188 -0
  53. data/lib/templates/bomboniere/src/main.js +10 -0
  54. data/lib/templates/bomboniere/src/router/index.js +31 -0
  55. data/lib/templates/bomboniere/src/views/About.vue +5 -0
  56. data/lib/templates/bomboniere/src/views/Action.vue +154 -0
  57. data/lib/templates/bomboniere/src/views/Home.vue +17 -0
  58. data/lib/templates/bomboniere/vue.config.js +3 -0
  59. metadata +47 -8
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'tomograph', '~> 2.0', '>= 2.2.0'
24
24
  spec.add_development_dependency 'bundler', '~> 1.12'
25
25
  spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
26
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rake', '>= 12.3.3'
27
27
  spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 0.49.1', '>= 0.49.1'
29
29
  spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
@@ -16,6 +16,7 @@ module Fitting
16
16
  end
17
17
 
18
18
  def statistics
19
+ puts 'DEPRECATED: deprecated method statistics, use new method save_test_data'
19
20
  responses = Fitting::Storage::Responses.new
20
21
 
21
22
  RSpec.configure do |config|
@@ -35,6 +36,10 @@ module Fitting
35
36
  FileUtils.rm_r Dir.glob("fitting_tests/*"), :force => true
36
37
 
37
38
  RSpec.configure do |config|
39
+ config.after(:each, type: :request) do
40
+ responses.add(response, inspect)
41
+ end
42
+
38
43
  config.after(:each, type: :controller) do
39
44
  responses.add(response, inspect)
40
45
  end
@@ -3,95 +3,36 @@ module Fitting
3
3
  class JSONSchema
4
4
  def initialize(json_schema)
5
5
  @json_schema = json_schema
6
+ @combinations = []
6
7
  end
7
8
 
8
9
  def combi
9
- return @combinations if @combinations
10
- @combinations = new_required(@json_schema)
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_required(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
10
+ inception(@json_schema, @combinations).each do |combination|
11
+ combination[0] = @json_schema.merge(combination[0])
12
+ combination[1] = ['required', combination[1]]
44
13
  end
45
14
  end
46
15
 
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_required(json_schema)
73
- res = []
74
- new_keys(json_schema).map do |new_key|
75
- new_json_shema = json_schema.dup
76
- if new_json_shema['required']
77
- new_json_shema['required'] += [new_key]
78
- else
79
- new_json_shema['required'] = [new_key]
16
+ def inception(json_schema, combinations)
17
+ json_schema.each do |key, value|
18
+ if key == 'properties' and json_schema['required'] != value.keys
19
+ schema = json_schema.dup
20
+ one_of = schema.delete('required') || []
21
+ schema['properties'].each_key do |property|
22
+ next if one_of.include?(property)
23
+ combinations.push([schema.merge('required' => one_of + [property]), "required.#{property}"])
24
+ end
25
+ elsif value.is_a?(Hash)
26
+ com = inception(value, [])
27
+ com.each do |combination|
28
+ combination[0] = { key => value.merge(combination[0])}
29
+ combination[1] = "#{key}.#{combination[1]}"
30
+ end
31
+ combinations += com
80
32
  end
81
- res.push([new_json_shema, ['required', new_key]])
82
33
  end
83
- res
84
- end
85
34
 
86
- def new_keys(json_schema)
87
- return [] unless json_schema && json_schema['properties']
88
- all = json_schema['properties'].keys.map(&:to_s)
89
- old = json_schema['required']
90
- if old
91
- all - old
92
- else
93
- all
94
- end
35
+ combinations
95
36
  end
96
37
  end
97
38
  end
@@ -3,85 +3,35 @@ module Fitting
3
3
  class JSONSchemaEnum
4
4
  def initialize(json_schema)
5
5
  @json_schema = json_schema
6
- end
7
-
8
- def combi
9
- return @combinations if @combinations
10
6
  @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
7
  end
36
8
 
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
9
+ def combi
10
+ inception(@json_schema, @combinations).each do |combination|
11
+ combination[0] = @json_schema.merge(combination[0])
12
+ combination[1] = ['enum', combination[1]]
54
13
  end
55
- old_json_schema
56
14
  end
57
15
 
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)
16
+ def inception(json_schema, combinations)
17
+ json_schema.each do |key, value|
18
+ if key == 'enum' && value.size > 1
19
+ schema = json_schema.dup
20
+ one_of = schema.delete('enum')
21
+ one_of.each_index do |index|
22
+ combinations.push([schema.merge('enum' => [one_of[index]]), "enum.#{one_of[index]}"])
23
+ end
24
+ elsif value.is_a?(Hash)
25
+ com = inception(value, [])
26
+ com.each do |combination|
27
+ combination[0] = { key => value.merge(combination[0])}
28
+ combination[1] = "#{key}.#{combination[1]}"
29
+ end
30
+ combinations += com
67
31
  end
68
32
  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
33
 
82
- def new_keys(json_schema)
83
- return [] unless json_schema['enum']
84
- json_schema['enum']
34
+ combinations
85
35
  end
86
36
  end
87
37
  end
@@ -0,0 +1,38 @@
1
+ module Fitting
2
+ class Cover
3
+ class JSONSchemaOneOf
4
+ def initialize(json_schema)
5
+ @json_schema = json_schema
6
+ @combinations = []
7
+ end
8
+
9
+ def combi
10
+ inception(@json_schema, @combinations).each do |combination|
11
+ combination[0] = @json_schema.merge(combination[0])
12
+ combination[1] = ['one_of', combination[1]]
13
+ end
14
+ end
15
+
16
+ def inception(json_schema, combinations)
17
+ json_schema.each do |key, value|
18
+ if key == 'oneOf'
19
+ schema = json_schema.dup
20
+ one_of = schema.delete('oneOf')
21
+ one_of.each_index do |index|
22
+ combinations.push([schema.merge('oneOf' => [one_of[index]]), "oneOf.#{index}"])
23
+ end
24
+ elsif value.is_a?(Hash)
25
+ com = inception(value, [])
26
+ com.each do |combination|
27
+ combination[0] = { key => value.merge(combination[0])}
28
+ combination[1] = "#{key}.#{combination[1]}"
29
+ end
30
+ combinations += com
31
+ end
32
+ end
33
+
34
+ combinations
35
+ end
36
+ end
37
+ end
38
+ end
@@ -13,7 +13,9 @@ module Fitting
13
13
  array += JSON.load(File.read(file))
14
14
  end
15
15
  @to_a = array.inject([]) do |res, tested_request|
16
- res.push(Fitting::Records::Spherical::Request.load(tested_request))
16
+ request = Fitting::Records::Spherical::Request.load(tested_request)
17
+ next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
18
+ res.push(request)
17
19
  end
18
20
  end
19
21
  end
@@ -1,6 +1,7 @@
1
1
  require 'json-schema'
2
2
  require 'fitting/cover/json_schema'
3
3
  require 'fitting/cover/json_schema_enum'
4
+ require 'fitting/cover/json_schema_one_of'
4
5
  require 'fitting/records/unit/combination'
5
6
 
6
7
  module Fitting
@@ -51,6 +52,19 @@ module Fitting
51
52
  @combinations_with_enum
52
53
  end
53
54
 
55
+ def combinations_with_one_of
56
+ return @combinations_with_one_of if @combinations_with_one_of
57
+ @combinations_with_one_of = []
58
+ qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi + Fitting::Cover::JSONSchemaOneOf.new(@json_schema).combi
59
+ qwe.map do |comb|
60
+ @combinations_with_one_of.push(Fitting::Records::Unit::Combination.new(
61
+ comb,
62
+ bodies
63
+ ))
64
+ end
65
+ @combinations_with_one_of
66
+ end
67
+
54
68
  def cover
55
69
  @cover ||= if bodies == []
56
70
  0
@@ -74,6 +88,18 @@ module Fitting
74
88
  (count + 1) * 100 / (combinations_with_enum.size + 1)
75
89
  end
76
90
  end
91
+
92
+ def cover_one_of
93
+ @cover_one_of ||= if bodies == []
94
+ 0
95
+ else
96
+ count = 0
97
+ combinations_with_one_of.map do |combination|
98
+ count += 1 unless combination.valid_bodies == []
99
+ end
100
+ (count + 1) * 100 / (combinations_with_one_of.size + 1)
101
+ end
102
+ end
77
103
  end
78
104
  end
79
105
  end
@@ -0,0 +1,53 @@
1
+ require 'fitting/report/responses'
2
+
3
+ module Fitting
4
+ module Report
5
+ class Action
6
+ def initialize(action)
7
+ @action = action
8
+ @tests = Fitting::Report::Tests.new([])
9
+ @responses = Fitting::Report::Responses.new(@action.responses)
10
+ end
11
+
12
+ def method
13
+ @action.method
14
+ end
15
+
16
+ def path
17
+ @action.path.to_s
18
+ end
19
+
20
+ def responses
21
+ @responses
22
+ end
23
+
24
+ def add_test(test)
25
+ @tests.push(test)
26
+ end
27
+
28
+ def path_match(find_path)
29
+ regexp =~ find_path
30
+ end
31
+
32
+ def regexp
33
+ return @regexp if @regexp
34
+
35
+ str = Regexp.escape(path)
36
+ str = str.gsub(/\\{\w+\\}/, '[^&=\/]+')
37
+ str = "\\A#{str}\\z"
38
+ @regexp = Regexp.new(str)
39
+ end
40
+
41
+ def tests
42
+ @tests
43
+ end
44
+
45
+ def details
46
+ {
47
+ tests_without_responses: @tests.without_responses,
48
+ responses_details: @responses.to_a.map { |r| {method: r.status, tests_size: r.tests.size, json_schema: r.id, combinations: r.details} }
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ require 'fitting/report/action'
2
+
3
+ module Fitting
4
+ module Report
5
+ class Actions
6
+ def initialize(prefix, tomogram_json_path)
7
+ actions = Tomograph::Tomogram.new(
8
+ prefix: prefix,
9
+ tomogram_json_path: tomogram_json_path
10
+ )
11
+ @actions = []
12
+ actions.to_a.map do |action|
13
+ @actions.push(Fitting::Report::Action.new(action))
14
+ end
15
+ end
16
+
17
+ def to_a
18
+ @actions
19
+ end
20
+
21
+ def join(tests)
22
+ tests.to_a.map do |test|
23
+ if is_there_a_suitable_action?(test)
24
+ cram_into_the_appropriate_action(test)
25
+ test.mark_action
26
+ end
27
+ end
28
+ end
29
+
30
+ def is_there_a_suitable_action?(test)
31
+ @actions.map do |action|
32
+ return true if test.method == action.method && action.path_match(test.path)
33
+ end
34
+
35
+ false
36
+ end
37
+
38
+ def cram_into_the_appropriate_action(test)
39
+ @actions.map do |action|
40
+ if test.method == action.method && action.path_match(test.path)
41
+ action.add_test(test)
42
+ return
43
+ end
44
+ end
45
+ end
46
+
47
+ def details(prefix)
48
+ {
49
+ tests_without_actions: prefix.tests.without_actions,
50
+ actions_details: @actions.map { |a| {method: a.method, path: a.path, tests_size: a.tests.size, responses: a.details} }
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end