Sha256: 4d27c36bb04ea31dcab06c16dd11b4469e6337e910c6935f994c7fa3b6d94eb7

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path('../test_helper', __FILE__)

class AnyOfRefSchemaTest < Minitest::Test
  def schema
    schema_fixture_path('any_of_ref_schema.json')
  end

  def test_any_of_ref_schema
    assert_valid schema, data_fixture_path('any_of_ref_data.json')
  end

  def test_any_of_ref_subschema_errors
    data = %({"names": ["jack"]})
    errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
    nested_errors = errors[0][:errors]
    assert_equal([:anyof_0, :anyof_1, :anyof_2], nested_errors.keys, 'should have nested errors for each anyOf subschema')
    assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'john'/i, nested_errors[:anyof_0][0][:message])
    assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'jane'/i, nested_errors[:anyof_1][0][:message])
    assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'jimmy'/i, nested_errors[:anyof_2][0][:message])
  end

  def test_any_of_ref_message
    data = %({"names": ["jack"]})
    errors = JSON::Validator.fully_validate(schema, data)
    expected_message = """The property '#/names/0' of type String did not match one or more of the required schemas. The schema specific errors were:

- anyOf #0:
    - The property '#/names/0' value \"jack\" did not match the regex 'john'
- anyOf #1:
    - The property '#/names/0' value \"jack\" did not match the regex 'jane'
- anyOf #2:
    - The property '#/names/0' value \"jack\" did not match the regex 'jimmy'"""
    assert_equal(expected_message, errors[0])
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
json-schema-openc-fork-0.0.2 test/test_any_of_ref_schema.rb
json-schema-2.5.1 test/test_any_of_ref_schema.rb
json-schema-openc-fork-0.0.1 test/test_any_of_ref_schema.rb
json-schema-2.5.0 test/test_any_of_ref_schema.rb