Checked 0.1.4 → 1.0.0

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.
Files changed (49) hide show
  1. data/Checked.gemspec +2 -3
  2. data/lib/Checked.rb +21 -9
  3. data/lib/Checked/Ask/Arrays.rb +31 -0
  4. data/lib/Checked/Ask/Ask.rb +21 -0
  5. data/lib/Checked/Ask/Strings.rb +27 -0
  6. data/lib/Checked/Ask/Vars.rb +21 -0
  7. data/lib/Checked/Base/Arch.rb +20 -0
  8. data/lib/Checked/Base/Base.rb +110 -0
  9. data/lib/Checked/Base/DSL.rb +73 -0
  10. data/lib/Checked/Base/DSL_Obj.rb +35 -0
  11. data/lib/Checked/{Clean.rb → Clean/Clean.rb} +1 -4
  12. data/lib/Checked/Clean/Strings.rb +94 -0
  13. data/lib/Checked/Demand/Arrays.rb +78 -0
  14. data/lib/Checked/Demand/Bools.rb +28 -0
  15. data/lib/Checked/{Demand.rb → Demand/Demand.rb} +12 -11
  16. data/lib/Checked/Demand/File_Paths.rb +63 -0
  17. data/lib/Checked/Demand/Hashs.rb +29 -0
  18. data/lib/Checked/Demand/Strings.rb +66 -0
  19. data/lib/Checked/Demand/Symbols.rb +21 -0
  20. data/lib/Checked/Demand/Vars.rb +65 -0
  21. data/lib/Checked/version.rb +1 -1
  22. data/spec/main.rb +5 -1
  23. data/spec/tests/Ask.rb +126 -8
  24. data/spec/tests/Clean.rb +66 -8
  25. data/spec/tests/DSL.rb +31 -0
  26. data/spec/tests/Demand.rb +220 -29
  27. metadata +38 -32
  28. data/lib/Checked/Args.rb +0 -55
  29. data/lib/Checked/Ask.rb +0 -69
  30. data/lib/Checked/Ask/DSL.rb +0 -31
  31. data/lib/Checked/Ask/Mods/Arrays.rb +0 -25
  32. data/lib/Checked/Ask/Mods/Strings.rb +0 -26
  33. data/lib/Checked/Ask/Mods/Vars.rb +0 -12
  34. data/lib/Checked/Base.rb +0 -119
  35. data/lib/Checked/Clean/DSL.rb +0 -16
  36. data/lib/Checked/Clean/Mods/Strings.rb +0 -104
  37. data/lib/Checked/Demand/DSL.rb +0 -29
  38. data/lib/Checked/Demand/Mods/Arrays.rb +0 -72
  39. data/lib/Checked/Demand/Mods/Bools.rb +0 -37
  40. data/lib/Checked/Demand/Mods/File_Addresses.rb +0 -59
  41. data/lib/Checked/Demand/Mods/Strings.rb +0 -51
  42. data/lib/Checked/Demand/Mods/Symbols.rb +0 -20
  43. data/lib/Checked/Demand/Mods/Vars.rb +0 -91
  44. data/spec/tests/Ask_Strings.rb +0 -57
  45. data/spec/tests/Checked.rb +0 -43
  46. data/spec/tests/Clean_Strings.rb +0 -76
  47. data/spec/tests/Demand_Arrays.rb +0 -31
  48. data/spec/tests/Demand_File_Addresses.rb +0 -61
  49. 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
- describe "require 'Checked/Clean'" do
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 'must include DSL' do
6
- ruby_e(%!
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
- end # === describe require 'Checked/Clean'
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 "require 'Checked/Demand'" do
5
+ describe "array! check!" do
3
6
 
4
- it 'must include DSL' do
5
- ruby_e(%!
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 require 'Checked/Demand'
11
+ end # === describe array! check!
13
12
 
14
- describe "Demand errors" do
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 recommend method if not found in current modules' do
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
- d = Checked::Demand.new('')
19
- d.<< :symbols!
20
- }.should.raise(NoMethodError)
21
- .message.should.be === "String, \"\", can not demand symbols!, which is found in: Arrays"
22
- end
23
-
24
- it 'must raise a NoMethodError when a missing method is used within a valid demand! method.' do
25
- Missing_Meth = Module.new do
26
- def file_content!
27
- something()
28
- end
29
- end
30
-
31
- d = Checked::Demand.new('')
32
- d.extend Missing_Meth
33
- lambda { d.<< :file_content! }
34
- .should.raise(NoMethodError)
35
- .message.should.match %r!undefined method `something' for!
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 Demand errors
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.1.4
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: 2011-12-29 00:00:00.000000000Z
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: &11239380 !ruby/object:Gem::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: *11239380
35
+ version_requirements: *12168560
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: bacon
27
- requirement: &11238020 !ruby/object:Gem::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: *11238020
46
+ version_requirements: *12167360
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: Bacon_Colored
38
- requirement: &11199900 !ruby/object:Gem::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: *11199900
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/Args.rb
64
- - lib/Checked/Ask.rb
65
- - lib/Checked/Ask/DSL.rb
66
- - lib/Checked/Ask/Mods/Arrays.rb
67
- - lib/Checked/Ask/Mods/Strings.rb
68
- - lib/Checked/Ask/Mods/Vars.rb
69
- - lib/Checked/Base.rb
70
- - lib/Checked/Clean.rb
71
- - lib/Checked/Clean/DSL.rb
72
- - lib/Checked/Clean/Mods/Strings.rb
73
- - lib/Checked/Demand.rb
74
- - lib/Checked/Demand/DSL.rb
75
- - lib/Checked/Demand/Mods/Arrays.rb
76
- - lib/Checked/Demand/Mods/Bools.rb
77
- - lib/Checked/Demand/Mods/File_Addresses.rb
78
- - lib/Checked/Demand/Mods/Strings.rb
79
- - lib/Checked/Demand/Mods/Symbols.rb
80
- - lib/Checked/Demand/Mods/Vars.rb
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/Clean_Strings.rb
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: