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,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "console" do
|
4
|
+
before {
|
5
|
+
entry_point = File.expand_path(File.join(__FILE__, '../../../../lib/babushka'))
|
6
|
+
Cmdline.should_receive(:exec).with("irb -r'#{entry_point}' --simple-prompt")
|
7
|
+
}
|
8
|
+
it "should launch a console via Kernel#exec" do
|
9
|
+
Cmdline::Parser.for(%w[console]).run
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "help" do
|
4
|
+
context "with no verb" do
|
5
|
+
before {
|
6
|
+
[
|
7
|
+
"Babushka v#{Babushka::VERSION}, (c) 2011 Ben Hoskings <ben@hoskings.net>",
|
8
|
+
"\nThe gist:",
|
9
|
+
" #{Base.program_name} <command> [options]",
|
10
|
+
"\nAlso:",
|
11
|
+
" #{Base.program_name} help <command> # Print command-specific usage info",
|
12
|
+
" #{Base.program_name} <dep name> # A shortcut for 'babushka meet <dep name>'",
|
13
|
+
" #{Base.program_name} babushka # Update babushka itself (what babushka.me/up does)",
|
14
|
+
"\nCommands:",
|
15
|
+
" help Print usage information",
|
16
|
+
" version Print the current version",
|
17
|
+
" list List the available deps",
|
18
|
+
" meet The main one: run a dep and all its dependencies.",
|
19
|
+
" sources Manage dep sources",
|
20
|
+
" console Start an interactive (irb-based) babushka session",
|
21
|
+
" search Search for deps in the community database",
|
22
|
+
" edit Load the file containing the specified dep in $EDITOR",
|
23
|
+
"\nCommands can be abbrev'ed, as long as they remain unique.",
|
24
|
+
" e.g. '#{Base.program_name} l' is short for '#{Base.program_name} list'.",
|
25
|
+
"\n"
|
26
|
+
].each {|line|
|
27
|
+
Cmdline::Helpers.should_receive(:log).with(line)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
it "should print the verb help information" do
|
31
|
+
Cmdline::Parser.for(%w[help]).run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context "with a verb" do
|
35
|
+
let(:parser) { Cmdline::Parser.for(%w[help meet]) }
|
36
|
+
before {
|
37
|
+
[
|
38
|
+
"Babushka v#{Babushka::VERSION}, (c) 2011 Ben Hoskings <ben@hoskings.net>",
|
39
|
+
"\nmeet - The main one: run a dep and all its dependencies."
|
40
|
+
].each {|line|
|
41
|
+
Cmdline::Helpers.should_receive(:log).with(line)
|
42
|
+
}
|
43
|
+
|
44
|
+
parser.should_receive(:log).with("
|
45
|
+
-v, --version Print the current version
|
46
|
+
-h, --help Show this information
|
47
|
+
-d, --debug Show more verbose logging, and realtime shell command output
|
48
|
+
--[no-]color, --[no-]colour Disable color in the output
|
49
|
+
-n, --dry-run Discover the curent state without making any changes
|
50
|
+
-y, --defaults Assume the default value for all vars without prompting, where possible
|
51
|
+
--show-args Show the arguments being passed between deps as they're run
|
52
|
+
--track-blocks Track deps' blocks in TextMate as they're run
|
53
|
+
")
|
54
|
+
|
55
|
+
Cmdline::Helpers.should_receive(:log).with("\n")
|
56
|
+
}
|
57
|
+
it "should print the help information for the verb" do
|
58
|
+
parser.run
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array, "to_list" do
|
4
|
+
it "no elements" do
|
5
|
+
[].to_list.should == ''
|
6
|
+
end
|
7
|
+
it "single element" do
|
8
|
+
%w[a].to_list.should == 'a'
|
9
|
+
end
|
10
|
+
it "two elements" do
|
11
|
+
%w[a b].to_list.should == 'a and b'
|
12
|
+
end
|
13
|
+
it "three elements" do
|
14
|
+
%w[a b c].to_list.should == 'a, b and c'
|
15
|
+
end
|
16
|
+
it "oxford comma" do
|
17
|
+
%w[a b c].to_list(:oxford => true).should == 'a, b, and c'
|
18
|
+
end
|
19
|
+
it "custom conjugation" do
|
20
|
+
%w[a b c].to_list(:conj => 'or').should == 'a, b or c'
|
21
|
+
end
|
22
|
+
describe "limits" do
|
23
|
+
it "below limit" do
|
24
|
+
%w[a b c].to_list(:limit => 4).should == 'a, b and c'
|
25
|
+
end
|
26
|
+
it "at limit" do
|
27
|
+
%w[a b c].to_list(:limit => 3).should == 'a, b and c'
|
28
|
+
end
|
29
|
+
it "above limit" do
|
30
|
+
%w[a b c].to_list(:limit => 2).should == 'a, b et al'
|
31
|
+
%w[a b c d e].to_list(:limit => 4).should == 'a, b, c, d et al'
|
32
|
+
end
|
33
|
+
it "with noun" do
|
34
|
+
%w[a b c].to_list(:limit => 2, :noun => 'items').should == 'a, b et al - 3 items'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Array, '#collapse' do
|
40
|
+
it "should work for empty lists" do
|
41
|
+
[].collapse('blah').should == []
|
42
|
+
[].collapse(/blah/).should == []
|
43
|
+
end
|
44
|
+
it "should select surnames from a list" do
|
45
|
+
[
|
46
|
+
'Ben Hoskings',
|
47
|
+
'Nathan Sampimon',
|
48
|
+
'Nathan de Vries'
|
49
|
+
].collapse(/Nathan /).should == ['Sampimon', 'de Vries']
|
50
|
+
end
|
51
|
+
it "should strip git branch prefixes" do
|
52
|
+
[
|
53
|
+
' next',
|
54
|
+
'* master',
|
55
|
+
' topic'
|
56
|
+
].collapse(/^\* /).should == [
|
57
|
+
'master'
|
58
|
+
]
|
59
|
+
end
|
60
|
+
it "should use the replacement if passed" do
|
61
|
+
[
|
62
|
+
"Chain fail2ban-nginx-catchall (1 references)",
|
63
|
+
"target prot opt source destination",
|
64
|
+
"DROP all -- 58.161.41.76 0.0.0.0/0 ",
|
65
|
+
"RETURN all -- 0.0.0.0/0 0.0.0.0/0 "
|
66
|
+
].collapse(/^DROP\s+[^\d]+([\d\.]+)\s+.*/, '\1').should == [
|
67
|
+
'58.161.41.76'
|
68
|
+
]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Array, '#local_group_by' do
|
73
|
+
it "should work for empty lists" do
|
74
|
+
[].group_by(&:length).should == {}
|
75
|
+
end
|
76
|
+
it "should do what you expect" do
|
77
|
+
%w[cat badger narwahl pug].local_group_by(&:length).should == {
|
78
|
+
3 => %w[cat pug],
|
79
|
+
6 => %w[badger],
|
80
|
+
7 => %w[narwahl]
|
81
|
+
}
|
82
|
+
end
|
83
|
+
it "should work with nils and such" do
|
84
|
+
%w[cat badger narwahl pug].local_group_by {|i|
|
85
|
+
i[/a[rt]/]
|
86
|
+
}.should == {
|
87
|
+
nil => %w[badger pug],
|
88
|
+
'at' => %w[cat],
|
89
|
+
'ar' => %w[narwahl]
|
90
|
+
}
|
91
|
+
end
|
92
|
+
it "should return nil for keys that don't match a group" do
|
93
|
+
%w[cat badger narwahl pug].local_group_by(&:length)[4].should be_nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def version_of *args
|
98
|
+
Babushka::VersionOf::Helpers.VersionOf *args
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
describe Array, '#versions' do
|
103
|
+
{
|
104
|
+
%w[a] => [version_of('a')],
|
105
|
+
%w[a b c] => [version_of('a'), version_of('b'), version_of('c')],
|
106
|
+
[version_of('a')] => [version_of('a')],
|
107
|
+
['a 0.1', 'b >= 0.6.0', 'c ~> 2.2'] => [version_of('a', '0.1'), version_of('b', '>= 0.6.0'), version_of('c', '~> 2.2')]
|
108
|
+
}.each_pair {|input, expected|
|
109
|
+
it "should return #{expected.inspect} when passed #{input.inspect}" do
|
110
|
+
input.versions.should == expected
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Hash, '#defaults!' do
|
116
|
+
it "should work for empty hashes" do
|
117
|
+
{}.defaults!(:a => 'b', :c => 'd').should == {:a => 'b', :c => 'd'}
|
118
|
+
end
|
119
|
+
it "should work for empty defaults" do
|
120
|
+
{:a => 'custom b', :c => 'custom d'}.defaults!({}).should == {:a => 'custom b', :c => 'custom d'}
|
121
|
+
end
|
122
|
+
it "should combine defaults with the hash" do
|
123
|
+
{:a => 'custom b', :c => 'custom d'}.defaults!({:e => 'f', :g => 'h'}).should == {:a => 'custom b', :c => 'custom d', :e => 'f', :g => 'h'}
|
124
|
+
end
|
125
|
+
it "should override default values" do
|
126
|
+
{:a => 'custom b', :e => 'custom e'}.defaults!({:e => 'f', :g => 'h'}).should == {:a => 'custom b', :e => 'custom e', :g => 'h'}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe String, "val_for" do
|
131
|
+
it "space separation" do
|
132
|
+
'key value'.val_for('key').should == 'value'
|
133
|
+
end
|
134
|
+
it "key/value separation" do
|
135
|
+
'key: value'.val_for('key').should == 'value'
|
136
|
+
'key = value'.val_for('key').should == 'value'
|
137
|
+
end
|
138
|
+
it "whitespace" do
|
139
|
+
' key value '.val_for('key').should == 'value'
|
140
|
+
end
|
141
|
+
it "whitespace in key" do
|
142
|
+
'space-separated key: value'.val_for('space-separated key').should == 'value'
|
143
|
+
end
|
144
|
+
it "whitespace in value" do
|
145
|
+
'key: space-separated value'.val_for('key').should == 'space-separated value'
|
146
|
+
end
|
147
|
+
it "whitespace in both" do
|
148
|
+
'key with spaces: space-separated value'.val_for('key with spaces').should == 'space-separated value'
|
149
|
+
end
|
150
|
+
it "key ending in non-word characters" do
|
151
|
+
"psql (PostgreSQL) 9.1.0".val_for('psql (PostgreSQL)').should == '9.1.0'
|
152
|
+
end
|
153
|
+
it "non-word leading characters" do
|
154
|
+
'*key: value'.val_for('*key').should == 'value'
|
155
|
+
'-key: value'.val_for('-key').should == 'value'
|
156
|
+
'-key: value'.val_for('key').should == nil
|
157
|
+
end
|
158
|
+
it "non-word leading tokens" do
|
159
|
+
'* key: value'.val_for('key').should == 'value'
|
160
|
+
'- key with spaces: value'.val_for('key with spaces').should == 'value'
|
161
|
+
' -- key with spaces: value'.val_for('key with spaces').should == 'value'
|
162
|
+
end
|
163
|
+
it "trailing characters" do
|
164
|
+
'key: value;'.val_for('key').should == 'value'
|
165
|
+
'key: value,'.val_for('key').should == 'value'
|
166
|
+
end
|
167
|
+
it "paths" do
|
168
|
+
"/dev/disk1s2 Apple_HFS /Volumes/TextMate 1.5.9".val_for("/dev/disk1s2 Apple_HFS").should == "/Volumes/TextMate 1.5.9"
|
169
|
+
"/dev/disk1s2 Apple_HFS /Volumes/TextMate 1.5.9".val_for(/^\/dev\/disk\d+s\d+\s+Apple_HFS\s+/).should == "/Volumes/TextMate 1.5.9"
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dep_definer_support'
|
3
|
+
|
4
|
+
describe "accepts_block_for behaviour" do
|
5
|
+
before {
|
6
|
+
Dep.stub!(:base_template).and_return(TestTemplate)
|
7
|
+
setup_test_lambdas
|
8
|
+
dep 'default'
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should define a declarer" do
|
12
|
+
Dep('default').context.should_not respond_to(:test_defining)
|
13
|
+
TestDepContext.accepts_block_for :test_defining
|
14
|
+
Dep('default').context.should respond_to(:test_defining)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return lambda" do
|
18
|
+
TestDepContext.accepts_block_for :test_defining
|
19
|
+
lambda = L{ 'blah' }
|
20
|
+
value_from_block = nil
|
21
|
+
dep 'returning test' do
|
22
|
+
value_from_block = test_defining &lambda
|
23
|
+
end.met?
|
24
|
+
value_from_block.should == lambda
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should accept and return a block" do
|
28
|
+
test_accepts_block_for_response :test_response, @lambda_hello, @lambda_hello
|
29
|
+
end
|
30
|
+
it "should accept and return a block for this system" do
|
31
|
+
test_accepts_block_for_response :test_this_system, @lambda_hello, @lambda_hello, :on => Base.host.system
|
32
|
+
end
|
33
|
+
it "should return nothing on a non-specified system" do
|
34
|
+
test_accepts_block_for_response :test_other_system, @lambda_hello, nil, :on => :nonexistent
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should use default blocks when no specific one is specified" do
|
38
|
+
lambda = L{ 'default value' }
|
39
|
+
TestDepContext.accepts_block_for :test_defaults, &lambda
|
40
|
+
value_from_block = nil
|
41
|
+
dep 'default test' do
|
42
|
+
value_from_block = test_defaults
|
43
|
+
end.met?
|
44
|
+
value_from_block.should == lambda
|
45
|
+
end
|
46
|
+
|
47
|
+
after { Base.sources.anonymous.deps.clear! }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "accepts_list_for behaviour" do
|
51
|
+
before {
|
52
|
+
Babushka::Base.stub!(:host).and_return FakeOSXSystemProfile.new
|
53
|
+
make_test_deps
|
54
|
+
}
|
55
|
+
it "should choose requires for the correct system" do
|
56
|
+
Dep('test build tools').context.requires.should == ['xcode tools']
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dep_definer_support'
|
3
|
+
|
4
|
+
describe "source_template" do
|
5
|
+
it "should return BaseTemplate" do
|
6
|
+
TestDepContext.source_template.should == Dep::BaseTemplate
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "args" do
|
11
|
+
describe "parsing style" do
|
12
|
+
it "should parse as named when just a single hash is passed" do
|
13
|
+
dep('1 arg', :a).tap {|dep|
|
14
|
+
dep.should_receive(:parse_named_arguments).with({:a => 'a'}).and_return({})
|
15
|
+
dep.with(:a => 'a')
|
16
|
+
}
|
17
|
+
end
|
18
|
+
it "should parse as a list when non-hash values are passed" do
|
19
|
+
dep('2 args', :a, :b).tap {|dep|
|
20
|
+
dep.should_receive(:parse_positional_arguments).with(['a', {'key' => 'value'}]).and_return({})
|
21
|
+
dep.with('a', 'key' => 'value')
|
22
|
+
}
|
23
|
+
end
|
24
|
+
it "should parse as a list when no args are passed" do
|
25
|
+
dep('no args').tap {|dep|
|
26
|
+
dep.should_receive(:parse_positional_arguments).with([]).and_return({})
|
27
|
+
dep.with
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "without arguments" do
|
32
|
+
it "should fail when called with unnamed args" do
|
33
|
+
L{ dep('no args').with('a') }.should raise_error(DepArgumentError, "The dep 'no args' accepts 0 arguments, but 1 was passed.")
|
34
|
+
end
|
35
|
+
it "should fail when called with named args that don't match" do
|
36
|
+
L{ dep('no args').with(:a => 'a') }.should raise_error(DepArgumentError, "The dep 'no args' received an unexpected argument :a.")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context "with the wrong number of arguments" do
|
40
|
+
it "should fail when called with the wrong number of unnamed args" do
|
41
|
+
L{ dep('1 arg', :a).with('a', 'b') }.should raise_error(DepArgumentError, "The dep '1 arg' accepts 1 argument, but 2 were passed.")
|
42
|
+
L{ dep('2 args', :a, :b).with('a') }.should raise_error(DepArgumentError, "The dep '2 args' accepts 2 arguments, but 1 was passed.")
|
43
|
+
end
|
44
|
+
it "should fail when called with named args that don't match" do
|
45
|
+
L{ dep('1 arg', :a).with(:a => 'a', :b => 'b') }.should raise_error(DepArgumentError, "The dep '1 arg' received an unexpected argument :b.")
|
46
|
+
L{ dep('1 arg', :a).with(:a => 'a', :b => 'b', :c => 'c') }.should raise_error(DepArgumentError, "The dep '1 arg' received unexpected arguments :b and :c.")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context "with empty arguments" do
|
50
|
+
subject { dep('2 args', :a, :b).with() }
|
51
|
+
it "should populate the args with Parameter objects" do
|
52
|
+
subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
|
53
|
+
end
|
54
|
+
it "should set the names correctly" do
|
55
|
+
subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
|
56
|
+
end
|
57
|
+
it "should not set the values" do
|
58
|
+
subject.args.values.each {|v| v.should_not be_set }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "with the right number of positional arguments" do
|
62
|
+
subject { dep('2 args', :a, :b).with('a', 'b') }
|
63
|
+
it "should populate the args with Parameter objects" do
|
64
|
+
subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
|
65
|
+
end
|
66
|
+
it "should set the names correctly" do
|
67
|
+
subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
|
68
|
+
end
|
69
|
+
it "should set the values" do
|
70
|
+
subject.args.values.each {|v| v.should be_set }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "with the correct named arguments" do
|
74
|
+
subject { dep('2 args', :a, :b).with(:a => 'a', :b => 'b') }
|
75
|
+
it "should populate the args with Parameter objects" do
|
76
|
+
subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
|
77
|
+
end
|
78
|
+
it "should set the names correctly" do
|
79
|
+
subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
|
80
|
+
end
|
81
|
+
it "should set the values" do
|
82
|
+
subject.args.values.each {|v| v.should be_set }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
context "with non-symbol names" do
|
86
|
+
it "should be rejected, singular" do
|
87
|
+
L{
|
88
|
+
dep('2 args', :a).with('a' => 'a')
|
89
|
+
}.should raise_error(DepArgumentError, %{The dep '2 args' received a non-symbol argument "a".})
|
90
|
+
end
|
91
|
+
it "should be rejected, plural" do
|
92
|
+
L{
|
93
|
+
dep('2 args', :a, :b).with('a' => 'a', 'b' => 'b')
|
94
|
+
}.should raise_error(DepArgumentError, %{The dep '2 args' received non-symbol arguments "a" and "b".})
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context "with incomplete named arguments" do
|
98
|
+
subject { dep('2 args', :a, :b).with(:a => 'a') }
|
99
|
+
it "should partially populate the args with Parameter objects" do
|
100
|
+
subject.args.map_values {|_,v| v.class }.should == {:a => Parameter}
|
101
|
+
end
|
102
|
+
it "should set the names that are present correctly" do
|
103
|
+
subject.args.map_values {|_,v| v.name }.should == {:a => :a}
|
104
|
+
end
|
105
|
+
it "should lazily create the missing parameter" do
|
106
|
+
subject.context.b.should be_an_instance_of(Parameter)
|
107
|
+
subject.context.b.name.should == :b
|
108
|
+
end
|
109
|
+
it "should set only the paramters that were passed" do
|
110
|
+
subject.context.a.should be_set
|
111
|
+
subject.context.b.should_not be_set
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "methods in deps" do
|
117
|
+
before {
|
118
|
+
dep 'helper method test' do
|
119
|
+
def helper_test
|
120
|
+
'hello from the helper method!'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
dep 'without helper method'
|
124
|
+
}
|
125
|
+
it "should only be defined on the specified dep" do
|
126
|
+
Dep('helper method test').context.should respond_to(:helper_test)
|
127
|
+
Dep('without helper method').context.should_not respond_to(:helper_test)
|
128
|
+
end
|
129
|
+
it "should return the right value" do
|
130
|
+
Dep('helper method test').context.helper_test.should == 'hello from the helper method!'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#on for scoping accepters" do
|
135
|
+
before {
|
136
|
+
Base.stub!(:host).and_return OSXSystemProfile.for_flavour
|
137
|
+
Base.host.stub!(:version).and_return '10.6.7'
|
138
|
+
@lambda = lambda = L{ 'hello from the lambda' }
|
139
|
+
@other_lambda = other_lambda = L{ 'hello from the other lambda' }
|
140
|
+
dep 'scoping' do
|
141
|
+
on :osx do
|
142
|
+
met?(&lambda)
|
143
|
+
end
|
144
|
+
on :linux do
|
145
|
+
met?(&other_lambda)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
}
|
149
|
+
it "should only allow choices that match" do
|
150
|
+
Dep('scoping').send(:payload)[:met?].should == {:osx => @lambda}
|
151
|
+
end
|
152
|
+
end
|