dry-validation 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -8
  3. data/CHANGELOG.md +34 -1
  4. data/Gemfile +2 -0
  5. data/Rakefile +12 -3
  6. data/config/errors.yml +1 -0
  7. data/dry-validation.gemspec +3 -2
  8. data/lib/dry/validation/executor.rb +3 -27
  9. data/lib/dry/validation/extensions/monads.rb +17 -0
  10. data/lib/dry/validation/extensions/struct.rb +32 -0
  11. data/lib/dry/validation/extensions.rb +7 -0
  12. data/lib/dry/validation/input_processor_compiler.rb +19 -3
  13. data/lib/dry/validation/message.rb +43 -30
  14. data/lib/dry/validation/message_compiler/visitor_opts.rb +39 -0
  15. data/lib/dry/validation/message_compiler.rb +98 -52
  16. data/lib/dry/validation/message_set.rb +59 -30
  17. data/lib/dry/validation/predicate_registry.rb +17 -6
  18. data/lib/dry/validation/result.rb +39 -17
  19. data/lib/dry/validation/schema/check.rb +5 -4
  20. data/lib/dry/validation/schema/class_interface.rb +6 -13
  21. data/lib/dry/validation/schema/dsl.rb +9 -3
  22. data/lib/dry/validation/schema/form.rb +12 -3
  23. data/lib/dry/validation/schema/json.rb +12 -3
  24. data/lib/dry/validation/schema/key.rb +6 -6
  25. data/lib/dry/validation/schema/rule.rb +14 -8
  26. data/lib/dry/validation/schema/value.rb +23 -21
  27. data/lib/dry/validation/schema.rb +9 -12
  28. data/lib/dry/validation/schema_compiler.rb +16 -2
  29. data/lib/dry/validation/version.rb +1 -1
  30. data/lib/dry/validation.rb +11 -23
  31. data/spec/extensions/monads/result_spec.rb +38 -0
  32. data/spec/extensions/struct/schema_spec.rb +32 -0
  33. data/spec/integration/custom_predicates_spec.rb +7 -6
  34. data/spec/integration/form/predicates/size/fixed_spec.rb +0 -2
  35. data/spec/integration/form/predicates/size/range_spec.rb +0 -2
  36. data/spec/integration/hints_spec.rb +2 -6
  37. data/spec/integration/json/defining_base_schema_spec.rb +41 -0
  38. data/spec/integration/{error_compiler_spec.rb → message_compiler_spec.rb} +79 -131
  39. data/spec/integration/result_spec.rb +26 -4
  40. data/spec/integration/schema/check_with_nested_el_spec.rb +1 -1
  41. data/spec/integration/schema/check_with_nth_el_spec.rb +1 -1
  42. data/spec/integration/schema/defining_base_schema_spec.rb +3 -0
  43. data/spec/integration/schema/dynamic_predicate_args_spec.rb +34 -9
  44. data/spec/integration/schema/form/defining_base_schema_spec.rb +41 -0
  45. data/spec/integration/schema/json_spec.rb +1 -0
  46. data/spec/integration/schema/macros/input_spec.rb +26 -0
  47. data/spec/integration/schema/macros/rule_spec.rb +2 -1
  48. data/spec/integration/schema/macros/value_spec.rb +1 -1
  49. data/spec/integration/schema/macros/when_spec.rb +1 -24
  50. data/spec/integration/schema/or_spec.rb +87 -0
  51. data/spec/integration/schema/predicates/custom_spec.rb +4 -4
  52. data/spec/integration/schema/predicates/even_spec.rb +10 -10
  53. data/spec/integration/schema/predicates/odd_spec.rb +10 -10
  54. data/spec/integration/schema/predicates/size/fixed_spec.rb +0 -3
  55. data/spec/integration/schema/predicates/size/range_spec.rb +0 -2
  56. data/spec/integration/schema/predicates/type_spec.rb +22 -0
  57. data/spec/integration/schema/using_types_spec.rb +14 -41
  58. data/spec/integration/schema/validate_spec.rb +83 -0
  59. data/spec/integration/schema/xor_spec.rb +5 -5
  60. data/spec/integration/schema_builders_spec.rb +4 -2
  61. data/spec/integration/schema_spec.rb +8 -0
  62. data/spec/shared/message_compiler.rb +11 -0
  63. data/spec/shared/predicate_helper.rb +5 -3
  64. data/spec/spec_helper.rb +15 -0
  65. data/spec/unit/input_processor_compiler/form_spec.rb +3 -3
  66. data/spec/unit/message_compiler/visit_failure_spec.rb +38 -0
  67. data/spec/unit/message_compiler/visit_spec.rb +16 -0
  68. data/spec/unit/message_compiler_spec.rb +7 -0
  69. data/spec/unit/predicate_registry_spec.rb +2 -2
  70. data/spec/unit/schema/key_spec.rb +19 -12
  71. data/spec/unit/schema/rule_spec.rb +14 -6
  72. data/spec/unit/schema/value_spec.rb +49 -52
  73. metadata +50 -20
  74. data/lib/dry/validation/constants.rb +0 -6
  75. data/lib/dry/validation/error.rb +0 -26
  76. data/lib/dry/validation/error_compiler.rb +0 -81
  77. data/lib/dry/validation/hint_compiler.rb +0 -104
  78. data/spec/unit/error_compiler_spec.rb +0 -7
  79. data/spec/unit/hint_compiler_spec.rb +0 -51
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  RSpec.describe Dry::Validation do
2
3
  shared_context 'uses custom predicates' do
3
4
  it 'uses provided custom predicates' do
@@ -29,7 +30,7 @@ RSpec.describe Dry::Validation do
29
30
  module Predicates
30
31
  include Dry::Logic::Predicates
31
32
 
32
- predicate(:email?) do |input|
33
+ def self.email?(input)
33
34
  input.include?('@') # for the lols
34
35
  end
35
36
  end
@@ -37,16 +38,16 @@ RSpec.describe Dry::Validation do
37
38
  end
38
39
 
39
40
  context 'when configured globally' do
40
- before do
41
- Dry::Validation::Schema.predicates(Test::Predicates)
42
- end
43
-
44
- subject!(:schema) do
41
+ subject(:schema) do
45
42
  Dry::Validation.Schema(base_class) do
46
43
  required(:email) { filled? & email? }
47
44
  end
48
45
  end
49
46
 
47
+ before do
48
+ Dry::Validation::Schema.predicates(Test::Predicates)
49
+ end
50
+
50
51
  after do
51
52
  # HACK: reset global predicates configuration
52
53
  Dry::Validation::Schema.configure do |config|
@@ -181,7 +181,6 @@ RSpec.describe 'Predicates: Size' do
181
181
  let(:input) { { 'foo' => '' } }
182
182
 
183
183
  it 'is not successful' do
184
- pending
185
184
  expect(result).to be_failing ['must be filled', 'length must be 3']
186
185
  end
187
186
  end
@@ -328,7 +327,6 @@ RSpec.describe 'Predicates: Size' do
328
327
  let(:input) { { 'foo' => '' } }
329
328
 
330
329
  it 'is not successful' do
331
- pending
332
330
  expect(result).to be_failing ['must be filled', 'length must be 3']
333
331
  end
334
332
  end
@@ -183,7 +183,6 @@ RSpec.describe 'Predicates: Size' do
183
183
  let(:input) { { 'foo' => '' } }
184
184
 
185
185
  it 'is not successful' do
186
- pending
187
186
  expect(result).to be_failing ['must be filled', 'length must be within 2 - 3']
188
187
  end
189
188
  end
@@ -331,7 +330,6 @@ RSpec.describe 'Predicates: Size' do
331
330
  let(:input) { { 'foo' => '' } }
332
331
 
333
332
  it 'is not successful' do
334
- pending
335
333
  expect(result).to be_failing ['must be filled', 'length must be within 2 - 3']
336
334
  end
337
335
  end
@@ -18,9 +18,7 @@ RSpec.describe 'Validation hints' do
18
18
  context 'with yaml messages' do
19
19
  subject(:schema) do
20
20
  Dry::Validation.Schema do
21
- required(:age) do |age|
22
- age.none? | (age.int? & age.gt?(18))
23
- end
21
+ required(:age).maybe(:int?, gt?: 18)
24
22
  end
25
23
  end
26
24
 
@@ -32,9 +30,7 @@ RSpec.describe 'Validation hints' do
32
30
  Dry::Validation.Schema do
33
31
  configure { configure { |c| c.messages = :i18n } }
34
32
 
35
- required(:age) do |age|
36
- age.none? | (age.int? & age.gt?(18))
37
- end
33
+ required(:age).maybe(:int?, gt?: 18)
38
34
  end
39
35
  end
40
36
 
@@ -0,0 +1,41 @@
1
+ require 'dry/validation/messages/i18n'
2
+ require 'i18n'
3
+
4
+ RSpec.describe 'Defining base schema class' do
5
+ subject(:schema) do
6
+ Dry::Validation.JSON(BaseSchema) do
7
+ required(:email).filled(:email?)
8
+ end
9
+ end
10
+
11
+ before do
12
+ class BaseSchema < Dry::Validation::Schema
13
+ configure do |config|
14
+ config.messages_file = SPEC_ROOT.join('fixtures/locales/en.yml')
15
+ config.messages = :i18n
16
+ end
17
+
18
+ def email?(value)
19
+ true
20
+ end
21
+
22
+ define! do
23
+ required(:name).filled
24
+ end
25
+ end
26
+ end
27
+
28
+ after do
29
+ Object.send(:remove_const, :BaseSchema)
30
+ end
31
+
32
+ it 'inherits predicates' do
33
+ expect(schema).to respond_to(:email?)
34
+ end
35
+
36
+ it 'inherits rules' do
37
+ expect(schema.('name' => '').messages).to eql(
38
+ name: ['must be filled'], email: ['is missing', 'must be an email']
39
+ )
40
+ end
41
+ end
@@ -1,8 +1,7 @@
1
- require 'dry/validation/messages'
2
- require 'dry/validation/error_compiler'
1
+ require 'dry/validation/message_compiler'
3
2
 
4
- RSpec.describe Dry::Validation::ErrorCompiler do
5
- subject(:error_compiler) { ErrorCompiler.new(messages) }
3
+ RSpec.describe Dry::Validation::MessageCompiler do
4
+ subject(:message_compiler) { MessageCompiler.new(messages) }
6
5
 
7
6
  include_context 'predicate helper'
8
7
 
@@ -39,16 +38,16 @@ RSpec.describe Dry::Validation::ErrorCompiler do
39
38
  describe '#call with flat inputs' do
40
39
  let(:ast) do
41
40
  [
42
- [:error, [:name, [:input, [:name, [:result, [nil, [:val, p(:key?, :name)]]]]]]],
43
- [:error, [:gender, [:input, [:gender, [:result, [nil, [:val, p(:key?, :gender)]]]]]]],
44
- [:error, [:age, [:input, [:age, [:result, [18, [:val, p(:gt?, 18)]]]]]]],
45
- [:error, [:email, [:input, [:email, [:result, ["", [:val, p(:filled?)]]]]]]],
46
- [:error, [:address, [:input, [:address, [:result, ["", [:val, p(:filled?)]]]]]]]
41
+ [:failure, [:name, p(:key?, :name)]],
42
+ [:failure, [:gender, p(:key?, :gender)]],
43
+ [:key, [:age, [:failure, [:age, p(:gt?, 18)]]]],
44
+ [:key, [:email, [:failure, [:email, p(:filled?, '')]]]],
45
+ [:key, [:address, [:failure, [:address, p(:filled?, '')]]]]
47
46
  ]
48
47
  end
49
48
 
50
49
  it 'converts error ast into another format' do
51
- expect(error_compiler.(ast).to_h).to eql(
50
+ expect(message_compiler.(ast).to_h).to eql(
52
51
  name: ["+name+ key is missing in the hash"],
53
52
  gender: ["Please provide your gender"],
54
53
  age: ["must be greater than 18"],
@@ -58,62 +57,11 @@ RSpec.describe Dry::Validation::ErrorCompiler do
58
57
  end
59
58
  end
60
59
 
61
- describe '#call with check errors' do
62
- let(:ast) do
63
- [[:error, [:newsletter, [
64
- :input, [[:settings, :newsletter], [
65
- :result, [
66
- [true, true],
67
- [
68
- :check, [
69
- :newsletter,
70
- [:implication, [
71
- [:key, [[:settings, :offers], p(:true?)]],
72
- [:key, [[:settings, :newsletter], p(:false?)]]]
73
- ]
74
- ]
75
- ]
76
- ]
77
- ]
78
- ]]]
79
- ]]
80
- end
81
-
82
- it 'converts error ast into another format' do
83
- expect(error_compiler.(ast).to_h).to eql(
84
- settings: { newsletter: ['must be false'] }
85
- )
86
- end
87
- end
88
-
89
- describe '#call with arr inputs' do
90
- let(:ast) do
91
- [[:error, [:payments,
92
- [:input, [
93
- :payments, [:result, [
94
- [{ method: "cc", amount: 1.23 }, { amount: 4.56 }], [:each, [
95
- [:el, [
96
- 1, [
97
- :result, [{ amount: 4.56 }, [:val, p(:key?, :method)]]
98
- ]
99
- ]]
100
- ]]]
101
- ]]]
102
- ]]]
103
- end
104
-
105
- it 'converts error ast into another format' do
106
- expect(error_compiler.(ast).to_h).to eql(
107
- payments: { 1 => { method: ['+method+ key is missing in the hash'] } }
108
- )
109
- end
110
- end
111
-
112
60
  describe '#visit with an :input node' do
113
61
  context 'full message' do
114
62
  it 'returns full message including rule name' do
115
- msg = error_compiler.with(full: true).visit(
116
- [:input, [:num, [:result, ['2', [:val, p(:int?)]]]]]
63
+ msg = message_compiler.with(full: true).visit(
64
+ [:failure, [:num, [:key, [:num, p(:int?, '2')]]]]
117
65
  )
118
66
 
119
67
  expect(msg).to eql('num must be an integer')
@@ -122,8 +70,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
122
70
 
123
71
  context 'rule name translations' do
124
72
  it 'translates rule name and its message' do
125
- msg = error_compiler.with(locale: :pl, full: true).visit(
126
- [:input, [:email, [:result, ['oops', [:val, p(:email?)]]]]]
73
+ msg = message_compiler.with(locale: :pl, full: true).visit(
74
+ [:failure, [:email, [:key, [:email, p(:email?, 'oops')]]]]
127
75
  )
128
76
 
129
77
  expect(msg).to eql('adres email nie jest poprawny')
@@ -132,8 +80,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
132
80
 
133
81
  describe ':empty?' do
134
82
  it 'returns valid message' do
135
- msg = error_compiler.visit(
136
- [:input, [:tags, [:result, [nil, [:val, p(:empty?)]]]]]
83
+ msg = message_compiler.visit(
84
+ [:failure, [:tags, [:key, [:tags, p(:empty?, nil)]]]]
137
85
  )
138
86
 
139
87
  expect(msg).to eql('must be empty')
@@ -142,8 +90,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
142
90
 
143
91
  describe ':excluded_from?' do
144
92
  it 'returns valid message' do
145
- msg = error_compiler.visit(
146
- [:input, [:num, [:result, [2, [:val, p(:excluded_from?, [1, 2, 3])]]]]]
93
+ msg = message_compiler.visit(
94
+ [:failure, [:num, [:key, [:num, p(:excluded_from?, [1, 2, 3], 2)]]]]
147
95
  )
148
96
 
149
97
  expect(msg).to eql('must not be one of: 1, 2, 3')
@@ -152,8 +100,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
152
100
 
153
101
  describe ':excludes?' do
154
102
  it 'returns valid message' do
155
- msg = error_compiler.visit(
156
- [:input, [:array, [:result, [[1, 2, 3], [:val, p(:excludes?, 2)]]]]]
103
+ msg = message_compiler.visit(
104
+ [:failure, [:array, [:key, [:array, p(:excludes?, 2, [1, 2])]]]]
157
105
  )
158
106
 
159
107
  expect(msg).to eql('must not include 2')
@@ -162,8 +110,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
162
110
 
163
111
  describe ':included_in?' do
164
112
  it 'returns valid message' do
165
- msg = error_compiler.visit(
166
- [:input, [:num, [:result, [2, [:val, p(:included_in?, [1, 2, 3])]]]]]
113
+ msg = message_compiler.visit(
114
+ [:failure, [:num, [:key, [:num, p(:included_in?, [1, 2, 3], :num)]]]]
167
115
  )
168
116
 
169
117
  expect(msg).to eql('must be one of: 1, 2, 3')
@@ -172,8 +120,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
172
120
 
173
121
  describe ':includes?' do
174
122
  it 'returns valid message' do
175
- msg = error_compiler.visit(
176
- [:input, [:num, [:result, [[1, 2, 3], [:val, p(:includes?, 2)]]]]]
123
+ msg = message_compiler.visit(
124
+ [:failure, [:num, [:key, [:num, p(:includes?, 2, [1])]]]]
177
125
  )
178
126
 
179
127
  expect(msg).to eql('must include 2')
@@ -182,8 +130,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
182
130
 
183
131
  describe ':gt?' do
184
132
  it 'returns valid message' do
185
- msg = error_compiler.visit(
186
- [:input, [:num, [:result, [2, [:val, p(:gt?, 3)]]]]]
133
+ msg = message_compiler.visit(
134
+ [:failure, [:num, [:key, [:num, p(:gt?, 3, 2)]]]]
187
135
  )
188
136
 
189
137
  expect(msg).to eql('must be greater than 3')
@@ -192,8 +140,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
192
140
 
193
141
  describe ':gteq?' do
194
142
  it 'returns valid message' do
195
- msg = error_compiler.visit(
196
- [:input, [:num, [:result, [2, [:val, p(:gteq?, 3)]]]]]
143
+ msg = message_compiler.visit(
144
+ [:failure, [:num, [:key, [:num, p(:gteq?, 3, 2)]]]]
197
145
  )
198
146
 
199
147
  expect(msg).to eql('must be greater than or equal to 3')
@@ -202,8 +150,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
202
150
 
203
151
  describe ':lt?' do
204
152
  it 'returns valid message' do
205
- msg = error_compiler.visit(
206
- [:input, [:num, [:result, [2, [:val, p(:lt?, 3)]]]]]
153
+ msg = message_compiler.visit(
154
+ [:failure, [:num, [:key, [:num, p(:lt?, 3, 2)]]]]
207
155
  )
208
156
 
209
157
  expect(msg).to eql('must be less than 3')
@@ -212,8 +160,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
212
160
 
213
161
  describe ':lteq?' do
214
162
  it 'returns valid message' do
215
- msg = error_compiler.visit(
216
- [:input, [:num, [:result, [2, [:val, p(:lteq?, 3)]]]]]
163
+ msg = message_compiler.visit(
164
+ [:failure, [:num, [:key, [:num, p(:lteq?, 3, 2)]]]]
217
165
  )
218
166
 
219
167
  expect(msg).to eql('must be less than or equal to 3')
@@ -222,8 +170,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
222
170
 
223
171
  describe ':hash?' do
224
172
  it 'returns valid message' do
225
- msg = error_compiler.visit(
226
- [:input, [:address, [:result, ['', [:val, p(:hash?, [])]]]]]
173
+ msg = message_compiler.visit(
174
+ [:failure, [:address, [:key, [:address, p(:hash?, '')]]]]
227
175
  )
228
176
 
229
177
  expect(msg).to eql('must be a hash')
@@ -232,8 +180,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
232
180
 
233
181
  describe ':array?' do
234
182
  it 'returns valid message' do
235
- msg = error_compiler.visit(
236
- [:input, [:phone_numbers, [:result, ['', [:val, p(:array?)]]]]]
183
+ msg = message_compiler.visit(
184
+ [:failure, [:phone_numbers, [:key, [:phone, p(:array?,'')]]]]
237
185
  )
238
186
 
239
187
  expect(msg).to eql('must be an array')
@@ -242,8 +190,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
242
190
 
243
191
  describe ':int?' do
244
192
  it 'returns valid message' do
245
- msg = error_compiler.visit(
246
- [:input, [:num, [:result, ['2', [:val, p(:int?)]]]]]
193
+ msg = message_compiler.visit(
194
+ [:failure, [:num, [:key, [:num, p(:int?, '2')]]]]
247
195
  )
248
196
 
249
197
  expect(msg).to eql('must be an integer')
@@ -252,8 +200,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
252
200
 
253
201
  describe ':float?' do
254
202
  it 'returns valid message' do
255
- msg = error_compiler.visit(
256
- [:input, [:num, [:result, ['2', [:val, p(:float?)]]]]]
203
+ msg = message_compiler.visit(
204
+ [:failure, [:num, [:key, [:num, p(:float?, '2')]]]]
257
205
  )
258
206
 
259
207
  expect(msg).to eql('must be a float')
@@ -262,8 +210,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
262
210
 
263
211
  describe ':decimal?' do
264
212
  it 'returns valid message' do
265
- msg = error_compiler.visit(
266
- [:input, [:num, [:result, ['2', [:val, p(:decimal?)]]]]]
213
+ msg = message_compiler.visit(
214
+ [:failure, [:num, [:key, [:num, p(:decimal?, '2')]]]]
267
215
  )
268
216
 
269
217
  expect(msg).to eql('must be a decimal')
@@ -272,8 +220,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
272
220
 
273
221
  describe ':date?' do
274
222
  it 'returns valid message' do
275
- msg = error_compiler.visit(
276
- [:input, [:num, [:result, ['2', [:val, p(:date?)]]]]]
223
+ msg = message_compiler.visit(
224
+ [:failure, [:num, [:key, [:num, p(:date?, '2')]]]]
277
225
  )
278
226
 
279
227
  expect(msg).to eql('must be a date')
@@ -282,8 +230,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
282
230
 
283
231
  describe ':date_time?' do
284
232
  it 'returns valid message' do
285
- msg = error_compiler.visit(
286
- [:input, [:num, [:result, ['2', [:val, p(:date_time?)]]]]]
233
+ msg = message_compiler.visit(
234
+ [:failure, [:num, [:key, [:num, p(:date_time?, '2')]]]]
287
235
  )
288
236
 
289
237
  expect(msg).to eql('must be a date time')
@@ -292,8 +240,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
292
240
 
293
241
  describe ':time?' do
294
242
  it 'returns valid message' do
295
- msg = error_compiler.visit(
296
- [:input, [:num, [:result, ['2', [:val, p(:time?)]]]]]
243
+ msg = message_compiler.visit(
244
+ [:failure, [:num, [:key, [:num, p(:time?, '2')]]]]
297
245
  )
298
246
 
299
247
  expect(msg).to eql('must be a time')
@@ -302,8 +250,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
302
250
 
303
251
  describe ':max_size?' do
304
252
  it 'returns valid message' do
305
- msg = error_compiler.visit(
306
- [:input, [:num, [:result, ['abcd', [:val, p(:max_size?, 3)]]]]]
253
+ msg = message_compiler.visit(
254
+ [:failure, [:num, [:key, [:num, p(:max_size?, 3, 'abcd')]]]]
307
255
  )
308
256
 
309
257
  expect(msg).to eql('size cannot be greater than 3')
@@ -312,8 +260,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
312
260
 
313
261
  describe ':min_size?' do
314
262
  it 'returns valid message' do
315
- msg = error_compiler.visit(
316
- [:input, [:num, [:result, ['ab', [:val, p(:min_size?, 3)]]]]]
263
+ msg = message_compiler.visit(
264
+ [:failure, [:num, [:key, [:num, p(:min_size?, 3, 'ab')]]]]
317
265
  )
318
266
 
319
267
  expect(msg).to eql('size cannot be less than 3')
@@ -322,8 +270,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
322
270
 
323
271
  describe ':none?' do
324
272
  it 'returns valid message' do
325
- msg = error_compiler.visit(
326
- [:input, [:num, [:result, [nil, [:val, p(:none?)]]]]]
273
+ msg = message_compiler.visit(
274
+ [:failure, [:num, [:key, [:num, p(:none?, nil)]]]]
327
275
  )
328
276
 
329
277
  expect(msg).to eql('cannot be defined')
@@ -332,32 +280,32 @@ RSpec.describe Dry::Validation::ErrorCompiler do
332
280
 
333
281
  describe ':size?' do
334
282
  it 'returns valid message when val is array and arg is int' do
335
- msg = error_compiler.visit(
336
- [:input, [:numbers, [:result, [[1], [:val, p(:size?, 3)]]]]]
283
+ msg = message_compiler.visit(
284
+ [:failure, [:numbers, [:key, [:numbers, p(:size?, 3, [1])]]]]
337
285
  )
338
286
 
339
287
  expect(msg).to eql('size must be 3')
340
288
  end
341
289
 
342
290
  it 'returns valid message when val is array and arg is range' do
343
- msg = error_compiler.visit(
344
- [:input, [:numbers, [:result, [[1], [:val, p(:size?, 3..4)]]]]]
291
+ msg = message_compiler.visit(
292
+ [:failure, [:numbers, [:key, [:numbers, p(:size?, 3..4, [1])]]]]
345
293
  )
346
294
 
347
295
  expect(msg).to eql('size must be within 3 - 4')
348
296
  end
349
297
 
350
298
  it 'returns valid message when arg is int' do
351
- msg = error_compiler.visit(
352
- [:input, [:num, [:result, ['ab', [:val, p(:size?, 3)]]]]]
299
+ msg = message_compiler.visit(
300
+ [:failure, [:num, [:key, [:num, p(:size?, 3, 'ab')]]]]
353
301
  )
354
302
 
355
303
  expect(msg).to eql('length must be 3')
356
304
  end
357
305
 
358
306
  it 'returns valid message when arg is range' do
359
- msg = error_compiler.visit(
360
- [:input, [:num, [:result, ['ab', [:val, p(:size?, 3..4)]]]]]
307
+ msg = message_compiler.visit(
308
+ [:failure, [:num, [:key, [:num, p(:size?, 3..4, 'ab')]]]]
361
309
  )
362
310
 
363
311
  expect(msg).to eql('length must be within 3 - 4')
@@ -366,8 +314,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
366
314
 
367
315
  describe ':str?' do
368
316
  it 'returns valid message' do
369
- msg = error_compiler.visit(
370
- [:input, [:num, [:result, [3, [:val, p(:str?)]]]]]
317
+ msg = message_compiler.visit(
318
+ [:failure, [:num, [:key, [:num, p(:str?, 3)]]]]
371
319
  )
372
320
 
373
321
  expect(msg).to eql('must be a string')
@@ -376,8 +324,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
376
324
 
377
325
  describe ':bool?' do
378
326
  it 'returns valid message' do
379
- msg = error_compiler.visit(
380
- [:input, [:num, [:result, [3, [:val, p(:bool?)]]]]]
327
+ msg = message_compiler.visit(
328
+ [:failure, [:num, [:key, [:num, p(:bool?, 3)]]]]
381
329
  )
382
330
 
383
331
  expect(msg).to eql('must be boolean')
@@ -386,8 +334,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
386
334
 
387
335
  describe ':format?' do
388
336
  it 'returns valid message' do
389
- msg = error_compiler.visit(
390
- [:input, [:str, [:result, ['Bar', [:val, p(:format?, /^F/)]]]]]
337
+ msg = message_compiler.visit(
338
+ [:failure, [:str, [:key, [:str, p(:format?, /^F/, 'Bar')]]]]
391
339
  )
392
340
 
393
341
  expect(msg).to eql('is in invalid format')
@@ -396,8 +344,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
396
344
 
397
345
  describe ':number?' do
398
346
  it 'returns valid message' do
399
- msg = error_compiler.visit(
400
- [:input, [:str, [:result, ["not a number", [:val, p(:number?)]]]]]
347
+ msg = message_compiler.visit(
348
+ [:failure, [:str, [:key, [:str, p(:number?, 'not a number')]]]]
401
349
  )
402
350
 
403
351
  expect(msg).to eql('must be a number')
@@ -406,8 +354,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
406
354
 
407
355
  describe ':odd?' do
408
356
  it 'returns valid message' do
409
- msg = error_compiler.visit(
410
- [:input, [:str, [:result, [1, [:val, p(:odd?)]]]]]
357
+ msg = message_compiler.visit(
358
+ [:failure, [:str, [:key, [:str, p(:odd?, 1)]]]]
411
359
  )
412
360
 
413
361
  expect(msg).to eql('must be odd')
@@ -416,8 +364,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
416
364
 
417
365
  describe ':even?' do
418
366
  it 'returns valid message' do
419
- msg = error_compiler.visit(
420
- [:input, [:str, [:result, [2, [:val, p(:even?)]]]]]
367
+ msg = message_compiler.visit(
368
+ [:failure, [:str, [:key, [:str, p(:even?, 2)]]]]
421
369
  )
422
370
 
423
371
  expect(msg).to eql('must be even')
@@ -426,8 +374,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
426
374
 
427
375
  describe ':eql?' do
428
376
  it 'returns valid message' do
429
- msg = error_compiler.visit(
430
- [:input, [:str, [:result, ['Foo', [:val, p(:eql?, 'Bar')]]]]]
377
+ msg = message_compiler.visit(
378
+ [:failure, [:str, [:key, [:str, p(:eql?, 'Bar', 'Foo')]]]]
431
379
  )
432
380
 
433
381
  expect(msg).to eql('must be equal to Bar')
@@ -436,8 +384,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
436
384
 
437
385
  describe ':not_eql?' do
438
386
  it 'returns valid message' do
439
- msg = error_compiler.visit(
440
- [:input, [:str, [:result, ['Foo', [:val, p(:not_eql?, 'Foo')]]]]]
387
+ msg = message_compiler.visit(
388
+ [:failure, [:str, [:key, [:str, p(:not_eql?, 'Foo', 'Foo')]]]]
441
389
  )
442
390
 
443
391
  expect(msg).to eql('must not be equal to Foo')
@@ -446,8 +394,8 @@ RSpec.describe Dry::Validation::ErrorCompiler do
446
394
 
447
395
  describe ':type?' do
448
396
  it 'returns valid message' do
449
- msg = error_compiler.visit(
450
- [:input, [:age, [:result, ['1', [:val, p(:type?, Integer)]]]]]
397
+ msg = message_compiler.visit(
398
+ [:failure, [:age, [:key, [:age, p(:type?, Integer, '1')]]]]
451
399
  )
452
400
 
453
401
  expect(msg).to eql('must be Integer')