fitting 2.17.0 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -3
  3. data/CHANGELOG.md +5 -0
  4. data/fitting.gemspec +7 -7
  5. data/lib/fitting/configuration/legacy.rb +6 -5
  6. data/lib/fitting/configuration/yaml.rb +2 -2
  7. data/lib/fitting/cover/json_schema.rb +3 -2
  8. data/lib/fitting/cover/json_schema_enum.rb +1 -1
  9. data/lib/fitting/cover/json_schema_one_of.rb +1 -1
  10. data/lib/fitting/cover/response.rb +1 -5
  11. data/lib/fitting/documentation.rb +0 -2
  12. data/lib/fitting/matchers/response_matcher.rb +2 -1
  13. data/lib/fitting/records/documented/request.rb +1 -0
  14. data/lib/fitting/records/realized_unit.rb +13 -15
  15. data/lib/fitting/records/spherical/request.rb +1 -1
  16. data/lib/fitting/records/spherical/requests.rb +2 -1
  17. data/lib/fitting/records/spherical/response.rb +2 -2
  18. data/lib/fitting/records/test_unit/request.rb +4 -0
  19. data/lib/fitting/records/tested/request.rb +1 -1
  20. data/lib/fitting/records/unit/combination.rb +5 -6
  21. data/lib/fitting/records/unit/json_schema.rb +38 -33
  22. data/lib/fitting/records/unit/request.rb +1 -0
  23. data/lib/fitting/records/unit/response.rb +1 -0
  24. data/lib/fitting/report/action.rb +6 -9
  25. data/lib/fitting/report/actions.rb +7 -5
  26. data/lib/fitting/report/combination.rb +1 -15
  27. data/lib/fitting/report/combinations.rb +5 -6
  28. data/lib/fitting/report/console.rb +4 -3
  29. data/lib/fitting/report/prefix.rb +42 -51
  30. data/lib/fitting/report/prefixes.rb +3 -3
  31. data/lib/fitting/report/response.rb +17 -18
  32. data/lib/fitting/report/responses.rb +9 -8
  33. data/lib/fitting/report/test.rb +9 -11
  34. data/lib/fitting/report/tests.rb +10 -13
  35. data/lib/fitting/request.rb +0 -1
  36. data/lib/fitting/response.rb +4 -3
  37. data/lib/fitting/statistics/cover_error.rb +2 -0
  38. data/lib/fitting/statistics/cover_error_enum.rb +2 -0
  39. data/lib/fitting/statistics/cover_error_one_of.rb +2 -0
  40. data/lib/fitting/statistics/list.rb +5 -4
  41. data/lib/fitting/statistics/not_covered_responses.rb +1 -1
  42. data/lib/fitting/statistics/percent.rb +2 -1
  43. data/lib/fitting/statistics/template.rb +10 -8
  44. data/lib/fitting/storage/white_list.rb +7 -0
  45. data/lib/fitting/templates/realized_template.rb +2 -0
  46. data/lib/fitting/tests.rb +1 -1
  47. data/lib/fitting/version.rb +1 -1
  48. data/lib/fitting.rb +5 -2
  49. data/lib/tasks/fitting.rake +62 -54
  50. metadata +17 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 122a6d2713a74d7e0610f1378b7be6fdd42d0798fa6f6a008dc114186f86eade
4
- data.tar.gz: 3af5cf786f1489c9b249603551fe64c2d1fbb6b69183054d9ddadc8553b0a6de
3
+ metadata.gz: 86988a5ed3f114df581b0d6c6550867e2f9864f05808b6ec66a063f2ad573c93
4
+ data.tar.gz: 0b1c58784f5838caea3942d022f9dfaa4196912a7f30119e0b3e1b71080f9e43
5
5
  SHA512:
6
- metadata.gz: f11047db22a04c8562c75be538152e61cbf78ecd223ac941a61adaca5c2edda6ad44d1a14ac2dd535ca3f5e20bc4ffde4c101e9b48f0525392e248f6c870157e
7
- data.tar.gz: 99309897c90a7ea145141a00a073cf82ad56091557c9cd0044a9c5421440f945439e510440820f0f48c7a9f5dd8abec246e6e1872d8ba77d25d8843e94519b80
6
+ metadata.gz: d8f5d03f52a1332fc7483f17c8bbfde3c3a751a1c8f539f65637137e8b6ef95d251574105b5cecd9f4292f47f3a951ad45d9a9c914cfbee450b2d1eee8f1e25e
7
+ data.tar.gz: d40fe0ae76fa5a381e19c1444d84ae90262571cbf2ab9d3198d299b71333f042ccd1a637f150c28403b2a4ccb96b7abf230d9638ffb4ef645700244c4d8194db
data/.rubocop.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.6
3
3
 
4
- Metrics/LineLength:
5
- Max: 120
4
+ Layout/LineLength:
5
+ Max: 130
6
6
 
7
7
  Style/Documentation:
8
8
  Enabled: false
@@ -18,3 +18,31 @@ Style/CaseEquality:
18
18
 
19
19
  Style/NilComparison:
20
20
  Enabled: false
21
+
22
+ Naming/MemoizedInstanceVariableName:
23
+ Enabled: false
24
+
25
+ Lint/UnreachableCode:
26
+ Enabled: false
27
+
28
+ Metrics/MethodLength:
29
+ Max: 50
30
+
31
+ # FIXME
32
+ Metrics/AbcSize:
33
+ Max: 50
34
+
35
+ Metrics/PerceivedComplexity:
36
+ Max: 20
37
+
38
+ Metrics/CyclomaticComplexity:
39
+ Max: 20
40
+
41
+ Metrics/ParameterLists:
42
+ Max: 7
43
+
44
+ Metrics/ClassLength:
45
+ Max: 150
46
+
47
+ Lint/UselessAssignment:
48
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ### 2.18.0 - 2021-09-29
4
+
5
+ * patch
6
+ * remove multi_json [#119](https://github.com/funbox/fitting/issues/119)
7
+
3
8
  ### 2.17.0 - 2021-09-20
4
9
 
5
10
  * features
data/fitting.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'fitting/version'
4
4
 
@@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.required_ruby_version = '>= 2.6.0'
21
22
  spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
22
- spec.add_runtime_dependency 'multi_json', '~> 1.11'
23
23
  spec.add_runtime_dependency 'tomograph', '~> 3.1', '>= 3.1.0'
24
24
  spec.add_development_dependency 'bundler', '~> 2.0'
25
- spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
26
- spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
27
- spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
28
- spec.add_development_dependency 'rubocop', '~> 0.49.1', '>= 0.49.1'
29
- spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
25
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
26
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
27
+ spec.add_development_dependency 'rspec', '~> 3.10'
28
+ spec.add_development_dependency 'rubocop', '~> 1.22.0'
29
+ spec.add_development_dependency 'simplecov', '~> 0.21'
30
30
  end
@@ -36,11 +36,12 @@ module Fitting
36
36
  drafter_4_apib_path: @drafter_4_apib_path,
37
37
  drafter_4_yaml_path: @drafter_4_yaml_path
38
38
  )
39
- else Tomograph::Tomogram.new(
40
- prefix: @prefix,
41
- apib_path: @apib_path,
42
- drafter_yaml_path: @drafter_yaml_path
43
- )
39
+ else
40
+ Tomograph::Tomogram.new(
41
+ prefix: @prefix,
42
+ apib_path: @apib_path,
43
+ drafter_yaml_path: @drafter_yaml_path
44
+ )
44
45
  end
45
46
  end
46
47
 
@@ -43,13 +43,13 @@ module Fitting
43
43
  Tomograph::Tomogram.new(
44
44
  prefix: @prefix,
45
45
  crafter_apib_path: @crafter_apib_path,
46
- crafter_yaml_path: @crafter_yaml_path,
46
+ crafter_yaml_path: @crafter_yaml_path
47
47
  )
48
48
  elsif @drafter_4_apib_path || @drafter_4_yaml_path
49
49
  Tomograph::Tomogram.new(
50
50
  prefix: @prefix,
51
51
  drafter_4_apib_path: @drafter_4_apib_path,
52
- drafter_4_yaml_path: @drafter_4_yaml_path,
52
+ drafter_4_yaml_path: @drafter_4_yaml_path
53
53
  )
54
54
  else
55
55
  Tomograph::Tomogram.new(
@@ -15,17 +15,18 @@ module Fitting
15
15
 
16
16
  def inception(json_schema, combinations)
17
17
  json_schema.each do |key, value|
18
- if key == 'properties' and json_schema['required'] != value.keys
18
+ if (key == 'properties') && (json_schema['required'] != value.keys)
19
19
  schema = json_schema.dup
20
20
  one_of = schema.delete('required') || []
21
21
  schema['properties'].each_key do |property|
22
22
  next if one_of.include?(property)
23
+
23
24
  combinations.push([schema.merge('required' => one_of + [property]), "required.#{property}"])
24
25
  end
25
26
  elsif value.is_a?(Hash)
26
27
  com = inception(value, [])
27
28
  com.each do |combination|
28
- combination[0] = { key => value.merge(combination[0])}
29
+ combination[0] = { key => value.merge(combination[0]) }
29
30
  combination[1] = "#{key}.#{combination[1]}"
30
31
  end
31
32
  combinations += com
@@ -24,7 +24,7 @@ module Fitting
24
24
  elsif value.is_a?(Hash)
25
25
  com = inception(value, [])
26
26
  com.each do |combination|
27
- combination[0] = { key => value.merge(combination[0])}
27
+ combination[0] = { key => value.merge(combination[0]) }
28
28
  combination[1] = "#{key}.#{combination[1]}"
29
29
  end
30
30
  combinations += com
@@ -24,7 +24,7 @@ module Fitting
24
24
  elsif value.is_a?(Hash)
25
25
  com = inception(value, [])
26
26
  com.each do |combination|
27
- combination[0] = { key => value.merge(combination[0])}
27
+ combination[0] = { key => value.merge(combination[0]) }
28
28
  combination[1] = "#{key}.#{combination[1]}"
29
29
  end
30
30
  combinations += com
@@ -13,11 +13,7 @@ module Fitting
13
13
  end
14
14
  end
15
15
 
16
- attr_reader :json_schemas
17
-
18
- attr_reader :combinations
19
-
20
- attr_reader :flags
16
+ attr_reader :json_schemas, :combinations, :flags
21
17
 
22
18
  def update(response)
23
19
  index = 0
@@ -1,5 +1,3 @@
1
- require 'multi_json'
2
-
3
1
  module Fitting
4
2
  class Documentation
5
3
  def initialize(tomogram, white_list)
@@ -39,7 +39,8 @@ module Fitting
39
39
  if response.within_prefix?(config.prefix)
40
40
  @response = response
41
41
  return true if @response.ignored?(config.ignore_list)
42
- return @response.fully_validates.valid?
42
+
43
+ @response.fully_validates.valid?
43
44
  else
44
45
  true
45
46
  end
@@ -35,6 +35,7 @@ module Fitting
35
35
  return false if @white_list[path.to_s] == nil
36
36
  return true if @white_list[path.to_s] == []
37
37
  return true if @white_list[path.to_s].include?(method)
38
+
38
39
  false
39
40
  end
40
41
 
@@ -9,27 +9,25 @@ module Fitting
9
9
  end
10
10
 
11
11
  def fully_covered?
12
+ all_good_documented = false
13
+ all_good_response_documented = false
14
+ all_good_response_json_schemas = false
15
+ all_good_valid_json_schemas = false
16
+
12
17
  test_file_paths.each do |_key, requests|
13
- all_good = requests.all?(&:documented?)
14
- return false unless all_good
15
- end
16
- test_file_paths.each do |_key, requests|
17
- all_good = requests.all?(&:response_documented?)
18
- return false unless all_good
19
- end
20
- test_file_paths.each do |_key, requests|
21
- all_good = requests.all?(&:response_json_schemas?)
22
- return false unless all_good
23
- end
24
- test_file_paths.each do |_key, requests|
25
- all_good = requests.all?(&:valid_json_schemas?)
26
- return false unless all_good
18
+ all_good_documented = requests.all?(&:documented?)
19
+ all_good_response_documented = requests.all?(&:response_documented?)
20
+ all_good_response_json_schemas = requests.all?(&:response_json_schemas?)
21
+ all_good_valid_json_schemas = requests.all?(&:valid_json_schemas?)
27
22
  end
28
- true
23
+
24
+ all_good_documented && all_good_response_documented &&
25
+ all_good_response_json_schemas && all_good_valid_json_schemas
29
26
  end
30
27
 
31
28
  def test_file_paths
32
29
  return @test_file_paths if @test_file_paths
30
+
33
31
  @test_file_paths = {}
34
32
  white_unit.map do |request|
35
33
  @test_file_paths[request.test_file_path] ||= []
@@ -27,7 +27,7 @@ module Fitting
27
27
  }
28
28
  end
29
29
 
30
- def to_json
30
+ def to_json(*_args)
31
31
  JSON.dump(to_hash)
32
32
  end
33
33
 
@@ -10,11 +10,12 @@ module Fitting
10
10
 
11
11
  array = []
12
12
  Dir['fitting_tests/*.json'].each do |file|
13
- array += JSON.load(File.read(file))
13
+ array += JSON.parse(File.read(file))
14
14
  end
15
15
  @to_a = array.inject([]) do |res, tested_request|
16
16
  request = Fitting::Records::Spherical::Request.load(tested_request)
17
17
  next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
18
+
18
19
  res.push(request)
19
20
  end
20
21
  end
@@ -14,7 +14,7 @@ module Fitting
14
14
  def to_hash
15
15
  {
16
16
  status: status,
17
- body: JSON.load(body)
17
+ body: JSON.parse(body)
18
18
  }
19
19
  rescue JSON::ParserError
20
20
  {
@@ -23,7 +23,7 @@ module Fitting
23
23
  }
24
24
  end
25
25
 
26
- def to_json
26
+ def to_json(*_args)
27
27
  JSON.dump(to_hash)
28
28
  end
29
29
 
@@ -37,6 +37,7 @@ module Fitting
37
37
  @documented_requests ||= @all_documented_requests.inject([]) do |res, documented_request|
38
38
  next res unless @tested_request.method == documented_request.method &&
39
39
  documented_request.path.match(@tested_request.path.to_s)
40
+
40
41
  res.push(documented_request)
41
42
  end
42
43
  end
@@ -49,6 +50,7 @@ module Fitting
49
50
  @documented_responses ||= documented_requests.inject([]) do |res, documented_request|
50
51
  documented_request.responses.map do |documented_response|
51
52
  next unless documented_response['status'] == response.status.to_s
53
+
52
54
  res.push(documented_response)
53
55
  end
54
56
  end.flatten.compact
@@ -71,6 +73,7 @@ module Fitting
71
73
  def valid_json_schemas
72
74
  @valid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
73
75
  next res unless JSON::Validator.validate(json_schema, response.body)
76
+
74
77
  res.push(json_schema)
75
78
  end.flatten
76
79
  end
@@ -78,6 +81,7 @@ module Fitting
78
81
  def invalid_json_schemas
79
82
  @invalid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
80
83
  next res if JSON::Validator.validate(json_schema, response.body)
84
+
81
85
  res.push(
82
86
  json_schema: json_schema,
83
87
  fully_validate: JSON::Validator.fully_validate(json_schema, response.body)
@@ -28,7 +28,7 @@ module Fitting
28
28
  end
29
29
 
30
30
  def test_path
31
- @test_path ||= @test_title[/#{'\(\.'}(.*?)#{'\)'}/m, 1] || @test_title[/#{'\.'}(.*?)#{'\"'}/m, 1]
31
+ @test_path ||= @test_title[/\\(\\.(.*?)\\)/m, 1] || @test_title[/\\.(.*?)\\"/m, 1]
32
32
  end
33
33
 
34
34
  def test_file_path
@@ -14,12 +14,11 @@ module Fitting
14
14
 
15
15
  def valid_bodies
16
16
  @valid_bodies ||= @bodies.inject([]) do |res, tested_body|
17
- begin
18
- next res unless JSON::Validator.validate(@json_schema, tested_body)
19
- res.push(tested_body)
20
- rescue JSON::Schema::UriError
21
- res.push(tested_body)
22
- end
17
+ next res unless JSON::Validator.validate(@json_schema, tested_body)
18
+
19
+ res.push(tested_body)
20
+ rescue JSON::Schema::UriError
21
+ res.push(tested_body)
23
22
  end
24
23
  end
25
24
  end
@@ -17,50 +17,55 @@ module Fitting
17
17
 
18
18
  def bodies
19
19
  @bodies ||= @tested_bodies.inject([]) do |res, tested_body|
20
- begin
21
- next res unless JSON::Validator.validate(@json_schema, tested_body)
22
- res.push(tested_body)
23
- rescue JSON::Schema::UriError
24
- res.push(tested_body)
25
- end
20
+ next res unless JSON::Validator.validate(@json_schema, tested_body)
21
+
22
+ res.push(tested_body)
23
+ rescue JSON::Schema::UriError
24
+ res.push(tested_body)
26
25
  end
27
26
  end
28
27
 
29
28
  def combinations
30
29
  return @combinations if @combinations
30
+
31
31
  @combinations = []
32
32
  cover_json_schema = Fitting::Cover::JSONSchema.new(@json_schema)
33
33
  cover_json_schema.combi.map do |comb|
34
34
  @combinations.push(Fitting::Records::Unit::Combination.new(
35
- comb,
36
- bodies
37
- ))
35
+ comb,
36
+ bodies
37
+ ))
38
38
  end
39
39
  @combinations
40
40
  end
41
41
 
42
42
  def combinations_with_enum
43
43
  return @combinations_with_enum if @combinations_with_enum
44
+
44
45
  @combinations_with_enum = []
45
- qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi
46
+ qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
47
+ Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi
46
48
  qwe.map do |comb|
47
49
  @combinations_with_enum.push(Fitting::Records::Unit::Combination.new(
48
- comb,
49
- bodies
50
- ))
50
+ comb,
51
+ bodies
52
+ ))
51
53
  end
52
54
  @combinations_with_enum
53
55
  end
54
56
 
55
57
  def combinations_with_one_of
56
58
  return @combinations_with_one_of if @combinations_with_one_of
59
+
57
60
  @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
61
+ qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi +
62
+ Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi +
63
+ Fitting::Cover::JSONSchemaOneOf.new(@json_schema).combi
59
64
  qwe.map do |comb|
60
65
  @combinations_with_one_of.push(Fitting::Records::Unit::Combination.new(
61
- comb,
62
- bodies
63
- ))
66
+ comb,
67
+ bodies
68
+ ))
64
69
  end
65
70
  @combinations_with_one_of
66
71
  end
@@ -79,26 +84,26 @@ module Fitting
79
84
 
80
85
  def cover_enum
81
86
  @cover_enum ||= if bodies == []
82
- 0
83
- else
84
- count = 0
85
- combinations_with_enum.map do |combination|
86
- count += 1 unless combination.valid_bodies == []
87
- end
88
- (count + 1) * 100 / (combinations_with_enum.size + 1)
89
- end
87
+ 0
88
+ else
89
+ count = 0
90
+ combinations_with_enum.map do |combination|
91
+ count += 1 unless combination.valid_bodies == []
92
+ end
93
+ (count + 1) * 100 / (combinations_with_enum.size + 1)
94
+ end
90
95
  end
91
96
 
92
97
  def cover_one_of
93
98
  @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
99
+ 0
100
+ else
101
+ count = 0
102
+ combinations_with_one_of.map do |combination|
103
+ count += 1 unless combination.valid_bodies == []
104
+ end
105
+ (count + 1) * 100 / (combinations_with_one_of.size + 1)
106
+ end
102
107
  end
103
108
  end
104
109
  end
@@ -27,6 +27,7 @@ module Fitting
27
27
  @tested_responses ||= @tested_requests.to_a.inject([]) do |res, tested_request|
28
28
  next res unless @documented_request.method == tested_request.method &&
29
29
  @documented_request.path.match(tested_request.path.to_s)
30
+
30
31
  res.push(tested_request.response)
31
32
  end
32
33
  end
@@ -22,6 +22,7 @@ module Fitting
22
22
  def tested_bodies
23
23
  @tested_bodies ||= @tested_responses.inject([]) do |res, tested_response|
24
24
  next res unless status == tested_response.status.to_s
25
+
25
26
  res.push(tested_response.body)
26
27
  end
27
28
  end
@@ -17,9 +17,7 @@ module Fitting
17
17
  @action.path.to_s
18
18
  end
19
19
 
20
- def responses
21
- @responses
22
- end
20
+ attr_reader :responses, :tests
23
21
 
24
22
  def add_test(test)
25
23
  @tests.push(test)
@@ -38,14 +36,13 @@ module Fitting
38
36
  @regexp = Regexp.new(str)
39
37
  end
40
38
 
41
- def tests
42
- @tests
43
- end
44
-
45
39
  def details
46
40
  {
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} }
41
+ tests_without_responses: @tests.without_responses,
42
+ responses_details: @responses.to_a.map do |r|
43
+ { method: r.status, tests_size: r.tests.size, json_schema: r.id,
44
+ combinations: r.details }
45
+ end
49
46
  }
50
47
  end
51
48
  end
@@ -16,14 +16,14 @@ module Fitting
16
16
 
17
17
  def join(tests)
18
18
  tests.to_a.map do |test|
19
- if is_there_a_suitable_action?(test)
19
+ if there_a_suitable_action?(test)
20
20
  cram_into_the_appropriate_action(test)
21
21
  test.mark_action
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
- def is_there_a_suitable_action?(test)
26
+ def there_a_suitable_action?(test)
27
27
  @actions.map do |action|
28
28
  return true if test.method == action.method && action.path_match(test.path)
29
29
  end
@@ -35,15 +35,17 @@ module Fitting
35
35
  @actions.map do |action|
36
36
  if test.method == action.method && action.path_match(test.path)
37
37
  action.add_test(test)
38
- return
38
+ break
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
43
  def details(prefix)
44
44
  {
45
- tests_without_actions: prefix.tests.without_actions,
46
- actions_details: @actions.map { |a| {method: a.method, path: a.path, tests_size: a.tests.size, responses: a.details} }
45
+ tests_without_actions: prefix.tests.without_actions,
46
+ actions_details: @actions.map do |a|
47
+ { method: a.method, path: a.path, tests_size: a.tests.size, responses: a.details }
48
+ end
47
49
  }
48
50
  end
49
51
  end
@@ -9,26 +9,12 @@ module Fitting
9
9
  @id = SecureRandom.hex
10
10
  end
11
11
 
12
- def json_schema
13
- @json_schema
14
- end
15
-
16
- def id
17
- @id
18
- end
19
-
20
- def type
21
- @type
22
- end
12
+ attr_reader :json_schema, :id, :type, :tests
23
13
 
24
14
  def name
25
15
  @combination
26
16
  end
27
17
 
28
- def tests
29
- @tests
30
- end
31
-
32
18
  def add_test(test)
33
19
  @tests.push(test)
34
20
  end
@@ -14,20 +14,21 @@ module Fitting
14
14
  end
15
15
 
16
16
  def size_with_tests
17
- @combinations.count { |c| c.tests.size != 0 }
17
+ @combinations.count { |c| !c.tests.empty? }
18
18
  end
19
19
 
20
20
  def join(tests)
21
21
  tests.to_a.map do |test|
22
- if is_there_a_suitable_combination?(test)
22
+ if there_a_suitable_combination?(test)
23
23
  cram_into_the_appropriate_combinations(test)
24
24
  test.mark_combination
25
25
  end
26
26
  end
27
27
  end
28
28
 
29
- def is_there_a_suitable_combination?(test)
29
+ def there_a_suitable_combination?(test)
30
30
  return false if @combinations.nil?
31
+
31
32
  @combinations.map do |combination|
32
33
  return true if JSON::Validator.fully_validate(combination.json_schema, test.body) == []
33
34
  end
@@ -37,9 +38,7 @@ module Fitting
37
38
 
38
39
  def cram_into_the_appropriate_combinations(test)
39
40
  @combinations.map do |combination|
40
- if JSON::Validator.fully_validate(combination.json_schema, test.body) == []
41
- combination.add_test(test)
42
- end
41
+ combination.add_test(test) if JSON::Validator.fully_validate(combination.json_schema, test.body) == []
43
42
  end
44
43
  end
45
44
  end
@@ -31,9 +31,10 @@ module Fitting
31
31
  end
32
32
 
33
33
  def good?
34
- return false if @tests_without_prefixes.size != 0
35
- return false if @tests_without_actions.size != 0
36
- return false if @tests_without_responses.size != 0
34
+ return false unless @tests_without_prefixes.empty?
35
+ return false unless @tests_without_actions.empty?
36
+ return false unless @tests_without_responses.empty?
37
+
37
38
  @good
38
39
  end
39
40
  end