discourse/plugins/chat/spec/support/api_schema_matcher.rb
Loïc Guitaut f7c57fbc19 DEV: Enable unless cops
We discussed the use of `unless` internally and decided to enforce
available rules from rubocop to restrict its most problematic uses.
2023-02-21 10:30:48 +01:00

17 lines
506 B
Ruby

# frozen_string_literal: true
RSpec::Matchers.define :match_response_schema do |schema|
match do |object|
schema_directory = "#{Dir.pwd}/plugins/chat/spec/support/api/schemas"
schema_path = "#{schema_directory}/#{schema}.json"
begin
JSON::Validator.validate!(schema_path, object, strict: true)
rescue JSON::Schema::ValidationError => e
puts "-- Printing response body after validation error\n"
pp object # rubocop:disable Lint/Debugger
raise e
end
end
end