fitting 2.17.0 → 2.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -3
- data/CHANGELOG.md +20 -0
- data/fitting.gemspec +9 -7
- data/lib/fitting/configuration/yaml.rb +13 -13
- data/lib/fitting/configuration.rb +3 -39
- data/lib/fitting/cover/json_schema.rb +3 -2
- data/lib/fitting/cover/json_schema_enum.rb +1 -1
- data/lib/fitting/cover/json_schema_one_of.rb +1 -1
- data/lib/fitting/cover/response.rb +1 -5
- data/lib/fitting/documentation.rb +0 -2
- data/lib/fitting/matchers/response_matcher.rb +2 -9
- data/lib/fitting/records/documented/request.rb +1 -0
- data/lib/fitting/records/realized_unit.rb +13 -15
- data/lib/fitting/records/spherical/request.rb +1 -1
- data/lib/fitting/records/spherical/requests.rb +2 -1
- data/lib/fitting/records/spherical/response.rb +2 -2
- data/lib/fitting/records/test_unit/request.rb +4 -0
- data/lib/fitting/records/tested/request.rb +4 -4
- data/lib/fitting/records/unit/combination.rb +5 -6
- data/lib/fitting/records/unit/json_schema.rb +38 -33
- data/lib/fitting/records/unit/request.rb +1 -0
- data/lib/fitting/records/unit/response.rb +1 -0
- data/lib/fitting/report/action.rb +6 -9
- data/lib/fitting/report/actions.rb +7 -5
- data/lib/fitting/report/combination.rb +1 -15
- data/lib/fitting/report/combinations.rb +4 -5
- data/lib/fitting/report/console.rb +33 -12
- data/lib/fitting/report/prefix.rb +42 -51
- data/lib/fitting/report/prefixes.rb +3 -3
- data/lib/fitting/report/response.rb +17 -18
- data/lib/fitting/report/responses.rb +9 -8
- data/lib/fitting/report/test.rb +9 -11
- data/lib/fitting/report/tests.rb +10 -13
- data/lib/fitting/request.rb +0 -1
- data/lib/fitting/response.rb +4 -3
- data/lib/fitting/statistics/cover_error.rb +2 -0
- data/lib/fitting/statistics/cover_error_enum.rb +2 -0
- data/lib/fitting/statistics/cover_error_one_of.rb +2 -0
- data/lib/fitting/statistics/list.rb +5 -4
- data/lib/fitting/statistics/not_covered_responses.rb +1 -1
- data/lib/fitting/statistics/percent.rb +2 -1
- data/lib/fitting/statistics/template.rb +10 -8
- data/lib/fitting/storage/responses.rb +2 -2
- data/lib/fitting/storage/white_list.rb +7 -0
- data/lib/fitting/templates/realized_template.rb +2 -0
- data/lib/fitting/tests.rb +1 -1
- data/lib/fitting/version.rb +1 -1
- data/lib/fitting.rb +9 -6
- data/lib/tasks/fitting.rake +63 -54
- metadata +29 -42
- data/lib/fitting/configuration/legacy.rb +0 -60
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 140967f23d0706212f16a4239f33e409fbb0430e7e7295850501426992909eed
         | 
| 4 | 
            +
              data.tar.gz: 1178f1070ea69b6a1ed9e76cb7904c11a23e6d41652eba2fa587353c0e1cb6ef
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7649a6fa86471ab46d38e67ec1ae9bd30141802a8169f966558db9fadd1db22fc904c2ff185870937831e93411aaf81fb44dffd16a9f87ac7e71c3cc40108c2b
         | 
| 7 | 
            +
              data.tar.gz: 9787db0e0c9bbd3f2f3b23fc0d10996642774838f41d974f3f90421b69a5d425c663d9675915a4275031d371f462aeeb799c71e2b819c2abe82df7faa1f2d1a9
         | 
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            AllCops:
         | 
| 2 | 
            -
              TargetRubyVersion: 2. | 
| 2 | 
            +
              TargetRubyVersion: 2.6
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
              Max:  | 
| 4 | 
            +
            Layout/LineLength:
         | 
| 5 | 
            +
              Max: 130
         | 
| 6 6 |  | 
| 7 7 | 
             
            Style/Documentation:
         | 
| 8 8 | 
             
              Enabled: false
         | 
| @@ -18,3 +18,34 @@ 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
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            Style/ZeroLengthPredicate:
         | 
| 51 | 
            +
              Enabled: false
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,25 @@ | |
| 1 1 | 
             
            # Change log
         | 
| 2 2 |  | 
| 3 | 
            +
            ### 2.18.3 - 2021-11-12
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            * patch
         | 
| 6 | 
            +
              * added print table console [#121](https://github.com/funbox/fitting/issues/121)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ### 2.18.2 - 2021-11-09
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            * patch
         | 
| 11 | 
            +
              * remove legacy [#123](https://github.com/funbox/fitting/issues/123)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ### 2.18.1 - 2021-10-12
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * patch
         | 
| 16 | 
            +
              * fix bugs and refactoring
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ### 2.18.0 - 2021-09-29
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            * patch
         | 
| 21 | 
            +
              * remove multi_json [#119](https://github.com/funbox/fitting/issues/119)
         | 
| 22 | 
            +
             | 
| 3 23 | 
             
            ### 2.17.0 - 2021-09-20
         | 
| 4 24 |  | 
| 5 25 | 
             
            * features
         | 
    
        data/fitting.gemspec
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            lib = File.expand_path(' | 
| 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,15 @@ 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 ' | 
| 23 | 
            +
              spec.add_runtime_dependency 'terminal-table', '~> 3.0', '>= 3.0.2'
         | 
| 23 24 | 
             
              spec.add_runtime_dependency 'tomograph', '~> 3.1', '>= 3.1.0'
         | 
| 25 | 
            +
             | 
| 24 26 | 
             
              spec.add_development_dependency 'bundler', '~> 2.0'
         | 
| 25 | 
            -
              spec.add_development_dependency 'byebug', '~>  | 
| 26 | 
            -
              spec.add_development_dependency 'rake', '~>  | 
| 27 | 
            -
              spec.add_development_dependency 'rspec', '~> 3. | 
| 28 | 
            -
              spec.add_development_dependency 'rubocop', '~>  | 
| 29 | 
            -
              spec.add_development_dependency 'simplecov', '~> 0. | 
| 27 | 
            +
              spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
         | 
| 28 | 
            +
              spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
         | 
| 29 | 
            +
              spec.add_development_dependency 'rspec', '~> 3.10'
         | 
| 30 | 
            +
              spec.add_development_dependency 'rubocop', '~> 1.22.0'
         | 
| 31 | 
            +
              spec.add_development_dependency 'simplecov', '~> 0.21'
         | 
| 30 32 | 
             
            end
         | 
| @@ -39,24 +39,24 @@ module Fitting | |
| 39 39 | 
             
                  end
         | 
| 40 40 |  | 
| 41 41 | 
             
                  def tomogram
         | 
| 42 | 
            -
                    @tomogram ||= if  | 
| 42 | 
            +
                    @tomogram ||= if crafter_yaml_path || crafter_apib_path
         | 
| 43 43 | 
             
                                    Tomograph::Tomogram.new(
         | 
| 44 | 
            -
                                      prefix:  | 
| 45 | 
            -
                                      crafter_apib_path:  | 
| 46 | 
            -
                                      crafter_yaml_path:  | 
| 44 | 
            +
                                      prefix: prefix,
         | 
| 45 | 
            +
                                      crafter_apib_path: crafter_apib_path,
         | 
| 46 | 
            +
                                      crafter_yaml_path: crafter_yaml_path
         | 
| 47 47 | 
             
                                    )
         | 
| 48 | 
            -
                                  elsif  | 
| 48 | 
            +
                                  elsif drafter_4_apib_path || drafter_4_yaml_path
         | 
| 49 49 | 
             
                                    Tomograph::Tomogram.new(
         | 
| 50 | 
            -
                                      prefix:  | 
| 51 | 
            -
                                      drafter_4_apib_path:  | 
| 52 | 
            -
                                      drafter_4_yaml_path:  | 
| 50 | 
            +
                                      prefix: prefix,
         | 
| 51 | 
            +
                                      drafter_4_apib_path: drafter_4_apib_path,
         | 
| 52 | 
            +
                                      drafter_4_yaml_path: drafter_4_yaml_path
         | 
| 53 53 | 
             
                                    )
         | 
| 54 54 | 
             
                                  else
         | 
| 55 55 | 
             
                                    Tomograph::Tomogram.new(
         | 
| 56 | 
            -
                                      prefix:  | 
| 57 | 
            -
                                      apib_path:  | 
| 58 | 
            -
                                      drafter_yaml_path:  | 
| 59 | 
            -
                                      tomogram_json_path:  | 
| 56 | 
            +
                                      prefix: prefix,
         | 
| 57 | 
            +
                                      apib_path: apib_path,
         | 
| 58 | 
            +
                                      drafter_yaml_path: drafter_yaml_path,
         | 
| 59 | 
            +
                                      tomogram_json_path: tomogram_json_path
         | 
| 60 60 | 
             
                                    )
         | 
| 61 61 | 
             
                                  end
         | 
| 62 62 | 
             
                  end
         | 
| @@ -80,7 +80,7 @@ module Fitting | |
| 80 80 | 
             
                  private
         | 
| 81 81 |  | 
| 82 82 | 
             
                  def default
         | 
| 83 | 
            -
                    @strict ||= false if  | 
| 83 | 
            +
                    @strict ||= false if strict.nil?
         | 
| 84 84 | 
             
                    @prefix ||= ''
         | 
| 85 85 | 
             
                    @ignore_list ||= []
         | 
| 86 86 | 
             
                  end
         | 
| @@ -1,47 +1,11 @@ | |
| 1 1 | 
             
            require 'fitting/configuration/yaml'
         | 
| 2 | 
            -
            require 'fitting/configuration/legacy'
         | 
| 3 2 | 
             
            require 'yaml'
         | 
| 4 3 |  | 
| 5 4 | 
             
            module Fitting
         | 
| 6 5 | 
             
              class Configuration
         | 
| 7 | 
            -
                 | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 10 | 
            -
                      one_yaml
         | 
| 11 | 
            -
                    elsif more_than_one_yaml?
         | 
| 12 | 
            -
                      more_than_one_yaml
         | 
| 13 | 
            -
                    else
         | 
| 14 | 
            -
                      legacy
         | 
| 15 | 
            -
                    end
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  def one_yaml?
         | 
| 19 | 
            -
                    File.file?('.fitting.yml')
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  def more_than_one_yaml?
         | 
| 23 | 
            -
                    !Dir['fitting/*.yml'].empty?
         | 
| 24 | 
            -
                  end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  def one_yaml
         | 
| 27 | 
            -
                    yaml = YAML.safe_load(File.read('.fitting.yml'))
         | 
| 28 | 
            -
                    Fitting::Configuration::Yaml.new(yaml)
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  def more_than_one_yaml
         | 
| 32 | 
            -
                    files.map do |file|
         | 
| 33 | 
            -
                      yaml = YAML.safe_load(File.read(file))
         | 
| 34 | 
            -
                      Fitting::Configuration::Yaml.new(yaml, file[8..-5])
         | 
| 35 | 
            -
                    end
         | 
| 36 | 
            -
                  end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  def legacy
         | 
| 39 | 
            -
                    Fitting::Configuration::Legacy.new
         | 
| 40 | 
            -
                  end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  def files
         | 
| 43 | 
            -
                    Dir['fitting/*.yml']
         | 
| 44 | 
            -
                  end
         | 
| 6 | 
            +
                def self.craft
         | 
| 7 | 
            +
                  yaml = YAML.safe_load(File.read('.fitting.yml'))
         | 
| 8 | 
            +
                  Fitting::Configuration::Yaml.new(yaml)
         | 
| 45 9 | 
             
                end
         | 
| 46 10 | 
             
              end
         | 
| 47 11 | 
             
            end
         | 
| @@ -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'  | 
| 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
         | 
| @@ -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 | 
            -
             | 
| 42 | 
            +
             | 
| 43 | 
            +
                      @response.fully_validates.valid?
         | 
| 43 44 | 
             
                    else
         | 
| 44 45 | 
             
                      true
         | 
| 45 46 | 
             
                    end
         | 
| @@ -83,13 +84,5 @@ module Fitting | |
| 83 84 | 
             
                    @response.strict_fully_validates.valid?
         | 
| 84 85 | 
             
                  end
         | 
| 85 86 | 
             
                end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                def match_schema
         | 
| 88 | 
            -
                  Response.new
         | 
| 89 | 
            -
                end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                def strictly_match_schema
         | 
| 92 | 
            -
                  StrictResponse.new
         | 
| 93 | 
            -
                end
         | 
| 94 87 | 
             
              end
         | 
| 95 88 | 
             
            end
         | 
| @@ -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 | 
            -
                       | 
| 14 | 
            -
                       | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 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 | 
            -
             | 
| 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] ||= []
         | 
| @@ -10,11 +10,12 @@ module Fitting | |
| 10 10 |  | 
| 11 11 | 
             
                      array = []
         | 
| 12 12 | 
             
                      Dir['fitting_tests/*.json'].each do |file|
         | 
| 13 | 
            -
                        array += JSON. | 
| 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. | 
| 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)
         | 
| @@ -6,9 +6,9 @@ module Fitting | |
| 6 6 | 
             
              class Records
         | 
| 7 7 | 
             
                class Tested
         | 
| 8 8 | 
             
                  class Request
         | 
| 9 | 
            -
                    def initialize(env_response,  | 
| 9 | 
            +
                    def initialize(env_response, metadata)
         | 
| 10 10 | 
             
                      @env_response = env_response
         | 
| 11 | 
            -
                      @ | 
| 11 | 
            +
                      @metadata = metadata
         | 
| 12 12 | 
             
                    end
         | 
| 13 13 |  | 
| 14 14 | 
             
                    def method
         | 
| @@ -28,11 +28,11 @@ module Fitting | |
| 28 28 | 
             
                    end
         | 
| 29 29 |  | 
| 30 30 | 
             
                    def test_path
         | 
| 31 | 
            -
                      @test_path ||= @ | 
| 31 | 
            +
                      @test_path ||= @metadata.fetch(:location)
         | 
| 32 32 | 
             
                    end
         | 
| 33 33 |  | 
| 34 34 | 
             
                    def test_file_path
         | 
| 35 | 
            -
                      @test_file_path ||=  | 
| 35 | 
            +
                      @test_file_path ||= @metadata.fetch(:file_path)
         | 
| 36 36 | 
             
                    end
         | 
| 37 37 |  | 
| 38 38 | 
             
                    def to_spherical
         | 
| @@ -14,12 +14,11 @@ module Fitting | |
| 14 14 |  | 
| 15 15 | 
             
                    def valid_bodies
         | 
| 16 16 | 
             
                      @valid_bodies ||= @bodies.inject([]) do |res, tested_body|
         | 
| 17 | 
            -
                         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 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 | 
            -
                         | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 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 | 
            -
             | 
| 36 | 
            -
             | 
| 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 + | 
| 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 | 
            -
             | 
| 49 | 
            -
             | 
| 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 + | 
| 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 | 
            -
             | 
| 62 | 
            -
             | 
| 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 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 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 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 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
         | 
| @@ -17,9 +17,7 @@ module Fitting | |
| 17 17 | 
             
                    @action.path.to_s
         | 
| 18 18 | 
             
                  end
         | 
| 19 19 |  | 
| 20 | 
            -
                   | 
| 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 | 
            -
             | 
| 48 | 
            -
             | 
| 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
         |