Sha256: f4d92b84a499ad438e82a51374b1dce2f7d0d3e2316122490bb622dc7ac07fe2

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 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 = File.basename(Dir.pwd)
    @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|
          File.open('/tmp/records', 'a') { |f| f.puts record.to_yaml }
          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)
      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.8.0 lib/rspec/openapi/result_recorder.rb