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,30 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestRequired < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_string_array
10
- assert_raises_unless_string_array 'required'
11
- end
12
-
13
- def test_passing_validation
14
- assert validator(['test']).valid?('test' => 123)
15
- end
16
-
17
- def test_passing_validation_when_property_has_false_value
18
- assert validator(['test']).valid?('test' => false)
19
- end
20
-
21
- def test_failing_validation
22
- refute validator(['test']).valid?({})
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::Required
29
- end
30
- end
@@ -1,107 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestSimpleValidator < Minitest::Test
7
- include Assertions
8
-
9
- def setup
10
- super
11
- @validator_class = Class.new(JSchema::SimpleValidator) do
12
- private
13
-
14
- self.keywords = ['param']
15
-
16
- def validate_args(param)
17
- true
18
- end
19
-
20
- def post_initialize(param)
21
- end
22
-
23
- def validate_instance(param)
24
- end
25
-
26
- def applicable_types
27
- [String]
28
- end
29
- end
30
- end
31
-
32
- def test_parent_attribute
33
- parent = Object.new
34
- example = @validator_class.new('param', parent)
35
- assert_equal parent, example.parent
36
- end
37
-
38
- def test_building_from_schema
39
- validator_example = build_from_schema('param' => 'test')
40
- assert_instance_of validator_class, validator_example
41
- end
42
-
43
- def test_building_from_empty_schema
44
- assert_nil build_from_schema
45
- end
46
-
47
- def test_passing_validation
48
- stub_validator nil, true do |vdr|
49
- assert vdr.valid?('instance')
50
- assert_nil vdr.validate('instance')
51
- end
52
- end
53
-
54
- def test_failing_validation
55
- stub_validator nil, false do |vdr|
56
- refute vdr.valid?('instance')
57
- assert_equal 'error', vdr.validate('instance')
58
- end
59
- end
60
-
61
- def test_invalid_params
62
- assert_raises(JSchema::InvalidSchema) do
63
- Class.new(JSchema::SimpleValidator) do
64
- private
65
-
66
- def validate_args
67
- false
68
- end
69
- end.new('test')
70
- end
71
- end
72
-
73
- def test_that_validation_always_passes_if_validator_is_not_applicable
74
- stub_validator [Fixnum], false do |vdr|
75
- assert vdr.valid?('instance')
76
- end
77
- end
78
-
79
- def test_failing_validation_when_validator_is_applicable
80
- stub_validator [Fixnum], false do |vdr|
81
- refute vdr.valid?(0)
82
- end
83
- end
84
-
85
- def test_failing_validation_when_instance_is_descendant_of_applicable_types
86
- stub_validator [Hash], false do |vdr|
87
- descendant_type = Class.new(Hash)
88
- refute vdr.valid?(descendant_type.new)
89
- end
90
- end
91
-
92
- private
93
-
94
- def stub_validator(applicable_types, valid)
95
- validator_example = validator 'test'
96
- validation_result = valid ? nil : 'error'
97
- validator_example.stub :applicable_types, applicable_types do
98
- validator_example.stub :validate_instance, validation_result do
99
- yield validator_example
100
- end
101
- end
102
- end
103
-
104
- def validator_class
105
- @validator_class
106
- end
107
- end
@@ -1,97 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestType < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_a_string_or_an_array
10
- assert_raises_unless 'type', :string, :array
11
- end
12
-
13
- def test_that_argument_is_a_unique_string_array
14
- assert_raises_unless_string_array 'type'
15
- end
16
-
17
- def test_passing_string_validation
18
- assert validator('string').valid?('str')
19
- end
20
-
21
- def test_failing_string_validation
22
- refute validator('string').valid?(1)
23
- end
24
-
25
- def test_passing_integer_validation
26
- assert validator('integer').valid?(1)
27
- assert validator('integer').valid?(2**64)
28
- end
29
-
30
- def test_failing_integer_validation
31
- refute validator('integer').valid?('str')
32
- end
33
-
34
- def test_passing_array_validation
35
- assert validator('array').valid?([])
36
- end
37
-
38
- def test_failing_array_validation
39
- refute validator('array').valid?('str')
40
- end
41
-
42
- def test_passing_boolean_validation
43
- assert validator('boolean').valid?(true)
44
- assert validator('boolean').valid?(false)
45
- end
46
-
47
- def test_failing_boolean_validation
48
- refute validator('boolean').valid?(nil)
49
- refute validator('boolean').valid?(0)
50
- end
51
-
52
- def test_passing_null_validation
53
- assert validator('null').valid?(nil)
54
- end
55
-
56
- def test_failing_null_validation
57
- refute validator('null').valid?(false)
58
- refute validator('null').valid?('')
59
- end
60
-
61
- def test_passing_object_validation
62
- assert validator('object').valid?('test' => 123)
63
- end
64
-
65
- def test_failing_object_validation
66
- refute validator('object').valid?([])
67
- end
68
-
69
- def test_passing_number_validation
70
- assert validator('number').valid?(1)
71
- assert validator('number').valid?(1.2)
72
- assert validator('number').valid?(BigDecimal.new('1.2'))
73
- assert validator('number').valid?(2**64)
74
- end
75
-
76
- def test_failing_number_validation
77
- refute validator('number').valid?('1')
78
- end
79
-
80
- def test_passing_multiple_type_validation
81
- mvalidator = validator ['string', 'null']
82
- assert mvalidator.valid?('str')
83
- assert mvalidator.valid?(nil)
84
- end
85
-
86
- def test_failing_multiple_type_validation
87
- mvalidator = validator ['string', 'null']
88
- refute mvalidator.valid?(1)
89
- refute mvalidator.valid?(false)
90
- end
91
-
92
- private
93
-
94
- def validator_class
95
- JSchema::Validator::Type
96
- end
97
- end
@@ -1,30 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'jschema'
3
-
4
- require_relative 'assertions'
5
-
6
- class TestUniqueItems < Minitest::Test
7
- include Assertions
8
-
9
- def test_that_argument_is_boolean
10
- assert_raises_unless 'uniqueItems', :boolean
11
- end
12
-
13
- def test_passing_validation_when_unique_items_is_true
14
- assert validator(true).valid?([1, 2])
15
- end
16
-
17
- def test_passing_validation_when_unique_items_is_false
18
- assert validator(false).valid?([1, 1])
19
- end
20
-
21
- def test_failing_validation
22
- refute validator(true).valid?([1, 1])
23
- end
24
-
25
- private
26
-
27
- def validator_class
28
- JSchema::Validator::UniqueItems
29
- end
30
- end
@@ -1,24 +0,0 @@
1
- require_relative 'argument_is_array_of_schemas_tests'
2
-
3
- module ValidationAgainstSchemasTests
4
- include SchemaValidationHelpers
5
- include ArgumentIsArrayOfSchemasTests
6
-
7
- def test_passing_validation_against_one_schema
8
- stub_schema_validations(true) do
9
- assert validator([generate_schema]).valid?('test')
10
- end
11
- end
12
-
13
- def test_failing_validation_against_one_schema
14
- stub_schema_validations(false) do
15
- refute validator([generate_schema]).valid?('test')
16
- end
17
- end
18
-
19
- def test_failing_validation_all_validations_fail
20
- stub_schema_validations(false, false) do
21
- refute validator([generate_schema, generate_schema]).valid?('test')
22
- end
23
- end
24
- end