Sha256: b96dc15046c5479733836326941521b2555e0985b78487d8e332f4aae3920427

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

class RSpec::OpenAPI::ResultRecorder
  def initialize(path_records)
    @path_records = path_records
    @error_records = {}
  end

  def record_results!
    title = RSpec::OpenAPI.title
    @path_records.each do |path, records|
      RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
        schema = RSpec::OpenAPI::DefaultSchema.build(title)
        schema[:info].merge!(RSpec::OpenAPI.info)
        RSpec::OpenAPI::SchemaMerger.merge!(spec, schema)
        new_from_zero = {}
        records.each do |record|
          begin
            record_schema = RSpec::OpenAPI::SchemaBuilder.build(record)
            RSpec::OpenAPI::SchemaMerger.merge!(spec, record_schema)
            RSpec::OpenAPI::SchemaMerger.merge!(new_from_zero, record_schema)
          rescue StandardError, NotImplementedError => e # e.g. SchemaBuilder raises a NotImplementedError
            @error_records[e] = record # Avoid failing the build
          end
        end
        RSpec::OpenAPI::SchemaCleaner.cleanup!(spec, new_from_zero)
        RSpec::OpenAPI::ComponentsUpdater.update!(spec, new_from_zero)
        RSpec::OpenAPI::SchemaCleaner.cleanup_empty_required_array!(spec)
        RSpec::OpenAPI::SchemaCleaner.sort_paths!(spec)
      end
    end
  end

  def errors?
    @error_records.any?
  end

  def error_message
    <<~ERR_MSG
      RSpec::OpenAPI got errors building #{@error_records.size} requests

      #{@error_records.map { |e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
    ERR_MSG
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-openapi-0.10.0 lib/rspec/openapi/result_recorder.rb