class GovukContentSchemaTestHelpers::ValidationErrorMessage

Attributes

payload[R]
schema_name[R]
type[R]

Public Class Methods

new(schema_name, type, payload) click to toggle source
# File lib/govuk-content-schema-test-helpers/rspec_matchers.rb, line 45
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-content-schema-test-helpers/rspec_matchers.rb, line 51
    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-content-schema-test-helpers/rspec_matchers.rb, line 63
def errors
  validator = Validator.new(schema_name, type, payload)
  validator.errors.map { |message| "- " + humanized_error(message) }.join("\n")
end
formatted_payload() click to toggle source
# File lib/govuk-content-schema-test-helpers/rspec_matchers.rb, line 68
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-content-schema-test-helpers/rspec_matchers.rb, line 73
def humanized_error(message)
  message.gsub("The property '#/'", "The item")
end