jschema 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jschema/json_reference.rb +1 -1
  3. data/lib/jschema/schema_uri.rb +6 -2
  4. data/lib/jschema/simple_validator.rb +3 -3
  5. data/lib/jschema/string_length_validator.rb +2 -2
  6. data/lib/jschema/validator/dependencies.rb +2 -2
  7. data/lib/jschema/validator/format.rb +7 -3
  8. data/lib/jschema/validator/items.rb +2 -2
  9. data/lib/jschema/validator/max_items.rb +2 -2
  10. data/lib/jschema/validator/max_properties.rb +2 -2
  11. data/lib/jschema/validator/maximum.rb +2 -2
  12. data/lib/jschema/validator/min_items.rb +2 -2
  13. data/lib/jschema/validator/min_properties.rb +2 -2
  14. data/lib/jschema/validator/minimum.rb +2 -2
  15. data/lib/jschema/validator/multiple_of.rb +2 -2
  16. data/lib/jschema/validator/pattern.rb +2 -2
  17. data/lib/jschema/validator/properties.rb +2 -2
  18. data/lib/jschema/validator/required.rb +2 -2
  19. data/lib/jschema/validator/unique_items.rb +2 -2
  20. metadata +4 -78
  21. data/test/assert_received.rb +0 -15
  22. data/test/string_length_validator_tests.rb +0 -18
  23. data/test/test_assert_received.rb +0 -39
  24. data/test/test_integration.rb +0 -30
  25. data/test/test_json_reference.rb +0 -115
  26. data/test/test_schema.rb +0 -132
  27. data/test/test_schema_ref.rb +0 -19
  28. data/test/test_schema_uri.rb +0 -56
  29. data/test/test_validator.rb +0 -29
  30. data/test/validator/argument_is_array_of_schemas_tests.rb +0 -22
  31. data/test/validator/assertions.rb +0 -56
  32. data/test/validator/properties_limit_tests.rb +0 -13
  33. data/test/validator/schema_validation_helpers.rb +0 -29
  34. data/test/validator/test_all_of.rb +0 -30
  35. data/test/validator/test_any_of.rb +0 -31
  36. data/test/validator/test_dependencies.rb +0 -106
  37. data/test/validator/test_enum.rb +0 -30
  38. data/test/validator/test_format.rb +0 -78
  39. data/test/validator/test_items.rb +0 -119
  40. data/test/validator/test_max_items.rb +0 -26
  41. data/test/validator/test_max_length.rb +0 -30
  42. data/test/validator/test_max_properties.rb +0 -29
  43. data/test/validator/test_maximum.rb +0 -58
  44. data/test/validator/test_min_items.rb +0 -27
  45. data/test/validator/test_min_length.rb +0 -30
  46. data/test/validator/test_min_properties.rb +0 -29
  47. data/test/validator/test_minimum.rb +0 -58
  48. data/test/validator/test_multiple_of.rb +0 -38
  49. data/test/validator/test_not.rb +0 -32
  50. data/test/validator/test_one_of.rb +0 -31
  51. data/test/validator/test_pattern.rb +0 -32
  52. data/test/validator/test_properties.rb +0 -128
  53. data/test/validator/test_required.rb +0 -30
  54. data/test/validator/test_simple_validator.rb +0 -107
  55. data/test/validator/test_type.rb +0 -97
  56. data/test/validator/test_unique_items.rb +0 -30
  57. data/test/validator/validation_against_schemas_tests.rb +0 -24
@@ -1,26 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestMaxItems < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_non_negative_iteger
10
- assert_raises_unless_non_negative_integer 'maxItems'
11
- end
12
-
13
- def test_passing_validation
14
- assert validator(3).valid?([1, 2])
15
- end
16
-
17
- def test_failing_validation
18
- refute validator(2).valid?([1, 2, 3])
19
- end
20
-
21
- private
22
-
23
- def validator_class
24
- JSchema::Validator::MaxItems
25
- end
26
- end
@@ -1,30 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative '../string_length_validator_tests'
6
-
7
- class TestMaxLength < Minitest::Test
8
- include Assertions
9
- include StringLengthValidatorTests
10
-
11
- def test_that_argument_is_a_positive_number
12
- assert_raises_for_values 'maxLength', [0]
13
- end
14
-
15
- def test_passing_validation
16
- assert validator(4).valid?('test')
17
- assert validator(10).valid?('test')
18
- assert validator(10).valid?('')
19
- end
20
-
21
- def test_failing_validation
22
- refute validator(3).valid?('test')
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::MaxLength
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'properties_limit_tests'
6
-
7
- class TestMaxProperties < Minitest::Test
8
- include Assertions
9
- include PropertiesLimitTests
10
-
11
- def test_building_validator_from_schema
12
- validator = build_from_schema('maxProperties' => 10)
13
- assert_instance_of JSchema::Validator::MaxProperties, validator
14
- end
15
-
16
- def test_passing_validation
17
- assert validator(1).valid?('test' => 1)
18
- end
19
-
20
- def test_failing_validation
21
- refute validator(1).valid?('test1' => 1, 'test2' => 2)
22
- end
23
-
24
- private
25
-
26
- def validator_class
27
- JSchema::Validator::MaxProperties
28
- end
29
- end
@@ -1,58 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestMaximum < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_maximum_is_a_number
10
- assert_raises_unless 'maximum', :integer, :number
11
- end
12
-
13
- def test_that_exclusive_maximum_is_boolean
14
- assert_raises(JSchema::InvalidSchema) do
15
- build_from_schema('maximum' => 1, 'exclusiveMaximum' => 0)
16
- end
17
- end
18
-
19
- def test_that_exclusive_maximum_can_not_be_specified_without_maximum
20
- assert_raises(JSchema::InvalidSchema) do
21
- build_from_schema('exclusiveMaximum' => false)
22
- end
23
- end
24
-
25
- def test_passing_validation_when_exclusive_maximum_is_not_specified
26
- assert build_from_schema('maximum' => 3).valid?(2)
27
- end
28
-
29
- def test_passing_validation_when_exclusive_maximum_is_false
30
- schema = build_from_schema('maximum' => 2, 'exclusiveMaximum' => false)
31
- assert schema.valid?(2)
32
- end
33
-
34
- def test_passing_validation_when_exclusive_maximum_is_true
35
- schema = build_from_schema('maximum' => 3, 'exclusiveMaximum' => true)
36
- assert schema.valid?(2)
37
- end
38
-
39
- def test_failing_validation_when_exclusive_maximum_is_not_specified
40
- refute build_from_schema('maximum' => 1).valid?(2)
41
- end
42
-
43
- def test_failing_validation_when_exclusive_maximum_is_false
44
- schema = build_from_schema('maximum' => 1, 'exclusiveMaximum' => false)
45
- refute schema.valid?(2)
46
- end
47
-
48
- def test_failing_validation_when_exclusive_maximum_is_true
49
- schema = build_from_schema('maximum' => 1, 'exclusiveMaximum' => true)
50
- refute schema.valid?(1)
51
- end
52
-
53
- private
54
-
55
- def validator_class
56
- JSchema::Validator::Maximum
57
- end
58
- end
@@ -1,27 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestMinItems < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_non_negative_iteger
10
- assert_raises_unless_non_negative_integer 'minItems'
11
- end
12
-
13
- def test_passing_validation
14
- assert validator(1).valid?([1, 2])
15
- assert validator(1).valid?([1])
16
- end
17
-
18
- def test_failing_validation
19
- refute validator(2).valid?([1])
20
- end
21
-
22
- private
23
-
24
- def validator_class
25
- JSchema::Validator::MinItems
26
- end
27
- end
@@ -1,30 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative '../string_length_validator_tests'
6
-
7
- class TestMinLength < Minitest::Test
8
- include Assertions
9
- include StringLengthValidatorTests
10
-
11
- def test_that_argument_is_not_a_negative_number
12
- assert_raises_unless_non_negative_integer 'minLength'
13
- end
14
-
15
- def test_passing_validation
16
- assert validator(4).valid?('test')
17
- assert validator(3).valid?('test')
18
- assert validator(0).valid?('')
19
- end
20
-
21
- def test_failing_validation
22
- refute validator(5).valid?('test')
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::MinLength
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'properties_limit_tests'
6
-
7
- class TestMinProperties < Minitest::Test
8
- include Assertions
9
- include PropertiesLimitTests
10
-
11
- def test_building_validator_from_schema
12
- validator = build_from_schema('minProperties' => 10)
13
- assert_instance_of JSchema::Validator::MinProperties, validator
14
- end
15
-
16
- def test_passing_validation
17
- assert validator(0).valid?('test' => 1)
18
- end
19
-
20
- def test_failing_validation
21
- refute validator(3).valid?('test1' => 1, 'test2' => 2)
22
- end
23
-
24
- private
25
-
26
- def validator_class
27
- JSchema::Validator::MinProperties
28
- end
29
- end
@@ -1,58 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestMinimum < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_minimum_is_a_number
10
- assert_raises_unless 'minimum', :integer, :number
11
- end
12
-
13
- def test_that_exclusive_minimum_is_boolean
14
- assert_raises(JSchema::InvalidSchema) do
15
- build_from_schema('minimum' => 1, 'exclusiveMinimum' => 0)
16
- end
17
- end
18
-
19
- def test_that_exclusive_minimum_can_not_be_specified_without_minimum
20
- assert_raises(JSchema::InvalidSchema) do
21
- build_from_schema('exclusiveMinimum' => false)
22
- end
23
- end
24
-
25
- def test_passing_validation_when_exclusive_minimum_is_not_specified
26
- assert build_from_schema('minimum' => 1).valid?(2)
27
- end
28
-
29
- def test_passing_validation_when_exclusive_minimum_is_false
30
- schema = build_from_schema('minimum' => 2, 'exclusiveMinimum' => false)
31
- assert schema.valid?(2)
32
- end
33
-
34
- def test_passing_validation_when_exclusive_minimum_is_true
35
- schema = build_from_schema('minimum' => 1, 'exclusiveMinimum' => true)
36
- assert schema.valid?(2)
37
- end
38
-
39
- def test_failing_validation_when_exclusive_minumum_is_not_specified
40
- refute build_from_schema('minimum' => 2).valid?(1)
41
- end
42
-
43
- def test_failing_validation_when_exclusive_minimum_is_false
44
- schema = build_from_schema('minimum' => 2, 'exclusiveMinimum' => false)
45
- refute schema.valid?(1)
46
- end
47
-
48
- def test_failing_validation_when_exclusive_minimum_is_true
49
- schema = build_from_schema('minimum' => 1, 'exclusiveMinimum' => true)
50
- refute schema.valid?(1)
51
- end
52
-
53
- private
54
-
55
- def validator_class
56
- JSchema::Validator::Minimum
57
- end
58
- end
@@ -1,38 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestMultipleOf < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_a_number
10
- assert_raises_unless 'multipleOf', :number, :integer
11
- end
12
-
13
- def test_that_argument_is_a_positive_number
14
- assert_raises_for_values 'multipleOf', [0, -0.5]
15
- end
16
-
17
- def test_passing_validation_when_argument_is_integer
18
- assert validator(2).valid?(4)
19
- end
20
-
21
- def test_passing_validation_when_argument_is_float
22
- assert validator(1.2).valid?(3.6)
23
- end
24
-
25
- def test_passing_validation_when_instance_is_negative
26
- assert validator(1.2).valid?(-3.6)
27
- end
28
-
29
- def test_failing_validation
30
- refute validator(3).valid?(7)
31
- end
32
-
33
- private
34
-
35
- def validator_class
36
- JSchema::Validator::MultipleOf
37
- end
38
- end
@@ -1,32 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'schema_validation_helpers'
6
-
7
- class TestNot < Minitest::Test
8
- include Assertions
9
- include SchemaValidationHelpers
10
-
11
- def test_that_argument_is_schema
12
- assert_raises_unless_schema 'not'
13
- end
14
-
15
- def test_passing_validation
16
- stub_schema_validations(false) do
17
- assert validator({}).valid?('test')
18
- end
19
- end
20
-
21
- def test_failing_validation
22
- stub_schema_validations(true) do
23
- refute validator({}).valid?('test')
24
- end
25
- end
26
-
27
- private
28
-
29
- def validator_class
30
- JSchema::Validator::Not
31
- end
32
- end
@@ -1,31 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'schema_validation_helpers'
6
- require_relative 'validation_against_schemas_tests'
7
-
8
- class TestOneOf < Minitest::Test
9
- include Assertions
10
- include SchemaValidationHelpers
11
- include ValidationAgainstSchemasTests
12
-
13
- def test_passing_validation_against_schemas
14
- stub_schema_validations(true, false, false) do
15
- schemas = [generate_schema, generate_schema, generate_schema]
16
- assert validator(schemas).valid?('test')
17
- end
18
- end
19
-
20
- def test_failing_validation_when_more_than_one_validation_passes
21
- stub_schema_validations(true) do
22
- refute validator([generate_schema, generate_schema]).valid?('test')
23
- end
24
- end
25
-
26
- private
27
-
28
- def validator_class
29
- JSchema::Validator::OneOf
30
- end
31
- end
@@ -1,32 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestPattern < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_only_valid_regexp_is_allowed
10
- assert_raises_unless 'pattern', :string
11
- end
12
-
13
- def test_that_validation_always_passes_for_non_strings
14
- assert validator('123').valid?(nil)
15
- assert validator('123').valid?([])
16
- end
17
-
18
- def test_passing_validation
19
- assert validator('123').valid?('test123')
20
- assert validator('\d+$').valid?('test123')
21
- end
22
-
23
- def test_failing_validation
24
- refute validator('123').valid?('test')
25
- end
26
-
27
- private
28
-
29
- def validator_class
30
- JSchema::Validator::Pattern
31
- end
32
- end
@@ -1,128 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'schema_validation_helpers'
6
-
7
- # rubocop:disable ClassLength
8
- class TestProperties < Minitest::Test
9
- include Assertions
10
- include SchemaValidationHelpers
11
-
12
- def test_invalid_properties_argument
13
- keywords.each do |keyword|
14
- assert_raises(JSchema::InvalidSchema) do
15
- build_from_schema(keyword => 1)
16
- end
17
- end
18
- end
19
-
20
- def test_passing_properties_validation_by_sub_schema
21
- keywords.each do |keyword|
22
- assert_passing_validation keyword
23
- end
24
- end
25
-
26
- def test_failing_properties_validation_by_sub_schema
27
- keywords.each do |keyword|
28
- assert_failing_validation keyword
29
- end
30
- end
31
-
32
- def test_passing_validation_when_additional_properties_are_not_allowed
33
- assert validator_with_additional_properties.valid?('test' => 123)
34
- end
35
-
36
- def test_failing_validation_when_additional_properties_are_not_allowed
37
- refute validator_with_additional_properties.valid?(
38
- 'test' => 123, 'additional' => 321)
39
- end
40
-
41
- def test_passing_validation_when_additional_properties_are_allowed
42
- validator = build_from_schema(
43
- 'additionalProperties' => true,
44
- 'properties' => { 'test' => {} }
45
- )
46
-
47
- assert validator.valid?('test' => 123, 'additional' => true)
48
- end
49
-
50
- def test_passing_validation_with_additional_and_pattern_properties
51
- validator = validator_with_additional_and_pattern_properties
52
- assert validator.valid?('test123' => true)
53
- end
54
-
55
- def test_failing_validation_with_additional_and_pattern_properties
56
- validator = validator_with_additional_and_pattern_properties
57
- refute validator.valid?('test' => true)
58
- end
59
-
60
- def test_passing_validation_when_any_properties_are_disallowed
61
- assert validator_with_disallowed_properties.valid?({})
62
- end
63
-
64
- def test_failing_validation_when_any_properties_are_disallowed
65
- refute validator_with_disallowed_properties.valid?('test' => 123)
66
- end
67
-
68
- def test_that_validation_always_passes_for_non_object_instances
69
- validator = build_from_schema('additionalProperties' => false)
70
- assert validator.valid?('test')
71
- end
72
-
73
- def test_building_validator_from_properties
74
- validator = build_from_schema('properties' => { 'test' => {} })
75
- assert_instance_of JSchema::Validator::Properties, validator
76
- end
77
-
78
- def test_building_validator_from_additional_properties
79
- validator = build_from_schema('additionalProperties' => false)
80
- assert_instance_of JSchema::Validator::Properties, validator
81
- end
82
-
83
- def test_building_validator_from_empty_schema
84
- assert_nil build_from_schema({})
85
- end
86
-
87
- private
88
-
89
- def validator_class
90
- JSchema::Validator::Properties
91
- end
92
-
93
- def keywords
94
- ['properties', 'patternProperties', 'additionalProperties']
95
- end
96
-
97
- def validator_with_additional_properties
98
- build_from_schema(
99
- 'additionalProperties' => false,
100
- 'properties' => { 'test' => {} }
101
- )
102
- end
103
-
104
- def validator_with_additional_and_pattern_properties
105
- build_from_schema(
106
- 'additionalProperties' => false,
107
- 'patternProperties' => { '\d+' => {} }
108
- )
109
- end
110
-
111
- def validator_with_disallowed_properties
112
- build_from_schema('additionalProperties' => false)
113
- end
114
-
115
- def assert_passing_validation(keyword)
116
- stub_schema_validations(true) do
117
- validator = build_from_schema(keyword => { 'test' => {} })
118
- assert validator.valid?('test' => 123)
119
- end
120
- end
121
-
122
- def assert_failing_validation(keyword)
123
- stub_schema_validations(false) do
124
- validator = build_from_schema(keyword => { 'test' => {} })
125
- refute validator.valid?('test' => 123)
126
- end
127
- end
128
- end