lib/rspec/openapi/hooks.rb in rspec-openapi-0.3.15 vs lib/rspec/openapi/hooks.rb in rspec-openapi-0.3.16
- old
+ new
@@ -4,10 +4,11 @@
require 'rspec/openapi/schema_builder'
require 'rspec/openapi/schema_file'
require 'rspec/openapi/schema_merger'
records = []
+records_errors = []
RSpec.configuration.after(:each) do |example|
if example.metadata[:type] == :request && example.metadata[:openapi] != false
record = RSpec::OpenAPI::RecordBuilder.build(self, example: example)
records << record if record
@@ -17,9 +18,23 @@
RSpec.configuration.after(:suite) do
title = File.basename(Dir.pwd)
RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec|
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
records.each do |record|
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
+ begin
+ RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
+ rescue => e # e.g. SchemaBuilder raises a NotImplementedError
+ # NOTE: Don't fail the build
+ records_errors << [e, record]
+ end
end
+ end
+ if records_errors.any?
+ error_message = <<~EOS
+ RSpec::OpenAPI got errors building #{records_errors.size} requests
+
+ #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
+ EOS
+ colorizer = ::RSpec::Core::Formatters::ConsoleCodes
+ RSpec.configuration.reporter.message colorizer.wrap(error_message, :failure)
end
end