schemacop 2.3.1 → 2.3.2

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: 27aa765ae3ba6709966f68e8e8f1bb5b5ee1c6fc00825fc76115646867fc022b
4
- data.tar.gz: 72a475d6ade1b525a9aaa57db7af3d4583910399c6c09fa34e8642dbd141e686
3
+ metadata.gz: f276c94be15a6c27b4c690e71cafe375db73b53984a700205a9b4a78024a31da
4
+ data.tar.gz: 82dabde2bd0e6fc7fb06a5ebef3b4cf2065e718a0c27bb419960199b9898b145
5
5
  SHA512:
6
- metadata.gz: bacfdb8c8716bf645fbf1b1a13652f5329dd3dc54e4f051bc1b20483913876f732ecfc599e5caad1e61a017e088de8750e688ba07a713f1bde3a6a3f7cd29dee
7
- data.tar.gz: 8aed666238204bbb9d9ee809fdc0c1584c6d60dc41cb84f466105e81e0bbf5d556d7c835d90582058f17f90287c641c96872bcfc1e1aa8218045ad3d693e1476
6
+ metadata.gz: 6bb7bcb290cffe2bdf0089e98dc977a2d6d90458875cd89d84756cd3749bfd925fa5ff1987fa4b19ad1c89cee52944385d7e84ea8e8dea417db8c7cb007a4507
7
+ data.tar.gz: 3d3122e09ff0aaed4605daec77228afbf38b02e604c0498bb8cd8c7a6bb5a8d17914378ba580f72d6e0155cef4dfa3b192689f7bf6a259d1efd8be82831ce746
@@ -10,6 +10,12 @@
10
10
  ### Changes
11
11
  -->
12
12
 
13
+ ## 2.3.2 (2019-09-26)
14
+
15
+ ### New features
16
+
17
+ * Add ability to return custom error messages from `:check` blocks
18
+
13
19
  ## 2.3.1 (2019-08-19)
14
20
 
15
21
  ### Changes
data/README.md CHANGED
@@ -203,8 +203,8 @@ the type checking, meaning that it only gets executed if the data has the right
203
203
  type and the proc in `if` (if any) has returned true.
204
204
 
205
205
  The proc passed to the `check` option is given the data being analyzed. It is to
206
- return true if the data passes the custom check. If it returns false, Schemacop
207
- considers the data to be invalid.
206
+ return true if the data passes the custom check. If it returns false or an error
207
+ message as a string, Schemacop considers the data to be invalid.
208
208
 
209
209
  The following example illustrates the use of the option `check`: Consider a
210
210
  scenario in which you want the following rule set:
@@ -224,6 +224,17 @@ end
224
224
  The above Type Line has type `:string` and two options (`min` and `check`). The
225
225
  option `min` is supported by the `:string` validator (covered later).
226
226
 
227
+ You can also specify a custom error message by returning a string:
228
+
229
+
230
+ ```ruby
231
+ Schema.new do
232
+ type :integer, check: proc { |i| i.even? ? true : 'Custom error' }
233
+ end
234
+ ```
235
+
236
+ This will include `Custom error` in the validation error message.
237
+
227
238
  ### Field Line
228
239
 
229
240
  Inside a Type Line of type `:hash`, you may specify an arbitrary number of field
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.2
@@ -109,7 +109,7 @@
109
109
  </div>
110
110
 
111
111
  <div id="footer">
112
- Generated on Mon Aug 19 12:55:07 2019 by
112
+ Generated on Thu Sep 26 13:19:46 2019 by
113
113
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
114
114
  0.9.20 (ruby-2.6.2).
115
115
  </div>
@@ -319,7 +319,7 @@
319
319
  </div>
320
320
 
321
321
  <div id="footer">
322
- Generated on Mon Aug 19 12:55:07 2019 by
322
+ Generated on Thu Sep 26 13:19:47 2019 by
323
323
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
324
324
  0.9.20 (ruby-2.6.2).
325
325
  </div>
@@ -135,7 +135,7 @@
135
135
  </div>
136
136
 
137
137
  <div id="footer">
138
- Generated on Mon Aug 19 12:55:08 2019 by
138
+ Generated on Thu Sep 26 13:19:47 2019 by
139
139
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140
140
  0.9.20 (ruby-2.6.2).
141
141
  </div>
@@ -701,7 +701,7 @@ called.</p>
701
701
  </div>
702
702
 
703
703
  <div id="footer">
704
- Generated on Mon Aug 19 12:55:07 2019 by
704
+ Generated on Thu Sep 26 13:19:46 2019 by
705
705
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
706
706
  0.9.20 (ruby-2.6.2).
707
707
  </div>
@@ -105,7 +105,7 @@
105
105
  </div>
106
106
 
107
107
  <div id="footer">
108
- Generated on Mon Aug 19 12:55:07 2019 by
108
+ Generated on Thu Sep 26 13:19:46 2019 by
109
109
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
110
  0.9.20 (ruby-2.6.2).
111
111
  </div>
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <div id="footer">
117
- Generated on Mon Aug 19 12:55:07 2019 by
117
+ Generated on Thu Sep 26 13:19:46 2019 by
118
118
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
119
  0.9.20 (ruby-2.6.2).
120
120
  </div>
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <div id="footer">
117
- Generated on Mon Aug 19 12:55:07 2019 by
117
+ Generated on Thu Sep 26 13:19:46 2019 by
118
118
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
119
  0.9.20 (ruby-2.6.2).
120
120
  </div>
@@ -399,7 +399,7 @@
399
399
  </div>
400
400
 
401
401
  <div id="footer">
402
- Generated on Mon Aug 19 12:55:07 2019 by
402
+ Generated on Thu Sep 26 13:19:46 2019 by
403
403
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
404
404
  0.9.20 (ruby-2.6.2).
405
405
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Mon Aug 19 12:55:07 2019 by
151
+ Generated on Thu Sep 26 13:19:47 2019 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.9.20 (ruby-2.6.2).
154
154
  </div>
@@ -279,7 +279,7 @@
279
279
  </div>
280
280
 
281
281
  <div id="footer">
282
- Generated on Mon Aug 19 12:55:07 2019 by
282
+ Generated on Thu Sep 26 13:19:47 2019 by
283
283
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
284
284
  0.9.20 (ruby-2.6.2).
285
285
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Mon Aug 19 12:55:08 2019 by
151
+ Generated on Thu Sep 26 13:19:47 2019 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.9.20 (ruby-2.6.2).
154
154
  </div>
@@ -135,7 +135,7 @@
135
135
  </div>
136
136
 
137
137
  <div id="footer">
138
- Generated on Mon Aug 19 12:55:07 2019 by
138
+ Generated on Thu Sep 26 13:19:47 2019 by
139
139
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140
140
  0.9.20 (ruby-2.6.2).
141
141
  </div>
@@ -1416,7 +1416,7 @@
1416
1416
  </div>
1417
1417
 
1418
1418
  <div id="footer">
1419
- Generated on Mon Aug 19 12:55:07 2019 by
1419
+ Generated on Thu Sep 26 13:19:46 2019 by
1420
1420
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1421
1421
  0.9.20 (ruby-2.6.2).
1422
1422
  </div>
@@ -232,7 +232,7 @@
232
232
  </div>
233
233
 
234
234
  <div id="footer">
235
- Generated on Mon Aug 19 12:55:07 2019 by
235
+ Generated on Thu Sep 26 13:19:46 2019 by
236
236
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
237
237
  0.9.20 (ruby-2.6.2).
238
238
  </div>
@@ -580,7 +580,7 @@
580
580
  </div>
581
581
 
582
582
  <div id="footer">
583
- Generated on Mon Aug 19 12:55:07 2019 by
583
+ Generated on Thu Sep 26 13:19:47 2019 by
584
584
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
585
585
  0.9.20 (ruby-2.6.2).
586
586
  </div>
@@ -604,7 +604,7 @@ as it formerly was the case in the constructor.</p>
604
604
  </div>
605
605
 
606
606
  <div id="footer">
607
- Generated on Mon Aug 19 12:55:07 2019 by
607
+ Generated on Thu Sep 26 13:19:46 2019 by
608
608
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
609
609
  0.9.20 (ruby-2.6.2).
610
610
  </div>
@@ -279,7 +279,7 @@
279
279
  </div>
280
280
 
281
281
  <div id="footer">
282
- Generated on Mon Aug 19 12:55:07 2019 by
282
+ Generated on Thu Sep 26 13:19:46 2019 by
283
283
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
284
284
  0.9.20 (ruby-2.6.2).
285
285
  </div>
@@ -222,7 +222,7 @@
222
222
  </div>
223
223
 
224
224
  <div id="footer">
225
- Generated on Mon Aug 19 12:55:07 2019 by
225
+ Generated on Thu Sep 26 13:19:47 2019 by
226
226
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
227
227
  0.9.20 (ruby-2.6.2).
228
228
  </div>
@@ -288,7 +288,7 @@
288
288
  </div>
289
289
 
290
290
  <div id="footer">
291
- Generated on Mon Aug 19 12:55:08 2019 by
291
+ Generated on Thu Sep 26 13:19:47 2019 by
292
292
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
293
293
  0.9.20 (ruby-2.6.2).
294
294
  </div>
@@ -161,7 +161,7 @@
161
161
  </div>
162
162
 
163
163
  <div id="footer">
164
- Generated on Mon Aug 19 12:55:07 2019 by
164
+ Generated on Thu Sep 26 13:19:46 2019 by
165
165
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
166
166
  0.9.20 (ruby-2.6.2).
167
167
  </div>
@@ -687,7 +687,7 @@ this exception is thrown.</p>
687
687
  </div>
688
688
 
689
689
  <div id="footer">
690
- Generated on Mon Aug 19 12:55:07 2019 by
690
+ Generated on Thu Sep 26 13:19:46 2019 by
691
691
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
692
692
  0.9.20 (ruby-2.6.2).
693
693
  </div>
@@ -285,7 +285,7 @@
285
285
  </div>
286
286
 
287
287
  <div id="footer">
288
- Generated on Mon Aug 19 12:55:08 2019 by
288
+ Generated on Thu Sep 26 13:19:47 2019 by
289
289
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
290
290
  0.9.20 (ruby-2.6.2).
291
291
  </div>
@@ -135,7 +135,7 @@
135
135
  </div>
136
136
 
137
137
  <div id="footer">
138
- Generated on Mon Aug 19 12:55:08 2019 by
138
+ Generated on Thu Sep 26 13:19:47 2019 by
139
139
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140
140
  0.9.20 (ruby-2.6.2).
141
141
  </div>
@@ -341,7 +341,7 @@
341
341
  </div>
342
342
 
343
343
  <div id="footer">
344
- Generated on Mon Aug 19 12:55:07 2019 by
344
+ Generated on Thu Sep 26 13:19:46 2019 by
345
345
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
346
346
  0.9.20 (ruby-2.6.2).
347
347
  </div>
@@ -347,7 +347,7 @@
347
347
  </div>
348
348
 
349
349
  <div id="footer">
350
- Generated on Mon Aug 19 12:55:07 2019 by
350
+ Generated on Thu Sep 26 13:19:46 2019 by
351
351
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
352
352
  0.9.20 (ruby-2.6.2).
353
353
  </div>
@@ -256,8 +256,8 @@ the type checking, meaning that it only gets executed if the data has the right
256
256
  type and the proc in <code>if</code> (if any) has returned true.</p>
257
257
 
258
258
  <p>The proc passed to the <code>check</code> option is given the data being analyzed. It is to
259
- return true if the data passes the custom check. If it returns false, Schemacop
260
- considers the data to be invalid.</p>
259
+ return true if the data passes the custom check. If it returns false or an error
260
+ message as a string, Schemacop considers the data to be invalid.</p>
261
261
 
262
262
  <p>The following example illustrates the use of the option <code>check</code>: Consider a
263
263
  scenario in which you want the following rule set:</p>
@@ -278,6 +278,15 @@ scenario in which you want the following rule set:</p>
278
278
  <p>The above Type Line has type <code>:string</code> and two options (<code>min</code> and <code>check</code>). The
279
279
  option <code>min</code> is supported by the <code>:string</code> validator (covered later).</p>
280
280
 
281
+ <p>You can also specify a custom error message by returning a string:</p>
282
+
283
+ <pre class="code ruby"><code class="ruby"><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
284
+ <span class='id identifier rubyid_type'>type</span> <span class='symbol'>:integer</span><span class='comma'>,</span> <span class='label'>check:</span> <span class='id identifier rubyid_proc'>proc</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='op'>|</span> <span class='id identifier rubyid_i'>i</span><span class='period'>.</span><span class='id identifier rubyid_even?'>even?</span> <span class='op'>?</span> <span class='kw'>true</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Custom error</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
285
+ <span class='kw'>end</span>
286
+ </code></pre>
287
+
288
+ <p>This will include <code>Custom error</code> in the validation error message.</p>
289
+
281
290
  <h3>Field Line</h3>
282
291
 
283
292
  <p>Inside a Type Line of type <code>:hash</code>, you may specify an arbitrary number of field
@@ -626,7 +635,7 @@ to <a href="http://www.subgit.com/">SubGit</a> for their great open source licen
626
635
  </div></div>
627
636
 
628
637
  <div id="footer">
629
- Generated on Mon Aug 19 12:55:07 2019 by
638
+ Generated on Thu Sep 26 13:19:46 2019 by
630
639
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
631
640
  0.9.20 (ruby-2.6.2).
632
641
  </div>
@@ -256,8 +256,8 @@ the type checking, meaning that it only gets executed if the data has the right
256
256
  type and the proc in <code>if</code> (if any) has returned true.</p>
257
257
 
258
258
  <p>The proc passed to the <code>check</code> option is given the data being analyzed. It is to
259
- return true if the data passes the custom check. If it returns false, Schemacop
260
- considers the data to be invalid.</p>
259
+ return true if the data passes the custom check. If it returns false or an error
260
+ message as a string, Schemacop considers the data to be invalid.</p>
261
261
 
262
262
  <p>The following example illustrates the use of the option <code>check</code>: Consider a
263
263
  scenario in which you want the following rule set:</p>
@@ -278,6 +278,15 @@ scenario in which you want the following rule set:</p>
278
278
  <p>The above Type Line has type <code>:string</code> and two options (<code>min</code> and <code>check</code>). The
279
279
  option <code>min</code> is supported by the <code>:string</code> validator (covered later).</p>
280
280
 
281
+ <p>You can also specify a custom error message by returning a string:</p>
282
+
283
+ <pre class="code ruby"><code class="ruby"><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
284
+ <span class='id identifier rubyid_type'>type</span> <span class='symbol'>:integer</span><span class='comma'>,</span> <span class='label'>check:</span> <span class='id identifier rubyid_proc'>proc</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='op'>|</span> <span class='id identifier rubyid_i'>i</span><span class='period'>.</span><span class='id identifier rubyid_even?'>even?</span> <span class='op'>?</span> <span class='kw'>true</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Custom error</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
285
+ <span class='kw'>end</span>
286
+ </code></pre>
287
+
288
+ <p>This will include <code>Custom error</code> in the validation error message.</p>
289
+
281
290
  <h3>Field Line</h3>
282
291
 
283
292
  <p>Inside a Type Line of type <code>:hash</code>, you may specify an arbitrary number of field
@@ -626,7 +635,7 @@ to <a href="http://www.subgit.com/">SubGit</a> for their great open source licen
626
635
  </div></div>
627
636
 
628
637
  <div id="footer">
629
- Generated on Mon Aug 19 12:55:07 2019 by
638
+ Generated on Thu Sep 26 13:19:46 2019 by
630
639
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
631
640
  0.9.20 (ruby-2.6.2).
632
641
  </div>
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Mon Aug 19 12:55:07 2019 by
105
+ Generated on Thu Sep 26 13:19:46 2019 by
106
106
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.20 (ruby-2.6.2).
108
108
  </div>
@@ -119,8 +119,12 @@ module Schemacop
119
119
  protected
120
120
 
121
121
  def validate_custom_check(data, collector)
122
- if option?(:check) && !option(:check).call(data)
123
- collector.error 'Custom :check failed.'
122
+ if option?(:check) && (check_result = option(:check).call(data)) != true
123
+ if check_result.is_a?(String)
124
+ collector.error "Custom :check failed: #{check_result}."
125
+ else
126
+ collector.error 'Custom :check failed.'
127
+ end
124
128
  end
125
129
  end
126
130
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 2.3.1 ruby lib
2
+ # stub: schemacop 2.3.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "2.3.1"
6
+ s.version = "2.3.2"
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 = "2019-08-19"
11
+ s.date = "2019-09-26"
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, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "doc/Schemacop.html".freeze, "doc/Schemacop/ArrayValidator.html".freeze, "doc/Schemacop/BooleanValidator.html".freeze, "doc/Schemacop/Collector.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/collector.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/collector_test.rb".freeze, "test/custom_check_test.rb".freeze, "test/custom_if_test.rb".freeze, "test/nil_dis_allow_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]
13
13
  s.homepage = "https://github.com/sitrox/schemacop".freeze
14
14
  s.licenses = ["MIT".freeze]
@@ -12,6 +12,13 @@ module Schemacop
12
12
  assert_verr { s.validate!(2.1) }
13
13
  end
14
14
 
15
+ def test_custom_error_message
16
+ s = Schema.new :integer, check: proc { |i| i.even? ? true : 'Custom error' }
17
+ assert_nil s.validate!(2)
18
+ exception = assert_verr { s.validate!(3) }
19
+ assert_match(/Custom :check failed: Custom error\./, exception.message)
20
+ end
21
+
15
22
  def test_integer_check_with_lambda
16
23
  s = Schema.new do
17
24
  type :integer, check: ->(i) { i.even? }
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: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler