|
1 | 1 | module StrictValidation |
2 | | - def test_strict_properties |
3 | | - schema = { |
4 | | - "$schema" => "http://json-schema.org/draft-04/schema#", |
5 | | - "properties" => { |
6 | | - "a" => {"type" => "string"}, |
7 | | - "b" => {"type" => "string"} |
| 2 | + module PropertiesTests |
| 3 | + def test_strict_properties |
| 4 | + schema = { |
| 5 | + "properties" => { |
| 6 | + "a" => {"type" => "string"}, |
| 7 | + "b" => {"type" => "string"} |
| 8 | + } |
8 | 9 | } |
9 | | - } |
10 | 10 |
|
11 | | - data = {"a" => "a"} |
12 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 11 | + data = {"a" => "a"} |
| 12 | + refute_valid schema,data,:strict => true |
13 | 13 |
|
14 | | - data = {"b" => "b"} |
15 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 14 | + data = {"b" => "b"} |
| 15 | + refute_valid schema,data,:strict => true |
16 | 16 |
|
17 | | - data = {"a" => "a", "b" => "b"} |
18 | | - assert(JSON::Validator.validate(schema,data,:strict => true)) |
| 17 | + data = {"a" => "a", "b" => "b"} |
| 18 | + assert_valid schema,data,:strict => true |
19 | 19 |
|
20 | | - data = {"a" => "a", "b" => "b", "c" => "c"} |
21 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
22 | | - end |
| 20 | + data = {"a" => "a", "b" => "b", "c" => "c"} |
| 21 | + refute_valid schema,data,:strict => true |
| 22 | + end |
23 | 23 |
|
24 | | - def test_strict_error_message |
25 | | - schema = { :type => 'object', :properties => { :a => { :type => 'string' } } } |
26 | | - data = { :a => 'abc', :b => 'abc' } |
27 | | - errors = JSON::Validator.fully_validate(schema,data,:strict => true) |
28 | | - assert_match("The property '#/' contained undefined properties: 'b' in schema", errors[0]) |
| 24 | + def test_strict_error_message |
| 25 | + schema = { :type => 'object', :properties => { :a => { :type => 'string' } } } |
| 26 | + data = { :a => 'abc', :b => 'abc' } |
| 27 | + errors = JSON::Validator.fully_validate(schema,data,:strict => true) |
| 28 | + assert_match("The property '#/' contained undefined properties: 'b' in schema", errors[0]) |
| 29 | + end |
29 | 30 | end |
30 | 31 |
|
31 | | - def test_strict_properties_additional_props |
32 | | - schema = { |
33 | | - "$schema" => "http://json-schema.org/draft-04/schema#", |
34 | | - "properties" => { |
35 | | - "a" => {"type" => "string"}, |
36 | | - "b" => {"type" => "string"} |
37 | | - }, |
38 | | - "additionalProperties" => {"type" => "integer"} |
39 | | - } |
| 32 | + module AdditionalPropertiesTests |
| 33 | + def test_strict_properties_additional_props |
| 34 | + schema = { |
| 35 | + "properties" => { |
| 36 | + "a" => {"type" => "string"}, |
| 37 | + "b" => {"type" => "string"} |
| 38 | + }, |
| 39 | + "additionalProperties" => {"type" => "integer"} |
| 40 | + } |
40 | 41 |
|
41 | | - data = {"a" => "a"} |
42 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 42 | + data = {"a" => "a"} |
| 43 | + refute_valid schema,data,:strict => true |
43 | 44 |
|
44 | | - data = {"b" => "b"} |
45 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 45 | + data = {"b" => "b"} |
| 46 | + refute_valid schema,data,:strict => true |
46 | 47 |
|
47 | | - data = {"a" => "a", "b" => "b"} |
48 | | - assert(JSON::Validator.validate(schema,data,:strict => true)) |
| 48 | + data = {"a" => "a", "b" => "b"} |
| 49 | + assert_valid schema,data,:strict => true |
49 | 50 |
|
50 | | - data = {"a" => "a", "b" => "b", "c" => "c"} |
51 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 51 | + data = {"a" => "a", "b" => "b", "c" => "c"} |
| 52 | + refute_valid schema,data,:strict => true |
52 | 53 |
|
53 | | - data = {"a" => "a", "b" => "b", "c" => 3} |
54 | | - assert(JSON::Validator.validate(schema,data,:strict => true)) |
| 54 | + data = {"a" => "a", "b" => "b", "c" => 3} |
| 55 | + assert_valid schema,data,:strict => true |
| 56 | + end |
55 | 57 | end |
56 | 58 |
|
57 | | - def test_strict_properties_pattern_props |
58 | | - schema = { |
59 | | - "properties" => { |
60 | | - "a" => {"type" => "string"}, |
61 | | - "b" => {"type" => "string"} |
62 | | - }, |
63 | | - "patternProperties" => {"\\d+ taco" => {"type" => "integer"}} |
64 | | - } |
| 59 | + module PatternPropertiesTests |
| 60 | + def test_strict_properties_pattern_props |
| 61 | + schema = { |
| 62 | + "properties" => { |
| 63 | + "a" => {"type" => "string"}, |
| 64 | + "b" => {"type" => "string"} |
| 65 | + }, |
| 66 | + "patternProperties" => {"\\d+ taco" => {"type" => "integer"}} |
| 67 | + } |
65 | 68 |
|
66 | | - data = {"a" => "a"} |
67 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 69 | + data = {"a" => "a"} |
| 70 | + refute_valid schema,data,:strict => true |
68 | 71 |
|
69 | | - data = {"b" => "b"} |
70 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 72 | + data = {"b" => "b"} |
| 73 | + refute_valid schema,data,:strict => true |
71 | 74 |
|
72 | | - data = {"a" => "a", "b" => "b"} |
73 | | - assert(JSON::Validator.validate(schema,data,:strict => true)) |
| 75 | + data = {"a" => "a", "b" => "b"} |
| 76 | + assert_valid schema,data,:strict => true |
74 | 77 |
|
75 | | - data = {"a" => "a", "b" => "b", "c" => "c"} |
76 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 78 | + data = {"a" => "a", "b" => "b", "c" => "c"} |
| 79 | + refute_valid schema,data,:strict => true |
77 | 80 |
|
78 | | - data = {"a" => "a", "b" => "b", "c" => 3} |
79 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 81 | + data = {"a" => "a", "b" => "b", "c" => 3} |
| 82 | + refute_valid schema,data,:strict => true |
80 | 83 |
|
81 | | - data = {"a" => "a", "b" => "b", "23 taco" => 3} |
82 | | - assert(JSON::Validator.validate(schema,data,:strict => true)) |
| 84 | + data = {"a" => "a", "b" => "b", "23 taco" => 3} |
| 85 | + assert_valid schema,data,:strict => true |
83 | 86 |
|
84 | | - data = {"a" => "a", "b" => "b", "23 taco" => "cheese"} |
85 | | - assert(!JSON::Validator.validate(schema,data,:strict => true)) |
| 87 | + data = {"a" => "a", "b" => "b", "23 taco" => "cheese"} |
| 88 | + refute_valid schema,data,:strict => true |
| 89 | + end |
86 | 90 | end |
87 | | - |
88 | 91 | end |
0 commit comments