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.
- 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_Strings.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
|
2
|
-
shared "Clean" do
|
3
|
-
|
4
|
-
extend Checked::Clean::DSL
|
5
|
-
|
6
|
-
end # === shared
|
7
|
-
|
8
|
-
describe "Clean :chop_ext" do
|
9
|
-
|
10
|
-
behaves_like 'Clean'
|
11
|
-
|
12
|
-
it "should chop off the extension of a file string: /etc/something.txt" do
|
13
|
-
clean("/etc/something.txt", :chop_ext).should == '/etc/something'
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should chop off the extension of a file string: /etc/something.rb" do
|
17
|
-
clean("/etc/something.rb", :chop_rb).should == '/etc/something'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not chop off a non-.rb extension for :chop_rb" do
|
21
|
-
clean("/etc/something.rbs", :chop_rb).should == '/etc/something.rbs'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should not chop off an extension if it has not" do
|
25
|
-
clean("/etc/something", :chop_rb).should == '/etc/something'
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should not chop off an extension if it includes '.' in a dir: /etc/rc.d/x-something" do
|
29
|
-
clean("/etc/rc.d/x-something", :chop_rb).should == '/etc/rc.d/x-something'
|
30
|
-
end
|
31
|
-
|
32
|
-
end # === describe
|
33
|
-
|
34
|
-
describe "Clean :ruby_name" do
|
35
|
-
|
36
|
-
behaves_like 'Clean'
|
37
|
-
|
38
|
-
it 'should return the basename without .rb' do
|
39
|
-
clean("/dir/some.path/String.rb", :ruby_name).should.be == 'String'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should be the equivalent to :chop_rb if it is just a filename without a dir' do
|
43
|
-
clean("String.rb", :ruby_name).should.be == 'String'
|
44
|
-
end
|
45
|
-
|
46
|
-
end # === describe :ruby_name
|
47
|
-
|
48
|
-
describe "Clean :chop_slash_r" do
|
49
|
-
|
50
|
-
behaves_like 'Clean'
|
51
|
-
|
52
|
-
it "should remove all instances of \\r" do
|
53
|
-
string = %@
|
54
|
-
Hi\r\n
|
55
|
-
Ok\r\n
|
56
|
-
@
|
57
|
-
clean(string, :chop_slash_r).should.be == string.gsub("\r", '')
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
end # === describe :chop_slash_r
|
62
|
-
|
63
|
-
|
64
|
-
describe "Clean :os_stardard" do
|
65
|
-
|
66
|
-
behaves_like 'Clean'
|
67
|
-
|
68
|
-
it "should remove all \\r and strip" do
|
69
|
-
string = %@
|
70
|
-
Hi\r\n
|
71
|
-
Ok\r\n
|
72
|
-
@
|
73
|
-
clean(string, :os_stardard).should.be == string.strip.gsub("\r", '')
|
74
|
-
end
|
75
|
-
|
76
|
-
end # === describe
|
data/spec/tests/Demand_Arrays.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "demand :symbols!" do
|
3
|
-
|
4
|
-
before {
|
5
|
-
@fail = Checked::Demand::Failed
|
6
|
-
@d = lambda { |val|
|
7
|
-
d=Checked::Demand.new(val)
|
8
|
-
d << :symbols!
|
9
|
-
d.target
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
it 'must require Array' do
|
14
|
-
m = should.raise(NoMethodError) {
|
15
|
-
@d.call :sym
|
16
|
-
}.message
|
17
|
-
m.should.include "Symbol, :sym, can not demand symbols!, which is found in"
|
18
|
-
m.should.include "in: Arrays"
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'must require Array be non-empty.' do
|
22
|
-
should.raise(@fail) {
|
23
|
-
@d.call( [] )
|
24
|
-
}.message.should.be == "Array, [], can't be empty."
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'must pass for Array of single Symbol instance' do
|
28
|
-
@d.call([:sym]).should.be == [:sym]
|
29
|
-
end
|
30
|
-
|
31
|
-
end # === describe Demand for Arrays
|
@@ -1,61 +0,0 @@
|
|
1
|
-
describe "Demand file_address!" do
|
2
|
-
|
3
|
-
it 'must fail if string has control characters' do
|
4
|
-
lambda {
|
5
|
-
d = Checked::Demand.new(File.expand_path "~/\tbashee")
|
6
|
-
d.<< :file_address!
|
7
|
-
}.should.raise(Checked::Demand::Failed)
|
8
|
-
.message.should.match %r!has invalid characters: !
|
9
|
-
end
|
10
|
-
|
11
|
-
end # === describe Demand file_address!
|
12
|
-
|
13
|
-
|
14
|
-
describe "Demand not_dir!" do
|
15
|
-
|
16
|
-
it 'must fail for an existing dir' do
|
17
|
-
lambda {
|
18
|
-
d = Checked::Demand.new(File.expand_path "~/")
|
19
|
-
d.<< :not_dir!
|
20
|
-
}.should.raise(Checked::Demand::Failed)
|
21
|
-
end
|
22
|
-
|
23
|
-
end # === describe Demand not_dir!
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
describe "Demand not_file!" do
|
28
|
-
|
29
|
-
it 'must fail for an existing file' do
|
30
|
-
lambda {
|
31
|
-
d = Checked::Demand.new(File.expand_path "~/.bashrc")
|
32
|
-
d.<< :not_file!
|
33
|
-
}.should.raise(Checked::Demand::Failed)
|
34
|
-
end
|
35
|
-
|
36
|
-
end # === describe Demand not_file!
|
37
|
-
|
38
|
-
|
39
|
-
describe "Demand :file_content!" do
|
40
|
-
|
41
|
-
it 'must fail for an empty string' do
|
42
|
-
lambda {
|
43
|
-
d = Checked::Demand.new('')
|
44
|
-
d.<< :file_content!
|
45
|
-
}.should.raise(Checked::Demand::Failed)
|
46
|
-
.message.should.be == "String, \"\", can't be empty."
|
47
|
-
end
|
48
|
-
|
49
|
-
end # === describe Demand :file_content!
|
50
|
-
|
51
|
-
describe "Demand :hostname!" do
|
52
|
-
|
53
|
-
it 'must not contain whitespace' do
|
54
|
-
lambda {
|
55
|
-
d = Checked::Demand.new('some name')
|
56
|
-
d.<< :hostname!
|
57
|
-
}.should.raise(Checked::Demand::Failed)
|
58
|
-
.message.should.be == 'String, "some name", has invalid characters: " "'
|
59
|
-
end
|
60
|
-
|
61
|
-
end # === describe Demand :hostname!
|
data/spec/tests/Demand_Vars.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "demand a! (certain class)" do
|
3
|
-
|
4
|
-
before do
|
5
|
-
@fail = Checked::Demand::Failed
|
6
|
-
@d = lambda { |val, k|
|
7
|
-
d = Checked::Demand.new(val)
|
8
|
-
d.a! k
|
9
|
-
d.target
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'must fail if invalid class' do
|
14
|
-
should.raise(@fail) {
|
15
|
-
@d.call('', Symbol)
|
16
|
-
}.message.should.include 'can only be of class/module: Symbol'
|
17
|
-
end
|
18
|
-
|
19
|
-
end # === describe demand a! (certain class)
|