Class: RSpec::OpenAPI::ResultRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/openapi/result_recorder.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_records) ⇒ ResultRecorder

Returns a new instance of ResultRecorder.



4
5
6
7
# File 'lib/rspec/openapi/result_recorder.rb', line 4

def initialize(path_records)
  @path_records = path_records
  @error_records = {}
end

Instance Method Details

#error_messageObject



27
28
29
30
31
32
33
# File 'lib/rspec/openapi/result_recorder.rb', line 27

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

#errors?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rspec/openapi/result_recorder.rb', line 23

def errors?
  @error_records.any?
end

#record_results!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rspec/openapi/result_recorder.rb', line 9

def record_results!
  @path_records.each do |paths, records|
    # A single record set may target multiple output files (e.g. both YAML and
    # JSON). The first path is the canonical source we read/merge into; the rest
    # mirror the same built spec, each formatted by its own extension.
    primary, *mirrors = Array(paths)
    next if primary.nil?

    load_path_config(primary)
    built_spec = build_spec(primary, records)
    mirrors.each { |mirror_path| RSpec::OpenAPI::SchemaFile.new(mirror_path).write(built_spec) }
  end
end