rubycut-babushka 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/README.markdown +246 -0
- data/Rakefile +26 -0
- data/bin/babushka +11 -0
- data/deps/babushka.rb +101 -0
- data/deps/dev.rb +12 -0
- data/deps/fhs.rb +31 -0
- data/deps/git.rb +29 -0
- data/deps/homebrew.rb +30 -0
- data/deps/os_x.rb +33 -0
- data/deps/packages.rb +22 -0
- data/deps/pkg_managers.rb +110 -0
- data/deps/ruby.rb +23 -0
- data/deps/rubygems.rb +24 -0
- data/deps/system.rb +10 -0
- data/deps/templates/app.rb +68 -0
- data/deps/templates/external.rb +12 -0
- data/deps/templates/installer.rb +31 -0
- data/deps/templates/managed.rb +105 -0
- data/deps/templates/ppa.rb +24 -0
- data/deps/templates/src.rb +42 -0
- data/deps/templates/tmbundle.rb +15 -0
- data/lib/babushka.rb +28 -0
- data/lib/babushka/accepts_block_for.rb +72 -0
- data/lib/babushka/accepts_list_for.rb +49 -0
- data/lib/babushka/accepts_value_for.rb +24 -0
- data/lib/babushka/base.rb +78 -0
- data/lib/babushka/bug_reporter.rb +55 -0
- data/lib/babushka/cmdline.rb +133 -0
- data/lib/babushka/cmdline/handler.rb +41 -0
- data/lib/babushka/cmdline/helpers.rb +127 -0
- data/lib/babushka/cmdline/parser.rb +69 -0
- data/lib/babushka/colorizer.rb +59 -0
- data/lib/babushka/core_patches/array.rb +171 -0
- data/lib/babushka/core_patches/blank.rb +22 -0
- data/lib/babushka/core_patches/bytes.rb +52 -0
- data/lib/babushka/core_patches/hash.rb +107 -0
- data/lib/babushka/core_patches/hashish.rb +14 -0
- data/lib/babushka/core_patches/integer.rb +25 -0
- data/lib/babushka/core_patches/io.rb +8 -0
- data/lib/babushka/core_patches/numeric.rb +16 -0
- data/lib/babushka/core_patches/object.rb +27 -0
- data/lib/babushka/core_patches/string.rb +116 -0
- data/lib/babushka/core_patches/symbol.rb +12 -0
- data/lib/babushka/core_patches/try.rb +15 -0
- data/lib/babushka/core_patches/uri.rb +24 -0
- data/lib/babushka/dep.rb +470 -0
- data/lib/babushka/dep_context.rb +18 -0
- data/lib/babushka/dep_definer.rb +115 -0
- data/lib/babushka/dep_pool.rb +49 -0
- data/lib/babushka/dep_runner.rb +85 -0
- data/lib/babushka/dsl.rb +26 -0
- data/lib/babushka/git_repo.rb +185 -0
- data/lib/babushka/helpers/git_helpers.rb +32 -0
- data/lib/babushka/helpers/log_helpers.rb +176 -0
- data/lib/babushka/helpers/path_helpers.rb +34 -0
- data/lib/babushka/helpers/run_helpers.rb +145 -0
- data/lib/babushka/helpers/shell_helpers.rb +229 -0
- data/lib/babushka/helpers/suggest_helpers.rb +16 -0
- data/lib/babushka/helpers/uri_helpers.rb +36 -0
- data/lib/babushka/ip.rb +160 -0
- data/lib/babushka/lambda_chooser.rb +40 -0
- data/lib/babushka/levenshtein.rb +125 -0
- data/lib/babushka/meta_dep.rb +65 -0
- data/lib/babushka/meta_dep_context.rb +15 -0
- data/lib/babushka/parameter.rb +143 -0
- data/lib/babushka/pkg_helper.rb +81 -0
- data/lib/babushka/pkg_helpers/apt_helper.rb +61 -0
- data/lib/babushka/pkg_helpers/base_helper.rb +19 -0
- data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +48 -0
- data/lib/babushka/pkg_helpers/binports_helper.rb +34 -0
- data/lib/babushka/pkg_helpers/brew_helper.rb +110 -0
- data/lib/babushka/pkg_helpers/gem_helper.rb +120 -0
- data/lib/babushka/pkg_helpers/macports_helper.rb +22 -0
- data/lib/babushka/pkg_helpers/npm_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/pacman_helper.rb +27 -0
- data/lib/babushka/pkg_helpers/pip_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/src_helper.rb +16 -0
- data/lib/babushka/pkg_helpers/yum_helper.rb +25 -0
- data/lib/babushka/popen.rb +40 -0
- data/lib/babushka/prompt.rb +176 -0
- data/lib/babushka/renderable.rb +67 -0
- data/lib/babushka/resource.rb +215 -0
- data/lib/babushka/run_reporter.rb +60 -0
- data/lib/babushka/shell.rb +108 -0
- data/lib/babushka/source.rb +216 -0
- data/lib/babushka/source_pool.rb +146 -0
- data/lib/babushka/system_definitions.rb +97 -0
- data/lib/babushka/system_profile.rb +210 -0
- data/lib/babushka/task.rb +142 -0
- data/lib/babushka/vars.rb +108 -0
- data/lib/babushka/version_of.rb +65 -0
- data/lib/babushka/version_str.rb +57 -0
- data/lib/babushka/xml_string.rb +28 -0
- data/lib/components.rb +82 -0
- data/lib/fancypath/fancypath.rb +200 -0
- data/lib/inkan/inkan.rb +76 -0
- data/spec/acceptance/acceptance.rb +43 -0
- data/spec/acceptance_helper.rb +113 -0
- data/spec/archives/Blah.app.zip +0 -0
- data/spec/archives/archive.tar +0 -0
- data/spec/archives/archive.tar.bz2 +0 -0
- data/spec/archives/archive.tar.gz +0 -0
- data/spec/archives/archive.tbz2 +0 -0
- data/spec/archives/archive.tgz +0 -0
- data/spec/archives/archive.zip +0 -0
- data/spec/archives/content.txt +5 -0
- data/spec/archives/invalid_archive +5 -0
- data/spec/archives/nested archive/content.txt +5 -0
- data/spec/archives/nested_archive.tar +0 -0
- data/spec/archives/really_a_gzip.zip +0 -0
- data/spec/archives/test-0.3.1.tgz +0 -0
- data/spec/archives/tgz_archive +0 -0
- data/spec/archives/zip_without_extension +0 -0
- data/spec/babushka/accepts_for_spec.rb +174 -0
- data/spec/babushka/accepts_for_support.rb +72 -0
- data/spec/babushka/cmdline/console_spec.rb +11 -0
- data/spec/babushka/cmdline/help_spec.rb +61 -0
- data/spec/babushka/cmdline/version_spec.rb +10 -0
- data/spec/babushka/core_patches_spec.rb +171 -0
- data/spec/babushka/dep_context_spec.rb +58 -0
- data/spec/babushka/dep_definer_spec.rb +152 -0
- data/spec/babushka/dep_definer_support.rb +36 -0
- data/spec/babushka/dep_spec.rb +567 -0
- data/spec/babushka/dep_support.rb +29 -0
- data/spec/babushka/deps_spec.rb +113 -0
- data/spec/babushka/gem_helper_spec.rb +90 -0
- data/spec/babushka/git_repo_spec.rb +396 -0
- data/spec/babushka/ip_spec.rb +131 -0
- data/spec/babushka/lambda_chooser_spec.rb +115 -0
- data/spec/babushka/meta_dep_definer_spec.rb +127 -0
- data/spec/babushka/meta_dep_wrapper_spec.rb +32 -0
- data/spec/babushka/parameter_spec.rb +135 -0
- data/spec/babushka/path_helpers_spec.rb +102 -0
- data/spec/babushka/prompt_spec.rb +188 -0
- data/spec/babushka/renderable_spec.rb +100 -0
- data/spec/babushka/resource_spec.rb +141 -0
- data/spec/babushka/run_helpers_spec.rb +26 -0
- data/spec/babushka/shell_helpers_spec.rb +244 -0
- data/spec/babushka/shell_spec.rb +19 -0
- data/spec/babushka/source_pool_spec.rb +320 -0
- data/spec/babushka/source_pool_support.rb +31 -0
- data/spec/babushka/source_spec.rb +382 -0
- data/spec/babushka/source_support.rb +17 -0
- data/spec/babushka/system_profile_spec.rb +61 -0
- data/spec/babushka/task_spec.rb +141 -0
- data/spec/babushka/uri_spec.rb +13 -0
- data/spec/babushka/vars_spec.rb +59 -0
- data/spec/babushka/version_of_spec.rb +110 -0
- data/spec/babushka/version_str_spec.rb +130 -0
- data/spec/babushka/version_str_support.rb +37 -0
- data/spec/babushka/xml_string_spec.rb +98 -0
- data/spec/deps/bad/broken.rb +7 -0
- data/spec/deps/bad/working.rb +3 -0
- data/spec/deps/good/meta.rb +14 -0
- data/spec/deps/good/test.rb +11 -0
- data/spec/deps/outer/deps.rb +19 -0
- data/spec/deps/outer/more deps.rb +11 -0
- data/spec/deps/params/params.rb +10 -0
- data/spec/fancypath/fancypath_spec.rb +272 -0
- data/spec/fancypath_support.rb +10 -0
- data/spec/inkan/inkan_spec.rb +217 -0
- data/spec/renderable/different_example.conf.erb +4 -0
- data/spec/renderable/example.conf.erb +3 -0
- data/spec/renderable/example.sh +6 -0
- data/spec/renderable/with_binding.conf.erb +4 -0
- data/spec/renderable/xml_example.conf.erb +8 -0
- data/spec/repos/remote.git.tgz +0 -0
- data/spec/spec_helper.rb +87 -0
- metadata +238 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "IP" do
|
4
|
+
it "should accept IPs, arrays and strings" do
|
5
|
+
IP.new(IP.new('10.0.1.1')).to_s.should == '10.0.1.1'
|
6
|
+
IP.new([10, 0, 1, 1]).to_s.should == '10.0.1.1'
|
7
|
+
IP.new('10.0.1.1').to_s.should == '10.0.1.1'
|
8
|
+
end
|
9
|
+
it "should work for valid IPs" do
|
10
|
+
[
|
11
|
+
'10.0.1.1' ,
|
12
|
+
'192.168.0.1' ,
|
13
|
+
'174.129.110.43'
|
14
|
+
].each {|string|
|
15
|
+
IP.new(string).should be_valid
|
16
|
+
}
|
17
|
+
end
|
18
|
+
it "should work for invalid IPs" do
|
19
|
+
[
|
20
|
+
'10.0.1.' ,
|
21
|
+
'.10.0.1' ,
|
22
|
+
'192.168.0' ,
|
23
|
+
'192.168.0.c' ,
|
24
|
+
'174.129.110.433'
|
25
|
+
].each {|string|
|
26
|
+
IP.new(string).should_not be_valid
|
27
|
+
}
|
28
|
+
end
|
29
|
+
describe "equality" do
|
30
|
+
it "should be equal to equivalent IPs" do
|
31
|
+
IP.new('10.0.1.1').should == IP.new([10, 0, 1, 1])
|
32
|
+
end
|
33
|
+
it "should not be equal to different IPs" do
|
34
|
+
IP.new('10.0.1.1').should_not == IP.new('10.0.0.1')
|
35
|
+
IP.new('10.0.1.1').should_not == IP.new('10.0.1')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "#next" do
|
39
|
+
it "should return the next IP in the range" do
|
40
|
+
IP.new('10.0.1.1').next.to_s.should == '10.0.1.2'
|
41
|
+
IP.new('10.0.1.255').next.to_s.should == '10.0.2.0'
|
42
|
+
IP.new('10.13.37.1').next.to_s.should == '10.13.37.2'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe "#prev" do
|
46
|
+
it "should return the previous IP in the range" do
|
47
|
+
IP.new('10.0.1.2').prev.to_s.should == '10.0.1.1'
|
48
|
+
IP.new('10.0.2.0').prev.to_s.should == '10.0.1.255'
|
49
|
+
IP.new('10.13.37.255').prev.to_s.should == '10.13.37.254'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "IPRange" do
|
55
|
+
it "should work for valid IPs" do
|
56
|
+
[
|
57
|
+
'10.0.1.x' ,
|
58
|
+
'10.0.x' ,
|
59
|
+
'174.129.x.x'
|
60
|
+
].each {|string|
|
61
|
+
IPRange.new(string).should be_valid
|
62
|
+
}
|
63
|
+
end
|
64
|
+
it "should work for invalid IPs" do
|
65
|
+
[
|
66
|
+
'10.0.1.1' ,
|
67
|
+
'10.0.x.1' ,
|
68
|
+
'10.0.x.' ,
|
69
|
+
'174.129.110.',
|
70
|
+
'174.129.x.43'
|
71
|
+
].each {|string|
|
72
|
+
IPRange.new(string).should_not be_valid
|
73
|
+
}
|
74
|
+
end
|
75
|
+
it "should collapse multiple wildcards" do
|
76
|
+
IPRange.new('10.0.1.x').bytes.should == [10, 0, 1, 'x']
|
77
|
+
IPRange.new('10.x').bytes.should == [10, 'x']
|
78
|
+
IPRange.new('10.x.x.x').bytes.should == [10, 'x']
|
79
|
+
IPRange.new('10.0.x').bytes.should == [10, 0, 'x']
|
80
|
+
IPRange.new('10.0.x.x').bytes.should == [10, 0, 'x']
|
81
|
+
end
|
82
|
+
describe "#padded_bytes" do
|
83
|
+
it "should pad the ranges back out to 4 terms" do
|
84
|
+
IPRange.new('10.0.1.x').padded_bytes.should == [10, 0, 1, 'x']
|
85
|
+
IPRange.new('10.x').padded_bytes.should == [10, 'x', 'x', 'x']
|
86
|
+
IPRange.new('10.x.x.x').padded_bytes.should == [10, 'x', 'x', 'x']
|
87
|
+
IPRange.new('10.0.x').padded_bytes.should == [10, 0, 'x', 'x']
|
88
|
+
IPRange.new('10.0.x.x').padded_bytes.should == [10, 0, 'x', 'x']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
describe "#first" do
|
92
|
+
it "should return the first IP in the range" do
|
93
|
+
IPRange.new('10.0.x').first.should == IP.new('10.0.0.1')
|
94
|
+
IPRange.new('10.13.37.x').first.should == IP.new('10.13.37.1')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
describe "#last" do
|
98
|
+
it "should return the last IP in the range" do
|
99
|
+
IPRange.new('10.0.x').last.should == IP.new('10.0.255.255')
|
100
|
+
IPRange.new('10.13.37.x').last.should == IP.new('10.13.37.255')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
describe "#ip_for" do
|
104
|
+
it "should combine network and address parts" do
|
105
|
+
IPRange.new('10.0.1.x').ip_for('x.x.x.1').should == IP.new('10.0.1.1')
|
106
|
+
IPRange.new('10.13.37.x').ip_for('x.254').should == IP.new('10.13.37.254')
|
107
|
+
end
|
108
|
+
it "should default uncovered sections to 0" do
|
109
|
+
IPRange.new('10.0.x').ip_for('x.x.x.1').should == IP.new('10.0.0.1')
|
110
|
+
IPRange.new('10.x').ip_for('x.254').should == IP.new('10.0.0.254')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
describe "#subnet" do
|
114
|
+
it "should return the subnet mask" do
|
115
|
+
IPRange.new('10.0.1.x').subnet.should == '255.255.255.0'
|
116
|
+
IPRange.new('10.x') .subnet.should == '255.0.0.0'
|
117
|
+
IPRange.new('10.x.x.x').subnet.should == '255.0.0.0'
|
118
|
+
IPRange.new('10.0.x') .subnet.should == '255.255.0.0'
|
119
|
+
IPRange.new('10.0.x.x').subnet.should == '255.255.0.0'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
describe "#broadcast" do
|
123
|
+
it "should return the broadcast address" do
|
124
|
+
IPRange.new('10.0.1.x').broadcast.should == '10.0.1.255'
|
125
|
+
IPRange.new('10.x') .broadcast.should == '10.255.255.255'
|
126
|
+
IPRange.new('10.x.x.x').broadcast.should == '10.255.255.255'
|
127
|
+
IPRange.new('10.0.x') .broadcast.should == '10.0.255.255'
|
128
|
+
IPRange.new('10.0.x.x').broadcast.should == '10.0.255.255'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe "lambda choosing" do
|
5
|
+
it "should return the value of the block when there are no choices" do
|
6
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
7
|
+
"block value"
|
8
|
+
}.choose(:ours, :on).should == "block value"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should choose the specified call" do
|
12
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
13
|
+
on :ours, "this is ours"
|
14
|
+
on :theirs, "this is theirs"
|
15
|
+
}.choose(:ours, :on).should == ["this is ours"]
|
16
|
+
describe "with a block value" do
|
17
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
18
|
+
on :ours, "this is ours"
|
19
|
+
on :theirs, "this is theirs"
|
20
|
+
"block value"
|
21
|
+
}.choose(:ours, :on).should == ["this is ours"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should pick the first choice from multiple choices" do
|
26
|
+
LambdaChooser.new(nil, :ours, :yours, :theirs) {
|
27
|
+
on :ours, "this is ours"
|
28
|
+
on :yours, "this is yours"
|
29
|
+
on :theirs, "this is theirs"
|
30
|
+
}.choose([:ours, :yours], :on).should == ["this is ours"]
|
31
|
+
LambdaChooser.new(nil, :ours, :yours, :theirs) {
|
32
|
+
on :yours, "this is yours"
|
33
|
+
on :ours, "this is ours"
|
34
|
+
on :theirs, "this is theirs"
|
35
|
+
}.choose([:ours, :yours], :on).should == ["this is ours"]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should reject :otherwise as a choice name" do
|
39
|
+
L{
|
40
|
+
LambdaChooser.new(nil, :ours, :yours, :otherwise)
|
41
|
+
}.should raise_error(ArgumentError, "You can't use :otherwise as a choice name, because it's reserved.")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should pick 'otherwise' if no choices match" do
|
45
|
+
LambdaChooser.new(nil, :ours, :yours, :theirs) {
|
46
|
+
on :ours, "this is ours"
|
47
|
+
on :yours, "this is yours"
|
48
|
+
otherwise "this is the default"
|
49
|
+
}.choose(:theirs, :on).should == ["this is the default"]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return 'nil' if no choices match and there's no 'otherwise'" do
|
53
|
+
LambdaChooser.new(nil, :ours, :yours, :theirs) {
|
54
|
+
on :yours, "this is yours"
|
55
|
+
on :ours, "this is ours"
|
56
|
+
}.choose(:theirs, :on).should == nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not join lists from multiple choices" do
|
60
|
+
LambdaChooser.new(
|
61
|
+
nil,
|
62
|
+
:apt, :brew, :macports, :yum, :linux, :osx, :ubuntu, :debian, :osx, :karmic, :gutsy, :lucid, :intrepid, :dapper, :breezy, :jaunty, :feisty, :edgy, :warty, :hardy, :maverick, :hoary, :lenny, :snow_leopard, :panther, :tiger, :leopard
|
63
|
+
) {
|
64
|
+
on :maverick, %w[ruby ruby1.8-dev]
|
65
|
+
on :apt, %w[ruby irb ruby1.8-dev libopenssl-ruby]
|
66
|
+
}.choose(
|
67
|
+
[:maverick, :ubuntu, :apt, :linux, :all],
|
68
|
+
:on
|
69
|
+
).should == %w[ruby ruby1.8-dev]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should default the choice method to #on" do
|
73
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
74
|
+
on :ours, "this is ours"
|
75
|
+
on :theirs, "this is theirs"
|
76
|
+
}.choose(:ours).should == ["this is ours"]
|
77
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
78
|
+
on :ours, "this is ours"
|
79
|
+
on :theirs, "this is theirs"
|
80
|
+
}.choose(:ours, nil).should == ["this is ours"]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should reject values and block together" do
|
84
|
+
L{
|
85
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
86
|
+
on :ours, "this is ours"
|
87
|
+
on :theirs, "this is theirs" do
|
88
|
+
'another value'
|
89
|
+
end
|
90
|
+
}.choose(:ours, :on)
|
91
|
+
}.should raise_error("You can supply values or a block, but not both.")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should reject unknown choosers" do
|
95
|
+
L{
|
96
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
97
|
+
on :ours, "this is ours"
|
98
|
+
on :someone_elses, "this is theirs"
|
99
|
+
}.choose(:ours, :on)
|
100
|
+
}.should raise_error("The choice 'someone_elses' isn't valid.")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return the data intact" do
|
104
|
+
{
|
105
|
+
"string" => ["string"],
|
106
|
+
%w[a r r a y] => %w[a r r a y],
|
107
|
+
{:h => 'a', :s => 'h'} => {:h => 'a', :s => 'h'}
|
108
|
+
}.each_pair {|input, expected|
|
109
|
+
LambdaChooser.new(nil, :ours, :theirs) {
|
110
|
+
on :ours, input
|
111
|
+
on :theirs, "this is theirs"
|
112
|
+
}.choose(:ours, :on).should == expected
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dep_definer_support'
|
3
|
+
|
4
|
+
describe "declaration" do
|
5
|
+
before {
|
6
|
+
@meta = meta 'test'
|
7
|
+
}
|
8
|
+
it "should work" do
|
9
|
+
L{ meta 'count_test' }.should change(Base.sources.anonymous.templates, :count).by(1)
|
10
|
+
end
|
11
|
+
it "should set the name" do
|
12
|
+
@meta.name.should == 'test'
|
13
|
+
end
|
14
|
+
it "should downcase the name" do
|
15
|
+
meta("Case_Test").name.should == 'case_test'
|
16
|
+
end
|
17
|
+
it "should set the source" do
|
18
|
+
@meta.source.should == Base.sources.anonymous
|
19
|
+
end
|
20
|
+
it "should define a dep context" do
|
21
|
+
@meta.context_class.should be_an_instance_of(Class)
|
22
|
+
@meta.context_class.ancestors.should include(Babushka::DepContext)
|
23
|
+
end
|
24
|
+
it "should define template on the context" do
|
25
|
+
@meta.context_class.source_template.should == @meta
|
26
|
+
end
|
27
|
+
it "should not define a dep helper" do
|
28
|
+
Object.new.should_not respond_to('test')
|
29
|
+
end
|
30
|
+
it "should not be marked as suffixed" do
|
31
|
+
@meta.opts[:suffix].should be_false
|
32
|
+
end
|
33
|
+
after { Base.sources.anonymous.templates.clear! }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "using" do
|
37
|
+
describe "invalid templates" do
|
38
|
+
it "should not define deps as options" do
|
39
|
+
L{
|
40
|
+
dep('something undefined', :template => 'undefined').should be_nil
|
41
|
+
}.should raise_error(TemplateNotFound, "There is no template named 'undefined' to define 'something undefined' against.")
|
42
|
+
end
|
43
|
+
it "should define deps as options" do
|
44
|
+
dep('something.undefined').should be_an_instance_of(Dep)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "without template" do
|
49
|
+
before {
|
50
|
+
@meta = meta('templateless_test') {}
|
51
|
+
}
|
52
|
+
it "should define deps based on the template" do
|
53
|
+
dep('templateless dep.templateless_test').template.should == @meta
|
54
|
+
end
|
55
|
+
after { Base.sources.anonymous.templates.clear! }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "with template" do
|
59
|
+
before {
|
60
|
+
@meta = meta 'template_test' do
|
61
|
+
def a_helper_method
|
62
|
+
'hello from the helper!'
|
63
|
+
end
|
64
|
+
template {
|
65
|
+
def a_helper
|
66
|
+
'hello from the helper in the template!'
|
67
|
+
end
|
68
|
+
met? {
|
69
|
+
'this dep is met.'
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
}
|
74
|
+
it "should define the helper on the context class" do
|
75
|
+
@meta.context_class.respond_to?(:a_helper).should be_false
|
76
|
+
@meta.context_class.new(nil).respond_to?(:a_helper).should be_false
|
77
|
+
dep('dep1.template_test').context.respond_to?(:a_helper).should be_true
|
78
|
+
end
|
79
|
+
it "should correctly define the helper method" do
|
80
|
+
dep('dep2.template_test').context.a_helper_method.should == 'hello from the helper!'
|
81
|
+
end
|
82
|
+
it "should correctly define the helper" do
|
83
|
+
dep('dep2.template_test').context.a_helper.should == 'hello from the helper in the template!'
|
84
|
+
end
|
85
|
+
it "should correctly define the met? block" do
|
86
|
+
dep('dep3.template_test').send(:process_task, :met?).should == 'this dep is met.'
|
87
|
+
end
|
88
|
+
it "should override the template correctly" do
|
89
|
+
dep('dep4.template_test') {
|
90
|
+
met? { 'overridden met? block.' }
|
91
|
+
}.send(:process_task, :met?).should == 'overridden met? block.'
|
92
|
+
end
|
93
|
+
after { Base.sources.anonymous.templates.clear! }
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "acceptors" do
|
97
|
+
before {
|
98
|
+
@meta = meta 'acceptor_test' do
|
99
|
+
accepts_list_for :list_test
|
100
|
+
accepts_block_for :block_test
|
101
|
+
template {
|
102
|
+
met? {
|
103
|
+
list_test == ['valid']
|
104
|
+
}
|
105
|
+
meet {
|
106
|
+
block_test.call
|
107
|
+
}
|
108
|
+
}
|
109
|
+
end
|
110
|
+
}
|
111
|
+
it "should handle accepts_list_for" do
|
112
|
+
dep('unmet accepts_list_for.acceptor_test') { list_test 'invalid' }.met?.should be_false
|
113
|
+
dep('met accepts_list_for.acceptor_test') { list_test 'valid' }.met?.should be_true
|
114
|
+
end
|
115
|
+
it "should handle accepts_block_for" do
|
116
|
+
block_called = false
|
117
|
+
dep('accepts_block_for.acceptor_test') {
|
118
|
+
list_test 'invalid'
|
119
|
+
block_test {
|
120
|
+
block_called = true
|
121
|
+
}
|
122
|
+
}.meet
|
123
|
+
block_called.should be_true
|
124
|
+
end
|
125
|
+
after { Base.sources.anonymous.templates.clear! }
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "name checks" do
|
4
|
+
it "should not allow blank names" do
|
5
|
+
L{ meta(nil) }.should raise_error(ArgumentError, "You can't define a template with a blank name.")
|
6
|
+
L{ meta('') }.should raise_error(ArgumentError, "You can't define a template with a blank name.")
|
7
|
+
end
|
8
|
+
it "should not allow reserved names" do
|
9
|
+
L{ meta(:base) }.should raise_error(ArgumentError, "You can't use 'base' for a template name, because it's reserved.")
|
10
|
+
end
|
11
|
+
it "should allow valid names" do
|
12
|
+
L{ meta(:a) }.should_not raise_error
|
13
|
+
L{ meta('b') }.should_not raise_error
|
14
|
+
L{ meta('valid') }.should_not raise_error
|
15
|
+
end
|
16
|
+
it "should not allow spaces and numbers" do
|
17
|
+
L{ meta('meta dep 2') }.should raise_error(ArgumentError, "You can't use 'meta dep 2' for a template name - it can only contain [a-z0-9_].")
|
18
|
+
end
|
19
|
+
it "should not allow invalid characters" do
|
20
|
+
L{ meta("meta\ndep") }.should raise_error(ArgumentError, "You can't use 'meta\ndep' for a template name - it can only contain [a-z0-9_].")
|
21
|
+
end
|
22
|
+
it "should not allow names that don't start with a letter" do
|
23
|
+
L{ meta('3d_dep') }.should raise_error(ArgumentError, "You can't use '3d_dep' for a template name - it must start with a letter.")
|
24
|
+
end
|
25
|
+
describe "duplicate declaration" do
|
26
|
+
before { meta 'duplicate' }
|
27
|
+
it "should be prevented" do
|
28
|
+
L{ meta(:duplicate) }.should raise_error(ArgumentError, "A template called 'duplicate' has already been defined.")
|
29
|
+
end
|
30
|
+
after { Base.sources.anonymous.templates.clear! }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Parameter do
|
4
|
+
it "should not be set without a value" do
|
5
|
+
Parameter.new(:test).set?.should be_false
|
6
|
+
end
|
7
|
+
it "should be set with a value" do
|
8
|
+
Parameter.new(:test, 'testy test').set?.should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".for" do
|
12
|
+
let(:input) { 'testy test' }
|
13
|
+
let(:param) { Parameter.for(:test, input) }
|
14
|
+
it "should return a parameter" do
|
15
|
+
param.should be_an_instance_of(Parameter)
|
16
|
+
end
|
17
|
+
context "with Parameter input" do
|
18
|
+
let(:input) { Parameter.new(:test, 'testy test') }
|
19
|
+
it "should not re-wrap the Parameter" do
|
20
|
+
Parameter.for(:test, input).object_id.should == input.object_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#==" do
|
26
|
+
it "should behave like a string when it's set" do
|
27
|
+
Parameter.new(:test, "a value").should == "a value"
|
28
|
+
Parameter.new(:test, "a value").should_not == "another value"
|
29
|
+
end
|
30
|
+
it "should prompt when the value isn't set" do
|
31
|
+
Prompt.should_receive(:get_value)
|
32
|
+
Parameter.new(:test) == "a value"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#to_s" do
|
37
|
+
it "should delegate to the value" do
|
38
|
+
Parameter.new(:test, "a value").to_s.should == "a value"
|
39
|
+
end
|
40
|
+
it "should convert non-string values to strings" do
|
41
|
+
Parameter.new(:test, 3065).to_s.should == "3065"
|
42
|
+
end
|
43
|
+
it "should interpolate" do
|
44
|
+
"a #{Parameter.new(:adjective, "nice")} param".should == "a nice param"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#to_str" do
|
49
|
+
it "should delegate to the value" do
|
50
|
+
File.exists?(Parameter.new(:path, "/bin")).should be_true
|
51
|
+
end
|
52
|
+
it "should fail when the value itself would fail" do
|
53
|
+
parameter = Parameter.new(:path, 3065)
|
54
|
+
message = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
55
|
+
"Coercion error: #<Babushka::Parameter:#{parameter.object_id} path: 3065>.to_str => String failed"
|
56
|
+
else
|
57
|
+
"Can't coerce 3065:Fixnum into a String"
|
58
|
+
end
|
59
|
+
L{
|
60
|
+
File.exists?(parameter)
|
61
|
+
}.should raise_error(TypeError, message)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#description' do
|
66
|
+
it "should describe unset parameters" do
|
67
|
+
Parameter.new(:test).description.should == 'test: [unset]'
|
68
|
+
end
|
69
|
+
it "should describe unset parameters with defaults" do
|
70
|
+
Parameter.new(:test).default("a default").description.should == 'test: [default: "a default"]'
|
71
|
+
end
|
72
|
+
it "should describe unset parameters with bang-defaults" do
|
73
|
+
Parameter.new(:test).default!("a bang-default").description.should == 'test: [default!: "a bang-default"]'
|
74
|
+
end
|
75
|
+
it "should describe set parameters" do
|
76
|
+
Parameter.new(:test, "a value").description.should == 'test: "a value"'
|
77
|
+
end
|
78
|
+
it "should describe non-string values" do
|
79
|
+
Parameter.new(:test, %w[non-string value]).description.should == 'test: ["non-string", "value"]'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "other stringy methods" do
|
84
|
+
it "should work with #/" do
|
85
|
+
(Parameter.new(:test, "/path") / 'joining') == "/path/joining"
|
86
|
+
end
|
87
|
+
it "should work with #[]" do
|
88
|
+
Parameter.new(:test, "The Rural Jurour")[/ur/].should == 'ur'
|
89
|
+
end
|
90
|
+
it "should work with #p" do
|
91
|
+
Parameter.new(:test, "/bin").p.should be_an_instance_of(Fancypath)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#default!" do
|
96
|
+
it "should be returned when no value is set" do
|
97
|
+
Parameter.new(:unset).default!('default!').to_s.should == 'default!'
|
98
|
+
end
|
99
|
+
it "should be ignored when a value is set" do
|
100
|
+
Parameter.new(:set, 'value').default!('default!').to_s.should == 'value'
|
101
|
+
end
|
102
|
+
it "should take precedence over default values" do
|
103
|
+
Parameter.new(:unset).default!('default!').default('default').to_s.should == 'default!'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "asking for values" do
|
108
|
+
it "should request a value when it's not present" do
|
109
|
+
Prompt.should_receive(:get_value).with('unset', {}).and_return('value')
|
110
|
+
Parameter.new(:unset).to_s.should == 'value'
|
111
|
+
end
|
112
|
+
it "should pass the default from #default" do
|
113
|
+
Prompt.should_receive(:get_value).with('unset', :default => 'default').and_return('default')
|
114
|
+
Parameter.new(:unset).default('default').to_s.should == 'default'
|
115
|
+
end
|
116
|
+
it "should pass the message from #ask" do
|
117
|
+
Prompt.should_receive(:get_value).with('What number am I thinking of', {}).and_return('7')
|
118
|
+
Parameter.new(:unset).ask('What number am I thinking of').to_s.should == '7'
|
119
|
+
end
|
120
|
+
describe "choices, from #choose" do
|
121
|
+
it "should pass to #choices when given as an array" do
|
122
|
+
Prompt.should_receive(:get_value).with('unset', :choices => %w[a b]).and_return('a')
|
123
|
+
Parameter.new(:unset).choose(%w[a b]).to_s.should == 'a'
|
124
|
+
end
|
125
|
+
it "should pass to #choices when given as splatted args" do
|
126
|
+
Prompt.should_receive(:get_value).with('unset', :choices => %w[a b]).and_return('a')
|
127
|
+
Parameter.new(:unset).choose('a', 'b').to_s.should == 'a'
|
128
|
+
end
|
129
|
+
it "should pass to #choice_descriptions when given as a hash" do
|
130
|
+
Prompt.should_receive(:get_value).with('unset', :choice_descriptions => {:a => 'a', :b => 'b'}).and_return('a')
|
131
|
+
Parameter.new(:unset).choose(:a => 'a', :b => 'b').to_s.should == 'a'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|