discourse/plugins/chat/spec/support/api_schema_matcher.rb
Jarek Radosz 694b5f108b
DEV: Fix various rubocop lints (#24749)
These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse:

Capybara/VisibilityMatcher
Lint/DeprecatedOpenSSLConstant
Lint/DisjunctiveAssignmentInConstructor
Lint/EmptyConditionalBody
Lint/EmptyEnsure
Lint/LiteralInInterpolation
Lint/NonLocalExitFromIterator
Lint/ParenthesesAsGroupedExpression
Lint/RedundantCopDisableDirective
Lint/RedundantRequireStatement
Lint/RedundantSafeNavigation
Lint/RedundantStringCoercion
Lint/RedundantWithIndex
Lint/RedundantWithObject
Lint/SafeNavigationChain
Lint/SafeNavigationConsistency
Lint/SelfAssignment
Lint/UnreachableCode
Lint/UselessMethodDefinition
Lint/Void

Previous PRs:
Lint/ShadowedArgument
Lint/DuplicateMethods
Lint/BooleanSymbol
RSpec/SpecFilePathSuffix
2023-12-06 23:25:00 +01:00

17 lines
474 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
raise e
end
end
end