schemacop 3.0.9 → 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8081d63289f1f0078e74dc2d404b549fa5529c2d9ae977fcff713ecd01312f27
4
- data.tar.gz: aff64b9eb5bc7a9a73a64c2ed0066584cfb59a18dff3566aadcd3c632f8599f8
3
+ metadata.gz: 8700be126ea3aced42828ce418ad665095584ba0e217eebb0cf2e42faf5b4aef
4
+ data.tar.gz: 9774973e128d64f02a06e84cfa19990b0a7b0890cf57d4fb94c0f5058337dd20
5
5
  SHA512:
6
- metadata.gz: 3084d61eb18f126ce9b88341d0809614f10c5ba74f39ece8fe7f1cc29c9b7f3d3fa89fadd55fe48fa515602bd80d755c326cfc4ce3d4850993d9cbf0e694a48b
7
- data.tar.gz: b55349b141d1c971923152ecf19793905fc1811bfcb8647271415706d3372bde616d159aa1e8202d4b5630a84443ae6c2d5ccb67acabb5f115db9270b9f0825b
6
+ metadata.gz: 0cdd515a0d47c7d707b8418fa5f0c7e6e73375ccb28bd2552b8c5f960e0279c75fb3a89c99b4ff677069c7a75e3d2f2376645d720d0d65980688602af09e4d28
7
+ data.tar.gz: 27cb5b5b8c4c8e14601c907c443d4fd904457ad0762c31af26aabf7d75febbf49459555e19665a1e56674b05601b4a223ccc18cb12fcebf9fddd526c3ec37442
data/.releaser_config CHANGED
@@ -1,4 +1,4 @@
1
1
  version_file: VERSION
2
2
  always_from_master: true
3
3
  gem_style: github
4
- ruby_command: ruby -S
4
+ ruby_command: ruby -S
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.10 (2021-03-19)
4
+
5
+ * If wrong type is given, report class of wrong type in error message
6
+
3
7
  ## 3.0.9 (2021-02-26)
4
8
 
5
9
  * Fix casting of blank strings
data/README_V3.md CHANGED
@@ -75,12 +75,12 @@ Schemacop can raise the following exceptions:
75
75
  Example:
76
76
 
77
77
  ```ruby
78
- schema = Schemacop::Schema3.new do
78
+ schema = Schemacop::Schema3.new :hash do
79
79
  int! :foo
80
80
  end
81
81
 
82
82
  schema.validate!(foo: 'bar')
83
- # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "integer".
83
+ # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "String", expected "integer".
84
84
  ```
85
85
 
86
86
  * `Schemacop::Exceptions::InvalidSchemaError`: This exception is raised when the
@@ -141,7 +141,7 @@ schema = Schemacop::Schema3.new :string, enum: ['foo', 'bar', 42]
141
141
 
142
142
  schema.validate!('foo') # => "foo"
143
143
  schema.validate!('bar') # => "bar"
144
- schema.validate!(42) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "string".
144
+ schema.validate!(42) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "string".
145
145
  ```
146
146
 
147
147
  The enum will also be provided in the json output:
@@ -178,7 +178,7 @@ Note that the default value you use is also validated against the schema:
178
178
  schema = Schemacop::Schema3.new :string, default: 42
179
179
 
180
180
  schema.validate!('foo') # => "foo"
181
- schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "string".
181
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "string".
182
182
  ```
183
183
 
184
184
  ## Nodes
@@ -328,10 +328,10 @@ schema.validate!(42) # => 42
328
328
  schema.validate!(43) # => Schemacop::Exceptions::ValidationError: /: Value must be a multiple of 2.
329
329
  schema.validate!(-2) # => Schemacop::Exceptions::ValidationError: /: Value must have a minimum of 0.
330
330
  schema.validate!(102) # => Schemacop::Exceptions::ValidationError: /: Value must have a maximum of 100.
331
- schema.validate!(42.1) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
332
- schema.validate!(4r) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
333
- schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
334
- schema.validate!(BigDecimal(5)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
331
+ schema.validate!(42.1) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Float", expected "integer".
332
+ schema.validate!(4r) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Rational", expected "integer".
333
+ schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Complex", expected "integer".
334
+ schema.validate!(BigDecimal(5)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "BigDecimal", expected "integer".
335
335
  ```
336
336
 
337
337
  With `cast_str` enabled:
@@ -400,7 +400,7 @@ schema.validate!(51) # => Schemacop::Exceptions::ValidationError: /:
400
400
  schema.validate!(42.5) # => 42.5
401
401
  schema.validate!(1.5r) # => (3/2)
402
402
  schema.validate!(BigDecimal(5)) # => 0.5e1
403
- schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "big_decimal" or "float" or "integer" or "rational".
403
+ schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Complex", expected "big_decimal" or "float" or "integer" or "rational"
404
404
  ```
405
405
 
406
406
  With `cast_str` enabled:
@@ -434,9 +434,9 @@ The symbol type is used to validate elements for the Ruby `Symbol` class.
434
434
  # Validates that the input is a symbol
435
435
  schema = Schemacop::Schema3.new(:symbol)
436
436
  schema.validate!(:foo) # => :foo
437
- schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
438
- schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
439
- schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
437
+ schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "String", expected "Symbol".
438
+ schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "Symbol".
439
+ schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "FalseClass", expected "Symbol".
440
440
  schema.validate!(:false) # => :false
441
441
  ```
442
442
 
@@ -472,9 +472,9 @@ The boolean type is used to validate Ruby booleans, i.e. the `TrueClass` and `Fa
472
472
  schema = Schemacop::Schema3.new(:boolean)
473
473
  schema.validate!(true) # => true
474
474
  schema.validate!(false) # => false
475
- schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
476
- schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
477
- schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
475
+ schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Symbol", expected "boolean".
476
+ schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "String", expected "boolean".
477
+ schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "boolean".
478
478
  ```
479
479
 
480
480
  With `cast_str` enabled:
@@ -528,7 +528,7 @@ end
528
528
 
529
529
  schema.validate!([]) # => Schemacop::Exceptions::ValidationError: /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}.
530
530
  schema.validate!([1, 5]) # => [1, 5]
531
- schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, expected "integer". /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}
531
+ schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, got type "String", expected "integer". /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}
532
532
  ```
533
533
 
534
534
  You can also use it with the tuple validation (see below), e.g. if you want
@@ -569,10 +569,10 @@ schema = Schemacop::Schema3.new :array do
569
569
  list :integer, minimum: 1, maximum: 5
570
570
  end
571
571
 
572
- schema.validate!([]) # => []
573
- schema.validate!([1, 3]) # => [1, 3]
574
- schema.validate!([0, 6]) # => Schemacop::Exceptions::ValidationError: /[0]: Value must have a minimum of 1. /[1]: Value must have a maximum of 5.
575
- schema.validate! ['foo'] # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, expected "integer".
572
+ schema.validate!([]) # => []
573
+ schema.validate!([1, 3]) # => [1, 3]
574
+ schema.validate!([0, 6]) # => Schemacop::Exceptions::ValidationError: /[0]: Value must have a minimum of 1. /[1]: Value must have a maximum of 5.
575
+ schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, got type "String", expected "integer".
576
576
  ```
577
577
 
578
578
  You can also build more complex structures, e.g. an array containing an arbitrary
@@ -587,7 +587,7 @@ end
587
587
 
588
588
  schema.validate!([]) # => []
589
589
  schema.validate!([[1], [2, 3]]) # => [[1], [2, 3]]
590
- schema.validate!([['foo'], [2, 3]]) # => Schemacop::Exceptions::ValidationError: /[0]/[0]: Invalid type, expected "integer".
590
+ schema.validate!([['foo'], [2, 3]]) # => Schemacop::Exceptions::ValidationError: /[0]/[0]: Invalid type, got type "String", expected "integer".
591
591
  ```
592
592
 
593
593
  Please note that you can only specify *one* `list` item:
@@ -649,7 +649,7 @@ end
649
649
 
650
650
  schema.validate!([]) # => Schemacop::Exceptions::ValidationError: /: Array has 0 items but must have exactly 2.
651
651
  schema.validate!([1, 'foo']) # => [1, "foo"]
652
- schema.validate!([1, 'foo', 'bar']) # => Schemacop::Exceptions::ValidationError: /[2]: Invalid type, expected "integer".
652
+ schema.validate!([1, 'foo', 'bar']) # => Schemacop::Exceptions::ValidationError: /[2]: Invalid type, got type "String", expected "integer".
653
653
  schema.validate!([1, 'foo', 2, 3]) # => [1, "foo", 2, 3]
654
654
  ```
655
655
 
@@ -808,7 +808,7 @@ schema = Schemacop::Schema3.new :hash do
808
808
  str? :foo
809
809
  end
810
810
 
811
- schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string".
811
+ schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Integer", expected "string".
812
812
  schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"}
813
813
  ```
814
814
 
@@ -892,7 +892,7 @@ end
892
892
 
893
893
  schema.validate!({id: 1}) # => {"id"=>1}
894
894
  schema.validate!({id: 1, foo: 'bar'}) # => {"id"=>1, "foo"=>"bar"}
895
- schema.validate!({id: 1, foo: 42}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string".
895
+ schema.validate!({id: 1, foo: 42}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Integer", expected "string".
896
896
  ```
897
897
 
898
898
  Using the option `property_names`, you can additionaly specify a pattern that
@@ -916,8 +916,8 @@ end
916
916
 
917
917
  schema.validate!({}) # => {}
918
918
  schema.validate!({foo: [1, 2, 3]}) # => {"foo"=>[1, 2, 3]}
919
- schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "array".
920
- schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, expected "array".
919
+ schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Symbol", expected "array".
920
+ schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, got type "Symbol", expected "array".
921
921
  ```
922
922
 
923
923
  ##### Dependencies
@@ -991,10 +991,10 @@ of allowed classes:
991
991
  schema = Schemacop::Schema3.new :object, classes: [String]
992
992
 
993
993
  schema.validate!(nil) # => nil
994
- schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
995
- schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
994
+ schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "TrueClass", expected "String".
995
+ schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Object", expected "String".
996
996
  schema.validate!('foo') # => "foo"
997
- schema.validate!('foo'.html_safe) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
997
+ schema.validate!('foo'.html_safe) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "ActiveSupport::SafeBuffer", expected "String".
998
998
  ```
999
999
 
1000
1000
  Here, the node checks if the given value is an instance of any of the given
@@ -1006,8 +1006,8 @@ If you want to allow subclasses, you can specify this by using the `strict` opti
1006
1006
  schema = Schemacop::Schema3.new :object, classes: [String], strict: false
1007
1007
 
1008
1008
  schema.validate!(nil) # => nil
1009
- schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
1010
- schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
1009
+ schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "TrueClass", expected "String".
1010
+ schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Object", expected "String".
1011
1011
  schema.validate!('foo') # => "foo"
1012
1012
  schema.validate!('foo'.html_safe) # => "foo"
1013
1013
  ```
@@ -1180,7 +1180,7 @@ schema.validate!({
1180
1180
  shipping_address: 'foo',
1181
1181
  billing_address: 42
1182
1182
  })
1183
- # => Schemacop::Exceptions::ValidationError: /shipping_address: Invalid type, expected "object". /billing_address: Invalid type, expected "object".
1183
+ # => Schemacop::Exceptions::ValidationError: /shipping_address: Invalid type, got type "String", expected "object". /billing_address: Invalid type, got type "Integer", expected "object".
1184
1184
 
1185
1185
  schema.validate!({
1186
1186
  shipping_address: {
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.9
1
+ 3.0.10
@@ -206,7 +206,7 @@ module Schemacop
206
206
  # Validate type #
207
207
  if allowed_types.any? && allowed_types.keys.none? { |c| data.send(type_assertion_method, c) }
208
208
  collection = allowed_types.values.map { |t| "\"#{t}\"" }.uniq.sort.join(' or ')
209
- result.error %(Invalid type, expected #{collection}.)
209
+ result.error "Invalid type, got type \"#{data.class}\", expected #{collection}."
210
210
  return nil
211
211
  end
212
212
 
data/schemacop.gemspec CHANGED
@@ -1,49 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.9 ruby lib
2
+ # stub: schemacop 3.0.10 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.9"
6
+ s.version = "3.0.10"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2021-02-26"
11
+ s.date = "2021-03-19"
12
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/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
- s.rubygems_version = "3.0.3".freeze
15
+ s.rubygems_version = "3.1.2".freeze
16
16
  s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions.".freeze
17
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
+ end
21
22
 
22
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
- s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
24
- s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
25
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
26
- s.add_development_dependency(%q<rake>.freeze, [">= 0"])
27
- s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
28
- s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
29
- s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
30
- s.add_development_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
31
- s.add_development_dependency(%q<pry>.freeze, [">= 0"])
32
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
33
- s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
34
- else
35
- s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
36
- s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
37
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
38
- s.add_dependency(%q<rake>.freeze, [">= 0"])
39
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
40
- s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
41
- s.add_dependency(%q<colorize>.freeze, [">= 0"])
42
- s.add_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
43
- s.add_dependency(%q<pry>.freeze, [">= 0"])
44
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
45
- s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
46
- end
23
+ if s.respond_to? :add_runtime_dependency then
24
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
25
+ s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
26
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
27
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
28
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
29
+ s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
30
+ s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
31
+ s.add_development_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
32
+ s.add_development_dependency(%q<pry>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
34
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
47
35
  else
48
36
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
49
37
  s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
@@ -3,7 +3,9 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class ArrayNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "array".'.freeze
6
+ def self.invalid_type_error(type)
7
+ "Invalid type, got type \"#{type}\", expected \"array\"."
8
+ end
7
9
 
8
10
  def test_basic
9
11
  schema :array
@@ -54,7 +56,7 @@ module Schemacop
54
56
  error '/', 'Array has 2 items but must have exactly 1.'
55
57
  end
56
58
  assert_validation [123] do
57
- error '/[0]', 'Invalid type, expected "object".'
59
+ error '/[0]', 'Invalid type, got type "Integer", expected "object".'
58
60
  end
59
61
  end
60
62
 
@@ -64,7 +66,7 @@ module Schemacop
64
66
  assert_json(type: :array)
65
67
 
66
68
  assert_validation 42 do
67
- error '/', EXP_INVALID_TYPE
69
+ error '/', ArrayNodeTest.invalid_type_error(Integer)
68
70
  end
69
71
 
70
72
  schema { ary! :foo }
@@ -79,11 +81,11 @@ module Schemacop
79
81
  )
80
82
 
81
83
  assert_validation foo: 42 do
82
- error '/foo', EXP_INVALID_TYPE
84
+ error '/foo', ArrayNodeTest.invalid_type_error(Integer)
83
85
  end
84
86
 
85
87
  assert_validation foo: {} do
86
- error '/foo', EXP_INVALID_TYPE
88
+ error '/foo', ArrayNodeTest.invalid_type_error(ActiveSupport::HashWithIndifferentAccess)
87
89
  end
88
90
  end
89
91
 
@@ -196,7 +198,7 @@ module Schemacop
196
198
  end
197
199
 
198
200
  assert_validation %i[foo] do
199
- error '/[0]', 'Invalid type, expected "string".'
201
+ error '/[0]', 'Invalid type, got type "Symbol", expected "string".'
200
202
  end
201
203
  end
202
204
 
@@ -230,7 +232,7 @@ module Schemacop
230
232
  end
231
233
 
232
234
  assert_validation([42, 42, { name: 'Hello' }]) do
233
- error '/[0]', 'Invalid type, expected "string".'
235
+ error '/[0]', 'Invalid type, got type "Integer", expected "string".'
234
236
  end
235
237
 
236
238
  assert_validation(['foo', 42, { namex: 'Hello' }]) do
@@ -305,7 +307,7 @@ module Schemacop
305
307
  assert_validation(['foo', 42])
306
308
  assert_validation(['foo', 42, 42])
307
309
  assert_validation(['foo', :foo]) do
308
- error '/[1]', 'Invalid type, expected "integer".'
310
+ error '/[1]', 'Invalid type, got type "Symbol", expected "integer".'
309
311
  end
310
312
  end
311
313
 
@@ -328,7 +330,7 @@ module Schemacop
328
330
  assert_validation(['foo', 42])
329
331
  assert_validation(['foo', 42, 'additional', 'another'])
330
332
  assert_validation(['foo', 42, 'additional', 42, 'another']) do
331
- error '/[3]', 'Invalid type, expected "string".'
333
+ error '/[3]', 'Invalid type, got type "Integer", expected "string".'
332
334
  end
333
335
 
334
336
  assert_cast(['foo', 42], ['foo', 42])
@@ -354,7 +356,7 @@ module Schemacop
354
356
  assert_validation(['foo', 42])
355
357
  assert_validation(['foo', 42, '1990-01-01'])
356
358
  assert_validation(['foo', 42, '1990-01-01', 42]) do
357
- error '/[3]', 'Invalid type, expected "string".'
359
+ error '/[3]', 'Invalid type, got type "Integer", expected "string".'
358
360
  end
359
361
  assert_validation(['foo', 42, '1990-01-01', 'foo']) do
360
362
  error '/[3]', 'String does not match format "date".'
@@ -439,7 +441,7 @@ module Schemacop
439
441
  assert_validation(['foo', 42, { foo: '1990-01-01', bar: :baz }])
440
442
 
441
443
  assert_validation(['foo', 42, { foo: 1234 }]) do
442
- error '/[2]/foo', 'Invalid type, expected "string".'
444
+ error '/[2]/foo', 'Invalid type, got type "Integer", expected "string".'
443
445
  end
444
446
  assert_validation(['foo', 42, { foo: 'String' }]) do
445
447
  error '/[2]/foo', 'String does not match format "date".'
@@ -555,16 +557,16 @@ module Schemacop
555
557
  # Even we put those types in the enum, they need to fail the validations,
556
558
  # as they are not arrays
557
559
  assert_validation('foo') do
558
- error '/', 'Invalid type, expected "array".'
560
+ error '/', ArrayNodeTest.invalid_type_error(String)
559
561
  end
560
562
  assert_validation(1) do
561
- error '/', 'Invalid type, expected "array".'
563
+ error '/', ArrayNodeTest.invalid_type_error(Integer)
562
564
  end
563
565
  assert_validation(:bar) do
564
- error '/', 'Invalid type, expected "array".'
566
+ error '/', ArrayNodeTest.invalid_type_error(Symbol)
565
567
  end
566
568
  assert_validation({ qux: 42 }) do
567
- error '/', 'Invalid type, expected "array".'
569
+ error '/', ArrayNodeTest.invalid_type_error(Hash)
568
570
  end
569
571
 
570
572
  # These need to fail validation, as they are not in the enum list
@@ -669,8 +671,8 @@ module Schemacop
669
671
  assert_validation([1, 2, 3, 4, 5, 6])
670
672
 
671
673
  assert_validation([1, :foo, 'bar']) do
672
- error '/[1]', 'Invalid type, expected "integer".'
673
- error '/[2]', 'Invalid type, expected "integer".'
674
+ error '/[1]', 'Invalid type, got type "Symbol", expected "integer".'
675
+ error '/[2]', 'Invalid type, got type "String", expected "integer".'
674
676
  end
675
677
  end
676
678
 
@@ -4,7 +4,10 @@ require 'test_helper'
4
4
  module Schemacop
5
5
  module V3
6
6
  class BooleanNodeTest < V3Test
7
- EXP_INVALID_TYPE = 'Invalid type, expected "boolean".'.freeze
7
+ def self.invalid_type_error(type)
8
+ type = type.class unless type.class == Class
9
+ "Invalid type, got type \"#{type}\", expected \"boolean\"."
10
+ end
8
11
 
9
12
  def test_basic
10
13
  schema :boolean
@@ -47,12 +50,12 @@ module Schemacop
47
50
  assert_json(type: :boolean)
48
51
 
49
52
  assert_validation 42 do
50
- error '/', EXP_INVALID_TYPE
53
+ error '/', BooleanNodeTest.invalid_type_error(Integer)
51
54
  end
52
55
 
53
56
  [:true, 'true', :false, 'false', 0, 1].each do |value|
54
57
  assert_validation value do
55
- error '/', EXP_INVALID_TYPE
58
+ error '/', BooleanNodeTest.invalid_type_error(value)
56
59
  end
57
60
  end
58
61
 
@@ -68,7 +71,7 @@ module Schemacop
68
71
 
69
72
  [:true, 'true', :false, 'false', 0, 1].each do |value|
70
73
  assert_validation name: value do
71
- error '/name', EXP_INVALID_TYPE
74
+ error '/name', BooleanNodeTest.invalid_type_error(value)
72
75
  end
73
76
  end
74
77
  end
@@ -87,13 +90,13 @@ module Schemacop
87
90
  # Even we put those types in the enum, they need to fail the validations,
88
91
  # as they are not booleans
89
92
  assert_validation('foo') do
90
- error '/', 'Invalid type, expected "boolean".'
93
+ error '/', BooleanNodeTest.invalid_type_error(String)
91
94
  end
92
95
  assert_validation(:bar) do
93
- error '/', 'Invalid type, expected "boolean".'
96
+ error '/', BooleanNodeTest.invalid_type_error(Symbol)
94
97
  end
95
98
  assert_validation({ qux: 42 }) do
96
- error '/', 'Invalid type, expected "boolean".'
99
+ error '/', BooleanNodeTest.invalid_type_error(Hash)
97
100
  end
98
101
 
99
102
  # These need to fail validation, as they are not in the enum list
@@ -3,8 +3,6 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class HashNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "hash".'.freeze
7
-
8
6
  def test_basic
9
7
  schema
10
8
  assert_validation({})
@@ -54,7 +52,7 @@ module Schemacop
54
52
 
55
53
  assert_validation(foo: 'bar', baz: 'foo', answer: '42')
56
54
  assert_validation(foo: 'bar', baz: 'foo', answer: 42) do
57
- error '/answer', 'Invalid type, expected "string".'
55
+ error '/answer', 'Invalid type, got type "Integer", expected "string".'
58
56
  end
59
57
 
60
58
  assert_json(
@@ -70,7 +68,7 @@ module Schemacop
70
68
  @schema.validate!({ foo: 'foo' })
71
69
  end
72
70
 
73
- assert_raises_with_message Exceptions::ValidationError, '/bar: Invalid type, expected "string".' do
71
+ assert_raises_with_message Exceptions::ValidationError, '/bar: Invalid type, got type "Symbol", expected "string".' do
74
72
  @schema.validate!({ foo: 'foo', bar: :baz })
75
73
  end
76
74
  end
@@ -247,7 +245,7 @@ module Schemacop
247
245
 
248
246
  assert_validation(name: 'John', xy: 'John', bar_baz: 'Doe') do
249
247
  error '/', 'Obsolete property "xy".'
250
- error '/bar_baz', 'Invalid type, expected "integer".'
248
+ error '/bar_baz', 'Invalid type, got type "String", expected "integer".'
251
249
  end
252
250
 
253
251
  assert_json(
@@ -276,7 +274,7 @@ module Schemacop
276
274
  assert_validation(keyword: 'value')
277
275
 
278
276
  assert_validation(keyword: 42) do
279
- error '/keyword', 'Invalid type, expected "string".'
277
+ error '/keyword', 'Invalid type, got type "Integer", expected "string".'
280
278
  end
281
279
 
282
280
  assert_json(
@@ -759,10 +757,10 @@ module Schemacop
759
757
  # Even we put those types in the enum, they need to fail the validations,
760
758
  # as they are not strings
761
759
  assert_validation({ foo: 123 }) do
762
- error '/foo', 'Invalid type, expected "string".'
760
+ error '/foo', 'Invalid type, got type "Integer", expected "string".'
763
761
  end
764
762
  assert_validation({ foo: :faz }) do
765
- error '/foo', 'Invalid type, expected "string".'
763
+ error '/foo', 'Invalid type, got type "Symbol", expected "string".'
766
764
  end
767
765
 
768
766
  # These need to fail validation, as they are not in the enum list
@@ -918,7 +916,7 @@ module Schemacop
918
916
  end
919
917
 
920
918
  assert_validation({ foo: '13' }) do
921
- error '/foo', 'Invalid type, expected "integer".'
919
+ error '/foo', 'Invalid type, got type "String", expected "integer".'
922
920
  end
923
921
 
924
922
  assert_cast(nil, nil)
@@ -937,7 +935,7 @@ module Schemacop
937
935
  assert_validation({ foo: 42, bar: 13 })
938
936
 
939
937
  assert_validation({ foo: '13' }) do
940
- error '/foo', 'Invalid type, expected "integer".'
938
+ error '/foo', 'Invalid type, got type "String", expected "integer".'
941
939
  end
942
940
 
943
941
  # assert_cast(nil, nil)
@@ -959,7 +957,7 @@ module Schemacop
959
957
  end
960
958
 
961
959
  assert_validation({ foo: '13' }) do
962
- error '/foo', 'Invalid type, expected "integer".'
960
+ error '/foo', 'Invalid type, got type "String", expected "integer".'
963
961
  end
964
962
 
965
963
  assert_cast(nil, nil)
@@ -3,7 +3,9 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class IntegerNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "integer".'.freeze
6
+ def self.invalid_type_error(type)
7
+ "Invalid type, got type \"#{type}\", expected \"integer\"."
8
+ end
7
9
 
8
10
  def test_basic
9
11
  schema :integer
@@ -59,11 +61,11 @@ module Schemacop
59
61
  )
60
62
 
61
63
  assert_validation 42.5 do
62
- error '/', EXP_INVALID_TYPE
64
+ error '/', IntegerNodeTest.invalid_type_error(Float)
63
65
  end
64
66
 
65
67
  assert_validation '42.5' do
66
- error '/', EXP_INVALID_TYPE
68
+ error '/', IntegerNodeTest.invalid_type_error(String)
67
69
  end
68
70
 
69
71
  schema { int! :age }
@@ -78,27 +80,27 @@ module Schemacop
78
80
  )
79
81
 
80
82
  assert_validation age: :foo do
81
- error '/age', EXP_INVALID_TYPE
83
+ error '/age', IntegerNodeTest.invalid_type_error(Symbol)
82
84
  end
83
85
 
84
86
  assert_validation age: '234' do
85
- error '/age', EXP_INVALID_TYPE
87
+ error '/age', IntegerNodeTest.invalid_type_error(String)
86
88
  end
87
89
 
88
90
  assert_validation age: 10.0 do
89
- error '/age', EXP_INVALID_TYPE
91
+ error '/age', IntegerNodeTest.invalid_type_error(Float)
90
92
  end
91
93
 
92
94
  assert_validation age: 4r do
93
- error '/age', EXP_INVALID_TYPE
95
+ error '/age', IntegerNodeTest.invalid_type_error(Rational)
94
96
  end
95
97
 
96
98
  assert_validation age: (4 + 0i) do
97
- error '/age', EXP_INVALID_TYPE
99
+ error '/age', IntegerNodeTest.invalid_type_error(Complex)
98
100
  end
99
101
 
100
102
  assert_validation age: BigDecimal(5) do
101
- error '/age', EXP_INVALID_TYPE
103
+ error '/age', IntegerNodeTest.invalid_type_error(BigDecimal)
102
104
  end
103
105
  end
104
106
 
@@ -210,7 +212,7 @@ module Schemacop
210
212
  assert_validation(nil)
211
213
  assert_validation(50)
212
214
  assert_validation(5.2) do
213
- error '/', 'Invalid type, expected "integer".'
215
+ error '/', IntegerNodeTest.invalid_type_error(Float)
214
216
  end
215
217
 
216
218
  assert_cast(5, 5)
@@ -289,18 +291,18 @@ module Schemacop
289
291
  # Even we put those types in the enum, they need to fail the validations,
290
292
  # as they are not integers
291
293
  assert_validation('foo') do
292
- error '/', 'Invalid type, expected "integer".'
294
+ error '/', IntegerNodeTest.invalid_type_error(String)
293
295
  end
294
296
  assert_validation(:bar) do
295
- error '/', 'Invalid type, expected "integer".'
297
+ error '/', IntegerNodeTest.invalid_type_error(Symbol)
296
298
  end
297
299
  assert_validation({ qux: 42 }) do
298
- error '/', 'Invalid type, expected "integer".'
300
+ error '/', IntegerNodeTest.invalid_type_error(Hash)
299
301
  end
300
302
 
301
303
  # This needs to fail as it is a number (float) and not an integer
302
304
  assert_validation(4.2) do
303
- error '/', 'Invalid type, expected "integer".'
305
+ error '/', IntegerNodeTest.invalid_type_error(Float)
304
306
  end
305
307
 
306
308
  # These need to fail validation, as they are not in the enum list
@@ -3,7 +3,9 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class NumberNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "big_decimal" or "float" or "integer" or "rational".'.freeze
6
+ def self.invalid_type_error(type)
7
+ "Invalid type, got type \"#{type}\", expected \"big_decimal\" or \"float\" or \"integer\" or \"rational\"."
8
+ end
7
9
 
8
10
  def test_basic
9
11
  schema :number
@@ -16,7 +18,7 @@ module Schemacop
16
18
  assert_validation(BigDecimal(6))
17
19
 
18
20
  assert_validation((6 + 0i)) do
19
- error '/', EXP_INVALID_TYPE
21
+ error '/', NumberNodeTest.invalid_type_error(Complex)
20
22
  end
21
23
 
22
24
  assert_json(type: :number)
@@ -52,7 +54,7 @@ module Schemacop
52
54
  assert_validation [30.3, 42.0]
53
55
  assert_validation [30, 30r, 30.0, BigDecimal(30)]
54
56
  assert_validation ['30.3', 30.3] do
55
- error '/[0]', EXP_INVALID_TYPE
57
+ error '/[0]', NumberNodeTest.invalid_type_error(String)
56
58
  end
57
59
  end
58
60
 
@@ -64,17 +66,17 @@ module Schemacop
64
66
  )
65
67
 
66
68
  assert_validation '42.5' do
67
- error '/', EXP_INVALID_TYPE
69
+ error '/', NumberNodeTest.invalid_type_error(String)
68
70
  end
69
71
 
70
72
  schema { num! :age }
71
73
 
72
74
  assert_validation age: :foo do
73
- error '/age', EXP_INVALID_TYPE
75
+ error '/age', NumberNodeTest.invalid_type_error(Symbol)
74
76
  end
75
77
 
76
78
  assert_validation age: '234' do
77
- error '/age', EXP_INVALID_TYPE
79
+ error '/age', NumberNodeTest.invalid_type_error(String)
78
80
  end
79
81
  end
80
82
 
@@ -261,13 +263,13 @@ module Schemacop
261
263
  # Even we put those types in the enum, they need to fail the validations,
262
264
  # as they are not numbers
263
265
  assert_validation('foo') do
264
- error '/', EXP_INVALID_TYPE
266
+ error '/', NumberNodeTest.invalid_type_error(String)
265
267
  end
266
268
  assert_validation(:bar) do
267
- error '/', EXP_INVALID_TYPE
269
+ error '/', NumberNodeTest.invalid_type_error(Symbol)
268
270
  end
269
271
  assert_validation({ qux: 42 }) do
270
- error '/', EXP_INVALID_TYPE
272
+ error '/', NumberNodeTest.invalid_type_error(Hash)
271
273
  end
272
274
 
273
275
  # These need to fail validation, as they are not in the enum list
@@ -28,10 +28,10 @@ module Schemacop
28
28
  assert_validation 'foo'
29
29
  assert_validation Date.today
30
30
  assert_validation({}.with_indifferent_access) do
31
- error '/', 'Invalid type, expected "Date" or "String".'
31
+ error '/', 'Invalid type, got type "ActiveSupport::HashWithIndifferentAccess", expected "Date" or "String".'
32
32
  end
33
33
  assert_validation DateTime.now do
34
- error '/', 'Invalid type, expected "Date" or "String".'
34
+ error '/', 'Invalid type, got type "DateTime", expected "Date" or "String".'
35
35
  end
36
36
  end
37
37
 
@@ -44,7 +44,7 @@ module Schemacop
44
44
  assert_validation DateTime.now
45
45
  assert_validation({}.with_indifferent_access)
46
46
  assert_validation Time.now do
47
- error '/', 'Invalid type, expected "Date" or "Hash" or "String".'
47
+ error '/', 'Invalid type, got type "Time", expected "Date" or "Hash" or "String".'
48
48
  end
49
49
  end
50
50
 
@@ -74,7 +74,7 @@ module Schemacop
74
74
  assert_validation myobj: ''
75
75
  assert_validation myobj: '42'
76
76
  assert_validation myobj: Date.today do
77
- error '/myobj', 'Invalid type, expected "String".'
77
+ error '/myobj', 'Invalid type, got type "Date", expected "String".'
78
78
  end
79
79
  assert_validation({}) do
80
80
  error '/myobj', 'Value must be given.'
@@ -134,13 +134,13 @@ module Schemacop
134
134
 
135
135
  # These will fail, as they aren't of one of the classed we defined above
136
136
  assert_validation([]) do
137
- error '/', 'Invalid type, expected "String" or "Symbol" or "TrueClass".'
137
+ error '/', 'Invalid type, got type "Array", expected "String" or "Symbol" or "TrueClass".'
138
138
  end
139
139
  assert_validation({ qux: '123' }) do
140
- error '/', 'Invalid type, expected "String" or "Symbol" or "TrueClass".'
140
+ error '/', 'Invalid type, got type "Hash", expected "String" or "Symbol" or "TrueClass".'
141
141
  end
142
142
  assert_validation(false) do
143
- error '/', 'Invalid type, expected "String" or "Symbol" or "TrueClass".'
143
+ error '/', 'Invalid type, got type "FalseClass", expected "String" or "Symbol" or "TrueClass".'
144
144
  end
145
145
  end
146
146
 
@@ -26,13 +26,13 @@ module Schemacop
26
26
  assert_validation(bar: { foo: 'String', baz: { foo: 42 } })
27
27
 
28
28
  assert_validation(foo: 42) do
29
- error '/foo', 'Invalid type, expected "string".'
29
+ error '/foo', 'Invalid type, got type "Integer", expected "string".'
30
30
  end
31
31
  assert_validation(bar: { foo: 42 }) do
32
- error '/bar/foo', 'Invalid type, expected "string".'
32
+ error '/bar/foo', 'Invalid type, got type "Integer", expected "string".'
33
33
  end
34
34
  assert_validation(bar: { foo: 'String', baz: { foo: '42' } }) do
35
- error '/bar/baz/foo', 'Invalid type, expected "integer".'
35
+ error '/bar/baz/foo', 'Invalid type, got type "String", expected "integer".'
36
36
  end
37
37
 
38
38
  assert_json({
@@ -306,7 +306,7 @@ module Schemacop
306
306
  with_context context do
307
307
  assert_validation(first_name: 'John', last_name: 'Doe')
308
308
  assert_validation(first_name: 'John', last_name: 42) do
309
- error '/last_name', 'Invalid type, expected "string".'
309
+ error '/last_name', 'Invalid type, got type "Integer", expected "string".'
310
310
  end
311
311
  end
312
312
 
@@ -3,7 +3,9 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class StringNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "string".'.freeze
6
+ def self.invalid_type_error(type)
7
+ "Invalid type, got type \"#{type}\", expected \"string\"."
8
+ end
7
9
 
8
10
  def test_basic
9
11
  schema :string
@@ -33,7 +35,7 @@ module Schemacop
33
35
  assert_json(type: :string)
34
36
 
35
37
  assert_validation 42 do
36
- error '/', EXP_INVALID_TYPE
38
+ error '/', StringNodeTest.invalid_type_error(Integer)
37
39
  end
38
40
 
39
41
  schema { str! :name }
@@ -41,11 +43,11 @@ module Schemacop
41
43
  assert_json(type: :object, properties: { name: { type: :string } }, required: %i[name], additionalProperties: false)
42
44
 
43
45
  assert_validation name: :foo do
44
- error '/name', EXP_INVALID_TYPE
46
+ error '/name', StringNodeTest.invalid_type_error(Symbol)
45
47
  end
46
48
 
47
49
  assert_validation name: 234 do
48
- error '/name', EXP_INVALID_TYPE
50
+ error '/name', StringNodeTest.invalid_type_error(Integer)
49
51
  end
50
52
  end
51
53
 
@@ -190,7 +192,7 @@ module Schemacop
190
192
  assert_validation ''
191
193
 
192
194
  assert_validation 234 do
193
- error '/', 'Invalid type, expected "string".'
195
+ error '/', StringNodeTest.invalid_type_error(Integer)
194
196
  end
195
197
 
196
198
  assert_cast(nil, nil)
@@ -218,7 +220,7 @@ module Schemacop
218
220
  # Integer value 42 is in the enum of allowed values, but it's not a string,
219
221
  # so the validation still fails
220
222
  assert_validation 42 do
221
- error '/', 'Invalid type, expected "string".'
223
+ error '/', StringNodeTest.invalid_type_error(Integer)
222
224
  end
223
225
  end
224
226
 
@@ -278,7 +280,7 @@ module Schemacop
278
280
  assert_validation(nil)
279
281
  assert_validation('Foo')
280
282
  assert_validation(5) do
281
- error '/', 'Invalid type, expected "string".'
283
+ error '/', StringNodeTest.invalid_type_error(Integer)
282
284
  end
283
285
 
284
286
  assert_cast('Foo', 'Foo')
@@ -297,7 +299,7 @@ module Schemacop
297
299
  assert_validation(nil)
298
300
  assert_validation('123')
299
301
  assert_validation(5) do
300
- error '/', 'Invalid type, expected "string".'
302
+ error '/', StringNodeTest.invalid_type_error(Integer)
301
303
  end
302
304
 
303
305
  assert_cast('123', 123)
@@ -364,13 +366,13 @@ module Schemacop
364
366
  # Even we put those types in the enum, they need to fail the validations,
365
367
  # as they are not strings
366
368
  assert_validation(1) do
367
- error '/', 'Invalid type, expected "string".'
369
+ error '/', StringNodeTest.invalid_type_error(Integer)
368
370
  end
369
371
  assert_validation(:bar) do
370
- error '/', 'Invalid type, expected "string".'
372
+ error '/', StringNodeTest.invalid_type_error(Symbol)
371
373
  end
372
374
  assert_validation({ qux: 42 }) do
373
- error '/', 'Invalid type, expected "string".'
375
+ error '/', StringNodeTest.invalid_type_error(Hash)
374
376
  end
375
377
 
376
378
  # These need to fail validation, as they are not in the enum list
@@ -3,7 +3,10 @@ require 'test_helper'
3
3
  module Schemacop
4
4
  module V3
5
5
  class SymbolNodeTest < V3Test
6
- EXP_INVALID_TYPE = 'Invalid type, expected "Symbol".'.freeze
6
+ def self.invalid_type_error(type)
7
+ type = type.class unless type.class == Class
8
+ "Invalid type, got type \"#{type}\", expected \"Symbol\"."
9
+ end
7
10
 
8
11
  def test_basic
9
12
  schema :symbol
@@ -11,10 +14,10 @@ module Schemacop
11
14
  assert_validation :foo
12
15
  assert_validation :'n0238n)Q(hqr3hrw3'
13
16
  assert_validation 42 do
14
- error '/', EXP_INVALID_TYPE
17
+ error '/', SymbolNodeTest.invalid_type_error(Integer)
15
18
  end
16
19
  assert_validation '42' do
17
- error '/', EXP_INVALID_TYPE
20
+ error '/', SymbolNodeTest.invalid_type_error(String)
18
21
  end
19
22
  assert_json({})
20
23
  end
@@ -56,13 +59,13 @@ module Schemacop
56
59
  # Even we put those types in the enum, they need to fail the validations,
57
60
  # as they are not symbols
58
61
  assert_validation('foo') do
59
- error '/', 'Invalid type, expected "Symbol".'
62
+ error '/', SymbolNodeTest.invalid_type_error(String)
60
63
  end
61
64
  assert_validation(1) do
62
- error '/', 'Invalid type, expected "Symbol".'
65
+ error '/', SymbolNodeTest.invalid_type_error(Integer)
63
66
  end
64
67
  assert_validation({ qux: 42 }) do
65
- error '/', 'Invalid type, expected "Symbol".'
68
+ error '/', SymbolNodeTest.invalid_type_error(Hash)
66
69
  end
67
70
 
68
71
  # These need to fail validation, as they are not in the enum list
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemacop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
294
  requirements: []
295
- rubygems_version: 3.0.3
295
+ rubygems_version: 3.1.2
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: Schemacop validates ruby structures consisting of nested hashes and arrays