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,13 +0,0 @@
1
- module PropertiesLimitTests
2
- def test_that_argument_is_an_integer
3
- assert_raises(JSchema::InvalidSchema) { validator 'string' }
4
- end
5
-
6
- def test_that_argument_can_be_big_integer
7
- validator 2**64
8
- end
9
-
10
- def test_that_argument_is_not_negative
11
- assert_raises(JSchema::InvalidSchema) { validator(-1) }
12
- end
13
- end
@@ -1,29 +0,0 @@
1
- module SchemaValidationHelpers
2
- class SchemaStub
3
- def initialize(validation_results)
4
- @validation_results = validation_results.cycle
5
- end
6
-
7
- def valid?(instance)
8
- validate(instance).empty?
9
- end
10
-
11
- def validate(instance)
12
- result = @validation_results.next
13
- result ? [] : ['error']
14
- end
15
- end
16
-
17
- def stub_schema_validations(*validation_results)
18
- schema = SchemaStub.new(validation_results)
19
- JSchema::Schema.stub :build, schema do
20
- yield
21
- end
22
- end
23
-
24
- def generate_schema
25
- @id ||= 0
26
- @id += 1
27
- { 'id' => @id.to_s }
28
- end
29
- end
@@ -1,30 +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 TestAllOf < Minitest::Test
9
- include Assertions
10
- include SchemaValidationHelpers
11
- include ValidationAgainstSchemasTests
12
-
13
- def test_passing_validation_against_schemas
14
- stub_schema_validations(true, true) do
15
- assert validator([generate_schema, generate_schema]).valid?('test')
16
- end
17
- end
18
-
19
- def test_failing_validation_against_schemas
20
- stub_schema_validations(false, true) do
21
- refute validator([generate_schema, generate_schema]).valid?('test')
22
- end
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::AllOf
29
- end
30
- 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 TestAnyOf < Minitest::Test
9
- include Assertions
10
- include SchemaValidationHelpers
11
- include ValidationAgainstSchemasTests
12
-
13
- def test_passing_validation_agaist_schemas
14
- stub_schema_validations(true, false, true) do
15
- schema = [generate_schema, generate_schema, generate_schema]
16
- assert validator(schema).valid?('test')
17
- end
18
- end
19
-
20
- def test_failing_validation_against_schemas
21
- stub_schema_validations(false, false) 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::AnyOf
30
- end
31
- end
@@ -1,106 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'schema_validation_helpers'
6
-
7
- class TestDependencies < Minitest::Test
8
- include Assertions
9
- include SchemaValidationHelpers
10
-
11
- def test_that_argument_is_an_object
12
- assert_raises_unless 'dependencies', :object
13
- end
14
-
15
- def test_that_each_value_of_argument_object_is_either_an_object_or_an_array
16
- assert_raises(JSchema::InvalidSchema) do
17
- validator('test' => 0)
18
- end
19
- end
20
-
21
- def test_that_property_dependency_has_at_least_one_element
22
- assert_raises(JSchema::InvalidSchema) do
23
- validator('test' => [])
24
- end
25
- end
26
-
27
- def test_that_property_dependency_includes_only_strings
28
- assert_raises(JSchema::InvalidSchema) do
29
- validator('test' => [0])
30
- end
31
- end
32
-
33
- def test_that_property_dependency_containt_uniq_elements
34
- assert_raises(JSchema::InvalidSchema) do
35
- validator('test' => ['property', 'property'])
36
- end
37
- end
38
-
39
- def test_that_argument_can_contain_schema_and_property_dependencies
40
- validator('schema_dependency' => {}, 'property_dependency' => ['test'])
41
- end
42
-
43
- def test_passing_schema_dependency_validation
44
- stub_schema_validations(true) do
45
- assert schema_dependencies_validator.valid?('test' => 0)
46
- end
47
- end
48
-
49
- def test_failing_schema_dependency_validation
50
- stub_schema_validations(false) do
51
- refute schema_dependencies_validator.valid?('test' => 0)
52
- end
53
- end
54
-
55
- def test_passing_validation_when_instance_has_no_dependencies
56
- stub_schema_validations(false) do
57
- assert schema_dependencies_validator.valid?('other' => 0)
58
- end
59
- end
60
-
61
- def test_passing_property_dependency_validation
62
- expect_required_validation(true) do
63
- assert property_dependencies_validator.valid?('test' => 0)
64
- end
65
- end
66
-
67
- def test_failing_property_dependency_validation
68
- expect_required_validation(false) do
69
- refute property_dependencies_validator.valid?('test' => 0)
70
- end
71
- end
72
-
73
- def test_passing_property_dependency_validation_no_dependencies
74
- expect_required_validation(false) do
75
- assert property_dependencies_validator.valid?('other' => 0)
76
- end
77
- end
78
-
79
- private
80
-
81
- def validator_class
82
- JSchema::Validator::Dependencies
83
- end
84
-
85
- def schema_dependencies_validator
86
- validator('test' => {})
87
- end
88
-
89
- def property_dependencies_validator
90
- validator('test' => ['required_property'])
91
- end
92
-
93
- def expect_required_validation(valid)
94
- validator_stub =
95
- Struct.new(:valid) do
96
- def validate(_)
97
- 'error' unless valid
98
- end
99
- end
100
-
101
- validator = validator_stub.new(valid)
102
- JSchema::Validator::Required.stub :new, validator do
103
- yield
104
- end
105
- end
106
- end
@@ -1,30 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestEnum < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_non_empty_array_of_unique_values
10
- assert_raises_unless_non_empty_array 'enum'
11
- end
12
-
13
- def test_passing_validation
14
- assert validator(['test']).valid?('test')
15
- end
16
-
17
- def test_passing_validtion_with_null
18
- assert validator([nil]).valid?(nil)
19
- end
20
-
21
- def test_failing_validation
22
- refute validator(['test']).valid?(0)
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::Enum
29
- end
30
- end
@@ -1,78 +0,0 @@
1
- require 'minitest/autorun'
2
- require_relative 'assertions'
3
-
4
- class TestFormat < Minitest::Test
5
- include Assertions
6
-
7
- def test_that_argument_is_string
8
- assert_raises_unless('format', :string)
9
- end
10
-
11
- def test_that_argument_is_one_of_allowed_formats
12
- assert_raises(JSchema::InvalidSchema) do
13
- validator 'unsupported_format'
14
- end
15
- end
16
-
17
- def test_passing_validation_by_date_time_format
18
- assert validator('date-time').valid?('2001-02-03T04:05:06+07:00')
19
- end
20
-
21
- def test_failing_validation_by_date_time_format
22
- refute validator('date-time').valid?('2001-x2-03T04:05:06+07:00')
23
- end
24
-
25
- def test_passing_validation_by_email_format
26
- assert validator('email').valid?('steve@apple.com')
27
- end
28
-
29
- def test_failing_validation_by_email_format
30
- refute validator('email').valid?('invalid_email')
31
- end
32
-
33
- def test_passing_validation_by_hostname_format
34
- assert validator('hostname').valid?('apple.com')
35
- end
36
-
37
- def test_failing_validation_by_hostname_format
38
- refute validator('hostname').valid?('invalid+hostname')
39
- end
40
-
41
- def test_passing_validation_by_ipv4_format
42
- assert validator('ipv4').valid?('127.0.0.1')
43
- end
44
-
45
- def test_failing_validation_by_ipv4_format
46
- refute validator('ipv4').valid?('0')
47
- end
48
-
49
- def test_passing_validation_by_ipv6_format
50
- assert validator('ipv6').valid?('::1')
51
- end
52
-
53
- def test_failing_validation_by_ipv6_format
54
- refute validator('ipv6').valid?('0')
55
- end
56
-
57
- def test_passing_validation_by_uri_format
58
- assert validator('uri').valid?('http://example.com/')
59
- end
60
-
61
- def test_failing_validation_by_uri_format
62
- refute validator('uri').valid?('://')
63
- end
64
-
65
- def test_passing_validation_by_regex
66
- assert validator('regex').valid?('\d+')
67
- end
68
-
69
- def test_failing_validation_by_regex
70
- refute validator('regex').valid?('**')
71
- end
72
-
73
- private
74
-
75
- def validator_class
76
- JSchema::Validator::Format
77
- end
78
- end
@@ -1,119 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
- require_relative 'schema_validation_helpers'
6
-
7
- class TestItems < Minitest::Test
8
- include Assertions
9
- include SchemaValidationHelpers
10
-
11
- def test_that_additional_items_must_be_boolean_or_schema
12
- assert_raises_unless 'additionalItems', :boolean, :object
13
- end
14
-
15
- def test_that_additional_items_accepts_only_valid_schema
16
- assert_raises_unless_schema 'additionalItems'
17
- end
18
-
19
- def test_that_items_must_be_object_or_array
20
- assert_raises_unless 'items', :object, :array
21
- end
22
-
23
- def test_that_items_must_be_a_valid_schema
24
- assert_raises_unless_schema 'items'
25
- end
26
-
27
- def test_that_items_must_be_schema_array
28
- assert_raises_unless_schema_array 'items'
29
- end
30
-
31
- def test_default_value_for_items
32
- validator = build_from_schema('additionalItems' => false)
33
- assert validator.valid? [1, 2, 3]
34
- end
35
-
36
- def test_passing_validation_by_items_schema
37
- stub_schema_validations(true) do
38
- assert build_from_schema('items' => {}).valid?(['test'])
39
- end
40
- end
41
-
42
- def test_passing_validation_by_items_schema_array
43
- basic_schema = generate_schema
44
- stub_schema_validations(true) do
45
- schema = { 'items' => [basic_schema, basic_schema] }
46
- assert build_from_schema(schema).valid?(['test', 'test'])
47
- end
48
- end
49
-
50
- def test_passing_validation_by_items_when_additional_items_is_omitted
51
- stub_schema_validations(true) do
52
- schema = { 'items' => [generate_schema] }
53
- assert build_from_schema(schema).valid?(['test', 'test'])
54
- end
55
- end
56
-
57
- def test_passing_validation_by_items_and_additional_items
58
- stub_schema_validations(true) do
59
- schema = {
60
- 'items' => [generate_schema],
61
- 'additionalItems' => generate_schema
62
- }
63
- assert build_from_schema(schema).valid?(['test', 'test'])
64
- end
65
- end
66
-
67
- def test_passing_validation_when_additional_items_are_not_allowed
68
- stub_schema_validations(true) do
69
- schema = {
70
- 'items' => [generate_schema],
71
- 'additionalItems' => false
72
- }
73
- assert build_from_schema(schema).valid?(['test'])
74
- end
75
- end
76
-
77
- def test_passing_validation_when_instance_size_is_less_than_items_size
78
- stub_schema_validations(true) do
79
- schema = {
80
- 'items' => [generate_schema, generate_schema],
81
- 'additionalItems' => false
82
- }
83
- assert build_from_schema(schema).valid?(['test'])
84
- end
85
- end
86
-
87
- def test_failing_validation_when_additional_items_are_not_allowed
88
- stub_schema_validations(true) do
89
- schema = {
90
- 'items' => [generate_schema],
91
- 'additionalItems' => false
92
- }
93
- refute build_from_schema(schema).valid?(['test', 'test'])
94
- end
95
- end
96
-
97
- def test_failing_validation_by_items_schema_array
98
- stub_schema_validations(false, true) do
99
- schema = { 'items' => [generate_schema, generate_schema] }
100
- refute build_from_schema(schema).valid?(['test', 'test'])
101
- end
102
- end
103
-
104
- def test_failing_validation_by_additional_items_schema
105
- stub_schema_validations(true, false) do
106
- schema = {
107
- 'items' => [generate_schema],
108
- 'additionalItems' => generate_schema
109
- }
110
- refute build_from_schema(schema).valid?(['test', 'test'])
111
- end
112
- end
113
-
114
- private
115
-
116
- def validator_class
117
- JSchema::Validator::Items
118
- end
119
- end