oval 0.0.6 → 0.0.7
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.
- checksums.yaml +7 -0
- data/CHANGELOG +5 -0
- data/Modulefile +1 -1
- data/README.md +106 -36
- data/lib/oval/match.rb +15 -4
- data/oval.gemspec +1 -1
- data/spec/unit/oval/match_spec.rb +2 -1
- data/spec/unit/oval_spec.rb +215 -0
- metadata +54 -155
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 122a3c31eab1e09c6a8c974fd7c6ae60ff7406ca9df2f3e992a5c2d0c716142f4fbfbb9916edf39b34011ee9b694e15347be763b72fbcaea48d9ce54a705d734
|
4
|
+
data.tar.gz: c0c39ef7355986b3cf9172a0b100684a257dad3ff5276b8a89978e3610705372fb700c85af0bf3881f4360666a2f691044f55089b69ebf6f4289552df8e6365a
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 3c13c5f753d31b5e21bd0c551a1ad84b2ab34108
|
7
|
+
data.tar.gz: 4d3c5c354ebe8920d852f46aef7a5018454db83c
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2014-02-09 Pawel Tomulik <ptomulik@meil.pw.edu.pl>
|
2
|
+
* release 0.0.7
|
3
|
+
* fixed match_spec.rb to work on 1.8 and 2.0
|
4
|
+
* revised examples in README.md and added specs to cover them
|
5
|
+
* fixed Oval::Match#validate to handle non-string TypeError
|
1
6
|
2014-02-08 Pawel Tomulik <ptomulik@meil.pw.edu.pl>
|
2
7
|
* release 0.0.6
|
3
8
|
* documented a way for validating arbitrary arguments
|
data/Modulefile
CHANGED
data/README.md
CHANGED
@@ -30,16 +30,16 @@ but it appeared early that it's suitable to validate arbitrary parameters
|
|
30
30
|
(variables).
|
31
31
|
|
32
32
|
The shape of acceptable data is described by a simple grammar. The validation
|
33
|
-
is then carried out by a recursive-descent parser
|
34
|
-
|
35
|
-
|
33
|
+
is then carried out by a recursive-descent parser which matches actual values
|
34
|
+
provided by caller to [declarators](#declarators) that comprise the declaration
|
35
|
+
of acceptable values.
|
36
36
|
|
37
|
-
A declaration consists of terminal and non-terminal declarators.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
A declaration consists of terminal and non-terminal declarators. Most *Oval*
|
38
|
+
methods with **ov_xxx** names are non-terminal declarators. All other values
|
39
|
+
(such as `:symbol`, `'string'`, `nil`, or `Class`) are terminals. Terminals use
|
40
|
+
`==` operator to match the values provided by caller. Non-terminal use its own
|
41
|
+
logic introducing more elaborate matching criteria (see for example
|
42
|
+
[ov\_collection](#ov_collection)).
|
43
43
|
|
44
44
|
**Oval** raises **Oval::DeclError** if the declaration is not well-formed. This
|
45
45
|
is raised from the point of declaration. Other, more common exception is the
|
@@ -167,10 +167,21 @@ In what follows, we'll document all the core declarators implemented in
|
|
167
167
|
- Example
|
168
168
|
|
169
169
|
```ruby
|
170
|
-
|
171
|
-
|
172
|
-
Oval
|
170
|
+
require 'oval'
|
171
|
+
class C
|
172
|
+
extend Oval
|
173
|
+
def self.ov
|
174
|
+
@oc = ov_options[ :bar => ov_anything ]
|
175
|
+
end
|
176
|
+
def self.foo(ops = {})
|
177
|
+
Oval.validate(ops, ov, 'ops')
|
178
|
+
end
|
173
179
|
end
|
180
|
+
C.foo() # should pass
|
181
|
+
C.foo :bar => 10 # should pass
|
182
|
+
C.foo :bar => nil # should pass
|
183
|
+
C.foo :bar => 'bar' # should pass
|
184
|
+
C.foo :foo => 10, :bar => 20 # Oval::ValueError "Invalid option :foo for ops. Allowed options are :bar"
|
174
185
|
```
|
175
186
|
|
176
187
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -198,13 +209,26 @@ In what follows, we'll document all the core declarators implemented in
|
|
198
209
|
- Example
|
199
210
|
|
200
211
|
```ruby
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
212
|
+
require 'oval'
|
213
|
+
class C
|
214
|
+
extend Oval
|
215
|
+
def self.ov_h
|
216
|
+
ov_collection[ Hash, { ov_instance_of[Symbol] => ov_anything } ]
|
217
|
+
end
|
218
|
+
def self.ov_a
|
219
|
+
ov_collection[ Array, ov_instance_of[String] ]
|
220
|
+
end
|
221
|
+
def self.foo(h, a)
|
222
|
+
Oval.validate(h, ov_h, 'h')
|
223
|
+
Oval.validate(a, ov_a, 'a')
|
224
|
+
end
|
207
225
|
end
|
226
|
+
C.foo({:x => 10}, ['xxx']) # Should bass
|
227
|
+
C.foo({:x => 10, :y => nil}, ['xxx', 'zzz']) # Should pass
|
228
|
+
C.foo(10,['xxx']) # Oval::ValueError, "Invalid value Fixnum for h.class. Should be equal Hash"
|
229
|
+
C.foo({:x => 10, 'y' => 20}, [ 'xxx' ]) # Oval::ValueError, 'Invalid object "y" of type String for h key. Should be an instance of Symbol'
|
230
|
+
C.foo({:x => 10}, 20) # Invalid value Fixnum for a.class. Should be equal Array
|
231
|
+
C.coo({:x => 10}, [ 'ten', 20 ]) # Oval::ValueError, "Invalid object 20 of type Fixnum for a[1]. Should be an instance of String"
|
208
232
|
```
|
209
233
|
|
210
234
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -222,10 +246,18 @@ In what follows, we'll document all the core declarators implemented in
|
|
222
246
|
- Example
|
223
247
|
|
224
248
|
```ruby
|
225
|
-
|
226
|
-
|
227
|
-
Oval
|
249
|
+
require 'oval'
|
250
|
+
class C
|
251
|
+
extend Oval
|
252
|
+
def self.ov
|
253
|
+
ov_instance_of[String]
|
254
|
+
end
|
255
|
+
def self.foo(s)
|
256
|
+
Oval.validate(s, ov, 's')
|
257
|
+
end
|
228
258
|
end
|
259
|
+
C.foo('bar') # Should pass
|
260
|
+
C.foo(10) # Oval::ValueError, "Invalid object 10 for s. Should be an instance of String"
|
229
261
|
```
|
230
262
|
|
231
263
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -243,10 +275,19 @@ In what follows, we'll document all the core declarators implemented in
|
|
243
275
|
- Example
|
244
276
|
|
245
277
|
```ruby
|
246
|
-
|
247
|
-
|
248
|
-
Oval
|
278
|
+
require 'oval'
|
279
|
+
class C
|
280
|
+
extend Oval
|
281
|
+
def self.ov
|
282
|
+
ov_kind_of[Numeric]
|
283
|
+
end
|
284
|
+
def self.foo(n)
|
285
|
+
Oval.validate(n, ov, 'n')
|
286
|
+
end
|
249
287
|
end
|
288
|
+
C.foo(10) # Should pass
|
289
|
+
C.foo(10.0) # Should pass
|
290
|
+
C.foo('10') # Oval::ValueError, 'Invalid object "10" of type String for n. Should be a kind of Numeric'
|
250
291
|
```
|
251
292
|
|
252
293
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -264,11 +305,20 @@ In what follows, we'll document all the core declarators implemented in
|
|
264
305
|
- Example
|
265
306
|
|
266
307
|
```ruby
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
308
|
+
require 'oval'
|
309
|
+
class C
|
310
|
+
extend Oval
|
311
|
+
def self.ov
|
312
|
+
# Only valid identifiers are allowed as :bar option
|
313
|
+
ov_match[/^[a-z_]\w+$/]
|
314
|
+
end
|
315
|
+
def self.foo(name)
|
316
|
+
Oval.validate(name, ov, 'name')
|
317
|
+
end
|
271
318
|
end
|
319
|
+
C.foo('var_23') # Should pass
|
320
|
+
C.foo(10) # Oval::ValueError, "Invalid value 10 for name. Should match /^[a-z_]\\w+$/ but it's not even convertible to String"
|
321
|
+
C.foo('10abc_') # Oval::ValueError, 'Invalid value "10abc_" for name. Should match /^[a-z_]\\w+$/'
|
272
322
|
```
|
273
323
|
|
274
324
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -285,12 +335,21 @@ In what follows, we'll document all the core declarators implemented in
|
|
285
335
|
- Example
|
286
336
|
|
287
337
|
```ruby
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
338
|
+
require 'oval'
|
339
|
+
class C
|
340
|
+
extend Oval
|
341
|
+
def self.ov
|
342
|
+
ov_one_of[ ov_instance_of[String], ov_kind_of[Numeric], nil ]
|
343
|
+
end
|
344
|
+
def self.foo(x)
|
345
|
+
Oval.validate(x, ov, 'x')
|
346
|
+
end
|
293
347
|
end
|
348
|
+
C.foo('str') # Should pass
|
349
|
+
C.foo(10) # Should pass
|
350
|
+
C.foo(10.0) # Should pass
|
351
|
+
C.foo(nil) # Should pass
|
352
|
+
C.foo([]) # Oval::ValueError, "Invalid value [] for x. Should be an instance of String, be a kind of Numeric or be equal nil"
|
294
353
|
```
|
295
354
|
|
296
355
|
[[Table of Contents](#table-of-contents)|[Index of Declarators](#index-of-declarators)]
|
@@ -334,10 +393,21 @@ In what follows, we'll document all the core declarators implemented in
|
|
334
393
|
- Example
|
335
394
|
|
336
395
|
```ruby
|
337
|
-
|
338
|
-
|
339
|
-
Oval
|
396
|
+
require 'oval'
|
397
|
+
class C
|
398
|
+
extend Oval
|
399
|
+
def self.ov
|
400
|
+
ov_options[ :bar => ov_subclass_of[Numeric] ]
|
401
|
+
end
|
402
|
+
def self.foo(ops = {})
|
403
|
+
Oval.validate(ops, ov, 'ops')
|
404
|
+
end
|
340
405
|
end
|
406
|
+
C.foo :bar => Integer # Should pass
|
407
|
+
C.foo :bar => Fixnum # Should pass
|
408
|
+
C.foo([]) # Oval::ValueError, "Invalid options [] of type Array. Should be a Hash
|
409
|
+
C.foo :foo => Fixnum # Oval::ValueError, "Invalid option :foo for ops. Allowed options are :bar"
|
410
|
+
C.foo :bar => 10 # Oval::ValueError, "Invalid class 10 for ops[:bar]. Should be subclass of Numeric"
|
341
411
|
```
|
342
412
|
|
343
413
|
###<a id="api-reference"></a>API Reference
|
data/lib/oval/match.rb
CHANGED
@@ -3,10 +3,21 @@ require 'oval/base'
|
|
3
3
|
class Oval::Match < Oval::Base
|
4
4
|
|
5
5
|
def validate(thing, subject = nil)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
begin
|
7
|
+
unless re.match(thing)
|
8
|
+
raise Oval::ValueError,
|
9
|
+
"Invalid value #{thing.inspect}#{for_subject(subject)}. " +
|
10
|
+
"Should #{it_should}"
|
11
|
+
end
|
12
|
+
rescue TypeError => err
|
13
|
+
ere = /(?:can't convert|no implicit conversion of) \S+ (?:in)?to String/
|
14
|
+
if ere.match(err.message)
|
15
|
+
raise Oval::ValueError,
|
16
|
+
"Invalid value #{thing.inspect}#{for_subject(subject)}. " +
|
17
|
+
"Should #{it_should} but it's not even convertible to String"
|
18
|
+
else
|
19
|
+
raise
|
20
|
+
end
|
10
21
|
end
|
11
22
|
end
|
12
23
|
|
data/oval.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = 'oval'
|
6
|
-
gem.version = '0.0.
|
6
|
+
gem.version = '0.0.7'
|
7
7
|
gem.authors = ["Pawel Tomulik"]
|
8
8
|
gem.email = ["ptomulik@meil.pw.edu.pl"]
|
9
9
|
gem.description = %q{Validate options when passed to methods}
|
@@ -82,7 +82,8 @@ describe Oval::Match do
|
|
82
82
|
[
|
83
83
|
[ /^[a-z_][a-z0-9_]+/, ['5643'], "Invalid value \"5643\". Should match #{(/^[a-z_][a-z0-9_]+/).inspect}" ],
|
84
84
|
[ /^[a-z_][a-z0-9_]+/, ['5643','subj'], "Invalid value \"5643\" for subj. Should match #{(/^[a-z_][a-z0-9_]+/).inspect}" ],
|
85
|
-
[ /^[a-z_][a-z0-9_]+/, [nil,'subj'], "Invalid value nil for subj. Should match #{(/^[a-z_][a-z0-9_]+/).inspect}" ]
|
85
|
+
[ /^[a-z_][a-z0-9_]+/, [nil,'subj'], "Invalid value nil for subj. Should match #{(/^[a-z_][a-z0-9_]+/).inspect}" ],
|
86
|
+
[ /^[a-z_][a-z0-9_]+/, [10,'subj'], "Invalid value 10 for subj. Should match #{(/^[a-z_][a-z0-9_]+/).inspect} but it's not even convertible to String" ]
|
86
87
|
].each do |re,args,msg|
|
87
88
|
context "#{described_class.name}[#{re.inspect}].validate(#{args.map{|x| x.inspect}.join(', ')})" do
|
88
89
|
let(:re) { re }
|
data/spec/unit/oval_spec.rb
CHANGED
@@ -63,6 +63,7 @@ describe Oval do
|
|
63
63
|
it { expect { subject.foo :foo => 10, :bar => 20 }.to raise_error Oval::ValueError, msg}
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
66
67
|
describe "Example 2" do
|
67
68
|
let(:subject) do
|
68
69
|
Class.new do
|
@@ -89,4 +90,218 @@ describe Oval do
|
|
89
90
|
it { expect { subject.foo :foo => 10, :bar => 20 }.to raise_error Oval::ValueError, msg}
|
90
91
|
end
|
91
92
|
end
|
93
|
+
|
94
|
+
describe "ov_anything example" do
|
95
|
+
let(:subject) do
|
96
|
+
Class.new do
|
97
|
+
extend Oval
|
98
|
+
def self.ov
|
99
|
+
@oc = ov_options[ :bar => ov_anything ]
|
100
|
+
end
|
101
|
+
def self.foo(ops = {})
|
102
|
+
Oval.validate(ops, ov, 'ops')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
it("should compile"){ subject }
|
107
|
+
context "foo" do
|
108
|
+
it { expect { subject.foo }.to_not raise_error }
|
109
|
+
end
|
110
|
+
[ 10, nil, "bar" ].each do |val|
|
111
|
+
context "foo :bar => #{val.inspect}" do
|
112
|
+
let(:val) { val }
|
113
|
+
it { expect { subject.foo :bar => val }.to_not raise_error }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context "foo :foo => 10, :bar => 20" do
|
117
|
+
let(:msg) { "Invalid option :foo for ops. Allowed options are :bar" }
|
118
|
+
it { expect { subject.foo :foo => 10, :bar => 20 }.to raise_error Oval::ValueError, msg}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "ov_collection example" do
|
123
|
+
let(:subject) do
|
124
|
+
Class.new do
|
125
|
+
extend Oval
|
126
|
+
def self.ov_h
|
127
|
+
ov_collection[ Hash, { ov_instance_of[Symbol] => ov_anything } ]
|
128
|
+
end
|
129
|
+
def self.ov_a
|
130
|
+
ov_collection[ Array, ov_instance_of[String] ]
|
131
|
+
end
|
132
|
+
def self.foo(h, a)
|
133
|
+
Oval.validate(h, ov_h, 'h')
|
134
|
+
Oval.validate(a, ov_a, 'a')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
it("should compile"){ subject }
|
139
|
+
[
|
140
|
+
[ {:x => 10}, [ 'xxx' ] ],
|
141
|
+
[ {:x => 10, :y => nil}, [ 'xxx', 'zzz' ] ]
|
142
|
+
].each do |args|
|
143
|
+
context "foo(#{args.map{|x| x.inspect}.join(', ')})" do
|
144
|
+
let(:args) { args}
|
145
|
+
it { expect { subject.foo(*args) }.to_not raise_error }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
context "foo(10,['xxx'])" do
|
149
|
+
let(:msg) { "Invalid value Fixnum for h.class. Should be equal Hash" }
|
150
|
+
it { expect { subject.foo(10,['xxx']) }.to raise_error Oval::ValueError, msg}
|
151
|
+
end
|
152
|
+
context "foo({:x => 10, 'y' => 20},['xxx'])" do
|
153
|
+
let(:msg) { 'Invalid object "y" of type String for h key. Should be an instance of Symbol' }
|
154
|
+
it { expect { subject.foo({:x => 10, 'y' => 20},['xxx']) }.to raise_error Oval::ValueError, msg}
|
155
|
+
end
|
156
|
+
context "foo({:x => 10},20)" do
|
157
|
+
let(:msg) { "Invalid value Fixnum for a.class. Should be equal Array" }
|
158
|
+
it { expect { subject.foo({:x => 10}, 20) }.to raise_error Oval::ValueError, msg}
|
159
|
+
end
|
160
|
+
context "foo({:x => 10},['ten', 20])" do
|
161
|
+
let(:msg) { "Invalid object 20 of type Fixnum for a[1]. Should be an instance of String" }
|
162
|
+
it { expect { subject.foo({:x => 10}, ['ten', 20]) }.to raise_error Oval::ValueError, msg}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "ov_instance_of example" do
|
167
|
+
let(:subject) do
|
168
|
+
Class.new do
|
169
|
+
extend Oval
|
170
|
+
def self.ov
|
171
|
+
ov_instance_of[String]
|
172
|
+
end
|
173
|
+
def self.foo(s)
|
174
|
+
Oval.validate(s, ov, 's')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
it("should compile"){ subject }
|
179
|
+
context "foo('bar')" do
|
180
|
+
it { expect { subject.foo('bar') }.to_not raise_error }
|
181
|
+
end
|
182
|
+
context "foo(10)" do
|
183
|
+
let(:msg) { "Invalid object 10 for s. Should be an instance of String" }
|
184
|
+
it { expect { subject.foo('bar') }.to_not raise_error }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "ov_kind_of example" do
|
189
|
+
let(:subject) do
|
190
|
+
Class.new do
|
191
|
+
extend Oval
|
192
|
+
def self.ov
|
193
|
+
ov_kind_of[Numeric]
|
194
|
+
end
|
195
|
+
def self.foo(n)
|
196
|
+
Oval.validate(n, ov, 'n')
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
it("should compile"){ subject }
|
201
|
+
context "foo(10)" do
|
202
|
+
it { expect { subject.foo(10) }.to_not raise_error }
|
203
|
+
end
|
204
|
+
context "foo(10.0)" do
|
205
|
+
it { expect { subject.foo(10.0) }.to_not raise_error }
|
206
|
+
end
|
207
|
+
context "foo('10')" do
|
208
|
+
let(:msg) { 'Invalid object "10" of type String for n. Should be a kind of Numeric' }
|
209
|
+
it { expect { subject.foo('10') }.to raise_error Oval::ValueError, msg}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "ov_match example" do
|
214
|
+
let(:subject) do
|
215
|
+
Class.new do
|
216
|
+
extend Oval
|
217
|
+
def self.ov
|
218
|
+
# Only valid identifiers are allowed as :bar option
|
219
|
+
ov_match[/^[a-z_]\w+$/]
|
220
|
+
end
|
221
|
+
def self.foo(name)
|
222
|
+
Oval.validate(name, ov, 'name')
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
it("should compile"){ subject }
|
227
|
+
context "foo('var_23')" do
|
228
|
+
it { expect { subject.foo('var_23') }.to_not raise_error }
|
229
|
+
end
|
230
|
+
context "foo(10)" do
|
231
|
+
let(:msg) { "Invalid value 10 for name. Should match /^[a-z_]\\w+$/ but it's not even convertible to String" }
|
232
|
+
it { expect { subject.foo(10) }.to raise_error Oval::ValueError, msg}
|
233
|
+
end
|
234
|
+
context "foo('10abc_')" do
|
235
|
+
let(:msg) { 'Invalid value "10abc_" for name. Should match /^[a-z_]\\w+$/' }
|
236
|
+
it { expect { subject.foo('10abc_') }.to raise_error Oval::ValueError, msg}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "ov_one_of example" do
|
241
|
+
let(:subject) do
|
242
|
+
Class.new do
|
243
|
+
extend Oval
|
244
|
+
def self.ov
|
245
|
+
ov_one_of[ ov_instance_of[String], ov_kind_of[Numeric], nil ]
|
246
|
+
end
|
247
|
+
def self.foo(x)
|
248
|
+
Oval.validate(x, ov, 'x')
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
it("should compile"){ subject }
|
253
|
+
context "foo('str')" do
|
254
|
+
it { expect { subject.foo('str') }.to_not raise_error }
|
255
|
+
end
|
256
|
+
context "foo(10)" do
|
257
|
+
it { expect { subject.foo(10) }.to_not raise_error }
|
258
|
+
end
|
259
|
+
context "foo(10.0)" do
|
260
|
+
it { expect { subject.foo(10.0) }.to_not raise_error }
|
261
|
+
end
|
262
|
+
context "foo(nil)" do
|
263
|
+
it { expect { subject.foo(nil) }.to_not raise_error }
|
264
|
+
end
|
265
|
+
context "foo([])" do
|
266
|
+
let(:msg) { 'Invalid value [] for x. Should be an instance of String, be a kind of Numeric or be equal nil' }
|
267
|
+
it { expect { subject.foo([]) }.to raise_error Oval::ValueError, msg}
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe "ov_options example" do
|
272
|
+
let(:subject) do
|
273
|
+
Class.new do
|
274
|
+
extend Oval
|
275
|
+
def self.ov
|
276
|
+
ov_options[ :bar => ov_subclass_of[Numeric] ]
|
277
|
+
end
|
278
|
+
def self.foo(ops = {})
|
279
|
+
Oval.validate(ops, ov, 'ops')
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
it("should compile"){ subject }
|
284
|
+
context "foo" do
|
285
|
+
it { expect { subject.foo }.to_not raise_error }
|
286
|
+
end
|
287
|
+
context "foo :bar => Integer" do
|
288
|
+
it { expect { subject.foo :bar => Integer }.to_not raise_error }
|
289
|
+
end
|
290
|
+
context "foo :bar => Fixnum" do
|
291
|
+
it { expect { subject.foo :bar => Fixnum }.to_not raise_error }
|
292
|
+
end
|
293
|
+
context "foo([])" do
|
294
|
+
let(:msg) { 'Invalid options [] of type Array. Should be a Hash' }
|
295
|
+
it { expect { subject.foo([]) }.to raise_error Oval::ValueError, msg}
|
296
|
+
end
|
297
|
+
context "foo :foo => Fixnum" do
|
298
|
+
let(:msg) { 'Invalid option :foo for ops. Allowed options are :bar' }
|
299
|
+
it { expect { subject.foo :foo => Fixnum }.to raise_error Oval::ValueError, msg}
|
300
|
+
end
|
301
|
+
context "foo :bar => 10" do
|
302
|
+
let(:msg) { 'Invalid class 10 for ops[:bar]. Should be subclass of Numeric' }
|
303
|
+
it { expect { subject.foo :bar => 10 }.to raise_error Oval::ValueError, msg}
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
92
307
|
end
|
metadata
CHANGED
@@ -1,151 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: oval
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Pawel Tomulik
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
date: 2014-02-09 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rspec-core
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec-expectations
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
16
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: mocha
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: coveralls
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- &id002
|
20
|
+
- ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
86
23
|
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-core
|
87
27
|
prerelease: false
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: yard
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
28
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- *id002
|
102
31
|
type: :development
|
32
|
+
version_requirements: *id003
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec-expectations
|
103
35
|
prerelease: false
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: redcarpet
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
36
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- *id002
|
118
39
|
type: :development
|
40
|
+
version_requirements: *id004
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
119
43
|
prerelease: false
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: github-markup
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ! '>='
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '0'
|
44
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- *id002
|
134
47
|
type: :development
|
135
|
-
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ! '>='
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '0'
|
48
|
+
version_requirements: *id005
|
142
49
|
description: Validate options when passed to methods
|
143
|
-
email:
|
50
|
+
email:
|
144
51
|
- ptomulik@meil.pw.edu.pl
|
145
52
|
executables: []
|
53
|
+
|
146
54
|
extensions: []
|
55
|
+
|
147
56
|
extra_rdoc_files: []
|
148
|
-
|
57
|
+
|
58
|
+
files:
|
149
59
|
- .fixtures.yml
|
150
60
|
- .gitignore
|
151
61
|
- .rspec
|
@@ -188,39 +98,29 @@ files:
|
|
188
98
|
- spec/unit/oval/subclass_of_spec.rb
|
189
99
|
- spec/unit/oval_spec.rb
|
190
100
|
homepage: https://github.com/ptomulik/rubygems-oval
|
191
|
-
licenses:
|
101
|
+
licenses:
|
192
102
|
- Apache 2.0
|
103
|
+
metadata: {}
|
104
|
+
|
193
105
|
post_install_message:
|
194
106
|
rdoc_options: []
|
195
|
-
|
107
|
+
|
108
|
+
require_paths:
|
196
109
|
- lib
|
197
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
segments:
|
204
|
-
- 0
|
205
|
-
hash: 3909914024463358041
|
206
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
-
none: false
|
208
|
-
requirements:
|
209
|
-
- - ! '>='
|
210
|
-
- !ruby/object:Gem::Version
|
211
|
-
version: '0'
|
212
|
-
segments:
|
213
|
-
- 0
|
214
|
-
hash: 3909914024463358041
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- *id002
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- *id002
|
215
116
|
requirements: []
|
117
|
+
|
216
118
|
rubyforge_project:
|
217
|
-
rubygems_version:
|
119
|
+
rubygems_version: 2.0.14
|
218
120
|
signing_key:
|
219
|
-
specification_version:
|
220
|
-
summary: Using hashes to pass options to methods is a very common ruby practice. With
|
221
|
-
|
222
|
-
meet requirements described in a hash declaration.
|
223
|
-
test_files:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Using hashes to pass options to methods is a very common ruby practice. With **Oval** method authors may restrict callers to pass only declared options that meet requirements described in a hash declaration.
|
123
|
+
test_files:
|
224
124
|
- spec/spec_helper.rb
|
225
125
|
- spec/unit/oval/anything_spec.rb
|
226
126
|
- spec/unit/oval/array_item_spec.rb
|
@@ -235,4 +135,3 @@ test_files:
|
|
235
135
|
- spec/unit/oval/options_spec.rb
|
236
136
|
- spec/unit/oval/subclass_of_spec.rb
|
237
137
|
- spec/unit/oval_spec.rb
|
238
|
-
has_rdoc:
|