schemacop 3.0.9 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.13
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-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -170,10 +170,10 @@ executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
+ - ".github/workflows/ruby.yml"
173
174
  - ".gitignore"
174
175
  - ".releaser_config"
175
176
  - ".rubocop.yml"
176
- - ".travis.yml"
177
177
  - ".yardopts"
178
178
  - CHANGELOG.md
179
179
  - Gemfile
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.2
4
- - 2.7.1
5
- - 3.0.0
6
- script:
7
- - bundle install
8
- - bundle exec rake test
9
- - bundle exec rubocop