class GovukContentSchemaTestHelpers::Validator

Public Class Methods

new(schema_name, variant, document) click to toggle source

@param schema - the format (like `topic`). Use `format.links` for the

# File lib/govuk-content-schema-test-helpers/validator.rb, line 6
def initialize(schema_name, variant, document)
  Util.check_govuk_content_schemas_path!

  @schema_name = schema_name
  @variant = variant
  @document = document
end

Public Instance Methods

errors() click to toggle source
# File lib/govuk-content-schema-test-helpers/validator.rb, line 18
def errors
  unless File.exist?(schema_path)
    raise ImproperlyConfiguredError, "Schema file not found at: #{schema_path}"
  end

  @errors ||= JSON::Validator.fully_validate(schema_path, @document)
end
valid?() click to toggle source
# File lib/govuk-content-schema-test-helpers/validator.rb, line 14
def valid?
  errors.empty?
end

Private Instance Methods

schema_path() click to toggle source
# File lib/govuk-content-schema-test-helpers/validator.rb, line 27
def schema_path
  File.join(
    Util.govuk_content_schemas_path,
    "dist",
    "formats",
    @schema_name,
    GovukContentSchemaTestHelpers.configuration.schema_type,
    "#{@variant}.json"
  )
end