class GovukSchemas::ValidationErrorMessage
@private
Attributes
payload[R]
schema_name[R]
type[R]
Public Class Methods
new(schema_name, type, payload)
click to toggle source
# File lib/govuk_schemas/rspec_matchers.rb, line 22 def initialize(schema_name, type, payload) @schema_name = schema_name @type = type @payload = payload end
Public Instance Methods
message()
click to toggle source
# File lib/govuk_schemas/rspec_matchers.rb, line 28 def message <<~DOC expected the payload to be valid against the '#{schema_name}' schema: #{formatted_payload} Validation errors: #{errors} DOC end
Private Instance Methods
errors()
click to toggle source
# File lib/govuk_schemas/rspec_matchers.rb, line 41 def errors schema = Schema.find(publisher_schema: schema_name) validator = JSON::Validator.fully_validate(schema, payload) validator.map { |message| "- " + humanized_error(message) }.join("\n") end
formatted_payload()
click to toggle source
# File lib/govuk_schemas/rspec_matchers.rb, line 47 def formatted_payload return payload if payload.is_a?(String) JSON.pretty_generate(payload) end
humanized_error(message)
click to toggle source
# File lib/govuk_schemas/rspec_matchers.rb, line 53 def humanized_error(message) message.gsub("The property '#/'", "The item") end