Sha256: f31811c066d6f1a2521bb02c8fd631ff43a56c896431c59986e90f35d9cfcedb

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require 'test/unit'
require File.dirname(__FILE__) + '/../lib/json-schema'

class AllOfRefSchemaTest < Test::Unit::TestCase
  def test_all_of_ref_schema_fails
    schema = File.join(File.dirname(__FILE__),"schemas/all_of_ref_schema.json")
    data = File.join(File.dirname(__FILE__),"data/all_of_ref_data.json")
    errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
    assert(!errors.empty?, "should have failed to validate")
  end

  def test_all_of_ref_schema_succeeds
    schema = File.join(File.dirname(__FILE__),"schemas/all_of_ref_schema.json")
    data   = %({"name": 42})
    errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
    assert(errors.empty?, "should have validated")
  end

  def test_all_of_ref_subschema_errors
    schema = File.join(File.dirname(__FILE__), 'schemas/all_of_ref_schema.json')
    data = File.join(File.dirname(__FILE__), 'data/all_of_ref_data.json')
    errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
    nested_errors = errors[0][:errors]
    assert_equal([:allof_0], nested_errors.keys, 'should have nested errors for each allOf subschema')
    assert_match(/the property '#\/name' of type String did not match the following type: integer/i, nested_errors[:allof_0][0][:message])
  end

  def test_all_of_ref_message
    schema = File.join(File.dirname(__FILE__), 'schemas/all_of_ref_schema.json')
    data = File.join(File.dirname(__FILE__), 'data/all_of_ref_data.json')
    errors = JSON::Validator.fully_validate(schema, data)
    expected_message = """The property '#/' of type Hash did not match all of the required schemas. The schema specific errors were:

- allOf #0:
    - The property '#/name' of type String did not match the following type: integer"""
    assert_equal(expected_message, errors[0])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json-schema-2.4.1 test/test_all_of_ref_schema.rb
json-schema-2.4.0 test/test_all_of_ref_schema.rb
json-schema-2.3.0 test/test_all_of_ref_schema.rb