capistrano-edge 2.5.6

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 (109) hide show
  1. data/CHANGELOG.rdoc +770 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +66 -0
  4. data/Rakefile +35 -0
  5. data/bin/cap +4 -0
  6. data/bin/capify +95 -0
  7. data/capistrano.gemspec +51 -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 +125 -0
  14. data/lib/capistrano/cli/help.txt +75 -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 +293 -0
  22. data/lib/capistrano/configuration/callbacks.rb +148 -0
  23. data/lib/capistrano/configuration/connections.rb +204 -0
  24. data/lib/capistrano/configuration/execution.rb +143 -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 +73 -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 +438 -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 +274 -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 +138 -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/ext/rails-database-migrations.rb +50 -0
  59. data/lib/capistrano/recipes/ext/web-disable-enable.rb +40 -0
  60. data/lib/capistrano/recipes/standard.rb +37 -0
  61. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  62. data/lib/capistrano/recipes/upgrade.rb +33 -0
  63. data/lib/capistrano/role.rb +102 -0
  64. data/lib/capistrano/server_definition.rb +56 -0
  65. data/lib/capistrano/shell.rb +260 -0
  66. data/lib/capistrano/ssh.rb +99 -0
  67. data/lib/capistrano/task_definition.rb +70 -0
  68. data/lib/capistrano/transfer.rb +216 -0
  69. data/lib/capistrano/version.rb +18 -0
  70. data/setup.rb +1346 -0
  71. data/test/cli/execute_test.rb +132 -0
  72. data/test/cli/help_test.rb +165 -0
  73. data/test/cli/options_test.rb +317 -0
  74. data/test/cli/ui_test.rb +28 -0
  75. data/test/cli_test.rb +17 -0
  76. data/test/command_test.rb +286 -0
  77. data/test/configuration/actions/file_transfer_test.rb +61 -0
  78. data/test/configuration/actions/inspect_test.rb +65 -0
  79. data/test/configuration/actions/invocation_test.rb +224 -0
  80. data/test/configuration/callbacks_test.rb +220 -0
  81. data/test/configuration/connections_test.rb +349 -0
  82. data/test/configuration/execution_test.rb +175 -0
  83. data/test/configuration/loading_test.rb +132 -0
  84. data/test/configuration/namespace_dsl_test.rb +311 -0
  85. data/test/configuration/roles_test.rb +144 -0
  86. data/test/configuration/servers_test.rb +121 -0
  87. data/test/configuration/variables_test.rb +184 -0
  88. data/test/configuration_test.rb +88 -0
  89. data/test/deploy/local_dependency_test.rb +76 -0
  90. data/test/deploy/remote_dependency_test.rb +114 -0
  91. data/test/deploy/scm/accurev_test.rb +23 -0
  92. data/test/deploy/scm/base_test.rb +55 -0
  93. data/test/deploy/scm/git_test.rb +184 -0
  94. data/test/deploy/scm/mercurial_test.rb +129 -0
  95. data/test/deploy/scm/none_test.rb +35 -0
  96. data/test/deploy/strategy/copy_test.rb +258 -0
  97. data/test/extensions_test.rb +69 -0
  98. data/test/fixtures/cli_integration.rb +5 -0
  99. data/test/fixtures/config.rb +5 -0
  100. data/test/fixtures/custom.rb +3 -0
  101. data/test/logger_test.rb +123 -0
  102. data/test/role_test.rb +11 -0
  103. data/test/server_definition_test.rb +121 -0
  104. data/test/shell_test.rb +90 -0
  105. data/test/ssh_test.rb +104 -0
  106. data/test/task_definition_test.rb +101 -0
  107. data/test/transfer_test.rb +160 -0
  108. data/test/utils.rb +38 -0
  109. metadata +321 -0
@@ -0,0 +1,129 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/mercurial'
3
+
4
+ class DeploySCMMercurialTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Mercurial
6
+ default_command "hg"
7
+ end
8
+
9
+ def setup
10
+ @config = { }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_head
17
+ assert_equal "tip", @source.head
18
+ end
19
+
20
+ def test_checkout
21
+ @config[:repository] = "http://example.com/project-hg"
22
+ dest = "/var/www"
23
+ assert_equal "hg clone --noupdate http://example.com/project-hg /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.checkout('8a8e00b8f11b', dest)
24
+ end
25
+
26
+ def test_diff
27
+ assert_equal "hg diff --rev tip", @source.diff('tip')
28
+ assert_equal "hg diff --rev 1 --rev 2", @source.diff('1', '2')
29
+ end
30
+
31
+ def test_log
32
+ assert_equal "hg log --rev 8a8e00b8f11b", @source.log('8a8e00b8f11b')
33
+ assert_equal "hg log --rev 0:3", @source.log('0', '3')
34
+ end
35
+
36
+ def test_query_revision
37
+ assert_equal "hg log -r 8a8e00b8f11b --template '{node|short}'", @source.query_revision('8a8e00b8f11b') { |o| o }
38
+ end
39
+
40
+ def test_username_should_be_backwards_compatible
41
+ # older versions of this module required :scm_user var instead
42
+ # of the currently preferred :scm_username
43
+ require 'capistrano/logger'
44
+ @config[:scm_user] = "fred"
45
+ text = "user:"
46
+ assert_equal "fred\n", @source.handle_data(mock_state, :test_stream, text)
47
+ # :scm_username takes priority
48
+ @config[:scm_username] = "wilma"
49
+ assert_equal "wilma\n", @source.handle_data(mock_state, :test_stream, text)
50
+ end
51
+
52
+ def test_sync
53
+ dest = "/var/www"
54
+ assert_equal "hg pull --repository /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
55
+
56
+ # With :scm_command
57
+ @config[:scm_command] = "/opt/local/bin/hg"
58
+ assert_equal "/opt/local/bin/hg pull --repository /var/www && /opt/local/bin/hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
59
+ end
60
+
61
+ def test_export
62
+ dest = "/var/www"
63
+ assert_raise(NotImplementedError) { @source.export('8a8e00b8f11b', dest) }
64
+ end
65
+
66
+ def test_sends_password_if_set
67
+ require 'capistrano/logger'
68
+ text = "password:"
69
+ @config[:scm_password] = "opensesame"
70
+ assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
71
+ end
72
+
73
+ def test_prompts_for_password_if_preferred
74
+ require 'capistrano/logger'
75
+ require 'capistrano/cli'
76
+ Capistrano::CLI.stubs(:password_prompt).with("hg password: ").returns("opensesame")
77
+ @config[:scm_prefer_prompt] = true
78
+ text = "password:"
79
+ assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
80
+ end
81
+
82
+
83
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
84
+ def test_command_should_default_to_default_command
85
+ assert_equal "hg", @source.command
86
+ @source.local { assert_equal "hg", @source.command }
87
+ end
88
+
89
+ def test_command_should_use_scm_command_if_available
90
+ @config[:scm_command] = "/opt/local/bin/hg"
91
+ assert_equal "/opt/local/bin/hg", @source.command
92
+ end
93
+
94
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
95
+ @config[:scm_command] = "/opt/local/bin/hg"
96
+ @source.local { assert_equal "/opt/local/bin/hg", @source.command }
97
+ end
98
+
99
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
100
+ @config[:scm_command] = "/opt/local/bin/hg"
101
+ @config[:local_scm_command] = "/usr/local/bin/hg"
102
+ assert_equal "/opt/local/bin/hg", @source.command
103
+ @source.local { assert_equal "/usr/local/bin/hg", @source.command }
104
+ end
105
+
106
+ def test_command_should_use_default_if_scm_command_is_default
107
+ @config[:scm_command] = :default
108
+ assert_equal "hg", @source.command
109
+ end
110
+
111
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
112
+ @config[:scm_command] = "/foo/bar/hg"
113
+ @config[:local_scm_command] = :default
114
+ @source.local { assert_equal "hg", @source.command }
115
+ end
116
+
117
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
118
+ @config[:scm_command] = "/foo/bar/hg"
119
+ @config[:local_scm_command] = :default
120
+ assert_equal "hg", @source.local.command
121
+ assert_equal "/foo/bar/hg", @source.command
122
+ end
123
+
124
+ private
125
+
126
+ def mock_state
127
+ { :channel => { :host => "abc" } }
128
+ end
129
+ end
@@ -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