Checked 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Checked.gemspec +2 -3
- data/lib/Checked.rb +21 -9
- data/lib/Checked/Ask/Arrays.rb +31 -0
- data/lib/Checked/Ask/Ask.rb +21 -0
- data/lib/Checked/Ask/Strings.rb +27 -0
- data/lib/Checked/Ask/Vars.rb +21 -0
- data/lib/Checked/Base/Arch.rb +20 -0
- data/lib/Checked/Base/Base.rb +110 -0
- data/lib/Checked/Base/DSL.rb +73 -0
- data/lib/Checked/Base/DSL_Obj.rb +35 -0
- data/lib/Checked/{Clean.rb → Clean/Clean.rb} +1 -4
- data/lib/Checked/Clean/Strings.rb +94 -0
- data/lib/Checked/Demand/Arrays.rb +78 -0
- data/lib/Checked/Demand/Bools.rb +28 -0
- data/lib/Checked/{Demand.rb → Demand/Demand.rb} +12 -11
- data/lib/Checked/Demand/File_Paths.rb +63 -0
- data/lib/Checked/Demand/Hashs.rb +29 -0
- data/lib/Checked/Demand/Strings.rb +66 -0
- data/lib/Checked/Demand/Symbols.rb +21 -0
- data/lib/Checked/Demand/Vars.rb +65 -0
- data/lib/Checked/version.rb +1 -1
- data/spec/main.rb +5 -1
- data/spec/tests/Ask.rb +126 -8
- data/spec/tests/Clean.rb +66 -8
- data/spec/tests/DSL.rb +31 -0
- data/spec/tests/Demand.rb +220 -29
- metadata +38 -32
- data/lib/Checked/Args.rb +0 -55
- data/lib/Checked/Ask.rb +0 -69
- data/lib/Checked/Ask/DSL.rb +0 -31
- data/lib/Checked/Ask/Mods/Arrays.rb +0 -25
- data/lib/Checked/Ask/Mods/Strings.rb +0 -26
- data/lib/Checked/Ask/Mods/Vars.rb +0 -12
- data/lib/Checked/Base.rb +0 -119
- data/lib/Checked/Clean/DSL.rb +0 -16
- data/lib/Checked/Clean/Mods/Strings.rb +0 -104
- data/lib/Checked/Demand/DSL.rb +0 -29
- data/lib/Checked/Demand/Mods/Arrays.rb +0 -72
- data/lib/Checked/Demand/Mods/Bools.rb +0 -37
- data/lib/Checked/Demand/Mods/File_Addresses.rb +0 -59
- data/lib/Checked/Demand/Mods/Strings.rb +0 -51
- data/lib/Checked/Demand/Mods/Symbols.rb +0 -20
- data/lib/Checked/Demand/Mods/Vars.rb +0 -91
- data/spec/tests/Ask_Strings.rb +0 -57
- data/spec/tests/Checked.rb +0 -43
- data/spec/tests/Clean_Strings.rb +0 -76
- data/spec/tests/Demand_Arrays.rb +0 -31
- data/spec/tests/Demand_File_Addresses.rb +0 -61
- data/spec/tests/Demand_Vars.rb +0 -19
data/spec/tests/Clean.rb
CHANGED
@@ -1,13 +1,71 @@
|
|
1
1
|
|
2
|
+
# ============================
|
3
|
+
# ============================ STRINGS
|
4
|
+
# ============================
|
2
5
|
|
3
|
-
|
6
|
+
|
7
|
+
describe "Clean :chop_ext" do
|
8
|
+
|
9
|
+
|
10
|
+
it "should chop off the extension of a file string: /etc/something.txt" do
|
11
|
+
BOX.string!("/etc/something.txt").chop_ext.should == '/etc/something'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should chop off the extension of a file string: /etc/something.rb" do
|
15
|
+
BOX.string!("/etc/something.rb").chop_rb.should == '/etc/something'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not chop off a non-.rb extension for :chop_rb" do
|
19
|
+
BOX.string!("/etc/something.rbs").chop_rb.should == '/etc/something.rbs'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not chop off an extension if it has not" do
|
23
|
+
BOX.string!("/etc/something").chop_rb.should == '/etc/something'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not chop off an extension if it includes '.' in a dir: /etc/rc.d/x-something" do
|
27
|
+
BOX.string!("/etc/rc.d/x-something").chop_rb.should == '/etc/rc.d/x-something'
|
28
|
+
end
|
29
|
+
|
30
|
+
end # === describe
|
31
|
+
|
32
|
+
describe "Clean :ruby_name" do
|
33
|
+
|
4
34
|
|
5
|
-
it '
|
6
|
-
|
7
|
-
require 'Checked/Clean'
|
8
|
-
puts Checked::Clean::DSL.to_s
|
9
|
-
!)
|
10
|
-
.should.be == 'Checked::Clean::DSL'
|
35
|
+
it 'should return the basename without .rb' do
|
36
|
+
BOX.string!("/dir/some.path/String.rb").ruby_name.should.be == 'String'
|
11
37
|
end
|
12
38
|
|
13
|
-
|
39
|
+
it 'should be the equivalent to :chop_rb if it is just a filename without a dir' do
|
40
|
+
BOX.string!("String.rb").ruby_name.should.be == 'String'
|
41
|
+
end
|
42
|
+
|
43
|
+
end # === describe :ruby_name
|
44
|
+
|
45
|
+
describe "Clean :chop_slash_r" do
|
46
|
+
|
47
|
+
it "should remove all instances of \\r" do
|
48
|
+
string = %@
|
49
|
+
Hi\r\n
|
50
|
+
Ok\r\n
|
51
|
+
@
|
52
|
+
BOX.string!(string).chop_slash_r.should.be == string.gsub("\r", '')
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end # === describe :chop_slash_r
|
57
|
+
|
58
|
+
|
59
|
+
describe "Clean :os_stardard" do
|
60
|
+
|
61
|
+
|
62
|
+
it "should remove all \\r and strip" do
|
63
|
+
string = %@
|
64
|
+
Hi\r\n
|
65
|
+
Ok\r\n
|
66
|
+
@
|
67
|
+
BOX.string!(string).os_stardard.should.be == string.strip.gsub("\r", '')
|
68
|
+
end
|
69
|
+
|
70
|
+
end # === describe
|
71
|
+
|
data/spec/tests/DSL.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
describe "String!" do
|
3
|
+
|
4
|
+
it 'returns a string' do
|
5
|
+
BOX.String!('str').should.be == 'str'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'raise Demand::Failed if not a string' do
|
9
|
+
lambda {
|
10
|
+
BOX.String!([])
|
11
|
+
}.should.raise(Checked::Demand::Failed)
|
12
|
+
.message.should.match %r!Array, \[\], must be a String!
|
13
|
+
end
|
14
|
+
|
15
|
+
end # === describe String!
|
16
|
+
|
17
|
+
|
18
|
+
describe "Array!" do
|
19
|
+
|
20
|
+
it 'returns an array' do
|
21
|
+
BOX.Array!([:arr]).should.be == [:arr]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raise Demand::Failed if not an Array' do
|
25
|
+
lambda {
|
26
|
+
BOX.Array!(:a)
|
27
|
+
}.should.raise(Checked::Demand::Failed)
|
28
|
+
.message.should.match %r!Symbol, :a, is not an Array.!
|
29
|
+
end
|
30
|
+
|
31
|
+
end # === describe String!
|
data/spec/tests/Demand.rb
CHANGED
@@ -1,39 +1,230 @@
|
|
1
|
+
# ============================
|
2
|
+
# ============================ ARRAYS
|
3
|
+
# ============================
|
1
4
|
|
2
|
-
describe "
|
5
|
+
describe "array! check!" do
|
3
6
|
|
4
|
-
it 'must
|
5
|
-
|
6
|
-
require 'Checked/Demand'
|
7
|
-
puts Checked::Demand::DSL.to_s
|
8
|
-
!)
|
9
|
-
.should.be == 'Checked::Demand::DSL'
|
7
|
+
it 'must return array' do
|
8
|
+
BOX.array!([:a, :b]).check!.should == [:a, :b]
|
10
9
|
end
|
11
10
|
|
12
|
-
end # === describe
|
11
|
+
end # === describe array! check!
|
13
12
|
|
14
|
-
describe "
|
13
|
+
describe "array! :symbols!" do
|
14
|
+
|
15
|
+
it 'must require Array be non-empty.' do
|
16
|
+
should.raise(Checked::Demand::Failed) {
|
17
|
+
BOX.array!( [] ).symbols!
|
18
|
+
}.message.should.be == "Array, [], can't be empty."
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'must positively validate an Array of single Symbol instance' do
|
22
|
+
lambda { BOX.array!([:sym]).symbols! }.should.not.raise
|
23
|
+
end
|
24
|
+
|
25
|
+
end # === describe Demand for Arrays
|
26
|
+
|
27
|
+
# ============================
|
28
|
+
# ============================ BOOLS
|
29
|
+
# ============================
|
30
|
+
|
31
|
+
describe "demand :bool!" do
|
32
|
+
|
33
|
+
it 'must raise Demand::Failed if not a boolean' do
|
34
|
+
should.raise(Checked::Demand::Failed) {
|
35
|
+
BOX.bool!( "Answer", :false ).check!
|
36
|
+
}.message.should.be == "Answer, :false, must be either of TrueClass or FalseClass."
|
37
|
+
end
|
38
|
+
|
39
|
+
end # === describe demand :bool!
|
40
|
+
|
41
|
+
describe "demand :bool! :true!" do
|
15
42
|
|
16
|
-
it 'must
|
43
|
+
it 'must pass validation if true' do
|
44
|
+
should.not.raise(Checked::Demand::Failed) {
|
45
|
+
BOX.bool!( "Answer", 1 === 1 ).true!
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must raise Demand::Failed if not true' do
|
50
|
+
should.raise(Checked::Demand::Failed) {
|
51
|
+
BOX.bool!( "ANSW", false ).true!
|
52
|
+
}.message.should.be == "ANSW, false, must be true (TrueClass)."
|
53
|
+
end
|
54
|
+
|
55
|
+
end # === describe demand :bool!
|
56
|
+
|
57
|
+
describe "demand :bool! :false!" do
|
58
|
+
|
59
|
+
it 'must pass validation if false' do
|
60
|
+
should.not.raise(Checked::Demand::Failed) {
|
61
|
+
BOX.bool!( "Comparison", 1 === 2 ).false!
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'must raise Demand::Failed if not false' do
|
66
|
+
should.raise(Checked::Demand::Failed) {
|
67
|
+
BOX.bool!( "ANSW", 1 == 1 ).false!
|
68
|
+
}.message.should.be == "ANSW, true, must be false (FalseClass)."
|
69
|
+
end
|
70
|
+
|
71
|
+
end # === describe demand :bool!
|
72
|
+
|
73
|
+
# ============================
|
74
|
+
# ============================ FILE_PATHS
|
75
|
+
# ============================
|
76
|
+
|
77
|
+
|
78
|
+
describe "Demand file_path!" do
|
79
|
+
|
80
|
+
it 'must fail if string has control characters' do
|
81
|
+
lambda {
|
82
|
+
BOX.file_path!("~/\tbashee").check!
|
83
|
+
}.should.raise(Checked::Demand::Failed)
|
84
|
+
.message.should.match %r!has invalid characters: !
|
85
|
+
end
|
86
|
+
|
87
|
+
end # === describe Demand file_path!
|
88
|
+
|
89
|
+
|
90
|
+
describe "Demand file_path! not_dir!" do
|
91
|
+
|
92
|
+
it 'must fail for an existing dir' do
|
93
|
+
lambda {
|
94
|
+
BOX.file_path!("~/").not_dir!
|
95
|
+
}.should.raise(Checked::Demand::Failed)
|
96
|
+
.message.should.match %r!~/", can't be an existing directory.!
|
97
|
+
end
|
98
|
+
|
99
|
+
end # === describe Demand not_dir!
|
100
|
+
|
101
|
+
describe "Demand file_path! not_file!" do
|
102
|
+
|
103
|
+
it 'must fail for an existing file' do
|
104
|
+
lambda {
|
105
|
+
BOX.file_path!("~/.bashrc").not_file!
|
106
|
+
}.should.raise(Checked::Demand::Failed)
|
107
|
+
.message.should.match %r!bashrc", can't be a file!
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'must return expand path' do
|
111
|
+
path = "~/,RANDOM"
|
112
|
+
target = File.expand_path(path)
|
113
|
+
BOX.file_path!(path).not_file!.should.be == target
|
114
|
+
end
|
115
|
+
|
116
|
+
end # === describe Demand not_file!
|
117
|
+
|
118
|
+
describe "Demand file_path! :hostname!" do
|
119
|
+
|
120
|
+
it 'must not contain whitespace' do
|
17
121
|
lambda {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
lambda {
|
34
|
-
|
35
|
-
.
|
122
|
+
BOX.file_path!('some name').hostname!
|
123
|
+
}.should.raise(Checked::Demand::Failed)
|
124
|
+
.message.should.be == 'String, "some name", has invalid characters: " "'
|
125
|
+
end
|
126
|
+
|
127
|
+
end # === describe Demand :hostname!
|
128
|
+
|
129
|
+
|
130
|
+
# ============================
|
131
|
+
# ============================ HASHS
|
132
|
+
# ============================
|
133
|
+
|
134
|
+
describe "Demand hash! :symbol_keys!" do
|
135
|
+
|
136
|
+
it 'must raise Fail if keys are not all symbols' do
|
137
|
+
lambda {
|
138
|
+
BOX.hash!( :hello=>'by', 'hi'=>'hiya' ).symbol_keys!
|
139
|
+
}.should.raise(Checked::Demand::Failed)
|
140
|
+
.message.should.match %r!must have all symbol keys!
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'must not raise Fail if keys are all symbols' do
|
144
|
+
lambda {
|
145
|
+
BOX.hash!( :helo=>'be', :hi=>'hi' ).symbol_keys!
|
146
|
+
}.should.not.raise(Checked::Demand::Failed)
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
end # === describe Demand hash! :symbol_keys!
|
151
|
+
|
152
|
+
|
153
|
+
# ============================
|
154
|
+
# ============================ STRINGS
|
155
|
+
# ============================
|
156
|
+
|
157
|
+
|
158
|
+
describe "Demand string! :file_read!" do
|
159
|
+
|
160
|
+
it 'returns a string with right carriage returns erased.' do
|
161
|
+
BOX.string!("test\r\ntest\r\n").file_content!.should == "test\ntest\n"
|
162
|
+
end
|
163
|
+
|
164
|
+
end # === describe Demand string! :file_read!
|
165
|
+
|
166
|
+
describe "Demand string! :file_content!" do
|
167
|
+
|
168
|
+
it 'must fail for an empty string' do
|
169
|
+
lambda {
|
170
|
+
BOX.string!('').file_content!
|
171
|
+
}.should.raise(Checked::Demand::Failed)
|
172
|
+
.message.should.be == "String, \"\", can't be empty."
|
173
|
+
end
|
174
|
+
|
175
|
+
end # === describe Demand :file_content!
|
176
|
+
|
177
|
+
# ============================
|
178
|
+
# ============================ SYMBOLS
|
179
|
+
# ============================
|
180
|
+
|
181
|
+
describe "Demand symbol! check!" do
|
182
|
+
|
183
|
+
it 'raises Demand::Failed if not Symbol' do
|
184
|
+
lambda {
|
185
|
+
BOX.symbol!('Name', []).check!
|
186
|
+
}.should.raise(Checked::Demand::Failed)
|
187
|
+
.message.should.be == "Name, [], must be a Symbol."
|
188
|
+
end
|
189
|
+
|
190
|
+
end # === describe Demand symbol! check!
|
191
|
+
|
192
|
+
# ============================
|
193
|
+
# ============================ VARS
|
194
|
+
# ============================
|
195
|
+
|
196
|
+
describe "Named :demand!" do
|
197
|
+
|
198
|
+
it 'must use name in errors' do
|
199
|
+
should.raise(Checked::Demand::Failed) {
|
200
|
+
BOX.demand!("Test Val", :a ).nil!
|
201
|
+
}.message.should == "Test Val, :a, must be nil."
|
202
|
+
end
|
203
|
+
|
204
|
+
end # === describe Named :demand
|
205
|
+
|
206
|
+
describe "DSL :demand!" do
|
207
|
+
|
208
|
+
it 'must raise error when demand fails.' do
|
209
|
+
should.raise(Checked::Demand::Failed) {
|
210
|
+
BOX.demand!( [] ).nil!
|
211
|
+
}.message.should == "Array, [], must be nil."
|
36
212
|
|
37
213
|
end
|
38
214
|
|
39
|
-
end # === describe
|
215
|
+
end # === describe :demand
|
216
|
+
|
217
|
+
describe "demand be!" do
|
218
|
+
|
219
|
+
before do
|
220
|
+
@fail = Checked::Demand::Failed
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'must fail if invalid class' do
|
224
|
+
should.raise(@fail) {
|
225
|
+
BOX.demand!([]).one_of!(Symbol)
|
226
|
+
}.message.should == "Array, [], can only be of class/module: Symbol"
|
227
|
+
end
|
228
|
+
|
229
|
+
end # === describe demand a! (certain class)
|
230
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Checked
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: Uni_Arch
|
16
|
+
requirement: &12169680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12169680
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rake
|
16
|
-
requirement: &
|
27
|
+
requirement: &12168560 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *12168560
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: bacon
|
27
|
-
requirement: &
|
38
|
+
requirement: &12167360 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *12167360
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: Bacon_Colored
|
38
|
-
requirement: &
|
49
|
+
requirement: &12166240 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *12166240
|
47
58
|
description: ! "\n Various DSLs to clean, question (Ask), and validate (Demand)
|
48
59
|
your objects,\n their classes (data types), and their properties.\n "
|
49
60
|
email:
|
@@ -60,36 +71,31 @@ files:
|
|
60
71
|
- README.rdoc
|
61
72
|
- Rakefile
|
62
73
|
- lib/Checked.rb
|
63
|
-
- lib/Checked/
|
64
|
-
- lib/Checked/Ask.rb
|
65
|
-
- lib/Checked/Ask/
|
66
|
-
- lib/Checked/Ask/
|
67
|
-
- lib/Checked/
|
68
|
-
- lib/Checked/
|
69
|
-
- lib/Checked/Base.rb
|
70
|
-
- lib/Checked/
|
71
|
-
- lib/Checked/Clean/
|
72
|
-
- lib/Checked/Clean/
|
73
|
-
- lib/Checked/Demand.rb
|
74
|
-
- lib/Checked/Demand/
|
75
|
-
- lib/Checked/Demand/
|
76
|
-
- lib/Checked/Demand/
|
77
|
-
- lib/Checked/Demand/
|
78
|
-
- lib/Checked/Demand/
|
79
|
-
- lib/Checked/Demand/
|
80
|
-
- lib/Checked/Demand/
|
74
|
+
- lib/Checked/Ask/Arrays.rb
|
75
|
+
- lib/Checked/Ask/Ask.rb
|
76
|
+
- lib/Checked/Ask/Strings.rb
|
77
|
+
- lib/Checked/Ask/Vars.rb
|
78
|
+
- lib/Checked/Base/Arch.rb
|
79
|
+
- lib/Checked/Base/Base.rb
|
80
|
+
- lib/Checked/Base/DSL.rb
|
81
|
+
- lib/Checked/Base/DSL_Obj.rb
|
82
|
+
- lib/Checked/Clean/Clean.rb
|
83
|
+
- lib/Checked/Clean/Strings.rb
|
84
|
+
- lib/Checked/Demand/Arrays.rb
|
85
|
+
- lib/Checked/Demand/Bools.rb
|
86
|
+
- lib/Checked/Demand/Demand.rb
|
87
|
+
- lib/Checked/Demand/File_Paths.rb
|
88
|
+
- lib/Checked/Demand/Hashs.rb
|
89
|
+
- lib/Checked/Demand/Strings.rb
|
90
|
+
- lib/Checked/Demand/Symbols.rb
|
91
|
+
- lib/Checked/Demand/Vars.rb
|
81
92
|
- lib/Checked/version.rb
|
82
93
|
- spec/helper.rb
|
83
94
|
- spec/main.rb
|
84
95
|
- spec/tests/Ask.rb
|
85
|
-
- spec/tests/Ask_Strings.rb
|
86
|
-
- spec/tests/Checked.rb
|
87
96
|
- spec/tests/Clean.rb
|
88
|
-
- spec/tests/
|
97
|
+
- spec/tests/DSL.rb
|
89
98
|
- spec/tests/Demand.rb
|
90
|
-
- spec/tests/Demand_Arrays.rb
|
91
|
-
- spec/tests/Demand_File_Addresses.rb
|
92
|
-
- spec/tests/Demand_Vars.rb
|
93
99
|
homepage: ''
|
94
100
|
licenses: []
|
95
101
|
post_install_message:
|