powcloud-sprinkle 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. data/.gitignore +5 -0
  2. data/CREDITS +33 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +241 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/bin/sprinkle +90 -0
  8. data/examples/packages/build_essential.rb +9 -0
  9. data/examples/packages/databases/mysql.rb +13 -0
  10. data/examples/packages/databases/sqlite3.rb +16 -0
  11. data/examples/packages/phusion.rb +55 -0
  12. data/examples/packages/ruby/rails.rb +9 -0
  13. data/examples/packages/ruby/ruby.rb +17 -0
  14. data/examples/packages/ruby/rubygems.rb +17 -0
  15. data/examples/packages/scm/git.rb +11 -0
  16. data/examples/packages/scm/subversion.rb +4 -0
  17. data/examples/packages/servers/apache.rb +15 -0
  18. data/examples/rails/README +15 -0
  19. data/examples/rails/deploy.rb +2 -0
  20. data/examples/rails/packages/database.rb +9 -0
  21. data/examples/rails/packages/essential.rb +9 -0
  22. data/examples/rails/packages/rails.rb +29 -0
  23. data/examples/rails/packages/scm.rb +11 -0
  24. data/examples/rails/packages/search.rb +11 -0
  25. data/examples/rails/packages/server.rb +28 -0
  26. data/examples/rails/rails.rb +73 -0
  27. data/examples/sprinkle/sprinkle.rb +38 -0
  28. data/lib/sprinkle/actors/actors.rb +17 -0
  29. data/lib/sprinkle/actors/capistrano.rb +140 -0
  30. data/lib/sprinkle/actors/local.rb +37 -0
  31. data/lib/sprinkle/actors/ssh.rb +123 -0
  32. data/lib/sprinkle/actors/vlad.rb +78 -0
  33. data/lib/sprinkle/configurable.rb +31 -0
  34. data/lib/sprinkle/deployment.rb +73 -0
  35. data/lib/sprinkle/extensions/arbitrary_options.rb +10 -0
  36. data/lib/sprinkle/extensions/array.rb +5 -0
  37. data/lib/sprinkle/extensions/blank_slate.rb +5 -0
  38. data/lib/sprinkle/extensions/dsl_accessor.rb +15 -0
  39. data/lib/sprinkle/extensions/string.rb +10 -0
  40. data/lib/sprinkle/extensions/symbol.rb +7 -0
  41. data/lib/sprinkle/installers/apt.rb +52 -0
  42. data/lib/sprinkle/installers/binary.rb +46 -0
  43. data/lib/sprinkle/installers/bsd_port.rb +33 -0
  44. data/lib/sprinkle/installers/deb.rb +38 -0
  45. data/lib/sprinkle/installers/freebsd_pkg.rb +37 -0
  46. data/lib/sprinkle/installers/freebsd_portinstall.rb +36 -0
  47. data/lib/sprinkle/installers/gem.rb +64 -0
  48. data/lib/sprinkle/installers/install_package.rb +79 -0
  49. data/lib/sprinkle/installers/installer.rb +120 -0
  50. data/lib/sprinkle/installers/mac_port.rb +38 -0
  51. data/lib/sprinkle/installers/noop.rb +20 -0
  52. data/lib/sprinkle/installers/openbsd_pkg.rb +47 -0
  53. data/lib/sprinkle/installers/opensolaris_pkg.rb +43 -0
  54. data/lib/sprinkle/installers/push_text.rb +45 -0
  55. data/lib/sprinkle/installers/rake.rb +37 -0
  56. data/lib/sprinkle/installers/rpm.rb +37 -0
  57. data/lib/sprinkle/installers/smart.rb +29 -0
  58. data/lib/sprinkle/installers/source.rb +190 -0
  59. data/lib/sprinkle/installers/transfer.rb +164 -0
  60. data/lib/sprinkle/installers/yum.rb +37 -0
  61. data/lib/sprinkle/package.rb +309 -0
  62. data/lib/sprinkle/policy.rb +125 -0
  63. data/lib/sprinkle/script.rb +23 -0
  64. data/lib/sprinkle/verifiers/directory.rb +16 -0
  65. data/lib/sprinkle/verifiers/executable.rb +53 -0
  66. data/lib/sprinkle/verifiers/file.rb +26 -0
  67. data/lib/sprinkle/verifiers/package.rb +26 -0
  68. data/lib/sprinkle/verifiers/process.rb +21 -0
  69. data/lib/sprinkle/verifiers/rpm.rb +21 -0
  70. data/lib/sprinkle/verifiers/ruby.rb +25 -0
  71. data/lib/sprinkle/verifiers/symlink.rb +30 -0
  72. data/lib/sprinkle/verify.rb +114 -0
  73. data/lib/sprinkle.rb +32 -0
  74. data/script/console +8 -0
  75. data/script/destroy +14 -0
  76. data/script/generate +14 -0
  77. data/spec/spec.opts +1 -0
  78. data/spec/spec_helper.rb +17 -0
  79. data/spec/sprinkle/actors/capistrano_spec.rb +265 -0
  80. data/spec/sprinkle/actors/local_spec.rb +29 -0
  81. data/spec/sprinkle/configurable_spec.rb +46 -0
  82. data/spec/sprinkle/deployment_spec.rb +80 -0
  83. data/spec/sprinkle/extensions/array_spec.rb +19 -0
  84. data/spec/sprinkle/extensions/string_spec.rb +21 -0
  85. data/spec/sprinkle/installers/apt_spec.rb +70 -0
  86. data/spec/sprinkle/installers/bsd_port_spec.rb +42 -0
  87. data/spec/sprinkle/installers/freebsd_pkg_spec.rb +49 -0
  88. data/spec/sprinkle/installers/freebsd_portinstall_spec.rb +42 -0
  89. data/spec/sprinkle/installers/gem_spec.rb +107 -0
  90. data/spec/sprinkle/installers/installer_spec.rb +151 -0
  91. data/spec/sprinkle/installers/mac_port_spec.rb +42 -0
  92. data/spec/sprinkle/installers/noop_spec.rb +23 -0
  93. data/spec/sprinkle/installers/openbsd_pkg_spec.rb +49 -0
  94. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +49 -0
  95. data/spec/sprinkle/installers/push_text_spec.rb +66 -0
  96. data/spec/sprinkle/installers/rake_spec.rb +29 -0
  97. data/spec/sprinkle/installers/rpm_spec.rb +50 -0
  98. data/spec/sprinkle/installers/source_spec.rb +371 -0
  99. data/spec/sprinkle/installers/transfer_spec.rb +98 -0
  100. data/spec/sprinkle/installers/yum_spec.rb +49 -0
  101. data/spec/sprinkle/package_spec.rb +466 -0
  102. data/spec/sprinkle/policy_spec.rb +126 -0
  103. data/spec/sprinkle/script_spec.rb +51 -0
  104. data/spec/sprinkle/sprinkle_spec.rb +25 -0
  105. data/spec/sprinkle/verify_spec.rb +174 -0
  106. metadata +244 -0
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::MacPort do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'package')
7
+ end
8
+
9
+ def create_port(ports, &block)
10
+ Sprinkle::Installers::MacPort.new(@package, ports, &block)
11
+ end
12
+
13
+ describe 'when created' do
14
+
15
+ it 'should accept a single package to install' do
16
+ @installer = create_port 'ruby'
17
+ @installer.port.should == 'ruby'
18
+ end
19
+
20
+ end
21
+
22
+ describe 'during installation' do
23
+
24
+ before do
25
+ @installer = create_port 'ruby' do
26
+ pre :install, 'op1'
27
+ post :install, 'op2'
28
+ end
29
+ @install_commands = @installer.send :install_commands
30
+ end
31
+
32
+ it 'should invoke the port installer for all specified packages' do
33
+ @install_commands.should =~ /port install ruby/
34
+ end
35
+
36
+ it 'should automatically insert pre/post commands for the specified package' do
37
+ @installer.send(:install_sequence).should == [ 'op1', 'port install ruby', 'op2' ]
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::Noop do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'spec')
7
+ end
8
+
9
+ def create_noop(names, options = {}, &block)
10
+ Sprinkle::Installers::Noop.new(@package, options, &block)
11
+ end
12
+
13
+ describe 'during installation' do
14
+
15
+ it 'should always be empty' do
16
+ @installer = create_noop 'spec'
17
+ @install_commands = @installer.send :install_commands
18
+ @install_commands.should == 'echo noop'
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::OpenbsdPkg do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'package')
7
+ end
8
+
9
+ def create_pkg(pkgs, &block)
10
+ Sprinkle::Installers::OpenbsdPkg.new(@package, pkgs, &block)
11
+ end
12
+
13
+ describe 'when created' do
14
+
15
+ it 'should accept a single package to install' do
16
+ @installer = create_pkg 'ruby'
17
+ @installer.packages.should == [ 'ruby' ]
18
+ end
19
+
20
+ it 'should accept an array of packages to install' do
21
+ @installer = create_pkg %w( gcc gdb g++ )
22
+ @installer.packages.should == ['gcc', 'gdb', 'g++']
23
+ end
24
+
25
+ end
26
+
27
+ describe 'during installation' do
28
+
29
+ before do
30
+ @installer = create_pkg 'ruby' do
31
+ pre :install, 'op1'
32
+ post :install, 'op2'
33
+ end
34
+ @install_commands = @installer.send :install_commands
35
+ end
36
+
37
+ it 'should invoke the freebsd_pkg installer for all specified packages' do
38
+ @install_commands.should =~ /pkg_add ruby/
39
+ end
40
+
41
+ it 'should automatically insert pre/post commands for the specified package' do
42
+ @installer.send(:install_sequence).should == [ 'op1', 'pkg_add ruby', 'op2' ]
43
+ end
44
+
45
+ it 'should install a specific version if defined'
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::OpensolarisPkg do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'package')
7
+ end
8
+
9
+ def create_pkg(pkgs, &block)
10
+ Sprinkle::Installers::OpensolarisPkg.new(@package, pkgs, &block)
11
+ end
12
+
13
+ describe 'when created' do
14
+
15
+ it 'should accept a single package to install' do
16
+ @installer = create_pkg 'ruby'
17
+ @installer.packages.should == [ 'ruby' ]
18
+ end
19
+
20
+ it 'should accept an array of packages to install' do
21
+ @installer = create_pkg %w( gcc gdb g++ )
22
+ @installer.packages.should == ['gcc', 'gdb', 'g++']
23
+ end
24
+
25
+ end
26
+
27
+ describe 'during installation' do
28
+
29
+ before do
30
+ @installer = create_pkg 'ruby' do
31
+ pre :install, 'op1'
32
+ post :install, 'op2'
33
+ end
34
+ @install_commands = @installer.send :install_commands
35
+ end
36
+
37
+ it 'should invoke the freebsd_pkg installer for all specified packages' do
38
+ @install_commands.should =~ /pkg install ruby/
39
+ end
40
+
41
+ it 'should automatically insert pre/post commands for the specified package' do
42
+ @installer.send(:install_sequence).should == [ 'op1', 'pkg install ruby', 'op2' ]
43
+ end
44
+
45
+ it 'should install a specific version if defined'
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::PushText do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'package')
7
+ @options = {:sudo => true}
8
+ end
9
+
10
+ def create_text(text, path, options={}, &block)
11
+ Sprinkle::Installers::PushText.new(@package, text, path, options, &block)
12
+ end
13
+
14
+ describe 'when created' do
15
+
16
+ it 'should accept a single package to install' do
17
+ @installer = create_text 'crazy-configuration-methods', '/etc/doomed/file.conf'
18
+ @installer.text.should == 'crazy-configuration-methods'
19
+ @installer.path.should == '/etc/doomed/file.conf'
20
+ end
21
+
22
+ end
23
+
24
+ describe 'during installation' do
25
+
26
+ before do
27
+ @installer = create_text 'another-hair-brained-idea', '/dev/mind/late-night' do
28
+ pre :install, 'op1'
29
+ post :install, 'op2'
30
+ end
31
+ @install_commands = @installer.send :install_commands
32
+ end
33
+
34
+ it 'should invoke the push text installer for all specified packages' do
35
+ @install_commands.should == %q[echo -e 'another-hair-brained-idea' |tee -a /dev/mind/late-night]
36
+ end
37
+
38
+ it 'should automatically insert pre/post commands for the specified package' do
39
+ @installer.send(:install_sequence).should == [ 'op1', "echo -e 'another-hair-brained-idea' |tee -a /dev/mind/late-night", 'op2' ]
40
+ end
41
+
42
+ end
43
+
44
+ describe 'running with sudo' do
45
+ before do
46
+ @installer = create_text "a special user", "/dev/mind/the-day-after", :sudo => true
47
+ @install_commands = @installer.send :install_commands
48
+ end
49
+
50
+ it "should invoke the push installer with sudo" do
51
+ @install_commands.should == %q[echo -e 'a special user' |sudo tee -a /dev/mind/the-day-after]
52
+ end
53
+ end
54
+
55
+ describe 'sending a string with single quotes' do
56
+ before do
57
+ @installer = create_text "I'm a string with a single quote", "/dev/mind/the-day-after"
58
+ @install_commands = @installer.send :install_commands
59
+ end
60
+
61
+ it "should correctly encode the single quote character" do
62
+ @install_commands.should == %q[echo -e 'I'\''m a string with a single quote' |tee -a /dev/mind/the-day-after]
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::Rake do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'spec')
7
+ end
8
+
9
+ def create_rake(names, options = {}, &block)
10
+ Sprinkle::Installers::Rake.new(@package, names, options, &block)
11
+ end
12
+
13
+ describe 'during installation' do
14
+
15
+ it 'should invoke the rake executer for all specified tasks' do
16
+ @installer = create_rake 'spec'
17
+ @install_commands = @installer.send :install_commands
18
+ @install_commands.should =~ /rake spec/
19
+ end
20
+
21
+ it 'should invoke the rake executer for all specified tasks' do
22
+ @installer = create_rake 'spec', :rakefile => '/some/Rakefile'
23
+ @install_commands = @installer.send :install_commands
24
+ @install_commands.should == "rake -f /some/Rakefile spec"
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::Rpm do
4
+
5
+ before do
6
+ @package = mock(Sprinkle::Package, :name => 'package')
7
+ end
8
+
9
+ def create_rpm(debs, &block)
10
+ Sprinkle::Installers::Rpm.new(@package, debs, &block)
11
+ end
12
+
13
+ describe 'when created' do
14
+
15
+ it 'should accept a single package to install' do
16
+ @installer = create_rpm 'ruby'
17
+ @installer.packages.should == [ 'ruby' ]
18
+ end
19
+
20
+ it 'should accept an array of packages to install' do
21
+ @installer = create_rpm %w( gcc gdb g++ )
22
+ @installer.packages.should == ['gcc', 'gdb', 'g++']
23
+ end
24
+
25
+ end
26
+
27
+ describe 'during installation' do
28
+
29
+ before do
30
+ @installer = create_rpm 'ruby' do
31
+ pre :install, 'op1'
32
+ post :install, 'op2'
33
+ end
34
+ @install_commands = @installer.send :install_commands
35
+ end
36
+
37
+ it 'should invoke the rpm installer for all specified packages' do
38
+ @install_commands.should =~ /rpm -Uvh ruby/
39
+ end
40
+
41
+ it 'should automatically insert pre/post commands for the specified package' do
42
+ @installer.send(:install_sequence).should == [ 'op1', 'rpm -Uvh ruby', 'op2' ]
43
+ end
44
+
45
+ it 'should specify a non interactive mode to the apt installer'
46
+ it 'should install a specific version if defined'
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,371 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Sprinkle::Installers::Source do
4
+ include Sprinkle::Deployment
5
+
6
+ before do
7
+ @source = 'ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz'
8
+
9
+ @deployment = deployment do
10
+ delivery :capistrano
11
+ source do
12
+ prefix '/usr'
13
+ archives '/usr/archives'
14
+ builds '/usr/builds'
15
+ end
16
+ end
17
+
18
+ @installer = create_source @source do
19
+ prefix '/usr/local'
20
+ archives '/usr/local/archives'
21
+ builds '/usr/local/builds'
22
+
23
+ enable %w( headers ssl deflate so )
24
+ disable %w( cache proxy rewrite )
25
+
26
+ with %w( debug extras )
27
+ without %w( fancyisms )
28
+
29
+ option %w( foo bar baz )
30
+ end
31
+
32
+ @installer.defaults(@deployment)
33
+ end
34
+
35
+ def create_source(source, version = nil, &block)
36
+ @package = mock(Sprinkle::Package, :name => 'package', :version => version)
37
+ Sprinkle::Installers::Source.new(@package, source, &block)
38
+ end
39
+
40
+ describe 'when created' do
41
+
42
+ it 'should accept a source archive name to install' do
43
+ @installer.source.should == @source
44
+ end
45
+
46
+ end
47
+
48
+ describe 'before installation' do
49
+
50
+ before do
51
+ @settings = { :prefix => '/usr/local', :archives => '/usr/local/tmp', :builds => '/usr/local/stage' }
52
+ end
53
+
54
+ it 'should fail if no installation area has been specified' do
55
+ @settings.delete(:prefix)
56
+ end
57
+
58
+ it 'should fail if no build area has been specified' do
59
+ @settings.delete(:builds)
60
+ end
61
+
62
+ it 'should fail if no source download area has been specified' do
63
+ @settings.delete(:archives)
64
+ end
65
+
66
+ after do
67
+ @settings.each { |k, v| @installer.send k, v }
68
+ lambda { @installer.install_sequence }.should raise_error
69
+ end
70
+
71
+ end
72
+
73
+ describe 'customized configuration' do
74
+
75
+ it 'should support specification of "enable" options' do
76
+ @installer.enable.should == %w( headers ssl deflate so )
77
+ end
78
+
79
+ it 'should support specification of "disable" options' do
80
+ @installer.disable.should == %w( cache proxy rewrite )
81
+ end
82
+
83
+ it 'should support specification of "with" options' do
84
+ @installer.with.should == %w( debug extras )
85
+ end
86
+
87
+ it 'should support specification of "without" options' do
88
+ @installer.without.should == %w( fancyisms )
89
+ end
90
+
91
+ it 'should support specification of "option" options' do
92
+ @installer.option.should == %w( foo bar baz )
93
+ end
94
+
95
+ it 'should support customized build area' do
96
+ @installer.prefix.should == '/usr/local'
97
+ end
98
+
99
+ it 'should support customized source area' do
100
+ @installer.archives.should == '/usr/local/archives'
101
+ end
102
+
103
+ it 'should support customized install area' do
104
+ @installer.builds.should == '/usr/local/builds'
105
+ end
106
+
107
+ end
108
+
109
+ describe 'during gnu source archive style installation' do
110
+
111
+ it 'should prepare the build, installation and source archives area' do
112
+ @installer.should_receive(:prepare).and_return(
113
+ [
114
+ 'mkdir -p /usr/local',
115
+ 'mkdir -p /usr/local/builds',
116
+ 'mkdir -p /usr/local/archives'
117
+ ]
118
+ )
119
+
120
+ end
121
+
122
+ it 'should download the source archive' do
123
+ @installer.should_receive(:download).and_return(
124
+ [
125
+ "wget -cq --directory-prefix='/usr/local/archives' #{@source}"
126
+ ]
127
+ )
128
+ end
129
+
130
+ it 'should extract the source archive' do
131
+ @installer.should_receive(:extract).and_return(
132
+ [
133
+ "bash -c 'cd /usr/local/builds && tar xzf /usr/local/archives/ruby-1.8.6-p111.tar.gz"
134
+ ]
135
+ )
136
+ end
137
+
138
+ it 'should configure the source' do
139
+ enable = %w( headers ssl deflate so ).inject([]) { |m, value| m << "--enable-#{value}"; m }
140
+ disable = %w( cache proxy rewrite ).inject([]) { |m, value| m << "--disable-#{value}"; m }
141
+
142
+ with = %w( debug extras ).inject([]) { |m, value| m << "--with-#{value}"; m }
143
+ without = %w( fancyisms ).inject([]) { |m, value| m << "--without-#{value}"; m }
144
+
145
+ options = "#{enable.join(' ')} #{disable.join(' ')} #{with.join(' ')} #{without.join(' ')}"
146
+
147
+ @installer.should_receive(:build).and_return(
148
+ [
149
+ "bash -c 'cd /usr/local/builds && ./configure --prefix=/usr/local #{options} > #{@package.name}-configure.log 2>&1'"
150
+ ]
151
+ )
152
+ end
153
+
154
+ it 'should build the source' do
155
+ @installer.should_receive(:build).and_return(
156
+ [
157
+ "bash -c 'cd /usr/local/builds && make > #{@package.name}-build.log 2>&1'"
158
+ ]
159
+ )
160
+ end
161
+
162
+ it 'should install the source' do
163
+ @installer.should_receive(:install).and_return(
164
+ [
165
+ "bash -c 'cd /usr/local/builds && make install > #{@package.name}-install.log 2>&1'"
166
+ ]
167
+ )
168
+ end
169
+
170
+ describe 'with a custom archive definition' do
171
+ before do
172
+ @installer.options[:custom_archive] = 'super-foo.tar'
173
+ end
174
+
175
+ it 'should install the source from the custom archive' do
176
+ @installer.send(:extract_commands).first.should =~ /super-foo/
177
+ @installer.send(:configure_commands).first.should =~ /super-foo/
178
+ @installer.send(:build_commands).first.should =~ /super-foo/
179
+ @installer.send(:install_commands).first.should =~ /super-foo/
180
+ end
181
+
182
+ end
183
+
184
+ describe 'during a customized install' do
185
+
186
+ before do
187
+ @installer = create_source @source do
188
+ custom_install 'ruby setup.rb'
189
+ end
190
+
191
+ @installer.defaults(@deployment)
192
+ end
193
+
194
+ it 'should store the custom install commands' do
195
+ @installer.options[:custom_install].should == 'ruby setup.rb'
196
+ end
197
+
198
+ it 'should identify as having a custom install command' do
199
+ @installer.should be_custom_install
200
+ end
201
+
202
+ it 'should not configure the source automatically' do
203
+ @installer.should_receive(:configure).and_return([])
204
+ end
205
+
206
+ it 'should not build the source automatically' do
207
+ @installer.should_receive(:build).and_return([])
208
+ end
209
+
210
+ it 'should install the source using a custom installation command' do
211
+ @installer.send(:custom_install_commands).first.should =~ /ruby setup.rb/
212
+ end
213
+
214
+ it 'should be run relative to the source build area' do
215
+ @installer.send(:custom_install_commands).first.should =~ %r{cd /usr/builds/ruby-1.8.6-p111}
216
+ end
217
+
218
+ describe 'with a customized directory' do
219
+
220
+ before do
221
+ @installer.options[:custom_dir] = 'test'
222
+ end
223
+
224
+ it 'should install the source from the custom dir path' do
225
+ @installer.send(:custom_install_commands).first.should =~ /test/
226
+ end
227
+
228
+ it 'should store the custom build dir path' do
229
+ @installer.options[:custom_dir].should == 'test'
230
+ end
231
+
232
+ end
233
+
234
+ end
235
+
236
+ after do
237
+ @installer.send :install_sequence
238
+ end
239
+
240
+ end
241
+
242
+ describe 'pre stage commands' do
243
+
244
+ before do
245
+ @commands = {
246
+ :prepare => %w( prepare1 prepare2 ),
247
+ :download => %w( down1 down2 ),
248
+ :extract => %w( ex1 ex2 ),
249
+ :configure => %w( conf1 conf2 ),
250
+ :build => %w( build1 build2 ),
251
+ :install => %w( install1 install2 )
252
+ }
253
+
254
+ @installer = create_source @source
255
+ @commands.each { |k, v| @installer.pre k, *v }
256
+ @installer.defaults(@deployment)
257
+ end
258
+
259
+ it 'should run all pre-prepare commands' do
260
+ @commands.each { |k, v| @installer.should_receive(:pre_commands).with(k).and_return(v) }
261
+ end
262
+
263
+ it 'should be run relative to the source build area' do
264
+ @commands.each { |stage, command| @installer.send(:pre_commands, stage).first.should =~ %r{cd /usr/builds/ruby-1.8.6-p111} }
265
+ end
266
+
267
+ after do
268
+ @installer.send :install_sequence
269
+ end
270
+
271
+ end
272
+
273
+ describe 'post stage commands' do
274
+
275
+ before do
276
+ @commands = {
277
+ :prepare => %w( prepare1 prepare2 ),
278
+ :download => %w( down1 down2 ),
279
+ :extract => %w( ex1 ex2 ),
280
+ :configure => %w( conf1 conf2 ),
281
+ :build => %w( build1 build2 ),
282
+ :install => %w( install1 install2 )
283
+ }
284
+
285
+ @installer = create_source @source
286
+ @commands.each { |k, v| @installer.post k, *v }
287
+ @installer.defaults(@deployment)
288
+ end
289
+
290
+ it 'should run all post-prepare commands' do
291
+ @commands.each { |k, v| @installer.should_receive(:post_commands).with(k).and_return(v) }
292
+ end
293
+
294
+ it 'should be run relative to the source build area' do
295
+ @commands.each { |stage, command| @installer.send(:post_commands, stage).first.should =~ %r{cd /usr/builds/ruby-1.8.6-p111} }
296
+ end
297
+
298
+ after do
299
+ @installer.send :install_sequence
300
+ end
301
+
302
+ end
303
+
304
+ describe 'install sequence' do
305
+
306
+ it 'should prepare, then download, then extract, then configure, then build, then install' do
307
+ %w( prepare download extract configure build install ).each do |stage|
308
+ @installer.should_receive(stage).ordered.and_return([])
309
+ end
310
+ end
311
+
312
+ after do
313
+ @installer.send :install_sequence
314
+ end
315
+
316
+ end
317
+
318
+ describe 'source extraction' do
319
+
320
+ it 'should support tgz archives' do
321
+ @installer.source = 'blah.tgz'
322
+ @extraction = 'tar xzf'
323
+ end
324
+
325
+ it 'should support tar.gz archives' do
326
+ @installer.source = 'blah.tgz'
327
+ @extraction = 'tar xzf'
328
+ end
329
+
330
+ it 'should support tar.bz2 archives' do
331
+ @installer.source = 'blah.tar.bz2'
332
+ @extraction = 'tar xjf'
333
+ end
334
+
335
+ it 'should support tb2 archives' do
336
+ @installer.source = 'blah.tb2'
337
+ @extraction = 'tar xjf'
338
+ end
339
+
340
+ it 'should support zip archives' do
341
+ @installer.source = 'blah.zip'
342
+ @extraction = 'unzip'
343
+ end
344
+
345
+ after do
346
+ @installer.send(:extract_command).should == @extraction
347
+ end
348
+
349
+ end
350
+
351
+ describe 'base dir calculation' do
352
+
353
+ %w( tar tar.gz tgz tar.bz2 tb2 zip ).each do |archive|
354
+
355
+ it "should recognize #{archive} style archives" do
356
+ @installer.source = "blah.#{archive}"
357
+ @installer.send(:base_dir).should == 'blah'
358
+ end
359
+
360
+ end
361
+
362
+ # def base_dir #:nodoc:
363
+ # if archive_name.split('/').last =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tar|tb2)/
364
+ # return $1
365
+ # end
366
+ # raise "Unknown base path for source archive: #{@source}, please update code knowledge"
367
+ # end
368
+
369
+ end
370
+
371
+ end