rubycut-babushka 0.10.8 → 0.15.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +17 -15
- data/README.markdown +163 -41
- data/Rakefile +1 -1
- data/bin/babushka +1 -1
- data/deps/apt.rb +44 -0
- data/deps/babushka.rb +54 -42
- data/deps/deprecated.rb +16 -0
- data/deps/dev.rb +28 -3
- data/deps/git.rb +27 -12
- data/deps/homebrew.rb +2 -2
- data/deps/packages.rb +14 -15
- data/deps/pkg_managers.rb +21 -75
- data/deps/ruby.rb +5 -19
- data/deps/rubygems.rb +3 -3
- data/deps/system.rb +2 -2
- data/deps/templates/app.rb +60 -41
- data/deps/templates/bin.rb +16 -0
- data/deps/templates/installer.rb +9 -9
- data/deps/templates/lib.rb +17 -0
- data/deps/templates/managed.rb +1 -38
- data/deps/templates/src.rb +16 -8
- data/deps/templates/task.rb +11 -0
- data/deps/templates/tmbundle.rb +16 -2
- data/lib/babushka.rb +2 -3
- data/lib/babushka/accepts_block_for.rb +5 -3
- data/lib/babushka/asset.rb +172 -0
- data/lib/babushka/base.rb +37 -8
- data/lib/babushka/bug_reporter.rb +6 -6
- data/lib/babushka/cmdline.rb +11 -10
- data/lib/babushka/cmdline/handler.rb +7 -3
- data/lib/babushka/cmdline/helpers.rb +15 -23
- data/lib/babushka/cmdline/parser.rb +1 -1
- data/lib/babushka/core_patches/object.rb +1 -1
- data/lib/babushka/core_patches/string.rb +8 -3
- data/lib/babushka/current_ruby.rb +44 -0
- data/lib/babushka/dep.rb +111 -185
- data/lib/babushka/dep_context.rb +8 -3
- data/lib/babushka/dep_definer.rb +45 -15
- data/lib/babushka/dep_pool.rb +5 -8
- data/lib/babushka/{meta_dep.rb → dep_template.rb} +21 -2
- data/lib/babushka/dsl.rb +3 -0
- data/lib/babushka/git_repo.rb +143 -49
- data/lib/babushka/helpers/git_helpers.rb +7 -6
- data/lib/babushka/helpers/log_helpers.rb +51 -13
- data/lib/babushka/helpers/path_helpers.rb +5 -7
- data/lib/babushka/helpers/run_helpers.rb +15 -55
- data/lib/babushka/helpers/shell_helpers.rb +18 -26
- data/lib/babushka/helpers/uri_helpers.rb +9 -18
- data/lib/babushka/lambda_chooser.rb +20 -13
- data/lib/babushka/parameter.rb +20 -4
- data/lib/babushka/path_checker.rb +72 -0
- data/lib/babushka/pkg_helper.rb +38 -13
- data/lib/babushka/pkg_helpers/apt_helper.rb +15 -8
- data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +15 -14
- data/lib/babushka/pkg_helpers/binports_helper.rb +7 -7
- data/lib/babushka/pkg_helpers/brew_helper.rb +17 -25
- data/lib/babushka/pkg_helpers/gem_helper.rb +36 -27
- data/lib/babushka/pkg_helpers/npm_helper.rb +9 -9
- data/lib/babushka/pkg_helpers/pacman_helper.rb +5 -4
- data/lib/babushka/pkg_helpers/pip_helper.rb +14 -10
- data/lib/babushka/pkg_helpers/unknown_pkg_helper.rb +19 -0
- data/lib/babushka/pkg_helpers/yum_helper.rb +1 -1
- data/lib/babushka/popen.rb +13 -10
- data/lib/babushka/prompt.rb +14 -1
- data/lib/babushka/renderable.rb +11 -9
- data/lib/babushka/resource.rb +5 -166
- data/lib/babushka/run_reporter.rb +12 -3
- data/lib/babushka/shell.rb +54 -44
- data/lib/babushka/source.rb +41 -20
- data/lib/babushka/source_pool.rb +20 -13
- data/lib/babushka/system_definitions.rb +11 -3
- data/lib/babushka/system_detector.rb +31 -0
- data/lib/babushka/system_matcher.rb +53 -0
- data/lib/babushka/system_profile.rb +67 -89
- data/lib/babushka/task.rb +36 -8
- data/lib/babushka/{meta_dep_context.rb → templated_dep_context.rb} +1 -1
- data/lib/babushka/vars.rb +46 -4
- data/lib/babushka/version_of.rb +35 -17
- data/lib/babushka/version_str.rb +12 -8
- data/lib/components.rb +9 -8
- data/lib/fancypath/fancypath.rb +109 -83
- data/lib/inkan/inkan.rb +14 -14
- data/lib/{babushka → levenshtein}/levenshtein.rb +0 -0
- data/spec/acceptance/acceptance.rb +4 -4
- data/spec/acceptance_helper.rb +10 -6
- data/spec/babushka/accepts_for_spec.rb +137 -142
- data/spec/babushka/accepts_for_support.rb +13 -6
- data/spec/babushka/asset_spec.rb +165 -0
- data/spec/babushka/cmdline/help_spec.rb +11 -9
- data/spec/babushka/cmdline/meet_spec.rb +15 -0
- data/spec/babushka/cmdline/version_spec.rb +1 -1
- data/spec/babushka/core_patches_spec.rb +9 -0
- data/spec/babushka/current_ruby_spec.rb +73 -0
- data/spec/babushka/dep_context_spec.rb +27 -13
- data/spec/babushka/dep_definer_spec.rb +108 -16
- data/spec/babushka/dep_spec.rb +87 -104
- data/spec/babushka/dep_template_spec.rb +176 -0
- data/spec/babushka/deps_spec.rb +48 -19
- data/spec/babushka/gem_helper_spec.rb +46 -59
- data/spec/babushka/git_repo_spec.rb +242 -51
- data/spec/babushka/ip_spec.rb +11 -11
- data/spec/babushka/lambda_chooser_spec.rb +47 -9
- data/spec/babushka/parameter_spec.rb +21 -0
- data/spec/babushka/path_checker_spec.rb +35 -0
- data/spec/babushka/path_helpers_spec.rb +51 -50
- data/spec/babushka/prompt_spec.rb +4 -4
- data/spec/babushka/renderable_spec.rb +61 -28
- data/spec/babushka/shell_helpers_spec.rb +110 -85
- data/spec/babushka/shell_spec.rb +15 -0
- data/spec/babushka/source_pool_spec.rb +204 -210
- data/spec/babushka/source_spec.rb +125 -42
- data/spec/babushka/source_support.rb +1 -1
- data/spec/babushka/system_profile_spec.rb +86 -49
- data/spec/babushka/task_spec.rb +80 -13
- data/spec/babushka/vars_spec.rb +2 -1
- data/spec/babushka/version_of_spec.rb +29 -2
- data/spec/babushka/version_str_spec.rb +91 -65
- data/spec/babushka/xml_string_spec.rb +1 -1
- data/spec/deps/bad/broken.rb +2 -2
- data/spec/deps/bad/working.rb +0 -1
- data/spec/deps/good/{meta.rb → template.rb} +0 -0
- data/spec/deps/good/test.rb +0 -3
- data/spec/deps/outer/deps.rb +0 -2
- data/spec/fancypath/fancypath_spec.rb +30 -0
- data/spec/inkan/inkan_spec.rb +34 -32
- data/spec/spec_helper.rb +7 -50
- data/spec/system_detector_spec.rb +70 -0
- metadata +163 -177
- data/deps/os_x.rb +0 -33
- data/deps/templates/ppa.rb +0 -24
- data/lib/babushka/core_patches/io.rb +0 -8
- data/lib/babushka/dep_runner.rb +0 -85
- data/lib/babushka/helpers/suggest_helpers.rb +0 -16
- data/lib/babushka/pkg_helpers/base_helper.rb +0 -19
- data/lib/babushka/pkg_helpers/macports_helper.rb +0 -22
- data/spec/babushka/dep_definer_support.rb +0 -36
- data/spec/babushka/meta_dep_definer_spec.rb +0 -127
- data/spec/babushka/meta_dep_wrapper_spec.rb +0 -32
- data/spec/babushka/resource_spec.rb +0 -141
- data/spec/babushka/run_helpers_spec.rb +0 -26
- data/spec/babushka/source_pool_support.rb +0 -31
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
SUCCEEDING_LS = 'ls /bin'
|
4
|
+
FAILING_LS = 'ls /missing'
|
5
5
|
|
6
6
|
describe "shell" do
|
7
7
|
it "should return something true on successful commands" do
|
8
|
-
shell('true').should_not be_nil
|
8
|
+
ShellHelpers.shell('true').should_not be_nil
|
9
9
|
end
|
10
10
|
it "should return nil on failed commands" do
|
11
|
-
shell('false').should be_nil
|
11
|
+
ShellHelpers.shell('false').should be_nil
|
12
12
|
end
|
13
13
|
it "should return output of successful commands" do
|
14
|
-
shell('echo lol').should == 'lol'
|
14
|
+
ShellHelpers.shell('echo lol').should == 'lol'
|
15
15
|
end
|
16
16
|
it "should accept multiline commands" do
|
17
|
-
shell("echo babu &&\necho shka").should == "babu\nshka"
|
17
|
+
ShellHelpers.shell("echo babu &&\necho shka").should == "babu\nshka"
|
18
18
|
end
|
19
19
|
it "should accept environment variables as the first argument" do
|
20
|
-
shell({'KEY' => 'value'}, "echo $KEY").should == "value"
|
20
|
+
ShellHelpers.shell({'KEY' => 'value'}, "echo $KEY").should == "value"
|
21
21
|
end
|
22
22
|
it "should provide the shell to supplied blocks when the command succeeds" do
|
23
23
|
(the_block = "").should_receive(:was_called)
|
24
|
-
shell(
|
24
|
+
ShellHelpers.shell(SUCCEEDING_LS) {|shell|
|
25
25
|
the_block.was_called
|
26
26
|
shell.stdout.should include('bash')
|
27
27
|
shell.stderr.should be_empty
|
@@ -29,37 +29,43 @@ describe "shell" do
|
|
29
29
|
end
|
30
30
|
it "should provide the shell to supplied blocks when the command fails" do
|
31
31
|
(the_block = "").should_receive(:was_called)
|
32
|
-
shell(
|
32
|
+
ShellHelpers.shell(FAILING_LS) {|shell|
|
33
33
|
the_block.was_called
|
34
34
|
shell.stdout.should be_empty
|
35
35
|
shell.stderr.should include("No such file or directory")
|
36
36
|
}
|
37
37
|
end
|
38
38
|
it "should accept :input parameter" do
|
39
|
-
shell('cat', :input => 'lol').should == "lol"
|
39
|
+
ShellHelpers.shell('cat', :input => 'lol').should == "lol"
|
40
40
|
end
|
41
41
|
context ":cd parameter" do
|
42
42
|
before { (tmp_prefix / 'dir_param').mkdir }
|
43
43
|
it "should run in the current directory when :cd isn't specified" do
|
44
|
-
shell("pwd").should == Dir.pwd
|
44
|
+
ShellHelpers.shell("pwd -P").should == Dir.pwd
|
45
45
|
end
|
46
46
|
it "should run in the specified directory" do
|
47
|
-
shell("pwd", :cd => (tmp_prefix / 'dir_param')).should == (tmp_prefix / 'dir_param').to_s
|
47
|
+
ShellHelpers.shell("pwd", :cd => (tmp_prefix / 'dir_param')).should == (tmp_prefix / 'dir_param').to_s
|
48
48
|
end
|
49
49
|
it "should expand the path" do
|
50
|
-
shell("pwd", :cd => '~').should == ENV['HOME']
|
50
|
+
ShellHelpers.shell("pwd", :cd => '~').should == ENV['HOME']
|
51
51
|
end
|
52
52
|
it "should raise when the path is nonexistent" do
|
53
53
|
L{
|
54
|
-
shell("pwd", :cd => (tmp_prefix / '
|
55
|
-
}.should raise_error(Errno::ENOENT, "No such file or directory - #{tmp_prefix / '
|
54
|
+
ShellHelpers.shell("pwd", :cd => (tmp_prefix / 'missing'))
|
55
|
+
}.should raise_error(Errno::ENOENT, "No such file or directory - #{tmp_prefix / 'missing'}")
|
56
|
+
end
|
57
|
+
it "should raise when the path isn't a directory" do
|
58
|
+
L{
|
59
|
+
(tmp_prefix / 'notadir').touch
|
60
|
+
ShellHelpers.shell("pwd", :cd => (tmp_prefix / 'notadir'))
|
61
|
+
}.should raise_error(Errno::ENOTDIR, "Not a directory - #{tmp_prefix / 'notadir'}")
|
56
62
|
end
|
57
63
|
context "with :create option" do
|
58
64
|
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
|
65
|
+
ShellHelpers.shell("pwd", :cd => (tmp_prefix / 'dir_param'), :create => true).should == (tmp_prefix / 'dir_param').to_s
|
60
66
|
end
|
61
67
|
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
|
68
|
+
ShellHelpers.shell("pwd", :cd => (tmp_prefix / 'dir_param_with_create'), :create => true).should == (tmp_prefix / 'dir_param_with_create').to_s
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
@@ -67,178 +73,197 @@ end
|
|
67
73
|
|
68
74
|
describe "shell?" do
|
69
75
|
it "should return the output for successful commands" do
|
70
|
-
shell?('echo lol').should == 'lol'
|
71
|
-
shell?(
|
76
|
+
ShellHelpers.shell?('echo lol').should == 'lol'
|
77
|
+
ShellHelpers.shell?(SUCCEEDING_LS).should be_true
|
72
78
|
end
|
73
79
|
it "should return false for failed commands" do
|
74
|
-
shell?('false').should be_false
|
75
|
-
shell?(
|
80
|
+
ShellHelpers.shell?('false').should be_false
|
81
|
+
ShellHelpers.shell?(FAILING_LS).should be_false
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
79
85
|
describe "shell!" do
|
80
86
|
it "should return the output for successful commands" do
|
81
|
-
shell!('echo lol').should == 'lol'
|
82
|
-
shell!(
|
87
|
+
ShellHelpers.shell!('echo lol').should == 'lol'
|
88
|
+
ShellHelpers.shell!(SUCCEEDING_LS).should be_true
|
83
89
|
end
|
84
90
|
it "should return false for failed commands" do
|
85
|
-
L{ shell!('false') }.should raise_error(Shell::ShellCommandFailed, "Shell command failed: 'false'")
|
86
|
-
L{ shell!(
|
91
|
+
L{ ShellHelpers.shell!('false') }.should raise_error(Shell::ShellCommandFailed, "Shell command failed: 'false'")
|
92
|
+
L{ ShellHelpers.shell!(FAILING_LS) }.should raise_error(Shell::ShellCommandFailed)
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
90
96
|
describe "raw_shell" do
|
91
97
|
it "should always return a Shell" do
|
92
|
-
raw_shell('true').should be_a(Shell)
|
93
|
-
raw_shell('false').should be_a(Shell)
|
98
|
+
ShellHelpers.raw_shell('true').should be_a(Shell)
|
99
|
+
ShellHelpers.raw_shell('false').should be_a(Shell)
|
94
100
|
end
|
95
101
|
it "should return stdout for succeeding commands" do
|
96
|
-
shell = raw_shell(
|
102
|
+
shell = ShellHelpers.raw_shell(SUCCEEDING_LS)
|
97
103
|
shell.stdout.should include("bash")
|
98
104
|
shell.stderr.should be_empty
|
99
105
|
end
|
100
106
|
it "should return stderr for failed commands" do
|
101
|
-
shell = raw_shell(
|
107
|
+
shell = ShellHelpers.raw_shell(FAILING_LS)
|
102
108
|
shell.stdout.should be_empty
|
103
109
|
shell.stderr.should include("No such file or directory")
|
104
110
|
end
|
105
111
|
it "should support sudo" do
|
106
|
-
should_receive(:shell).with('whoami', :sudo => true).once
|
107
|
-
raw_shell('whoami', :sudo => true)
|
112
|
+
ShellHelpers.should_receive(:shell).with('whoami', :sudo => true).once
|
113
|
+
ShellHelpers.raw_shell('whoami', :sudo => true)
|
108
114
|
end
|
109
115
|
it "should handle env vars" do
|
110
|
-
raw_shell({'KEY' => 'value'}, 'echo $KEY').stdout.should == "value\n"
|
116
|
+
ShellHelpers.raw_shell({'KEY' => 'value'}, 'echo $KEY').stdout.should == "value\n"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'login_shell' do
|
121
|
+
it "should return something true on successful commands" do
|
122
|
+
ShellHelpers.login_shell('true').should_not be_nil
|
123
|
+
end
|
124
|
+
it "should return nil on failed commands" do
|
125
|
+
ShellHelpers.login_shell('false').should be_nil
|
126
|
+
end
|
127
|
+
it "should run as the given user" do
|
128
|
+
ShellHelpers.should_receive(:shell_cmd).with('echo $SHELL', {}).and_return('')
|
129
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, "sudo -u batman bash -l -c 'whoami'", {}).once
|
130
|
+
ShellHelpers.login_shell('whoami', :as => 'batman')
|
111
131
|
end
|
112
132
|
end
|
113
133
|
|
114
134
|
describe 'argument behaviour' do
|
115
135
|
context "with a single string" do
|
116
136
|
it "should support compound commands" do
|
117
|
-
shell("echo trousers | tr a-z A-Z").should == 'TROUSERS'
|
137
|
+
ShellHelpers.shell("echo trousers | tr a-z A-Z").should == 'TROUSERS'
|
118
138
|
end
|
119
139
|
it "should fail with unclosed quotes" do
|
120
|
-
shell('echo blah"').should be_nil
|
140
|
+
ShellHelpers.shell('echo blah"').should be_nil
|
121
141
|
end
|
122
142
|
end
|
123
143
|
context "with an array" do
|
124
144
|
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'
|
145
|
+
ShellHelpers.shell(%w[echo trousers | tr a-z A-Z]).should == 'trousers | tr a-z A-Z'
|
126
146
|
end
|
127
147
|
it "should escape unclosed quotes" do
|
128
|
-
shell(['echo', 'blah"']).should == 'blah"'
|
148
|
+
ShellHelpers.shell(['echo', 'blah"']).should == 'blah"'
|
129
149
|
end
|
130
150
|
end
|
131
151
|
end
|
132
152
|
|
133
153
|
describe "sudo" do
|
134
154
|
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.")
|
155
|
+
L{ ShellHelpers.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
156
|
end
|
137
157
|
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')
|
158
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo -u root whoami', {}).once
|
159
|
+
ShellHelpers.sudo('whoami')
|
140
160
|
end
|
141
161
|
it "should run as the given user" do
|
142
|
-
should_receive(:shell_cmd).with({}, 'sudo -u batman whoami', {}).once
|
143
|
-
sudo('whoami', :as => 'batman')
|
162
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo -u batman whoami', {}).once
|
163
|
+
ShellHelpers.sudo('whoami', :as => 'batman')
|
144
164
|
end
|
145
165
|
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')
|
166
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo -u batman whoami', {}).once
|
167
|
+
ShellHelpers.shell('whoami', :sudo => 'batman')
|
148
168
|
end
|
149
169
|
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')
|
170
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo -u root whoami', {}).once
|
171
|
+
ShellHelpers.shell('whoami', :as => 'root')
|
152
172
|
end
|
153
173
|
context "when already running as the sudo user" do
|
154
174
|
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')
|
175
|
+
ShellHelpers.stub!(:current_username).and_return('root')
|
176
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
177
|
+
ShellHelpers.sudo('whoami')
|
158
178
|
end
|
159
179
|
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')
|
180
|
+
ShellHelpers.stub!(:current_username).and_return('batman')
|
181
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
182
|
+
ShellHelpers.sudo('whoami', :as => 'batman')
|
163
183
|
end
|
164
184
|
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')
|
185
|
+
ShellHelpers.stub!(:current_username).and_return('batman')
|
186
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
187
|
+
ShellHelpers.shell('whoami', :sudo => 'batman')
|
188
|
+
end
|
189
|
+
it "should not sudo with a :sudo => Parameter username" do
|
190
|
+
ShellHelpers.stub!(:current_username).and_return('batman')
|
191
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
192
|
+
ShellHelpers.shell('whoami', :sudo => Parameter.new('username').default!('batman'))
|
168
193
|
end
|
169
194
|
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')
|
195
|
+
ShellHelpers.stub!(:current_username).and_return('root')
|
196
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'whoami', {}).once
|
197
|
+
ShellHelpers.shell('whoami', :as => 'root')
|
173
198
|
end
|
174
199
|
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')
|
200
|
+
ShellHelpers.stub!(:current_username).and_return('root')
|
201
|
+
ShellHelpers.should_receive(:shell_cmd).with({'KEY' => 'value'}, 'echo $KEY', {}).once
|
202
|
+
ShellHelpers.sudo({'KEY' => 'value'}, 'echo $KEY')
|
178
203
|
end
|
179
204
|
end
|
180
205
|
describe "compound commands" do
|
181
206
|
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)
|
207
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\`"', {}).once
|
208
|
+
ShellHelpers.sudo("echo \\`whoami\\`", :su => true)
|
184
209
|
end
|
185
210
|
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)
|
211
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\` > %s/su_with_redirect"' % tmp_prefix, {}).once
|
212
|
+
ShellHelpers.sudo("echo \\`whoami\\` > %s/su_with_redirect" % tmp_prefix)
|
188
213
|
end
|
189
214
|
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)
|
215
|
+
ShellHelpers.should_receive(:shell_cmd).with({}, 'sudo su - root -c "echo \\`whoami\\` | tee %s/su_with_pipe"' % tmp_prefix, {}).once
|
216
|
+
ShellHelpers.sudo("echo \\`whoami\\` | tee %s/su_with_pipe" % tmp_prefix)
|
192
217
|
end
|
193
218
|
end
|
194
219
|
end
|
195
220
|
|
196
221
|
describe "log_shell" do
|
197
222
|
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'
|
223
|
+
LogHelpers.should_receive(:log).with("Getting uptime...", {:newline=>false}).once
|
224
|
+
ShellHelpers.should_receive(:shell).with('uptime', {:spinner=>true}).and_return("days and days")
|
225
|
+
LogHelpers.should_receive(:log).with(" done.", {:as=>nil, :indentation=>false}).once
|
226
|
+
ShellHelpers.log_shell 'Getting uptime', 'uptime'
|
202
227
|
end
|
203
228
|
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'
|
229
|
+
LogHelpers.should_receive(:log).with("Setting sail for fail...", {:newline=>false}).once
|
230
|
+
ShellHelpers.should_receive(:shell).with('false', {:spinner=>true}).and_return(nil)
|
231
|
+
LogHelpers.should_receive(:log).with(" failed", {:as=>:error, :indentation=>false}).once
|
232
|
+
ShellHelpers.log_shell 'Setting sail for fail', 'false'
|
208
233
|
end
|
209
234
|
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'
|
235
|
+
LogHelpers.should_receive(:log).with("Echoing some vars...", {:newline=>false}).once
|
236
|
+
ShellHelpers.should_receive(:shell).with({'KEY' => 'value'}, 'echo $KEY', {:spinner=>true}).and_return('value')
|
237
|
+
LogHelpers.should_receive(:log).with(" done.", {:as=>nil, :indentation=>false}).once
|
238
|
+
ShellHelpers.log_shell 'Echoing some vars', {'KEY' => 'value'}, 'echo $KEY'
|
214
239
|
end
|
215
240
|
end
|
216
241
|
|
217
242
|
describe "which" do
|
218
243
|
it "should return a string" do
|
219
|
-
which('ls').should be_an_instance_of(String)
|
244
|
+
ShellHelpers.which('ls').should be_an_instance_of(String)
|
220
245
|
end
|
221
246
|
it "should return the path for valid commands" do
|
222
247
|
path = `which ls`.chomp
|
223
|
-
which('ls').should == path
|
248
|
+
ShellHelpers.which('ls').should == path
|
224
249
|
end
|
225
250
|
it "should return nil for nonexistent commands" do
|
226
|
-
which('
|
251
|
+
ShellHelpers.which('missing').should be_nil
|
227
252
|
end
|
228
253
|
it "should handle command parameter passed as Symbol" do
|
229
254
|
path = `which ls`.chomp
|
230
|
-
which(:ls).should == path
|
255
|
+
ShellHelpers.which(:ls).should == path
|
231
256
|
end
|
232
257
|
end
|
233
258
|
|
234
259
|
describe "cmd_dir" do
|
235
260
|
it "should return a string" do
|
236
|
-
cmd_dir('ruby').should be_an_instance_of(String)
|
261
|
+
ShellHelpers.cmd_dir('ruby').should be_an_instance_of(String)
|
237
262
|
end
|
238
263
|
it "should return the cmd_dir of an existing command" do
|
239
|
-
cmd_dir('ruby').should == `which ruby`.chomp.gsub(/\/ruby$/, '')
|
264
|
+
ShellHelpers.cmd_dir('ruby').should == `which ruby`.chomp.gsub(/\/ruby$/, '')
|
240
265
|
end
|
241
266
|
it "should return nil for nonexistent commands" do
|
242
|
-
cmd_dir('
|
267
|
+
ShellHelpers.cmd_dir('missing').should be_nil
|
243
268
|
end
|
244
269
|
end
|
data/spec/babushka/shell_spec.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
describe Shell, "arguments" do
|
5
|
+
it "should reject calls with no arguments, since exec will explode anyway" do
|
6
|
+
L{ Shell.new }.should raise_error(ArgumentError, "wrong number of arguments (0 for 1+)")
|
7
|
+
end
|
8
|
+
end
|
2
9
|
|
3
10
|
describe Shell, '#ok?' do
|
4
11
|
it "should return true on success" do
|
@@ -17,3 +24,11 @@ describe Shell, '#result' do
|
|
17
24
|
Shell.new('false', {}).run(&:result).should == 1
|
18
25
|
end
|
19
26
|
end
|
27
|
+
|
28
|
+
describe Shell do
|
29
|
+
it "should close stdin, so subprocesses don't wait for input forever" do
|
30
|
+
Timeout::timeout(1) do
|
31
|
+
Shell.new('cat', {}).run(&:result).should == 0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,248 +1,244 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'source_support'
|
3
|
-
require 'source_pool_support'
|
4
3
|
|
5
|
-
describe SourcePool
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
4
|
+
describe SourcePool do
|
5
|
+
def define_in source
|
6
|
+
Base.sources.load_context :source => source do
|
7
|
+
yield
|
8
|
+
end
|
19
9
|
end
|
20
|
-
end
|
21
10
|
|
22
|
-
|
11
|
+
let(:source1) { Source.new(nil, :name => 'source_1').tap {|s| s.stub!(:load!) } }
|
12
|
+
let(:source2) { Source.new(nil, :name => 'source_2').tap {|s| s.stub!(:load!) } }
|
13
|
+
let!(:anonymous_meta) { define_in(Base.sources.anonymous) { meta 'anonymous_meta' } }
|
14
|
+
let!(:core_meta) { define_in(Base.sources.core) { meta 'core_meta' } }
|
15
|
+
let!(:core_from) { define_in(Base.sources.core) { meta 'core_from' } }
|
16
|
+
let!(:meta1) { define_in(source1) { meta :meta_1 } }
|
17
|
+
let!(:meta2) { define_in(source1) { meta 'meta_2' } }
|
18
|
+
let!(:meta3) { define_in(source2) { meta :meta_3 } }
|
19
|
+
let!(:meta4) { define_in(source2) { meta 'meta_4' } }
|
20
|
+
let!(:from1) { define_in(source1) { meta 'from_test' } }
|
21
|
+
let!(:from2) { define_in(source2) { meta 'from_test' } }
|
22
|
+
let!(:from2_2) { define_in(source2) { meta 'from_test_2' } }
|
23
|
+
|
23
24
|
before {
|
24
|
-
|
25
|
+
[Base.sources.anonymous, Base.sources.core, source1, source2].each {|s| s.stub!(:load!) }
|
26
|
+
Source.stub!(:present).and_return [source1, source2]
|
25
27
|
}
|
26
|
-
|
27
|
-
|
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
|
28
|
+
|
29
|
+
describe SourcePool, '#source_for' do
|
36
30
|
before {
|
37
|
-
|
38
|
-
Source.stub!(:present).and_return([
|
39
|
-
Base.sources.load_context :source => @source do
|
40
|
-
@namespaced_dep = dep 'Base.sources.dep_for tests'
|
41
|
-
end
|
31
|
+
Base.sources.stub!(:current).and_return([source1])
|
32
|
+
Source.stub!(:present).and_return([source2])
|
42
33
|
}
|
43
|
-
it "should
|
44
|
-
Base.sources.
|
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'
|
34
|
+
it "should find core sources" do
|
35
|
+
Base.sources.source_for('source_1').should == source1
|
62
36
|
end
|
63
|
-
|
64
|
-
|
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'
|
37
|
+
it "should find cloned sources" do
|
38
|
+
Base.sources.source_for('source_2').should == source2
|
87
39
|
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
40
|
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
41
|
|
102
|
-
describe
|
103
|
-
|
104
|
-
|
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
|
42
|
+
describe Dep, '#dep_for, disregarding sources' do
|
43
|
+
let!(:the_dep) { dep 'Base.sources.dep_for tests' }
|
44
|
+
it "should work for strings" do
|
45
|
+
Base.sources.dep_for('Base.sources.dep_for tests').should == the_dep
|
109
46
|
end
|
110
|
-
it "should
|
111
|
-
Base.sources.
|
47
|
+
it "should work for deps" do
|
48
|
+
Base.sources.dep_for(the_dep).should == the_dep
|
112
49
|
end
|
113
|
-
it "should not find
|
114
|
-
|
115
|
-
Base.sources.
|
50
|
+
it "should not find the dep with namespacing" do
|
51
|
+
GitHelpers.stub!(:git) # To avoid cloning.
|
52
|
+
Base.sources.dep_for('namespaced:Base.sources.dep_for tests').should be_nil
|
116
53
|
end
|
117
|
-
context "with
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
54
|
+
context "with namespaced dep defined" do
|
55
|
+
let(:source) { Source.new(nil, :name => 'namespaced') }
|
56
|
+
let!(:namespaced_dep) {
|
57
|
+
define_in(source) { dep 'Base.sources.dep_for tests' }
|
58
|
+
}
|
59
|
+
before {
|
60
|
+
Source.stub!(:present).and_return([source])
|
61
|
+
}
|
62
|
+
it "should find the dep" do
|
63
|
+
Base.sources.dep_for('namespaced:Base.sources.dep_for tests').should == namespaced_dep
|
130
64
|
end
|
131
65
|
end
|
132
66
|
end
|
133
|
-
|
67
|
+
|
68
|
+
describe SourcePool, '#dep_for' do
|
69
|
+
let!(:dep1) { define_in(source1) { dep 'dep 1' } }
|
70
|
+
let!(:dep2) { define_in(source1) { dep 'dep 2' } }
|
71
|
+
let!(:dep3) { define_in(source2) { dep 'dep 3' } }
|
72
|
+
let!(:dep4) { define_in(source2) { dep 'dep 4' } }
|
73
|
+
before {
|
74
|
+
Base.sources.stub!(:current).and_return([source1, source2])
|
75
|
+
Source.stub!(:present).and_return([source1, source2])
|
76
|
+
}
|
77
|
+
it "should look up the correct deps without namespacing" do
|
78
|
+
Base.sources.dep_for('dep 1').should == dep1
|
79
|
+
Base.sources.dep_for('dep 4').should == dep4
|
80
|
+
end
|
134
81
|
it "should find the dep when the namespace is correct" do
|
135
|
-
Base.sources.
|
136
|
-
Base.sources.
|
82
|
+
Base.sources.dep_for('source_1:dep 1').should == dep1
|
83
|
+
Base.sources.dep_for('source_2:dep 4').should == dep4
|
137
84
|
end
|
138
85
|
it "should not find the dep when the namespace is wrong" do
|
139
|
-
Base.sources.
|
140
|
-
Base.sources.
|
86
|
+
Base.sources.dep_for('source_1:dep 3').should be_nil
|
87
|
+
Base.sources.dep_for('source_2:dep 2').should be_nil
|
141
88
|
end
|
142
89
|
end
|
143
|
-
after {
|
144
|
-
Base.sources.anonymous.templates.clear!
|
145
|
-
Base.sources.core.templates.clear!
|
146
|
-
}
|
147
|
-
end
|
148
90
|
|
149
|
-
describe SourcePool, '#
|
150
|
-
|
91
|
+
describe SourcePool, '#dep_for core' do
|
92
|
+
let(:core) { Source.new(nil, :name => 'core').tap {|s| s.stub!(:load!) } }
|
93
|
+
let!(:dep1) { define_in(core) { dep 'dep 1' } }
|
151
94
|
before {
|
152
|
-
|
95
|
+
Base.sources.stub!(:current).and_return([core])
|
153
96
|
}
|
154
|
-
it "should
|
155
|
-
dep '
|
97
|
+
it "should find the correct deps without namespacing" do
|
98
|
+
Base.sources.dep_for('dep 1').should == dep1
|
99
|
+
end
|
100
|
+
it "should find the dep when the namespace is correct" do
|
101
|
+
Base.sources.dep_for('core:dep 1').should == dep1
|
102
|
+
end
|
103
|
+
it "should not find the dep when the namespace is wrong" do
|
104
|
+
GitHelpers.stub!(:git) # To avoid cloning.
|
105
|
+
Base.sources.dep_for('non_core:dep 1').should be_nil
|
156
106
|
end
|
157
107
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
108
|
+
|
109
|
+
describe SourcePool, '#load_context' do
|
110
|
+
context "without a template" do
|
111
|
+
before {
|
112
|
+
Dep.should_receive(:new).with('load_context', Base.sources.anonymous, [], {}, nil)
|
113
|
+
}
|
114
|
+
it "should pass the correct options" do
|
115
|
+
dep 'load_context'
|
165
116
|
end
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
117
|
+
end
|
118
|
+
context "with a template" do
|
119
|
+
let(:source) { Source.new(nil) }
|
120
|
+
let!(:template) {
|
121
|
+
Base.sources.load_context :source => source do
|
122
|
+
meta 'load_context_template'
|
123
|
+
end
|
124
|
+
}
|
125
|
+
let!(:the_dep) {
|
126
|
+
Base.sources.load_context :source => source do
|
127
|
+
dep 'defining test with template.load_context_template'
|
128
|
+
end
|
129
|
+
}
|
130
|
+
it "should use the template" do
|
131
|
+
the_dep.template.should == template
|
170
132
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
133
|
+
after {
|
134
|
+
source.remove!
|
135
|
+
}
|
174
136
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
137
|
+
context "with nesting" do
|
138
|
+
it "should maintain the outer context after the inner one returns" do
|
139
|
+
Base.sources.load_context :source => source1 do
|
140
|
+
Base.sources.current_load_source.should == source1
|
141
|
+
Base.sources.load_context :source => source2 do
|
142
|
+
Base.sources.current_load_source.should == source2
|
143
|
+
end
|
144
|
+
Base.sources.current_load_source.should == source1
|
188
145
|
end
|
189
|
-
Base.sources.current_load_source.should == @source1
|
190
146
|
end
|
191
147
|
end
|
192
148
|
end
|
193
|
-
end
|
194
149
|
|
195
|
-
describe
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
150
|
+
describe SourcePool, '#template_for' do
|
151
|
+
|
152
|
+
context "without namespacing" do
|
153
|
+
it "should find templates in the anonymous source" do
|
154
|
+
Base.sources.template_for('anonymous_meta').should == anonymous_meta
|
155
|
+
end
|
156
|
+
it "should find templates in the core source" do
|
157
|
+
Base.sources.template_for('core_meta').should == core_meta
|
158
|
+
end
|
159
|
+
it "should not find templates from non-default sources" do
|
160
|
+
Base.sources.template_for('meta_1').should be_nil
|
161
|
+
Base.sources.template_for('meta_3').should be_nil
|
162
|
+
end
|
163
|
+
context "with :from" do
|
164
|
+
it "should find the template in the same source" do
|
165
|
+
Base.sources.template_for('from_test', :from => source1).should == from1
|
166
|
+
Base.sources.template_for('from_test', :from => source2).should == from2
|
167
|
+
end
|
168
|
+
context "when it doesn't exist in the :from source" do
|
169
|
+
it "should find the template in the core source" do
|
170
|
+
Base.sources.template_for('core_from', :from => source1).should == core_from
|
171
|
+
end
|
172
|
+
it "should not find the template in other sources" do
|
173
|
+
Base.sources.template_for('from_test_2', :from => source1).should be_nil
|
174
|
+
Base.sources.template_for('from_test_2', :from => source2).should_not be_nil
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
202
178
|
end
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
179
|
+
|
180
|
+
context "with namespacing" do
|
181
|
+
it "should find the dep when the namespace is correct" do
|
182
|
+
Base.sources.template_for('source_1:meta_1').should == meta1
|
183
|
+
Base.sources.template_for('source_2:meta_4').should == meta4
|
184
|
+
end
|
185
|
+
it "should not find the dep when the namespace is wrong" do
|
186
|
+
Base.sources.template_for('source_1:').should be_nil
|
187
|
+
Base.sources.template_for('source_2:meta 2').should be_nil
|
188
|
+
end
|
207
189
|
end
|
208
190
|
end
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
191
|
+
|
192
|
+
describe "template selection during defining" do
|
193
|
+
context "with namespacing" do
|
194
|
+
it "should use templates from the named source" do
|
195
|
+
dep('template selection 1', :template => 'source_1:meta_1').template.should == meta1
|
213
196
|
end
|
214
|
-
it "should not find
|
197
|
+
it "should not find the template with the wrong source prefix, and raise" do
|
215
198
|
L{
|
216
|
-
|
217
|
-
}.should raise_error(TemplateNotFound, "There is no template named '
|
199
|
+
dep('template selection 2', :template => 'source_2:meta_1').template
|
200
|
+
}.should raise_error(TemplateNotFound, "There is no template named 'source_2:meta_1' to define 'template selection 2' against.")
|
218
201
|
end
|
219
202
|
end
|
220
|
-
context "
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
203
|
+
context "without namespacing" do
|
204
|
+
context "with :template option" do
|
205
|
+
it "should find a template in the same source" do
|
206
|
+
define_in(source1) { dep 'template selection 3', :template => 'meta_1' }.template.should == meta1
|
207
|
+
end
|
208
|
+
it "should not find a template in the wrong source, and raise" do
|
209
|
+
L{
|
210
|
+
define_in(source1) { dep 'template selection 4', :template => 'meta_3' }.template
|
211
|
+
}.should raise_error(TemplateNotFound, "There is no template named 'meta_3' to define 'template selection 4' against.")
|
212
|
+
end
|
226
213
|
end
|
227
|
-
|
228
|
-
|
214
|
+
context "with suffixes" do
|
215
|
+
it "should find a template in the same source" do
|
216
|
+
define_in(source1) { dep 'template selection 3.meta_1' }.template.should == meta1
|
217
|
+
end
|
218
|
+
it "should find a template in the core source" do
|
219
|
+
define_in(source1) { dep 'template selection 3.core_meta' }.template.should == core_meta
|
220
|
+
end
|
221
|
+
it "should not find a template in the wrong source, and use the base template" do
|
222
|
+
define_in(source1) { dep 'template selection 4.meta_3' }.template.should == Dep::BaseTemplate
|
223
|
+
end
|
229
224
|
end
|
230
225
|
end
|
231
226
|
end
|
227
|
+
|
232
228
|
after {
|
233
229
|
Base.sources.anonymous.templates.clear!
|
234
230
|
Base.sources.core.templates.clear!
|
235
231
|
}
|
236
232
|
end
|
237
233
|
|
234
|
+
|
238
235
|
describe "template selection during defining from a real source" do
|
236
|
+
let(:source) { Source.new('spec/deps/good', :name => 'good source').tap(&:load!) }
|
239
237
|
before {
|
240
|
-
|
241
|
-
@source.load!
|
242
|
-
Source.stub!(:present).and_return([@source])
|
238
|
+
Source.stub!(:present).and_return([source])
|
243
239
|
}
|
244
240
|
it "should have loaded deps" do
|
245
|
-
|
241
|
+
source.deps.names.should =~ [
|
246
242
|
'test dep 1',
|
247
243
|
'test dep 2',
|
248
244
|
'option-templated dep',
|
@@ -250,29 +246,27 @@ describe "template selection during defining from a real source" do
|
|
250
246
|
]
|
251
247
|
end
|
252
248
|
it "should have loaded templates" do
|
253
|
-
|
249
|
+
source.templates.names.should =~ [
|
254
250
|
'test_template',
|
255
251
|
'test_meta_1'
|
256
252
|
]
|
257
253
|
end
|
258
254
|
it "should have defined deps against the correct template" do
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
255
|
+
source.find('test dep 1').template.should == Dep::BaseTemplate
|
256
|
+
source.find('test dep 2').template.should == Dep::BaseTemplate
|
257
|
+
source.find('option-templated dep').template.should == source.find_template('test_template')
|
258
|
+
source.find('suffix-templated dep.test_template').template.should == source.find_template('test_template')
|
263
259
|
end
|
264
260
|
end
|
265
261
|
|
266
262
|
describe "nested source loads" do
|
263
|
+
let(:outer_source) { Source.new('spec/deps/outer', :name => 'outer source').tap(&:load!) }
|
264
|
+
let(:nested_source) { Source.new('spec/deps/good', :name => 'nested source') }
|
267
265
|
before {
|
268
|
-
|
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!
|
266
|
+
Source.stub!(:present).and_return([outer_source, nested_source])
|
273
267
|
}
|
274
268
|
it "should have loaded outer deps" do
|
275
|
-
|
269
|
+
outer_source.deps.names.should =~ [
|
276
270
|
'test dep 1',
|
277
271
|
'externally templated',
|
278
272
|
'locally templated',
|
@@ -280,21 +274,21 @@ describe "nested source loads" do
|
|
280
274
|
'separate file',
|
281
275
|
'separate file.another_local_template'
|
282
276
|
]
|
283
|
-
|
277
|
+
nested_source.deps.names.should == []
|
284
278
|
end
|
285
279
|
it "should have loaded outer templates" do
|
286
|
-
|
280
|
+
outer_source.templates.names.should =~ [
|
287
281
|
'local_template',
|
288
282
|
'another_local_template'
|
289
283
|
]
|
290
|
-
|
284
|
+
nested_source.templates.names.should == []
|
291
285
|
end
|
292
286
|
context "after defining external deps" do
|
293
287
|
before {
|
294
|
-
|
288
|
+
outer_source.find('externally templated').context
|
295
289
|
}
|
296
290
|
it "should have loaded the nested deps" do
|
297
|
-
|
291
|
+
nested_source.deps.names.should =~ [
|
298
292
|
'test dep 1',
|
299
293
|
'test dep 2',
|
300
294
|
'option-templated dep',
|
@@ -302,7 +296,7 @@ describe "nested source loads" do
|
|
302
296
|
]
|
303
297
|
end
|
304
298
|
it "should have loaded the nested templates" do
|
305
|
-
|
299
|
+
nested_source.templates.names.should =~ [
|
306
300
|
'test_template',
|
307
301
|
'test_meta_1'
|
308
302
|
]
|
@@ -310,11 +304,11 @@ describe "nested source loads" do
|
|
310
304
|
end
|
311
305
|
|
312
306
|
it "should have defined deps against the correct template" do
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
307
|
+
outer_source.find('test dep 1').template.should == Dep::BaseTemplate
|
308
|
+
outer_source.find('externally templated').template.should == nested_source.find_template('test_template')
|
309
|
+
outer_source.find('locally templated').template.should == outer_source.find_template('local_template')
|
310
|
+
outer_source.find('locally templated.local_template').template.should == outer_source.find_template('local_template')
|
311
|
+
outer_source.find('separate file').template.should == outer_source.find_template('another_local_template')
|
312
|
+
outer_source.find('separate file.another_local_template').template.should == outer_source.find_template('another_local_template')
|
319
313
|
end
|
320
314
|
end
|