1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
require File.expand_path('support/test_helper', __dir__)
class FilesTest < Minitest::Test
#
# These tests are ONLY run if there is an appropriate JSON backend parser available
#
def test_schema_from_file
assert_valid schema_fixture_path('good_schema_1.json'), { 'a' => 5 }
refute_valid schema_fixture_path('good_schema_1.json'), { 'a' => 'bad' }
end
def test_data_from_file_v3
schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } }
assert_valid schema, data_fixture_path('good_data_1.json'), uri: true
refute_valid schema, data_fixture_path('bad_data_1.json'), uri: true
end
def test_data_from_json_v3
schema = { '$schema' => 'http://json-schema.org/draft-03/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } }
assert_valid schema, '{"a": 5}', json: true
refute_valid schema, '{"a": "poop"}', json: true
end
def test_data_from_file_v4
schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } }
assert_valid schema, data_fixture_path('good_data_1.json'), uri: true
refute_valid schema, data_fixture_path('bad_data_1.json'), uri: true
end
def test_data_from_json_v4
schema = { '$schema' => 'http://json-schema.org/draft-04/schema#', 'type' => 'object', 'properties' => { 'a' => { 'type' => 'integer' } } }
assert_valid schema, '{"a": 5}', json: true
refute_valid schema, '{"a": "poop"}', json: true
end
def test_both_from_file
assert_valid schema_fixture_path('good_schema_1.json'), data_fixture_path('good_data_1.json'), uri: true
refute_valid schema_fixture_path('good_schema_1.json'), data_fixture_path('bad_data_1.json'), uri: true
end
def test_file_ref
assert_valid schema_fixture_path('good_schema_2.json'), { 'b' => { 'a' => 5 } }
refute_valid schema_fixture_path('good_schema_1.json'), { 'b' => { 'a' => 'boo' } }
end
def test_file_extends
assert_valid schema_fixture_path('good_schema_extends1.json'), { 'a' => 5 }
assert_valid schema_fixture_path('good_schema_extends2.json'), { 'a' => 5, 'b' => { 'a' => 5 } }
end
end
|