schemacop 2.4.6 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.releaser_config +0 -1
  4. data/.rubocop.yml +25 -1
  5. data/.travis.yml +3 -1
  6. data/CHANGELOG.md +33 -0
  7. data/README.md +53 -710
  8. data/README_V2.md +775 -0
  9. data/README_V3.md +1197 -0
  10. data/Rakefile +8 -12
  11. data/VERSION +1 -1
  12. data/lib/schemacop.rb +35 -36
  13. data/lib/schemacop/base_schema.rb +37 -0
  14. data/lib/schemacop/railtie.rb +10 -0
  15. data/lib/schemacop/schema.rb +1 -60
  16. data/lib/schemacop/schema2.rb +22 -0
  17. data/lib/schemacop/schema3.rb +21 -0
  18. data/lib/schemacop/scoped_env.rb +25 -13
  19. data/lib/schemacop/v2.rb +25 -0
  20. data/lib/schemacop/{caster.rb → v2/caster.rb} +16 -2
  21. data/lib/schemacop/{collector.rb → v2/collector.rb} +5 -2
  22. data/lib/schemacop/{dupper.rb → v2/dupper.rb} +1 -1
  23. data/lib/schemacop/{field_node.rb → v2/field_node.rb} +4 -3
  24. data/lib/schemacop/v2/node.rb +142 -0
  25. data/lib/schemacop/{node_resolver.rb → v2/node_resolver.rb} +1 -1
  26. data/lib/schemacop/v2/node_supporting_field.rb +70 -0
  27. data/lib/schemacop/{node_supporting_type.rb → v2/node_supporting_type.rb} +8 -5
  28. data/lib/schemacop/{node_with_block.rb → v2/node_with_block.rb} +3 -2
  29. data/lib/schemacop/v2/root_node.rb +0 -0
  30. data/lib/schemacop/v2/validator/array_validator.rb +32 -0
  31. data/lib/schemacop/{validator → v2/validator}/boolean_validator.rb +1 -1
  32. data/lib/schemacop/v2/validator/float_validator.rb +7 -0
  33. data/lib/schemacop/v2/validator/hash_validator.rb +37 -0
  34. data/lib/schemacop/v2/validator/integer_validator.rb +7 -0
  35. data/lib/schemacop/{validator → v2/validator}/nil_validator.rb +1 -1
  36. data/lib/schemacop/v2/validator/number_validator.rb +21 -0
  37. data/lib/schemacop/v2/validator/object_validator.rb +29 -0
  38. data/lib/schemacop/v2/validator/string_validator.rb +39 -0
  39. data/lib/schemacop/{validator → v2/validator}/symbol_validator.rb +1 -1
  40. data/lib/schemacop/v3.rb +45 -0
  41. data/lib/schemacop/v3/all_of_node.rb +27 -0
  42. data/lib/schemacop/v3/any_of_node.rb +28 -0
  43. data/lib/schemacop/v3/array_node.rb +218 -0
  44. data/lib/schemacop/v3/boolean_node.rb +16 -0
  45. data/lib/schemacop/v3/combination_node.rb +45 -0
  46. data/lib/schemacop/v3/context.rb +17 -0
  47. data/lib/schemacop/v3/dsl_scope.rb +46 -0
  48. data/lib/schemacop/v3/global_context.rb +114 -0
  49. data/lib/schemacop/v3/hash_node.rb +258 -0
  50. data/lib/schemacop/v3/integer_node.rb +13 -0
  51. data/lib/schemacop/v3/is_not_node.rb +32 -0
  52. data/lib/schemacop/v3/node.rb +219 -0
  53. data/lib/schemacop/v3/node_registry.rb +49 -0
  54. data/lib/schemacop/v3/number_node.rb +18 -0
  55. data/lib/schemacop/v3/numeric_node.rb +76 -0
  56. data/lib/schemacop/v3/object_node.rb +40 -0
  57. data/lib/schemacop/v3/one_of_node.rb +28 -0
  58. data/lib/schemacop/v3/reference_node.rb +49 -0
  59. data/lib/schemacop/v3/result.rb +58 -0
  60. data/lib/schemacop/v3/string_node.rb +124 -0
  61. data/lib/schemacop/v3/symbol_node.rb +13 -0
  62. data/schemacop.gemspec +24 -27
  63. data/test/lib/test_helper.rb +152 -0
  64. data/test/schemas/nested/group.rb +6 -0
  65. data/test/schemas/user.rb +7 -0
  66. data/test/unit/schemacop/v2/casting_test.rb +120 -0
  67. data/test/unit/schemacop/v2/collector_test.rb +47 -0
  68. data/test/unit/schemacop/v2/custom_check_test.rb +95 -0
  69. data/test/unit/schemacop/v2/custom_if_test.rb +97 -0
  70. data/test/unit/schemacop/v2/defaults_test.rb +95 -0
  71. data/test/unit/schemacop/v2/empty_test.rb +16 -0
  72. data/test/unit/schemacop/v2/nil_dis_allow_test.rb +43 -0
  73. data/test/unit/schemacop/v2/node_resolver_test.rb +28 -0
  74. data/test/unit/schemacop/v2/short_forms_test.rb +351 -0
  75. data/test/unit/schemacop/v2/types_test.rb +88 -0
  76. data/test/unit/schemacop/v2/validator_array_test.rb +99 -0
  77. data/test/unit/schemacop/v2/validator_boolean_test.rb +17 -0
  78. data/test/unit/schemacop/v2/validator_float_test.rb +59 -0
  79. data/test/unit/schemacop/v2/validator_hash_test.rb +95 -0
  80. data/test/unit/schemacop/v2/validator_integer_test.rb +48 -0
  81. data/test/unit/schemacop/v2/validator_nil_test.rb +15 -0
  82. data/test/unit/schemacop/v2/validator_number_test.rb +62 -0
  83. data/test/unit/schemacop/v2/validator_object_test.rb +141 -0
  84. data/test/unit/schemacop/v2/validator_string_test.rb +78 -0
  85. data/test/unit/schemacop/v2/validator_symbol_test.rb +18 -0
  86. data/test/unit/schemacop/v3/all_of_node_test.rb +198 -0
  87. data/test/unit/schemacop/v3/any_of_node_test.rb +218 -0
  88. data/test/unit/schemacop/v3/array_node_test.rb +815 -0
  89. data/test/unit/schemacop/v3/boolean_node_test.rb +126 -0
  90. data/test/unit/schemacop/v3/global_context_test.rb +164 -0
  91. data/test/unit/schemacop/v3/hash_node_test.rb +884 -0
  92. data/test/unit/schemacop/v3/integer_node_test.rb +323 -0
  93. data/test/unit/schemacop/v3/is_not_node_test.rb +173 -0
  94. data/test/unit/schemacop/v3/node_test.rb +148 -0
  95. data/test/unit/schemacop/v3/number_node_test.rb +292 -0
  96. data/test/unit/schemacop/v3/object_node_test.rb +170 -0
  97. data/test/unit/schemacop/v3/one_of_node_test.rb +187 -0
  98. data/test/unit/schemacop/v3/reference_node_test.rb +351 -0
  99. data/test/unit/schemacop/v3/string_node_test.rb +334 -0
  100. data/test/unit/schemacop/v3/symbol_node_test.rb +75 -0
  101. metadata +157 -150
  102. data/doc/Schemacop.html +0 -146
  103. data/doc/Schemacop/ArrayValidator.html +0 -329
  104. data/doc/Schemacop/BooleanValidator.html +0 -145
  105. data/doc/Schemacop/Caster.html +0 -379
  106. data/doc/Schemacop/Collector.html +0 -787
  107. data/doc/Schemacop/Dupper.html +0 -214
  108. data/doc/Schemacop/Exceptions.html +0 -115
  109. data/doc/Schemacop/Exceptions/InvalidSchemaError.html +0 -124
  110. data/doc/Schemacop/Exceptions/ValidationError.html +0 -124
  111. data/doc/Schemacop/FieldNode.html +0 -421
  112. data/doc/Schemacop/FloatValidator.html +0 -158
  113. data/doc/Schemacop/HashValidator.html +0 -293
  114. data/doc/Schemacop/IntegerValidator.html +0 -158
  115. data/doc/Schemacop/NilValidator.html +0 -145
  116. data/doc/Schemacop/Node.html +0 -1438
  117. data/doc/Schemacop/NodeResolver.html +0 -258
  118. data/doc/Schemacop/NodeSupportingField.html +0 -590
  119. data/doc/Schemacop/NodeSupportingType.html +0 -612
  120. data/doc/Schemacop/NodeWithBlock.html +0 -289
  121. data/doc/Schemacop/NumberValidator.html +0 -232
  122. data/doc/Schemacop/ObjectValidator.html +0 -298
  123. data/doc/Schemacop/RootNode.html +0 -171
  124. data/doc/Schemacop/Schema.html +0 -699
  125. data/doc/Schemacop/StringValidator.html +0 -295
  126. data/doc/Schemacop/SymbolValidator.html +0 -145
  127. data/doc/ScopedEnv.html +0 -351
  128. data/doc/_index.html +0 -379
  129. data/doc/class_list.html +0 -51
  130. data/doc/css/common.css +0 -1
  131. data/doc/css/full_list.css +0 -58
  132. data/doc/css/style.css +0 -496
  133. data/doc/file.README.html +0 -833
  134. data/doc/file_list.html +0 -56
  135. data/doc/frames.html +0 -17
  136. data/doc/index.html +0 -833
  137. data/doc/inheritance.graphml +0 -524
  138. data/doc/inheritance.pdf +0 -825
  139. data/doc/js/app.js +0 -303
  140. data/doc/js/full_list.js +0 -216
  141. data/doc/js/jquery.js +0 -4
  142. data/doc/method_list.html +0 -587
  143. data/doc/top-level-namespace.html +0 -112
  144. data/lib/schemacop/node.rb +0 -139
  145. data/lib/schemacop/node_supporting_field.rb +0 -58
  146. data/lib/schemacop/root_node.rb +0 -4
  147. data/lib/schemacop/validator/array_validator.rb +0 -30
  148. data/lib/schemacop/validator/float_validator.rb +0 -5
  149. data/lib/schemacop/validator/hash_validator.rb +0 -35
  150. data/lib/schemacop/validator/integer_validator.rb +0 -5
  151. data/lib/schemacop/validator/number_validator.rb +0 -19
  152. data/lib/schemacop/validator/object_validator.rb +0 -27
  153. data/lib/schemacop/validator/string_validator.rb +0 -37
  154. data/test/casting_test.rb +0 -100
  155. data/test/collector_test.rb +0 -45
  156. data/test/custom_check_test.rb +0 -93
  157. data/test/custom_if_test.rb +0 -95
  158. data/test/defaults_test.rb +0 -93
  159. data/test/empty_test.rb +0 -14
  160. data/test/nil_dis_allow_test.rb +0 -41
  161. data/test/node_resolver_test.rb +0 -26
  162. data/test/short_forms_test.rb +0 -349
  163. data/test/test_helper.rb +0 -13
  164. data/test/types_test.rb +0 -84
  165. data/test/validator_array_test.rb +0 -97
  166. data/test/validator_boolean_test.rb +0 -15
  167. data/test/validator_float_test.rb +0 -57
  168. data/test/validator_hash_test.rb +0 -93
  169. data/test/validator_integer_test.rb +0 -46
  170. data/test/validator_nil_test.rb +0 -13
  171. data/test/validator_number_test.rb +0 -60
  172. data/test/validator_object_test.rb +0 -139
  173. data/test/validator_string_test.rb +0 -76
  174. data/test/validator_symbol_test.rb +0 -16
@@ -0,0 +1,13 @@
1
+ module Schemacop
2
+ module V3
3
+ class SymbolNode < Node
4
+ def as_json
5
+ {} # Not supported by Json Schema
6
+ end
7
+
8
+ def allowed_types
9
+ { Symbol => 'Symbol' }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,60 +1,57 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 2.4.6 ruby lib
2
+ # stub: schemacop 3.0.0.rc3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "2.4.6"
6
+ s.version = "3.0.0.rc3"
7
7
 
8
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
8
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2020-06-29"
12
- s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "doc/Schemacop.html".freeze, "doc/Schemacop/ArrayValidator.html".freeze, "doc/Schemacop/BooleanValidator.html".freeze, "doc/Schemacop/Caster.html".freeze, "doc/Schemacop/Collector.html".freeze, "doc/Schemacop/Dupper.html".freeze, "doc/Schemacop/Exceptions.html".freeze, "doc/Schemacop/Exceptions/InvalidSchemaError.html".freeze, "doc/Schemacop/Exceptions/ValidationError.html".freeze, "doc/Schemacop/FieldNode.html".freeze, "doc/Schemacop/FloatValidator.html".freeze, "doc/Schemacop/HashValidator.html".freeze, "doc/Schemacop/IntegerValidator.html".freeze, "doc/Schemacop/NilValidator.html".freeze, "doc/Schemacop/Node.html".freeze, "doc/Schemacop/NodeResolver.html".freeze, "doc/Schemacop/NodeSupportingField.html".freeze, "doc/Schemacop/NodeSupportingType.html".freeze, "doc/Schemacop/NodeWithBlock.html".freeze, "doc/Schemacop/NumberValidator.html".freeze, "doc/Schemacop/ObjectValidator.html".freeze, "doc/Schemacop/RootNode.html".freeze, "doc/Schemacop/Schema.html".freeze, "doc/Schemacop/StringValidator.html".freeze, "doc/Schemacop/SymbolValidator.html".freeze, "doc/ScopedEnv.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/inheritance.graphml".freeze, "doc/inheritance.pdf".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/caster.rb".freeze, "lib/schemacop/collector.rb".freeze, "lib/schemacop/dupper.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/field_node.rb".freeze, "lib/schemacop/node.rb".freeze, "lib/schemacop/node_resolver.rb".freeze, "lib/schemacop/node_supporting_field.rb".freeze, "lib/schemacop/node_supporting_type.rb".freeze, "lib/schemacop/node_with_block.rb".freeze, "lib/schemacop/root_node.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/validator/array_validator.rb".freeze, "lib/schemacop/validator/boolean_validator.rb".freeze, "lib/schemacop/validator/float_validator.rb".freeze, "lib/schemacop/validator/hash_validator.rb".freeze, "lib/schemacop/validator/integer_validator.rb".freeze, "lib/schemacop/validator/nil_validator.rb".freeze, "lib/schemacop/validator/number_validator.rb".freeze, "lib/schemacop/validator/object_validator.rb".freeze, "lib/schemacop/validator/string_validator.rb".freeze, "lib/schemacop/validator/symbol_validator.rb".freeze, "schemacop.gemspec".freeze, "test/casting_test.rb".freeze, "test/collector_test.rb".freeze, "test/custom_check_test.rb".freeze, "test/custom_if_test.rb".freeze, "test/defaults_test.rb".freeze, "test/empty_test.rb".freeze, "test/nil_dis_allow_test.rb".freeze, "test/node_resolver_test.rb".freeze, "test/short_forms_test.rb".freeze, "test/test_helper.rb".freeze, "test/types_test.rb".freeze, "test/validator_array_test.rb".freeze, "test/validator_boolean_test.rb".freeze, "test/validator_float_test.rb".freeze, "test/validator_hash_test.rb".freeze, "test/validator_integer_test.rb".freeze, "test/validator_nil_test.rb".freeze, "test/validator_number_test.rb".freeze, "test/validator_object_test.rb".freeze, "test/validator_string_test.rb".freeze, "test/validator_symbol_test.rb".freeze]
11
+ s.date = "2021-01-28"
12
+ s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/root_node.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
13
13
  s.homepage = "https://github.com/sitrox/schemacop".freeze
14
14
  s.licenses = ["MIT".freeze]
15
15
  s.rubygems_version = "3.0.3".freeze
16
16
  s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions.".freeze
17
- s.test_files = ["test/casting_test.rb".freeze, "test/collector_test.rb".freeze, "test/custom_check_test.rb".freeze, "test/custom_if_test.rb".freeze, "test/defaults_test.rb".freeze, "test/empty_test.rb".freeze, "test/nil_dis_allow_test.rb".freeze, "test/node_resolver_test.rb".freeze, "test/short_forms_test.rb".freeze, "test/test_helper.rb".freeze, "test/types_test.rb".freeze, "test/validator_array_test.rb".freeze, "test/validator_boolean_test.rb".freeze, "test/validator_float_test.rb".freeze, "test/validator_hash_test.rb".freeze, "test/validator_integer_test.rb".freeze, "test/validator_nil_test.rb".freeze, "test/validator_number_test.rb".freeze, "test/validator_object_test.rb".freeze, "test/validator_string_test.rb".freeze, "test/validator_symbol_test.rb".freeze]
17
+ s.test_files = ["test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
18
18
 
19
19
  if s.respond_to? :specification_version then
20
20
  s.specification_version = 4
21
21
 
22
22
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
23
  s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
24
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.3"])
24
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
25
25
  s.add_development_dependency(%q<rake>.freeze, [">= 0"])
26
- s.add_development_dependency(%q<ci_reporter>.freeze, ["~> 2.0"])
27
- s.add_development_dependency(%q<ci_reporter_minitest>.freeze, [">= 0"])
28
- s.add_development_dependency(%q<haml>.freeze, [">= 0"])
26
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
27
+ s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
29
28
  s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
30
- s.add_development_dependency(%q<yard>.freeze, [">= 0"])
31
- s.add_development_dependency(%q<rubocop>.freeze, ["= 0.35.1"])
32
- s.add_development_dependency(%q<redcarpet>.freeze, [">= 0"])
29
+ s.add_development_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
33
30
  s.add_development_dependency(%q<pry>.freeze, [">= 0"])
31
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
32
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
34
33
  else
35
34
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
36
- s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
35
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
37
36
  s.add_dependency(%q<rake>.freeze, [">= 0"])
38
- s.add_dependency(%q<ci_reporter>.freeze, ["~> 2.0"])
39
- s.add_dependency(%q<ci_reporter_minitest>.freeze, [">= 0"])
40
- s.add_dependency(%q<haml>.freeze, [">= 0"])
37
+ s.add_dependency(%q<minitest>.freeze, [">= 0"])
38
+ s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
41
39
  s.add_dependency(%q<colorize>.freeze, [">= 0"])
42
- s.add_dependency(%q<yard>.freeze, [">= 0"])
43
- s.add_dependency(%q<rubocop>.freeze, ["= 0.35.1"])
44
- s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
40
+ s.add_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
45
41
  s.add_dependency(%q<pry>.freeze, [">= 0"])
42
+ s.add_dependency(%q<byebug>.freeze, [">= 0"])
43
+ s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
46
44
  end
47
45
  else
48
46
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
49
- s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
47
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
50
48
  s.add_dependency(%q<rake>.freeze, [">= 0"])
51
- s.add_dependency(%q<ci_reporter>.freeze, ["~> 2.0"])
52
- s.add_dependency(%q<ci_reporter_minitest>.freeze, [">= 0"])
53
- s.add_dependency(%q<haml>.freeze, [">= 0"])
49
+ s.add_dependency(%q<minitest>.freeze, [">= 0"])
50
+ s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
54
51
  s.add_dependency(%q<colorize>.freeze, [">= 0"])
55
- s.add_dependency(%q<yard>.freeze, [">= 0"])
56
- s.add_dependency(%q<rubocop>.freeze, ["= 0.35.1"])
57
- s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
52
+ s.add_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
58
53
  s.add_dependency(%q<pry>.freeze, [">= 0"])
54
+ s.add_dependency(%q<byebug>.freeze, [">= 0"])
55
+ s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
59
56
  end
60
57
  end
@@ -0,0 +1,152 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ # TODO: Move to more sensible location
5
+ def assert_verr(&block)
6
+ assert_raises(Schemacop::V2::Exceptions::ValidationError, &block)
7
+ end
8
+
9
+ # TODO: Move to more sensible location
10
+ def assert_nothing_raised(&_block)
11
+ yield
12
+ assert true
13
+ end
14
+
15
+ require 'minitest/autorun'
16
+ require 'minitest/reporters'
17
+ require 'schemacop'
18
+ require 'pry'
19
+ require 'colorize'
20
+ require 'byebug'
21
+
22
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)]
23
+
24
+ class SchemacopTest < Minitest::Test
25
+ def assert_is_a(klass, object)
26
+ assert object.is_a?(klass),
27
+ "Expected object with class #{object.class.inspect} to be a #{klass.inspect}."
28
+ end
29
+ end
30
+
31
+ class V2Test < SchemacopTest
32
+ def setup
33
+ Schemacop.default_schema_version = 2
34
+ end
35
+ end
36
+
37
+ class V3Test < SchemacopTest
38
+ class ValidationAssertion
39
+ attr_reader :errors
40
+
41
+ def initialize(&block)
42
+ @errors = {}
43
+ instance_exec(&block)
44
+ end
45
+
46
+ def error(path, exp)
47
+ @errors[path] ||= []
48
+ @errors[path] << exp
49
+ end
50
+ end
51
+
52
+ def setup
53
+ Schemacop.default_schema_version = 3
54
+ end
55
+
56
+ # Help test raise errors message
57
+ # https://ruby-doc.org/stdlib-2.1.5/libdoc/test/unit/rdoc/Test/Unit/Assertions.html#method-i-assert_raise
58
+ def assert_raises_with_message(exception, expected, msg = nil, &block)
59
+ case expected
60
+ when String
61
+ assert = :assert_equal
62
+ when Regexp
63
+ assert = :assert_match
64
+ else
65
+ fail TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}"
66
+ end
67
+
68
+ ex = assert_raises(exception, *msg, &block)
69
+ msg = message(msg, '') { "Expected Exception(#{exception}) was raised, but the message doesn't match" }
70
+
71
+ if assert == :assert_equal
72
+ assert_equal(expected, ex.message, msg)
73
+ else
74
+ msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.message}" }
75
+ assert expected =~ ex.message, msg
76
+ block.binding.eval('proc{|_|$~=_}').call($LAST_MATCH_INFO)
77
+ end
78
+ return ex
79
+ end
80
+
81
+ def schema(type = :hash, **options, &block)
82
+ @schema = Schemacop::Schema3.new(type, **options, &block)
83
+ end
84
+
85
+ def with_context(context, &block)
86
+ Schemacop.with_context(context, &block)
87
+ end
88
+
89
+ def assert_validation(data, &block)
90
+ result = @schema.validate(data)
91
+
92
+ if block_given?
93
+ assertion = ValidationAssertion.new(&block)
94
+
95
+ assert_equal assertion.errors.keys.sort,
96
+ result.messages_by_path.keys.sort,
97
+ 'Unexpected validation error paths'
98
+
99
+ assertion.errors.each do |path, expected_errors|
100
+ actual_errors = result.messages_by_path[path].dup
101
+
102
+ assert_equal expected_errors.size,
103
+ actual_errors.size,
104
+ "Unexpected number of messages for path #{path}"
105
+
106
+ expected_errors.each do |expected_error|
107
+ match = actual_errors.find do |ae|
108
+ if expected_error.is_a?(Regexp)
109
+ expected_error.match?(ae)
110
+ else
111
+ expected_error == ae
112
+ end
113
+ end
114
+
115
+ if match
116
+ actual_errors.delete(match)
117
+ else
118
+ assert match,
119
+ "Did not find error #{expected_error.inspect} in path #{path}, errors: " \
120
+ + result.messages_by_path[path].inspect
121
+ end
122
+ end
123
+ end
124
+ else
125
+ assert result.errors.empty?,
126
+ "Expected data #{data.inspect} to match schema #{@schema.as_json}, but got errors: #{result.messages}."
127
+ end
128
+ end
129
+
130
+ def assert_json(expected_json)
131
+ # TODO: Double "as_json" should not be necessary
132
+ assert_equal expected_json.as_json, @schema.as_json.as_json
133
+ end
134
+
135
+ def assert_match_any(array, exp)
136
+ assert array.any? { |element| element.match?(exp) },
137
+ "Expected any of #{array.inspect} to match #{exp}."
138
+ end
139
+
140
+ def assert_cast(input_data, expected_data)
141
+ input_data_was = Marshal.load(Marshal.dump(input_data))
142
+ result = @schema.validate(input_data)
143
+ assert_empty result.errors
144
+ assert_equal expected_data, result.data, 'Unexpected result data.'
145
+
146
+ if input_data.nil?
147
+ assert_nil input_data_was, 'Expected input_data to stay the same.'
148
+ else
149
+ assert_equal input_data, input_data_was, 'Expected input_data to stay the same.'
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,6 @@
1
+ schema do
2
+ str! :name
3
+ ary? :users do
4
+ ref 'user'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ schema do
2
+ str! :first_name
3
+ str! :last_name
4
+ ary? :groups do
5
+ ref 'nested/group'
6
+ end
7
+ end
@@ -0,0 +1,120 @@
1
+ require 'test_helper'
2
+
3
+ module Schemacop
4
+ module V2
5
+ class CastingTest < V2Test
6
+ def test_basic
7
+ s = Schema.new :integer, cast: [String]
8
+
9
+ input = '42'
10
+ output = s.validate!(input)
11
+
12
+ assert_equal(42, output)
13
+ end
14
+
15
+ def test_field
16
+ s = Schema.new do
17
+ req :foo, :integer, cast: [String]
18
+ end
19
+
20
+ input = { foo: '42' }
21
+ output = s.validate!(input)
22
+
23
+ assert_equal({ foo: '42' }, input)
24
+ assert_equal({ foo: 42 }, output)
25
+ end
26
+
27
+ def test_first_type_matches
28
+ s = Schema.new do
29
+ type TrueClass
30
+ type :integer, cast: [String]
31
+ end
32
+
33
+ assert_equal(42, s.validate!('42'))
34
+ assert_equal(42, s.validate!(42))
35
+ assert_equal(true, s.validate!(true))
36
+ end
37
+
38
+ def test_with_if
39
+ s = Schema.new do
40
+ type Float, if: proc { |data| !data.is_a?(String) || data.match(/\d+\.\d+/) }, cast: [String]
41
+ type Integer, cast: [String]
42
+ end
43
+
44
+ assert_equal 42.2, s.validate!('42.2')
45
+ assert_equal 42, s.validate!('42')
46
+ end
47
+
48
+ def test_arrays
49
+ s = Schema.new do
50
+ req :foo, :array, :integer, cast: [String]
51
+ end
52
+
53
+ assert_equal(
54
+ { foo: [1, 2, 3] },
55
+ s.validate!(foo: %w[1 2 3])
56
+ )
57
+ end
58
+
59
+ def test_check_after_cast
60
+ s = Schema.new do
61
+ type Integer, cast: [String], check: proc { |v| v > 41 }
62
+ end
63
+
64
+ assert_equal 42, s.validate!('42')
65
+ assert_equal 43, s.validate!('43')
66
+ assert_equal 42, s.validate!(42)
67
+ assert_verr { s.validate!('41') }
68
+ assert_verr { s.validate!(42.2) }
69
+ end
70
+
71
+ def test_multilple_types
72
+ e = assert_raises Exceptions::InvalidSchemaError do
73
+ Schema.new do
74
+ type :number, cast: [String]
75
+ end
76
+ end
77
+
78
+ assert_equal 'Casting is only allowed for single-value datatypes, '\
79
+ 'but type Schemacop::V2::NumberValidator has classes ["Integer", "Float"].',
80
+ e.message
81
+ end
82
+
83
+ def test_custom_castings
84
+ s = Schema.new do
85
+ type :integer, cast: { String => proc { |v| Integer(v) } }
86
+ end
87
+
88
+ assert_equal 42, s.validate!('42')
89
+ end
90
+
91
+ def test_decimal_basis_castings
92
+ s = Schema.new do
93
+ type :integer, cast: [String]
94
+ end
95
+
96
+ assert_equal 1, s.validate!('01')
97
+ assert_equal 8, s.validate!('08')
98
+ assert_equal 11, s.validate!('011')
99
+ end
100
+
101
+ def test_string_to_nil_castings
102
+ s = Schema.new do
103
+ opt :int_field, :integer, cast: [String]
104
+ opt :float_field, :float, cast: [String]
105
+ end
106
+
107
+ expected_int = { int_field: nil }
108
+ expected_float = { float_field: nil }
109
+
110
+ assert_equal expected_int, s.validate!(int_field: nil)
111
+ assert_equal expected_int, s.validate!(int_field: '')
112
+ assert_equal expected_int, s.validate!(int_field: ' ')
113
+
114
+ assert_equal expected_float, s.validate!(float_field: nil)
115
+ assert_equal expected_float, s.validate!(float_field: '')
116
+ assert_equal expected_float, s.validate!(float_field: ' ')
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Schemacop
4
+ module V2
5
+ class CollectorTest < V2Test
6
+ def test_no_root_node
7
+ s = Schema.new do
8
+ req :a, :string
9
+ end
10
+
11
+ col = s.validate(a: 0)
12
+ assert col.exceptions.first[:path].first !~ %r{^/root}, 'Root node is present in the path.'
13
+ end
14
+
15
+ def test_correct_path
16
+ s = Schema.new do
17
+ req :long_symbol, :string
18
+ req 'long_string', :string
19
+ req 123, :string
20
+ end
21
+
22
+ col = s.validate('long_string' => 0, long_symbol: 0, 123 => 0)
23
+
24
+ symbol = col.exceptions[0]
25
+ string = col.exceptions[1]
26
+ number = col.exceptions[2]
27
+
28
+ assert symbol[:path].first =~ %r{^/long_symbol}
29
+ assert string[:path].first =~ %r{^/long_string}
30
+ assert number[:path].first =~ %r{^/123}
31
+ end
32
+
33
+ def test_nested_paths
34
+ s = Schema.new do
35
+ req :one do
36
+ req :two, :string
37
+ end
38
+ req :three, :string
39
+ end
40
+
41
+ col = s.validate(one: { two: 0 }, three: 0)
42
+ assert_equal 2, col.exceptions[0][:path].length
43
+ assert_equal 1, col.exceptions[1][:path].length
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+
3
+ module Schemacop
4
+ module V2
5
+ class CustomCheckTest < V2Test
6
+ def test_integer_check_short_form
7
+ s = Schema.new :integer, check: proc { |i| i.even? }
8
+ assert_nothing_raised { s.validate!(2) }
9
+ assert_nothing_raised { s.validate!(-8) }
10
+ assert_nothing_raised { s.validate!(0) }
11
+ assert_verr { s.validate!(1) }
12
+ assert_verr { s.validate!(-7) }
13
+ assert_verr { s.validate!(2.1) }
14
+ end
15
+
16
+ def test_custom_error_message
17
+ s = Schema.new :integer, check: proc { |i| i.even? ? true : 'Custom error' }
18
+ assert_nothing_raised { s.validate!(2) }
19
+ exception = assert_verr { s.validate!(3) }
20
+ assert_match(/Custom :check failed: Custom error\./, exception.message)
21
+ end
22
+
23
+ def test_integer_check_with_lambda
24
+ s = Schema.new do
25
+ type :integer, check: ->(i) { i.even? }
26
+ end
27
+
28
+ assert_nothing_raised { s.validate!(2) }
29
+ assert_nothing_raised { s.validate!(-8) }
30
+ assert_nothing_raised { s.validate!(0) }
31
+ assert_verr { s.validate!(1) }
32
+ assert_verr { s.validate!(-7) }
33
+ assert_verr { s.validate!(2.1) }
34
+ end
35
+
36
+ def test_in_type_dsl
37
+ s = Schema.new do
38
+ type :number, check: proc { |x| x == 42 }
39
+ end
40
+ assert_nothing_raised { s.validate!(42) }
41
+ assert_verr { s.validate!(42.1) }
42
+ assert_verr { s.validate!(0) }
43
+ end
44
+
45
+ def test_with_array
46
+ s = Schema.new do
47
+ type :array, check: proc { |a| a.first == 1 } do
48
+ type :integer
49
+ end
50
+ end
51
+ assert_nothing_raised { s.validate!([1, 2, 3]) }
52
+ assert_verr { s.validate!([2, 3, 4]) }
53
+ end
54
+
55
+ def test_with_array_nested
56
+ s = Schema.new do
57
+ type :array, check: proc { |a| a.first == 4 } do
58
+ type :integer, check: proc { |i| i >= 2 }
59
+ end
60
+ end
61
+
62
+ assert_nothing_raised { s.validate!([4, 3, 2]) }
63
+ assert_verr { s.validate!([3, 2]) }
64
+ assert_verr { s.validate!([4, 1]) }
65
+ end
66
+
67
+ def test_with_hash
68
+ s = Schema.new :hash, check: proc { |h| h.all? { |k, v| k == v } } do
69
+ opt 1, :integer
70
+ opt 'two', :string
71
+ end
72
+ assert_nothing_raised { s.validate!(1 => 1, 'two' => 'two') }
73
+ assert_verr { s.validate!(1 => 2, 'two' => 'two') }
74
+ assert_verr { s.validate!(1 => 1, 'two' => 'one') }
75
+ end
76
+
77
+ def test_mixed_if_check
78
+ s = Schema.new do
79
+ req :first_name,
80
+ :string,
81
+ if: proc { |str| str.start_with?('Sand') },
82
+ check: proc { |str| str == 'Sandy' }
83
+ req :first_name, :string, min: 3
84
+ end
85
+
86
+ assert_nothing_raised { s.validate!(first_name: 'Bob') }
87
+ assert_nothing_raised { s.validate!(first_name: 'Sandy') }
88
+ assert_nothing_raised { s.validate!(first_name: 'Sansibar') }
89
+
90
+ assert_verr { s.validate!(first_name: 'Sandkasten') }
91
+ assert_verr { s.validate!(first_name: 'a') }
92
+ end
93
+ end
94
+ end
95
+ end