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,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class RunTester; extend RunHelpers end
|
4
|
+
|
5
|
+
describe "grep" do
|
6
|
+
it "should grep existing files" do
|
7
|
+
RunTester.grep('include', 'spec/spec_helper.rb').should include("include Babushka\n")
|
8
|
+
end
|
9
|
+
it "should return nil when there are no matches" do
|
10
|
+
RunTester.grep('lol', 'spec/spec_helper.rb').should be_nil
|
11
|
+
end
|
12
|
+
it "should return nil for nonexistent files" do
|
13
|
+
RunTester.grep('lol', '/nonexistent').should be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "change_line" do
|
18
|
+
path = "#{tmp_prefix}/babushka_run_helper_change_line"
|
19
|
+
it "should not mangle a file" do
|
20
|
+
File.open(path, "w") { |f| f.write "one\ntwo\nthree\n" }
|
21
|
+
RunTester.change_line("two", "changed", path)
|
22
|
+
lines = File.open(path, "r") { |f| f.readlines.map{ |l| l.chomp } }
|
23
|
+
lines.values_at(0,3,4).should == ["one", "changed", "three"]
|
24
|
+
lines.length.should == 5 # two comments added
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
SucceedingLs = 'ls /bin'
|
4
|
+
FailingLs = 'ls /nonexistent'
|
5
|
+
|
6
|
+
describe "shell" do
|
7
|
+
it "should return something true on successful commands" do
|
8
|
+
shell('true').should_not be_nil
|
9
|
+
end
|
10
|
+
it "should return nil on failed commands" do
|
11
|
+
shell('false').should be_nil
|
12
|
+
end
|
13
|
+
it "should return output of successful commands" do
|
14
|
+
shell('echo lol').should == 'lol'
|
15
|
+
end
|
16
|
+
it "should accept multiline commands" do
|
17
|
+
shell("echo babu &&\necho shka").should == "babu\nshka"
|
18
|
+
end
|
19
|
+
it "should accept environment variables as the first argument" do
|
20
|
+
shell({'KEY' => 'value'}, "echo $KEY").should == "value"
|
21
|
+
end
|
22
|
+
it "should provide the shell to supplied blocks when the command succeeds" do
|
23
|
+
(the_block = "").should_receive(:was_called)
|
24
|
+
shell(SucceedingLs) {|shell|
|
25
|
+
the_block.was_called
|
26
|
+
shell.stdout.should include('bash')
|
27
|
+
shell.stderr.should be_empty
|
28
|
+
}
|
29
|
+
end
|
30
|
+
it "should provide the shell to supplied blocks when the command fails" do
|
31
|
+
(the_block = "").should_receive(:was_called)
|
32
|
+
shell(FailingLs) {|shell|
|
33
|
+
the_block.was_called
|
34
|
+
shell.stdout.should be_empty
|
35
|
+
shell.stderr.should include("No such file or directory")
|
36
|
+
}
|
37
|
+
end
|
38
|
+
it "should accept :input parameter" do
|
39
|
+
shell('cat', :input => 'lol').should == "lol"
|
40
|
+
end
|
41
|
+
context ":cd parameter" do
|
42
|
+
before { (tmp_prefix / 'dir_param').mkdir }
|
43
|
+
it "should run in the current directory when :cd isn't specified" do
|
44
|
+
shell("pwd").should == Dir.pwd
|
45
|
+
end
|
46
|
+
it "should run in the specified directory" do
|
47
|
+
shell("pwd", :cd => (tmp_prefix / 'dir_param')).should == (tmp_prefix / 'dir_param').to_s
|
48
|
+
end
|
49
|
+
it "should expand the path" do
|
50
|
+
shell("pwd", :cd => '~').should == ENV['HOME']
|
51
|
+
end
|
52
|
+
it "should raise when the path is nonexistent" do
|
53
|
+
L{
|
54
|
+
shell("pwd", :cd => (tmp_prefix / 'nonexistent'))
|
55
|
+
}.should raise_error(Errno::ENOENT, "No such file or directory - #{tmp_prefix / 'nonexistent'}")
|
56
|
+
end
|
57
|
+
context "with :create option" do
|
58
|
+
it "should run in the specified directory" do
|
59
|
+
shell("pwd", :cd => (tmp_prefix / 'dir_param'), :create => true).should == (tmp_prefix / 'dir_param').to_s
|
60
|
+
end
|
61
|
+
it "should create and run when the path is nonexistent" do
|
62
|
+
shell("pwd", :cd => (tmp_prefix / 'dir_param_with_create'), :create => true).should == (tmp_prefix / 'dir_param_with_create').to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "shell?" do
|
69
|
+
it "should return the output for successful commands" do
|
70
|
+
shell?('echo lol').should == 'lol'
|
71
|
+
shell?(SucceedingLs).should be_true
|
72
|
+
end
|
73
|
+
it "should return false for failed commands" do
|
74
|
+
shell?('false').should be_false
|
75
|
+
shell?(FailingLs).should be_false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "shell!" do
|
80
|
+
it "should return the output for successful commands" do
|
81
|
+
shell!('echo lol').should == 'lol'
|
82
|
+
shell!(SucceedingLs).should be_true
|
83
|
+
end
|
84
|
+
it "should return false for failed commands" do
|
85
|
+
L{ shell!('false') }.should raise_error(Shell::ShellCommandFailed, "Shell command failed: 'false'")
|
86
|
+
L{ shell!(FailingLs) }.should raise_error(Shell::ShellCommandFailed)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "raw_shell" do
|
91
|
+
it "should always return a Shell" do
|
92
|
+
raw_shell('true').should be_a(Shell)
|
93
|
+
raw_shell('false').should be_a(Shell)
|
94
|
+
end
|
95
|
+
it "should return stdout for succeeding commands" do
|
96
|
+
shell = raw_shell(SucceedingLs)
|
97
|
+
shell.stdout.should include("bash")
|
98
|
+
shell.stderr.should be_empty
|
99
|
+
end
|
100
|
+
it "should return stderr for failed commands" do
|
101
|
+
shell = raw_shell(FailingLs)
|
102
|
+
shell.stdout.should be_empty
|
103
|
+
shell.stderr.should include("No such file or directory")
|
104
|
+
end
|
105
|
+
it "should support sudo" do
|
106
|
+
should_receive(:shell).with('whoami', :sudo => true).once
|
107
|
+
raw_shell('whoami', :sudo => true)
|
108
|
+
end
|
109
|
+
it "should handle env vars" do
|
110
|
+
raw_shell({'KEY' => 'value'}, 'echo $KEY').stdout.should == "value\n"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'argument behaviour' do
|
115
|
+
context "with a single string" do
|
116
|
+
it "should support compound commands" do
|
117
|
+
shell("echo trousers | tr a-z A-Z").should == 'TROUSERS'
|
118
|
+
end
|
119
|
+
it "should fail with unclosed quotes" do
|
120
|
+
shell('echo blah"').should be_nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
context "with an array" do
|
124
|
+
it "should treat as a command and args" do
|
125
|
+
shell(%w[echo trousers | tr a-z A-Z]).should == 'trousers | tr a-z A-Z'
|
126
|
+
end
|
127
|
+
it "should escape unclosed quotes" do
|
128
|
+
shell(['echo', 'blah"']).should == 'blah"'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "sudo" do
|
134
|
+
it "should reject array input" do
|
135
|
+
L{ sudo(%w[whoami]) }.should raise_error(ArgumentError, "#sudo commands have to be passed as a single string, not splatted strings or an array, since the `sudo` is composed from strings.")
|
136
|
+
end
|
137
|
+
it "should run as root when no user is given" do
|
138
|
+
should_receive(:shell_cmd).with({}, 'sudo -u root whoami', {}).once
|
139
|
+
sudo('whoami')
|
140
|
+
end
|
141
|
+
it "should run as the given user" do
|
142
|
+
should_receive(:shell_cmd).with({}, 'sudo -u batman whoami', {}).once
|
143
|
+
sudo('whoami', :as => 'batman')
|
144
|
+
end
|
145
|
+
it "should treat :sudo => 'string' as a username" do
|
146
|
+
should_receive(:shell_cmd).with({}, 'sudo -u batman whoami', {}).once
|
147
|
+
shell('whoami', :sudo => 'batman')
|
148
|
+
end
|
149
|
+
it "should sudo from #shell when :as is specified" do
|
150
|
+
should_receive(:shell_cmd).with({}, 'sudo -u root whoami', {}).once
|
151
|
+
shell('whoami', :as => 'root')
|
152
|
+
end
|
153
|
+
context "when already running as the sudo user" do
|
154
|
+
it "should not sudo when the user is already root" do
|
155
|
+
stub!(:current_username).and_return('root')
|
156
|
+
should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
157
|
+
sudo('whoami')
|
158
|
+
end
|
159
|
+
it "should not sudo with :as" do
|
160
|
+
stub!(:current_username).and_return('batman')
|
161
|
+
should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
162
|
+
sudo('whoami', :as => 'batman')
|
163
|
+
end
|
164
|
+
it "should not sudo with a :sudo => 'string' username" do
|
165
|
+
stub!(:current_username).and_return('batman')
|
166
|
+
should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
167
|
+
shell('whoami', :sudo => 'batman')
|
168
|
+
end
|
169
|
+
it "should not sudo from #shell when :as is specified" do
|
170
|
+
stub!(:current_username).and_return('root')
|
171
|
+
should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
172
|
+
shell('whoami', :as => 'root')
|
173
|
+
end
|
174
|
+
it "should handle env vars properly" do
|
175
|
+
stub!(:current_username).and_return('root')
|
176
|
+
should_receive(:shell_cmd).with({'KEY' => 'value'}, 'echo $KEY', {}).once
|
177
|
+
sudo({'KEY' => 'value'}, 'echo $KEY')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
describe "compound commands" do
|
181
|
+
it "should use 'sudo su -' when opts[:su] is supplied" do
|
182
|
+
should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\`"', {}).once
|
183
|
+
sudo("echo \\`whoami\\`", :su => true)
|
184
|
+
end
|
185
|
+
it "should use 'sudo su -' for redirects" do
|
186
|
+
should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\` > %s/su_with_redirect"' % tmp_prefix, {}).once
|
187
|
+
sudo("echo \\`whoami\\` > %s/su_with_redirect" % tmp_prefix)
|
188
|
+
end
|
189
|
+
it "should use 'sudo su -' for pipes" do
|
190
|
+
should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\` | tee %s/su_with_pipe"' % tmp_prefix, {}).once
|
191
|
+
sudo("echo \\`whoami\\` | tee %s/su_with_pipe" % tmp_prefix)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "log_shell" do
|
197
|
+
it "should log correctly for a successful command" do
|
198
|
+
should_receive(:log).with("Getting uptime...", {:newline=>false}).once
|
199
|
+
should_receive(:shell).with('uptime', {:spinner=>true}).and_return("days and days")
|
200
|
+
should_receive(:log).with(" done.", {:as=>nil, :indentation=>false}).once
|
201
|
+
log_shell 'Getting uptime', 'uptime'
|
202
|
+
end
|
203
|
+
it "should log correctly for a failing command" do
|
204
|
+
should_receive(:log).with("Setting sail for fail...", {:newline=>false}).once
|
205
|
+
should_receive(:shell).with('false', {:spinner=>true}).and_return(nil)
|
206
|
+
should_receive(:log).with(" failed", {:as=>:error, :indentation=>false}).once
|
207
|
+
log_shell 'Setting sail for fail', 'false'
|
208
|
+
end
|
209
|
+
it "should handle env vars" do
|
210
|
+
should_receive(:log).with("Echoing some vars...", {:newline=>false}).once
|
211
|
+
should_receive(:shell).with({'KEY' => 'value'}, 'echo $KEY', {:spinner=>true}).and_return('value')
|
212
|
+
should_receive(:log).with(" done.", {:as=>nil, :indentation=>false}).once
|
213
|
+
log_shell 'Echoing some vars', {'KEY' => 'value'}, 'echo $KEY'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "which" do
|
218
|
+
it "should return a string" do
|
219
|
+
which('ls').should be_an_instance_of(String)
|
220
|
+
end
|
221
|
+
it "should return the path for valid commands" do
|
222
|
+
path = `which ls`.chomp
|
223
|
+
which('ls').should == path
|
224
|
+
end
|
225
|
+
it "should return nil for nonexistent commands" do
|
226
|
+
which('nonexistent').should be_nil
|
227
|
+
end
|
228
|
+
it "should handle command parameter passed as Symbol" do
|
229
|
+
path = `which ls`.chomp
|
230
|
+
which(:ls).should == path
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "cmd_dir" do
|
235
|
+
it "should return a string" do
|
236
|
+
cmd_dir('ruby').should be_an_instance_of(String)
|
237
|
+
end
|
238
|
+
it "should return the cmd_dir of an existing command" do
|
239
|
+
cmd_dir('ruby').should == `which ruby`.chomp.gsub(/\/ruby$/, '')
|
240
|
+
end
|
241
|
+
it "should return nil for nonexistent commands" do
|
242
|
+
cmd_dir('nonexistent').should be_nil
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shell, '#ok?' do
|
4
|
+
it "should return true on success" do
|
5
|
+
Shell.new('true', {}).run(&:ok?).should be_true
|
6
|
+
end
|
7
|
+
it "should return false on failure" do
|
8
|
+
Shell.new('false', {}).run(&:ok?).should be_false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Shell, '#result' do
|
13
|
+
it "should return zero on success" do
|
14
|
+
Shell.new('true', {}).run(&:result).should == 0
|
15
|
+
end
|
16
|
+
it "should return non-zero on failure" do
|
17
|
+
Shell.new('false', {}).run(&:result).should == 1
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'source_support'
|
3
|
+
require 'source_pool_support'
|
4
|
+
|
5
|
+
describe SourcePool, '#source_for' do
|
6
|
+
before {
|
7
|
+
@source1 = Source.new nil, :name => 'source_1'
|
8
|
+
@source1.stub!(:load!)
|
9
|
+
@source2 = Source.new nil, :name => 'source_2'
|
10
|
+
@source2.stub!(:load!)
|
11
|
+
Base.sources.stub!(:current).and_return([@source1])
|
12
|
+
Source.stub!(:present).and_return([@source2])
|
13
|
+
}
|
14
|
+
it "should find core sources" do
|
15
|
+
Base.sources.source_for('source_1').should == @source1
|
16
|
+
end
|
17
|
+
it "should find cloned sources" do
|
18
|
+
Base.sources.source_for('source_2').should == @source2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Dep, '#dep_for, disregarding sources' do
|
23
|
+
before {
|
24
|
+
@dep = dep 'Base.sources.dep_for tests'
|
25
|
+
}
|
26
|
+
it "should work for strings" do
|
27
|
+
Base.sources.dep_for('Base.sources.dep_for tests').should == @dep
|
28
|
+
end
|
29
|
+
it "should work for deps" do
|
30
|
+
Base.sources.dep_for(@dep).should == @dep
|
31
|
+
end
|
32
|
+
it "should not find the dep with namespacing" do
|
33
|
+
Base.sources.dep_for('namespaced:namespaced Base.sources.dep_for tests').should be_nil
|
34
|
+
end
|
35
|
+
context "with namespaced dep defined" do
|
36
|
+
before {
|
37
|
+
@source = Source.new(nil, :name => 'namespaced')
|
38
|
+
Source.stub!(:present).and_return([@source])
|
39
|
+
Base.sources.load_context :source => @source do
|
40
|
+
@namespaced_dep = dep 'Base.sources.dep_for tests'
|
41
|
+
end
|
42
|
+
}
|
43
|
+
it "should work with namespacing" do
|
44
|
+
Base.sources.dep_for('namespaced:Base.sources.dep_for tests').should == @namespaced_dep
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe SourcePool, '#dep_for' do
|
50
|
+
before {
|
51
|
+
@source1 = Source.new nil, :name => 'source_1'
|
52
|
+
@source1.stub!(:load!)
|
53
|
+
@source2 = Source.new nil, :name => 'source_2'
|
54
|
+
@source2.stub!(:load!)
|
55
|
+
Base.sources.load_context :source => @source1 do
|
56
|
+
@dep1 = dep 'dep 1'
|
57
|
+
@dep2 = dep 'dep 2'
|
58
|
+
end
|
59
|
+
Base.sources.load_context :source => @source2 do
|
60
|
+
@dep3 = dep 'dep 3'
|
61
|
+
@dep4 = dep 'dep 4'
|
62
|
+
end
|
63
|
+
Base.sources.stub!(:current).and_return([@source1, @source2])
|
64
|
+
Source.stub!(:present).and_return([@source1, @source2])
|
65
|
+
}
|
66
|
+
it "should look up the correct deps without namespacing" do
|
67
|
+
Base.sources.dep_for('dep 1').should == @dep1
|
68
|
+
Base.sources.dep_for('dep 4').should == @dep4
|
69
|
+
end
|
70
|
+
it "should find the dep when the namespace is correct" do
|
71
|
+
Base.sources.dep_for('source_1:dep 1').should == @dep1
|
72
|
+
Base.sources.dep_for('source_2:dep 4').should == @dep4
|
73
|
+
end
|
74
|
+
it "should not find the dep when the namespace is wrong" do
|
75
|
+
Base.sources.dep_for('source_1:dep 3').should be_nil
|
76
|
+
Base.sources.dep_for('source_2:dep 2').should be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe SourcePool, '#dep_for core' do
|
81
|
+
before {
|
82
|
+
@core = Source.new nil, :name => 'core'
|
83
|
+
@core.stub!(:load!)
|
84
|
+
Base.sources.load_context :source => @core do
|
85
|
+
@dep1 = dep 'dep 1'
|
86
|
+
@dep2 = dep 'dep 2'
|
87
|
+
end
|
88
|
+
Base.sources.stub!(:current).and_return([@core])
|
89
|
+
}
|
90
|
+
it "should find the correct deps without namespacing" do
|
91
|
+
Base.sources.dep_for('dep 1').should == @dep1
|
92
|
+
Base.sources.dep_for('dep 4').should == @dep4
|
93
|
+
end
|
94
|
+
it "should find the dep when the namespace is correct" do
|
95
|
+
Base.sources.dep_for('core:dep 1').should == @dep1
|
96
|
+
end
|
97
|
+
it "should not find the dep when the namespace is wrong" do
|
98
|
+
Base.sources.dep_for('non_core:dep 1').should be_nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe SourcePool, '#template_for' do
|
103
|
+
before {
|
104
|
+
mock_sources
|
105
|
+
}
|
106
|
+
context "without namespacing" do
|
107
|
+
it "should find templates in the anonymous source" do
|
108
|
+
Base.sources.template_for('anonymous_meta').should == @anonymous_meta
|
109
|
+
end
|
110
|
+
it "should find templates in the core source" do
|
111
|
+
Base.sources.template_for('core_meta').should == @core_meta
|
112
|
+
end
|
113
|
+
it "should not find templates from non-default sources" do
|
114
|
+
Base.sources.template_for('meta_1').should be_nil
|
115
|
+
Base.sources.template_for('meta_3').should be_nil
|
116
|
+
end
|
117
|
+
context "with :from" do
|
118
|
+
it "should find the template in the same source" do
|
119
|
+
Base.sources.template_for('from_test', :from => @source1).should == @from1
|
120
|
+
Base.sources.template_for('from_test', :from => @source2).should == @from2
|
121
|
+
end
|
122
|
+
context "when it doesn't exist in the :from source" do
|
123
|
+
it "should find the template in the core source" do
|
124
|
+
Base.sources.template_for('core_from', :from => @source1).should == @core_from
|
125
|
+
end
|
126
|
+
it "should not find the template in other sources" do
|
127
|
+
Base.sources.template_for('from_test_2', :from => @source1).should be_nil
|
128
|
+
Base.sources.template_for('from_test_2', :from => @source2).should_not be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
context "with namespacing" do
|
134
|
+
it "should find the dep when the namespace is correct" do
|
135
|
+
Base.sources.template_for('source_1:meta_1').should == @meta1
|
136
|
+
Base.sources.template_for('source_2:meta_4').should == @meta4
|
137
|
+
end
|
138
|
+
it "should not find the dep when the namespace is wrong" do
|
139
|
+
Base.sources.template_for('source_1:').should be_nil
|
140
|
+
Base.sources.template_for('source_2:meta 2').should be_nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
after {
|
144
|
+
Base.sources.anonymous.templates.clear!
|
145
|
+
Base.sources.core.templates.clear!
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
describe SourcePool, '#load_context' do
|
150
|
+
context "without a template" do
|
151
|
+
before {
|
152
|
+
Dep.should_receive(:new).with('load_context', Base.sources.anonymous, [], {}, nil)
|
153
|
+
}
|
154
|
+
it "should pass the correct options" do
|
155
|
+
dep 'load_context'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
context "with a template" do
|
159
|
+
let(:source) {
|
160
|
+
Source.new *make_source_remote('load_context')
|
161
|
+
}
|
162
|
+
let!(:template) {
|
163
|
+
Base.sources.load_context :source => source do
|
164
|
+
meta 'load_context_template'
|
165
|
+
end
|
166
|
+
}
|
167
|
+
let!(:the_dep) {
|
168
|
+
Base.sources.load_context :source => source do
|
169
|
+
dep 'defining test with template.load_context_template'
|
170
|
+
end
|
171
|
+
}
|
172
|
+
it "should use the template" do
|
173
|
+
the_dep.template.should == template
|
174
|
+
end
|
175
|
+
after {
|
176
|
+
source.remove!
|
177
|
+
}
|
178
|
+
end
|
179
|
+
context "with nesting" do
|
180
|
+
before {
|
181
|
+
@source1, @source2 = Source.new(nil), Source.new(nil)
|
182
|
+
}
|
183
|
+
it "should maintain the outer context after the inner one returns" do
|
184
|
+
Base.sources.load_context :source => @source1 do
|
185
|
+
Base.sources.current_load_source.should == @source1
|
186
|
+
Base.sources.load_context :source => @source2 do
|
187
|
+
Base.sources.current_load_source.should == @source2
|
188
|
+
end
|
189
|
+
Base.sources.current_load_source.should == @source1
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "template selection during defining" do
|
196
|
+
before {
|
197
|
+
mock_sources
|
198
|
+
}
|
199
|
+
context "with namespacing" do
|
200
|
+
it "should use templates from the named source" do
|
201
|
+
dep('template selection 1', :template => 'source_1:meta_1').template.should == @meta1
|
202
|
+
end
|
203
|
+
it "should not find the template with the wrong source prefix, and raise" do
|
204
|
+
L{
|
205
|
+
dep('template selection 2', :template => 'source_2:meta_1')
|
206
|
+
}.should raise_error(TemplateNotFound, "There is no template named 'source_2:meta_1' to define 'template selection 2' against.")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
context "without namespacing" do
|
210
|
+
context "with :template option" do
|
211
|
+
it "should find a template in the same source" do
|
212
|
+
mock_dep('template selection 3', :template => 'meta_1', :in => @source1).template.should == @meta1
|
213
|
+
end
|
214
|
+
it "should not find a template in the wrong source, and raise" do
|
215
|
+
L{
|
216
|
+
mock_dep('template selection 4', :template => 'meta_3', :in => @source1).template
|
217
|
+
}.should raise_error(TemplateNotFound, "There is no template named 'meta_3' to define 'template selection 4' against.")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
context "with suffixes" do
|
221
|
+
it "should find a template in the same source" do
|
222
|
+
mock_dep('template selection 3.meta_1', :in => @source1).template.should == @meta1
|
223
|
+
end
|
224
|
+
it "should find a template in the core source" do
|
225
|
+
mock_dep('template selection 3.core_meta', :in => @source1).template.should == @core_meta
|
226
|
+
end
|
227
|
+
it "should not find a template in the wrong source, and use the base template" do
|
228
|
+
mock_dep('template selection 4.meta_3', :in => @source1).template.should == Dep::BaseTemplate
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
after {
|
233
|
+
Base.sources.anonymous.templates.clear!
|
234
|
+
Base.sources.core.templates.clear!
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "template selection during defining from a real source" do
|
239
|
+
before {
|
240
|
+
@source = Source.new('spec/deps/good', :name => 'good source')
|
241
|
+
@source.load!
|
242
|
+
Source.stub!(:present).and_return([@source])
|
243
|
+
}
|
244
|
+
it "should have loaded deps" do
|
245
|
+
@source.deps.names.should =~ [
|
246
|
+
'test dep 1',
|
247
|
+
'test dep 2',
|
248
|
+
'option-templated dep',
|
249
|
+
'suffix-templated dep.test_template'
|
250
|
+
]
|
251
|
+
end
|
252
|
+
it "should have loaded templates" do
|
253
|
+
@source.templates.names.should =~ [
|
254
|
+
'test_template',
|
255
|
+
'test_meta_1'
|
256
|
+
]
|
257
|
+
end
|
258
|
+
it "should have defined deps against the correct template" do
|
259
|
+
@source.find('test dep 1').template.should == Dep::BaseTemplate
|
260
|
+
@source.find('test dep 2').template.should == Dep::BaseTemplate
|
261
|
+
@source.find('option-templated dep').template.should == @source.find_template('test_template')
|
262
|
+
@source.find('suffix-templated dep.test_template').template.should == @source.find_template('test_template')
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "nested source loads" do
|
267
|
+
before {
|
268
|
+
@outer_source = Source.new('spec/deps/outer', :name => 'outer source')
|
269
|
+
@nested_source = Source.new('spec/deps/good', :name => 'nested source')
|
270
|
+
|
271
|
+
Source.stub!(:present).and_return([@outer_source, @nested_source])
|
272
|
+
@outer_source.load!
|
273
|
+
}
|
274
|
+
it "should have loaded outer deps" do
|
275
|
+
@outer_source.deps.names.should =~ [
|
276
|
+
'test dep 1',
|
277
|
+
'externally templated',
|
278
|
+
'locally templated',
|
279
|
+
'locally templated.local_template',
|
280
|
+
'separate file',
|
281
|
+
'separate file.another_local_template'
|
282
|
+
]
|
283
|
+
@nested_source.deps.names.should == []
|
284
|
+
end
|
285
|
+
it "should have loaded outer templates" do
|
286
|
+
@outer_source.templates.names.should =~ [
|
287
|
+
'local_template',
|
288
|
+
'another_local_template'
|
289
|
+
]
|
290
|
+
@nested_source.templates.names.should == []
|
291
|
+
end
|
292
|
+
context "after defining external deps" do
|
293
|
+
before {
|
294
|
+
@outer_source.find('externally templated').context
|
295
|
+
}
|
296
|
+
it "should have loaded the nested deps" do
|
297
|
+
@nested_source.deps.names.should =~ [
|
298
|
+
'test dep 1',
|
299
|
+
'test dep 2',
|
300
|
+
'option-templated dep',
|
301
|
+
'suffix-templated dep.test_template'
|
302
|
+
]
|
303
|
+
end
|
304
|
+
it "should have loaded the nested templates" do
|
305
|
+
@nested_source.templates.names.should =~ [
|
306
|
+
'test_template',
|
307
|
+
'test_meta_1'
|
308
|
+
]
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should have defined deps against the correct template" do
|
313
|
+
@outer_source.find('test dep 1').template.should == Dep::BaseTemplate
|
314
|
+
@outer_source.find('externally templated').template.should == @nested_source.find_template('test_template')
|
315
|
+
@outer_source.find('locally templated').template.should == @outer_source.find_template('local_template')
|
316
|
+
@outer_source.find('locally templated.local_template').template.should == @outer_source.find_template('local_template')
|
317
|
+
@outer_source.find('separate file').template.should == @outer_source.find_template('another_local_template')
|
318
|
+
@outer_source.find('separate file.another_local_template').template.should == @outer_source.find_template('another_local_template')
|
319
|
+
end
|
320
|
+
end
|