fotonauts-capistrano 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/CHANGELOG.rdoc +728 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +66 -0
  4. data/Rakefile +34 -0
  5. data/bin/cap +4 -0
  6. data/bin/capify +78 -0
  7. data/capistrano.gemspec +49 -0
  8. data/examples/sample.rb +14 -0
  9. data/lib/capistrano.rb +2 -0
  10. data/lib/capistrano/callback.rb +45 -0
  11. data/lib/capistrano/cli.rb +47 -0
  12. data/lib/capistrano/cli/execute.rb +84 -0
  13. data/lib/capistrano/cli/help.rb +118 -0
  14. data/lib/capistrano/cli/help.txt +62 -0
  15. data/lib/capistrano/cli/options.rb +224 -0
  16. data/lib/capistrano/cli/ui.rb +40 -0
  17. data/lib/capistrano/command.rb +283 -0
  18. data/lib/capistrano/configuration.rb +43 -0
  19. data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
  20. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  21. data/lib/capistrano/configuration/actions/invocation.rb +193 -0
  22. data/lib/capistrano/configuration/callbacks.rb +148 -0
  23. data/lib/capistrano/configuration/connections.rb +196 -0
  24. data/lib/capistrano/configuration/execution.rb +132 -0
  25. data/lib/capistrano/configuration/loading.rb +197 -0
  26. data/lib/capistrano/configuration/namespaces.rb +197 -0
  27. data/lib/capistrano/configuration/roles.rb +65 -0
  28. data/lib/capistrano/configuration/servers.rb +85 -0
  29. data/lib/capistrano/configuration/variables.rb +127 -0
  30. data/lib/capistrano/errors.rb +15 -0
  31. data/lib/capistrano/extensions.rb +57 -0
  32. data/lib/capistrano/logger.rb +59 -0
  33. data/lib/capistrano/processable.rb +53 -0
  34. data/lib/capistrano/recipes/compat.rb +32 -0
  35. data/lib/capistrano/recipes/deploy.rb +555 -0
  36. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  37. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  38. data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
  39. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  40. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  41. data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
  42. data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
  43. data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
  44. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  45. data/lib/capistrano/recipes/deploy/scm/git.rb +271 -0
  46. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  47. data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
  48. data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
  49. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  50. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  51. data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
  52. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  53. data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
  54. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  55. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  56. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
  57. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  58. data/lib/capistrano/recipes/standard.rb +37 -0
  59. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  60. data/lib/capistrano/recipes/upgrade.rb +33 -0
  61. data/lib/capistrano/role.rb +102 -0
  62. data/lib/capistrano/server_definition.rb +56 -0
  63. data/lib/capistrano/shell.rb +260 -0
  64. data/lib/capistrano/ssh.rb +79 -0
  65. data/lib/capistrano/task_definition.rb +70 -0
  66. data/lib/capistrano/transfer.rb +216 -0
  67. data/lib/capistrano/version.rb +18 -0
  68. data/setup.rb +1346 -0
  69. data/test/cli/execute_test.rb +132 -0
  70. data/test/cli/help_test.rb +165 -0
  71. data/test/cli/options_test.rb +317 -0
  72. data/test/cli/ui_test.rb +28 -0
  73. data/test/cli_test.rb +17 -0
  74. data/test/command_test.rb +286 -0
  75. data/test/configuration/actions/file_transfer_test.rb +61 -0
  76. data/test/configuration/actions/inspect_test.rb +65 -0
  77. data/test/configuration/actions/invocation_test.rb +210 -0
  78. data/test/configuration/callbacks_test.rb +220 -0
  79. data/test/configuration/connections_test.rb +348 -0
  80. data/test/configuration/execution_test.rb +175 -0
  81. data/test/configuration/loading_test.rb +132 -0
  82. data/test/configuration/namespace_dsl_test.rb +305 -0
  83. data/test/configuration/roles_test.rb +143 -0
  84. data/test/configuration/servers_test.rb +121 -0
  85. data/test/configuration/variables_test.rb +180 -0
  86. data/test/configuration_test.rb +88 -0
  87. data/test/deploy/local_dependency_test.rb +76 -0
  88. data/test/deploy/remote_dependency_test.rb +114 -0
  89. data/test/deploy/scm/accurev_test.rb +23 -0
  90. data/test/deploy/scm/base_test.rb +55 -0
  91. data/test/deploy/scm/git_test.rb +159 -0
  92. data/test/deploy/scm/mercurial_test.rb +129 -0
  93. data/test/deploy/scm/none_test.rb +35 -0
  94. data/test/deploy/strategy/copy_test.rb +258 -0
  95. data/test/extensions_test.rb +69 -0
  96. data/test/fixtures/cli_integration.rb +5 -0
  97. data/test/fixtures/config.rb +5 -0
  98. data/test/fixtures/custom.rb +3 -0
  99. data/test/logger_test.rb +123 -0
  100. data/test/role_test.rb +11 -0
  101. data/test/server_definition_test.rb +121 -0
  102. data/test/shell_test.rb +90 -0
  103. data/test/ssh_test.rb +102 -0
  104. data/test/task_definition_test.rb +101 -0
  105. data/test/transfer_test.rb +160 -0
  106. data/test/utils.rb +38 -0
  107. metadata +310 -0
@@ -0,0 +1,35 @@
1
+ require 'utils'
2
+ require 'capistrano/recipes/deploy/scm/none'
3
+
4
+ class DeploySCMNoneTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::None
6
+ default_command 'none'
7
+ end
8
+
9
+ def setup
10
+ @config = {}
11
+ def @config.exists?(name); key?(name); end
12
+ @source = TestSCM.new(@config)
13
+ end
14
+
15
+ def test_the_truth
16
+ assert true
17
+ end
18
+
19
+ def test_checkout_on_linux
20
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(false)
21
+ @config[:repository] = '.'
22
+ rev = ''
23
+ dest = '/var/www'
24
+ assert_equal "cp -R . /var/www", @source.checkout(rev, dest)
25
+ end
26
+
27
+ def test_checkout_on_windows
28
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(true)
29
+ @config[:repository] = '.'
30
+ rev = ''
31
+ dest = 'c:/Documents and settings/admin/tmp'
32
+ assert_equal "xcopy . \"c:/Documents and settings/admin/tmp\" /S/I/Y/Q/E", @source.checkout(rev, dest)
33
+ end
34
+
35
+ end
@@ -0,0 +1,258 @@
1
+ require "utils"
2
+ require 'capistrano/logger'
3
+ require 'capistrano/recipes/deploy/strategy/copy'
4
+ require 'stringio'
5
+
6
+ class DeployStrategyCopyTest < Test::Unit::TestCase
7
+ def setup
8
+ @config = { :application => "captest",
9
+ :logger => Capistrano::Logger.new(:output => StringIO.new),
10
+ :releases_path => "/u/apps/test/releases",
11
+ :release_path => "/u/apps/test/releases/1234567890",
12
+ :real_revision => "154" }
13
+ @source = mock("source")
14
+ @config.stubs(:source).returns(@source)
15
+ @strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
16
+ end
17
+
18
+ def test_deploy_with_defaults_should_use_tar_gz_and_checkout
19
+ Dir.expects(:tmpdir).returns("/temp/dir")
20
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
21
+ @strategy.expects(:system).with(:local_checkout)
22
+
23
+ prepare_standard_compress_and_copy!
24
+ @strategy.deploy!
25
+ end
26
+
27
+ def test_deploy_with_exclusions_should_remove_patterns_from_destination
28
+ @config[:copy_exclude] = ".git"
29
+ Dir.expects(:tmpdir).returns("/temp/dir")
30
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
31
+ @strategy.expects(:system).with(:local_checkout)
32
+ Dir.expects(:glob).with("/temp/dir/1234567890/.git", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
33
+
34
+ FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
35
+ prepare_standard_compress_and_copy!
36
+ @strategy.deploy!
37
+ end
38
+
39
+ def test_deploy_with_exclusions_should_remove_glob_patterns_from_destination
40
+ @config[:copy_exclude] = ".gi*"
41
+ Dir.expects(:tmpdir).returns("/temp/dir")
42
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
43
+ @strategy.expects(:system).with(:local_checkout)
44
+ Dir.expects(:glob).with("/temp/dir/1234567890/.gi*", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
45
+
46
+ FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
47
+ prepare_standard_compress_and_copy!
48
+ @strategy.deploy!
49
+ end
50
+
51
+ def test_deploy_with_export_should_use_tar_gz_and_export
52
+ Dir.expects(:tmpdir).returns("/temp/dir")
53
+ @config[:copy_strategy] = :export
54
+ @source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
55
+ @strategy.expects(:system).with(:local_export)
56
+
57
+ prepare_standard_compress_and_copy!
58
+ @strategy.deploy!
59
+ end
60
+
61
+ def test_deploy_with_zip_should_use_zip_and_checkout
62
+ Dir.expects(:tmpdir).returns("/temp/dir")
63
+ Dir.expects(:chdir).with("/temp/dir").yields
64
+ @config[:copy_compression] = :zip
65
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
66
+
67
+ @strategy.expects(:system).with(:local_checkout)
68
+ @strategy.expects(:system).with("zip -qr 1234567890.zip 1234567890")
69
+ @strategy.expects(:upload).with("/temp/dir/1234567890.zip", "/tmp/1234567890.zip")
70
+ @strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
71
+
72
+ mock_file = mock("file")
73
+ mock_file.expects(:puts).with("154")
74
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
75
+
76
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
77
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
78
+
79
+ @strategy.deploy!
80
+ end
81
+
82
+ def test_deploy_with_bzip2_should_use_bz2_and_checkout
83
+ Dir.expects(:tmpdir).returns("/temp/dir")
84
+ Dir.expects(:chdir).with("/temp/dir").yields
85
+ @config[:copy_compression] = :bzip2
86
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
87
+
88
+ @strategy.expects(:system).with(:local_checkout)
89
+ @strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
90
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
91
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
92
+
93
+ mock_file = mock("file")
94
+ mock_file.expects(:puts).with("154")
95
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
96
+
97
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
98
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
99
+
100
+ @strategy.deploy!
101
+ end
102
+
103
+ def test_deploy_with_unknown_compression_type_should_error
104
+ @config[:copy_compression] = :bogus
105
+ Dir.expects(:tmpdir).returns("/temp/dir")
106
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
107
+ @strategy.stubs(:system)
108
+ File.stubs(:open)
109
+
110
+ assert_raises(ArgumentError) { @strategy.deploy! }
111
+ end
112
+
113
+ def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
114
+ Dir.expects(:tmpdir).never
115
+ Dir.expects(:chdir).with("/other/path").yields
116
+ @config[:copy_dir] = "/other/path"
117
+ @source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)
118
+
119
+ @strategy.expects(:system).with(:local_checkout)
120
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
121
+ @strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
122
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
123
+
124
+ mock_file = mock("file")
125
+ mock_file.expects(:puts).with("154")
126
+ File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
127
+
128
+ FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
129
+ FileUtils.expects(:rm_rf).with("/other/path/1234567890")
130
+
131
+ @strategy.deploy!
132
+ end
133
+
134
+ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
135
+ @config[:copy_remote_dir] = "/somewhere/else"
136
+ Dir.expects(:tmpdir).returns("/temp/dir")
137
+ Dir.expects(:chdir).yields
138
+ @source.expects(:checkout).returns(:local_checkout)
139
+
140
+ @strategy.expects(:system).with(:local_checkout)
141
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
142
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
143
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
144
+
145
+ mock_file = mock("file")
146
+ mock_file.expects(:puts).with("154")
147
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
148
+
149
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
150
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
151
+
152
+ @strategy.deploy!
153
+ end
154
+
155
+ def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
156
+ @config[:copy_cache] = true
157
+
158
+ Dir.stubs(:tmpdir).returns("/temp/dir")
159
+ File.expects(:exists?).with("/temp/dir/captest").returns(false)
160
+ Dir.expects(:chdir).with("/temp/dir/captest").yields
161
+
162
+ @source.expects(:checkout).with("154", "/temp/dir/captest").returns(:local_checkout)
163
+ @strategy.expects(:system).with(:local_checkout)
164
+
165
+ FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
166
+
167
+ prepare_directory_tree!("/temp/dir/captest")
168
+
169
+ prepare_standard_compress_and_copy!
170
+ @strategy.deploy!
171
+ end
172
+
173
+ def test_with_copy_cache_should_update_cache_if_cache_exists_and_then_copy
174
+ @config[:copy_cache] = true
175
+
176
+ Dir.stubs(:tmpdir).returns("/temp/dir")
177
+ File.expects(:exists?).with("/temp/dir/captest").returns(true)
178
+ Dir.expects(:chdir).with("/temp/dir/captest").yields
179
+
180
+ @source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
181
+ @strategy.expects(:system).with(:local_sync)
182
+
183
+ FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
184
+
185
+ prepare_directory_tree!("/temp/dir/captest")
186
+
187
+ prepare_standard_compress_and_copy!
188
+ @strategy.deploy!
189
+ end
190
+
191
+ def test_with_copy_cache_with_custom_cache_dir_should_use_specified_cache_dir
192
+ @config[:copy_cache] = "/u/caches/captest"
193
+
194
+ Dir.stubs(:tmpdir).returns("/temp/dir")
195
+ File.expects(:exists?).with("/u/caches/captest").returns(true)
196
+ Dir.expects(:chdir).with("/u/caches/captest").yields
197
+
198
+ @source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
199
+ @strategy.expects(:system).with(:local_sync)
200
+
201
+ FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
202
+
203
+ prepare_directory_tree!("/u/caches/captest")
204
+
205
+ prepare_standard_compress_and_copy!
206
+ @strategy.deploy!
207
+ end
208
+
209
+ def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
210
+ @config[:copy_cache] = true
211
+ @config[:copy_exclude] = "*/bar.txt"
212
+
213
+ Dir.stubs(:tmpdir).returns("/temp/dir")
214
+ File.expects(:exists?).with("/temp/dir/captest").returns(true)
215
+ Dir.expects(:chdir).with("/temp/dir/captest").yields
216
+
217
+ @source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
218
+ @strategy.expects(:system).with(:local_sync)
219
+
220
+ FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
221
+
222
+ prepare_directory_tree!("/temp/dir/captest", true)
223
+
224
+ prepare_standard_compress_and_copy!
225
+ @strategy.deploy!
226
+ end
227
+
228
+ private
229
+
230
+ def prepare_directory_tree!(cache, exclude=false)
231
+ Dir.expects(:glob).with("*", File::FNM_DOTMATCH).returns([".", "..", "app", "foo.txt"])
232
+ File.expects(:directory?).with("app").returns(true)
233
+ FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
234
+ File.expects(:directory?).with("foo.txt").returns(false)
235
+ FileUtils.expects(:ln).with("#{cache}/foo.txt", "/temp/dir/1234567890/foo.txt")
236
+
237
+ Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
238
+
239
+ unless exclude
240
+ File.expects(:directory?).with("app/bar.txt").returns(false)
241
+ FileUtils.expects(:ln).with("#{cache}/app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
242
+ end
243
+ end
244
+
245
+ def prepare_standard_compress_and_copy!
246
+ Dir.expects(:chdir).with("/temp/dir").yields
247
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
248
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
249
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
250
+
251
+ mock_file = mock("file")
252
+ mock_file.expects(:puts).with("154")
253
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
254
+
255
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
256
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
257
+ end
258
+ end
@@ -0,0 +1,69 @@
1
+ require "utils"
2
+ require 'capistrano'
3
+
4
+ class ExtensionsTest < Test::Unit::TestCase
5
+ module CustomExtension
6
+ def do_something(command)
7
+ run(command)
8
+ end
9
+ end
10
+
11
+ def setup
12
+ @config = Capistrano::Configuration.new
13
+ end
14
+
15
+ def teardown
16
+ Capistrano::EXTENSIONS.keys.each { |e| Capistrano.remove_plugin(e) }
17
+ end
18
+
19
+ def test_register_plugin_should_add_instance_method_on_configuration_and_return_true
20
+ assert !@config.respond_to?(:custom_stuff)
21
+ assert Capistrano.plugin(:custom_stuff, CustomExtension)
22
+ assert @config.respond_to?(:custom_stuff)
23
+ end
24
+
25
+ def test_register_plugin_that_already_exists_should_return_false
26
+ assert Capistrano.plugin(:custom_stuff, CustomExtension)
27
+ assert !Capistrano.plugin(:custom_stuff, CustomExtension)
28
+ end
29
+
30
+ def test_register_plugin_with_public_method_name_should_fail
31
+ method = Capistrano::Configuration.public_instance_methods.first
32
+ assert_not_nil method, "need a public instance method for testing"
33
+ assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
34
+ end
35
+
36
+ def test_register_plugin_with_protected_method_name_should_fail
37
+ method = Capistrano::Configuration.protected_instance_methods.first
38
+ assert_not_nil method, "need a protected instance method for testing"
39
+ assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
40
+ end
41
+
42
+ def test_register_plugin_with_private_method_name_should_fail
43
+ method = Capistrano::Configuration.private_instance_methods.first
44
+ assert_not_nil method, "need a private instance method for testing"
45
+ assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
46
+ end
47
+
48
+ def test_unregister_plugin_that_does_not_exist_should_return_false
49
+ assert !Capistrano.remove_plugin(:custom_stuff)
50
+ end
51
+
52
+ def test_unregister_plugin_should_remove_method_and_return_true
53
+ assert Capistrano.plugin(:custom_stuff, CustomExtension)
54
+ assert @config.respond_to?(:custom_stuff)
55
+ assert Capistrano.remove_plugin(:custom_stuff)
56
+ assert !@config.respond_to?(:custom_stuff)
57
+ end
58
+
59
+ def test_registered_plugin_proxy_should_return_proxy_object
60
+ Capistrano.plugin(:custom_stuff, CustomExtension)
61
+ assert_instance_of Capistrano::ExtensionProxy, @config.custom_stuff
62
+ end
63
+
64
+ def test_proxy_object_should_delegate_to_configuration
65
+ Capistrano.plugin(:custom_stuff, CustomExtension)
66
+ @config.expects(:run).with("hello")
67
+ @config.custom_stuff.do_something("hello")
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ role :test, "www.capistrano.test"
2
+
3
+ task :testing, :roles => :test do
4
+ set :testing_occurred, true
5
+ end
@@ -0,0 +1,5 @@
1
+ set :application, "foo"
2
+ set :repository, "1/2/#{application}"
3
+ set :gateway, "#{__FILE__}.example.com"
4
+
5
+ role :web, "www.example.com", :primary => true
@@ -0,0 +1,3 @@
1
+ ConfigurationLoadingTest::MockConfig.instance(:must_exist).load do
2
+ ping! :custom
3
+ end
@@ -0,0 +1,123 @@
1
+ require "utils"
2
+ require 'capistrano/logger'
3
+ require 'stringio'
4
+
5
+ class LoggerTest < Test::Unit::TestCase
6
+ def setup
7
+ @io = StringIO.new
8
+ @logger = Capistrano::Logger.new(:output => @io)
9
+ end
10
+
11
+ def test_logger_should_use_STDERR_by_default
12
+ logger = Capistrano::Logger.new
13
+ assert_equal STDERR, logger.device
14
+ end
15
+
16
+ def test_logger_should_use_output_option_if_output_responds_to_puts
17
+ logger = Capistrano::Logger.new(:output => STDOUT)
18
+ assert_equal STDOUT, logger.device
19
+ end
20
+
21
+ def test_logger_should_open_file_if_output_does_not_respond_to_puts
22
+ File.expects(:open).with("logs/capistrano.log", "a").returns(:mock)
23
+ logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
24
+ assert_equal :mock, logger.device
25
+ end
26
+
27
+ def test_close_should_not_close_device_if_device_is_default
28
+ logger = Capistrano::Logger.new
29
+ logger.device.expects(:close).never
30
+ logger.close
31
+ end
32
+
33
+ def test_close_should_not_close_device_is_device_is_explicitly_given
34
+ logger = Capistrano::Logger.new(:output => STDOUT)
35
+ STDOUT.expects(:close).never
36
+ logger.close
37
+ end
38
+
39
+ def test_close_should_close_device_when_device_was_implicitly_opened
40
+ f = mock("file", :close => nil)
41
+ File.expects(:open).with("logs/capistrano.log", "a").returns(f)
42
+ logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
43
+ logger.close
44
+ end
45
+
46
+ def test_log_with_level_greater_than_threshold_should_ignore_message
47
+ @logger.level = 3
48
+ @logger.log(4, "message")
49
+ assert @io.string.empty?
50
+ end
51
+
52
+ def test_log_with_level_equal_to_threshold_should_log_message
53
+ @logger.level = 3
54
+ @logger.log(3, "message")
55
+ assert @io.string.include?("message")
56
+ end
57
+
58
+ def test_log_with_level_less_than_threshold_should_log_message
59
+ @logger.level = 3
60
+ @logger.log(2, "message")
61
+ assert @io.string.include?("message")
62
+ end
63
+
64
+ def test_log_with_multiline_message_should_log_each_line_separately
65
+ @logger.log(0, "first line\nsecond line")
66
+ assert @io.string.include?("*** first line")
67
+ assert @io.string.include?("*** second line")
68
+ end
69
+
70
+ def test_log_with_line_prefix_should_insert_line_prefix_before_message
71
+ @logger.log(0, "message", "prefix")
72
+ assert @io.string.include?("*** [prefix] message")
73
+ end
74
+
75
+ def test_log_with_level_0_should_have_strong_indent
76
+ @logger.log(0, "message")
77
+ assert @io.string.match(/^\*\*\* message/)
78
+ end
79
+
80
+ def test_log_with_level_1_should_have_weaker_indent
81
+ @logger.level = 1
82
+ @logger.log(1, "message")
83
+ assert @io.string.match(/^ \*\* message/)
84
+ end
85
+
86
+ def test_log_with_level_2_should_have_weaker_indent
87
+ @logger.level = 2
88
+ @logger.log(2, "message")
89
+ assert @io.string.match(/^ \* message/)
90
+ end
91
+
92
+ def test_log_with_level_3_should_have_weakest_indent
93
+ @logger.level = 3
94
+ @logger.log(3, "message")
95
+ assert @io.string.match(/^ message/)
96
+ end
97
+
98
+ def test_important_should_delegate_to_log_with_level_IMPORTANT
99
+ @logger.expects(:log).with(Capistrano::Logger::IMPORTANT, "message", "prefix")
100
+ @logger.important("message", "prefix")
101
+ end
102
+
103
+ def test_info_should_delegate_to_log_with_level_INFO
104
+ @logger.expects(:log).with(Capistrano::Logger::INFO, "message", "prefix")
105
+ @logger.info("message", "prefix")
106
+ end
107
+
108
+ def test_debug_should_delegate_to_log_with_level_DEBUG
109
+ @logger.expects(:log).with(Capistrano::Logger::DEBUG, "message", "prefix")
110
+ @logger.debug("message", "prefix")
111
+ end
112
+
113
+ def test_trace_should_delegate_to_log_with_level_TRACE
114
+ @logger.expects(:log).with(Capistrano::Logger::TRACE, "message", "prefix")
115
+ @logger.trace("message", "prefix")
116
+ end
117
+
118
+ def test_ordering_of_levels
119
+ assert Capistrano::Logger::IMPORTANT < Capistrano::Logger::INFO
120
+ assert Capistrano::Logger::INFO < Capistrano::Logger::DEBUG
121
+ assert Capistrano::Logger::DEBUG < Capistrano::Logger::TRACE
122
+ end
123
+ end