Class: GovukContentSchemaTestHelpers::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk-content-schema-test-helpers/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_name, variant, document) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • schema
    • the format (like ‘topic`). Use `format.links` for the



6
7
8
9
10
11
12
# 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

Instance Method Details

#errorsObject



18
19
20
21
22
23
24
# 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?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/govuk-content-schema-test-helpers/validator.rb', line 14

def valid?
  errors.empty?
end