Sha256: 3714008c38639666ff6fc50badbe0af83aa888252d2736421206159384ce2feb

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

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

class JSONSchemaValidation < Test::Unit::TestCase
  def valid_schema
    {
      "$schema" => "http://json-schema.org/draft-03/schema#",
      "type" => "object",
      "properties" => {
        "b" => {
          "required" => true
        }
      }
    }
  end

  def invalid_schema
    {
      "$schema" => "http://json-schema.org/draft-03/schema#",
      "type" => "object",
      "properties" => {
        "b" => {
          "required" => "true"
        }
      }
    }
  end

  def test_draft03_validation
    data = {"b" => {"a" => 5}}
    assert(JSON::Validator.validate(valid_schema,data,:validate_schema => true))
    assert(!JSON::Validator.validate(invalid_schema,data,:validate_schema => true))
  end

  def test_validate_just_schema
    errors = JSON::Validator.fully_validate_schema(valid_schema)
    assert_equal [], errors

    errors = JSON::Validator.fully_validate_schema(invalid_schema)
    assert_equal 1, errors.size
    assert_match /the property .*required.*did not match/i, errors.first
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
json-schema-1.2.1 test/test_schema_validation.rb
json-schema-1.2.0 test/test_schema_validation.rb
json-schema-2.0.0 test/test_schema_validation.rb
json-schema-1.1.1 test/test_schema_validation.rb
json-schema-1.1.0 test/test_schema_validation.rb
json-schema-1.0.12 test/test_schema_validation.rb
json-schema-1.0.11 test/test_schema_validation.rb
json-schema-1.0.10 test/test_schema_validation.rb
json-schema-1.0.9 test/test_schema_validation.rb
json-schema-1.0.8 test/test_schema_validation.rb
json-schema-1.0.7 test/test_schema_validation.rb
json-schema-1.0.6 test/test_schema_validation.rb
json-schema-1.0.5 test/test_schema_validation.rb
json-schema-1.0.4 test/test_schema_validation.rb
json-schema-1.0.3 test/test_schema_validation.rb
json-schema-1.0.2 test/test_schema_validation.rb
seomoz-json-schema-1.0.1 test/test_schema_validation.rb