oval 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.fixtures.yml +3 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.scripts/build-module.sh +25 -0
- data/.travis.yml +22 -0
- data/.yardopts +4 -0
- data/CHANGELOG +2 -0
- data/Gemfile +17 -0
- data/LICENSE +13 -0
- data/Modulefile +8 -0
- data/README.md +280 -0
- data/README_DEVEL.md +27 -0
- data/Rakefile +25 -0
- data/lib/oval.rb +18 -0
- data/lib/oval/anything.rb +12 -0
- data/lib/oval/array_item.rb +25 -0
- data/lib/oval/base.rb +58 -0
- data/lib/oval/class_decl_base.rb +27 -0
- data/lib/oval/collection.rb +125 -0
- data/lib/oval/hash_item.rb +41 -0
- data/lib/oval/instance_of.rb +11 -0
- data/lib/oval/kind_of.rb +11 -0
- data/lib/oval/one_of.rb +36 -0
- data/lib/oval/options.rb +61 -0
- data/lib/oval/subclass_of.rb +11 -0
- data/oval.gemspec +19 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/unit/oval/anything_spec.rb +38 -0
- data/spec/unit/oval/array_item_spec.rb +60 -0
- data/spec/unit/oval/base_spec.rb +184 -0
- data/spec/unit/oval/class_decl_base_spec.rb +73 -0
- data/spec/unit/oval/collection_spec.rb +267 -0
- data/spec/unit/oval/hash_item_spec.rb +146 -0
- data/spec/unit/oval/instance_of_spec.rb +44 -0
- data/spec/unit/oval/kind_of_spec.rb +45 -0
- data/spec/unit/oval/one_of_spec.rb +62 -0
- data/spec/unit/oval/options_spec.rb +215 -0
- data/spec/unit/oval/subclass_of_spec.rb +34 -0
- data/spec/unit/oval_spec.rb +75 -0
- metadata +123 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'oval/subclass_of'
|
3
|
+
|
4
|
+
|
5
|
+
describe Oval::SubclassOf do
|
6
|
+
it "should be subclass of Oval::ClassDeclBase" do
|
7
|
+
described_class.should < Oval::ClassDeclBase
|
8
|
+
end
|
9
|
+
describe "#validate" do
|
10
|
+
[
|
11
|
+
[Integer,[Fixnum]],
|
12
|
+
].each do |klass,args|
|
13
|
+
context "#{described_class.name}[#{klass.name}].validate(#{args.map{|x| x.inspect}.join(', ')})" do
|
14
|
+
let(:klass) { klass }
|
15
|
+
let(:args) { args }
|
16
|
+
let(:subject) { described_class[klass] }
|
17
|
+
it { expect { subject.validate(*args) }.to_not raise_error }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
[
|
21
|
+
[Integer,[:foo], "Invalid class :foo. Should be subclass of Integer"],
|
22
|
+
[Integer,[String], "Invalid class String. Should be subclass of Integer"],
|
23
|
+
[Integer,[String,'foo'], "Invalid class String for foo. Should be subclass of Integer"],
|
24
|
+
].each do |klass,args,msg|
|
25
|
+
context "#{described_class.name}[#{klass.name}].validate(#{args.map{|x| x.inspect}.join(', ')})" do
|
26
|
+
let(:klass) { klass }
|
27
|
+
let(:args) { args }
|
28
|
+
let(:msg) { msg }
|
29
|
+
let(:subject) { described_class[klass] }
|
30
|
+
it { expect { subject.validate(*args) }.to raise_error Oval::ValueError, msg}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'oval'
|
3
|
+
|
4
|
+
describe Oval do
|
5
|
+
let(:subject) { Class.new { extend Oval; def to_s; 'OvalReceiver'; end } }
|
6
|
+
describe "the receiver" do
|
7
|
+
let(:subject) { Class.new { extend Oval } }
|
8
|
+
it { should respond_to :ov_anything }
|
9
|
+
it { should respond_to :ov_collection }
|
10
|
+
it { should respond_to :ov_instance_of }
|
11
|
+
it { should respond_to :ov_kind_of }
|
12
|
+
it { should respond_to :ov_one_of }
|
13
|
+
it { should respond_to :ov_options }
|
14
|
+
it { should respond_to :ov_subclass_of }
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:ov_anything) { should be Oval::Anything }
|
18
|
+
its(:ov_collection) { should be Oval::Collection }
|
19
|
+
its(:ov_instance_of) { should be Oval::InstanceOf }
|
20
|
+
its(:ov_kind_of) { should be Oval::KindOf }
|
21
|
+
its(:ov_one_of) { should be Oval::OneOf }
|
22
|
+
its(:ov_options) { should be Oval::Options }
|
23
|
+
its(:ov_subclass_of) { should be Oval::SubclassOf }
|
24
|
+
end
|
25
|
+
|
26
|
+
# examples from README.md and other sources
|
27
|
+
describe Oval do
|
28
|
+
describe "Example 1" do
|
29
|
+
let(:subject) do
|
30
|
+
Class.new do
|
31
|
+
extend Oval
|
32
|
+
def self.foo(ops = {})
|
33
|
+
ov_options[ :foo => ov_anything ].validate(ops, 'ops')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
it("should compile"){ subject }
|
38
|
+
context "foo" do
|
39
|
+
it { expect { subject.foo }.to_not raise_error }
|
40
|
+
end
|
41
|
+
context "foo :foo => 10" do
|
42
|
+
it { expect { subject.foo :foo => 10 }.to_not raise_error }
|
43
|
+
end
|
44
|
+
context "foo :foo => 10, :bar => 20" do
|
45
|
+
let(:msg) { "Invalid option :bar for ops. Allowed options are :foo" }
|
46
|
+
it { expect { subject.foo :foo => 10, :bar => 20 }.to raise_error Oval::ValueError, msg}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
describe "Example 2" do
|
50
|
+
let(:subject) do
|
51
|
+
Class.new do
|
52
|
+
extend Oval
|
53
|
+
# create a singleton declaration ov
|
54
|
+
def self.ov
|
55
|
+
@ov ||= ov_options[ :foo => ov_anything ]
|
56
|
+
end
|
57
|
+
# use ov to validate ops
|
58
|
+
def self.foo(ops = {})
|
59
|
+
ov.validate(ops, 'ops')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
it("should compile"){ subject }
|
64
|
+
context "foo" do
|
65
|
+
it { expect { subject.foo }.to_not raise_error }
|
66
|
+
end
|
67
|
+
context "foo :foo => 10" do
|
68
|
+
it { expect { subject.foo :foo => 10 }.to_not raise_error }
|
69
|
+
end
|
70
|
+
context "foo :foo => 10, :bar => 20" do
|
71
|
+
let(:msg) { "Invalid option :bar for ops. Allowed options are :foo" }
|
72
|
+
it { expect { subject.foo :foo => 10, :bar => 20 }.to raise_error Oval::ValueError, msg}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oval
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pawel Tomulik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
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
|
+
description: Validate options when passed to methods
|
31
|
+
email:
|
32
|
+
- ptomulik@meil.pw.edu.pl
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .fixtures.yml
|
38
|
+
- .gitignore
|
39
|
+
- .rspec
|
40
|
+
- .scripts/build-module.sh
|
41
|
+
- .travis.yml
|
42
|
+
- .yardopts
|
43
|
+
- CHANGELOG
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- Modulefile
|
47
|
+
- README.md
|
48
|
+
- README_DEVEL.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/oval.rb
|
51
|
+
- lib/oval/anything.rb
|
52
|
+
- lib/oval/array_item.rb
|
53
|
+
- lib/oval/base.rb
|
54
|
+
- lib/oval/class_decl_base.rb
|
55
|
+
- lib/oval/collection.rb
|
56
|
+
- lib/oval/hash_item.rb
|
57
|
+
- lib/oval/instance_of.rb
|
58
|
+
- lib/oval/kind_of.rb
|
59
|
+
- lib/oval/one_of.rb
|
60
|
+
- lib/oval/options.rb
|
61
|
+
- lib/oval/subclass_of.rb
|
62
|
+
- oval.gemspec
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/unit/oval/anything_spec.rb
|
65
|
+
- spec/unit/oval/array_item_spec.rb
|
66
|
+
- spec/unit/oval/base_spec.rb
|
67
|
+
- spec/unit/oval/class_decl_base_spec.rb
|
68
|
+
- spec/unit/oval/collection_spec.rb
|
69
|
+
- spec/unit/oval/hash_item_spec.rb
|
70
|
+
- spec/unit/oval/instance_of_spec.rb
|
71
|
+
- spec/unit/oval/kind_of_spec.rb
|
72
|
+
- spec/unit/oval/one_of_spec.rb
|
73
|
+
- spec/unit/oval/options_spec.rb
|
74
|
+
- spec/unit/oval/subclass_of_spec.rb
|
75
|
+
- spec/unit/oval_spec.rb
|
76
|
+
homepage: https://github.com/ptomulik/rubygems-oval
|
77
|
+
licenses:
|
78
|
+
- Apache 2.0
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
hash: 2694836225048202330
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: 2694836225048202330
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.23
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Using hashes to pass options to methods is a very common ruby practice. With
|
107
|
+
**Oval** method authors may restrict callers to pass only declared options that
|
108
|
+
meet requirements described in a hash declaration.
|
109
|
+
test_files:
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/unit/oval/anything_spec.rb
|
112
|
+
- spec/unit/oval/array_item_spec.rb
|
113
|
+
- spec/unit/oval/base_spec.rb
|
114
|
+
- spec/unit/oval/class_decl_base_spec.rb
|
115
|
+
- spec/unit/oval/collection_spec.rb
|
116
|
+
- spec/unit/oval/hash_item_spec.rb
|
117
|
+
- spec/unit/oval/instance_of_spec.rb
|
118
|
+
- spec/unit/oval/kind_of_spec.rb
|
119
|
+
- spec/unit/oval/one_of_spec.rb
|
120
|
+
- spec/unit/oval/options_spec.rb
|
121
|
+
- spec/unit/oval/subclass_of_spec.rb
|
122
|
+
- spec/unit/oval_spec.rb
|
123
|
+
has_rdoc:
|