capistrano 2.0.0 → 2.1.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.
@@ -97,38 +97,45 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
97
97
  end
98
98
 
99
99
  def test_sudo_should_default_to_sudo
100
- @config.expects(:run).with("sudo ls", {})
100
+ @config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
101
101
  @config.sudo "ls"
102
102
  end
103
103
 
104
104
  def test_sudo_should_use_sudo_variable_definition
105
- @config.expects(:run).with("/opt/local/bin/sudo ls", {})
105
+ @config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
106
106
  @config.options[:sudo] = "/opt/local/bin/sudo"
107
107
  @config.sudo "ls"
108
108
  end
109
109
 
110
110
  def test_sudo_should_interpret_as_option_as_user
111
- @config.expects(:run).with("sudo -u app ls", {})
111
+ @config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
112
112
  @config.sudo "ls", :as => "app"
113
113
  end
114
114
 
115
115
  def test_sudo_should_pass_options_through_to_run
116
- @config.expects(:run).with("sudo ls", :foo => "bar")
116
+ @config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
117
117
  @config.sudo "ls", :foo => "bar"
118
118
  end
119
119
 
120
- def test_sudo_behavior_callback_should_send_password_when_prompted
120
+ def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
121
+ @config.set :sudo_prompt, "give it to me: "
122
+ @config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
123
+ @config.sudo "ls"
124
+ end
125
+
126
+ def test_sudo_behavior_callback_should_send_password_when_prompted_with_default_sudo_prompt
121
127
  ch = mock("channel")
122
128
  ch.expects(:send_data).with("g00b3r\n")
123
129
  @config.options[:password] = "g00b3r"
124
- @config.sudo_behavior_callback(nil)[ch, nil, "Password: "]
130
+ @config.sudo_behavior_callback(nil)[ch, nil, "sudo password: "]
125
131
  end
126
132
 
127
- def test_sudo_behavior_callback_should_send_password_when_prompted_with_SuSE_dialect
133
+ def test_sudo_behavior_callback_should_send_password_when_prompted_with_custom_sudo_prompt
128
134
  ch = mock("channel")
129
135
  ch.expects(:send_data).with("g00b3r\n")
136
+ @config.set :sudo_prompt, "give it to me: "
130
137
  @config.options[:password] = "g00b3r"
131
- @config.sudo_behavior_callback(nil)[ch, nil, "user's password: "]
138
+ @config.sudo_behavior_callback(nil)[ch, nil, "give it to me: "]
132
139
  end
133
140
 
134
141
  def test_sudo_behavior_callback_with_incorrect_password_on_first_prompt
@@ -96,7 +96,7 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
96
96
  def test_establish_connections_to_should_raise_one_connection_error_on_failure
97
97
  Capistrano::SSH.expects(:connect).times(2).raises(Exception)
98
98
  assert_raises(Capistrano::ConnectionError) {
99
- @config.establish_connections_to(%w(cap1 cap2)).map { |s| servers(s) }
99
+ @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
100
100
  }
101
101
  end
102
102
 
@@ -104,7 +104,7 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
104
104
  Capistrano::SSH.expects(:connect).times(2).raises(Exception)
105
105
 
106
106
  begin
107
- @config.establish_connections_to(%w(cap1 cap2)).map { |s| servers(s) }
107
+ @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
108
108
  flunk "expected an exception to be raised"
109
109
  rescue Capistrano::ConnectionError => e
110
110
  assert e.respond_to?(:hosts)
@@ -116,7 +116,7 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
116
116
  Capistrano::SSH.expects(:connect).times(2).raises(Exception).then.returns(:success)
117
117
 
118
118
  begin
119
- @config.establish_connections_to(%w(cap1 cap2)).map { |s| servers(s) }
119
+ @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
120
120
  flunk "expected an exception to be raised"
121
121
  rescue Capistrano::ConnectionError => e
122
122
  assert_equal %w(cap1), e.hosts.map { |h| h.to_s }
@@ -116,4 +116,12 @@ class ConfigurationLoadingTest < Test::Unit::TestCase
116
116
  require "#{File.dirname(__FILE__)}/../fixtures/custom"
117
117
  end
118
118
  end
119
+
120
+ def test_require_in_multiple_instances_should_load_recipes_in_each_instance
121
+ config2 = MockConfig.new
122
+ @config.require "#{File.dirname(__FILE__)}/../fixtures/custom"
123
+ config2.require "#{File.dirname(__FILE__)}/../fixtures/custom"
124
+ assert_equal :custom, @config.ping
125
+ assert_equal :custom, config2.ping
126
+ end
119
127
  end
@@ -280,4 +280,18 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase
280
280
  inner = @config.namespaces[:outer].namespaces[:inner]
281
281
  assert_nil inner.search_task(:first)
282
282
  end
283
+
284
+ def test_top_should_return_self_if_self_is_top
285
+ assert_equal @config, @config.top
286
+ end
287
+
288
+ def test_top_should_return_parent_if_parent_is_top
289
+ @config.namespace(:outer) {}
290
+ assert_equal @config, @config.namespaces[:outer].top
291
+ end
292
+
293
+ def test_top_should_return_topmost_parent_if_self_is_deeply_nested
294
+ @config.namespace(:outer) { namespace(:middle) { namespace(:inner) {} } }
295
+ assert_equal @config, @config.namespaces[:outer].namespaces[:middle].namespaces[:inner].top
296
+ end
283
297
  end
@@ -0,0 +1,23 @@
1
+ require "#{File.dirname(__FILE__)}/../../utils"
2
+ require 'capistrano/recipes/deploy/scm/accurev'
3
+
4
+ class AccurevTest < Test::Unit::TestCase
5
+ include Capistrano::Deploy::SCM
6
+
7
+ def test_internal_revision_to_s
8
+ assert_equal 'foo/1', Accurev::InternalRevision.new('foo', 1).to_s
9
+ assert_equal 'foo/highest', Accurev::InternalRevision.new('foo', 'highest').to_s
10
+ end
11
+
12
+ def test_internal_revision_parse
13
+ revision = Accurev::InternalRevision.parse('foo')
14
+ assert_equal 'foo', revision.stream
15
+ assert_equal 'highest', revision.transaction_id
16
+ assert_equal 'foo/highest', revision.to_s
17
+
18
+ revision = Accurev::InternalRevision.parse('foo/1')
19
+ assert_equal 'foo', revision.stream
20
+ assert_equal '1', revision.transaction_id
21
+ assert_equal 'foo/1', revision.to_s
22
+ end
23
+ end
@@ -0,0 +1,112 @@
1
+ require "#{File.dirname(__FILE__)}/../../utils"
2
+ require 'capistrano/recipes/deploy/scm/git'
3
+
4
+ class DeploySCMGitTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Git
6
+ default_command "git"
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 "HEAD", @source.head
18
+ @config[:branch] = "master"
19
+ assert_equal "master", @source.head
20
+ end
21
+
22
+ def test_checkout
23
+ @config[:repository] = "git@somehost.com:project.git"
24
+ dest = "/var/www"
25
+ assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy HEAD", @source.checkout('Not used', dest)
26
+
27
+ # With branch
28
+ @config[:branch] = "origin/foo"
29
+ assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy origin/foo", @source.checkout('Not used', dest)
30
+ end
31
+
32
+ def test_diff
33
+ assert_equal "git diff master", @source.diff('master')
34
+ assert_equal "git diff master..branch", @source.diff('master', 'branch')
35
+ end
36
+
37
+ def test_log
38
+ assert_equal "git log master", @source.log('master')
39
+ assert_equal "git log master..branch", @source.log('master', 'branch')
40
+ end
41
+
42
+ def test_query_revision
43
+ assert_equal "git rev-parse HEAD", @source.query_revision('HEAD') { |o| o }
44
+ end
45
+
46
+ def test_command_should_be_backwards_compatible
47
+ # 1.x version of this module used ":git", not ":scm_command"
48
+ @config[:git] = "/srv/bin/git"
49
+ assert_equal "/srv/bin/git", @source.command
50
+ end
51
+
52
+ def test_sync
53
+ dest = "/var/www"
54
+ assert_equal "cd #{dest} && git fetch origin && git merge origin/HEAD", @source.sync('Not used', dest)
55
+
56
+ # With branch
57
+ @config[:branch] = "origin/foo"
58
+ assert_equal "cd #{dest} && git fetch origin && git merge origin/foo", @source.sync('Not used', dest)
59
+ end
60
+
61
+ def test_shallow_clone
62
+ @config[:repository] = "git@somehost.com:project.git"
63
+ @config[:git_shallow_clone] = 1
64
+ dest = "/var/www"
65
+ assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy HEAD", @source.checkout('Not used', dest)
66
+
67
+ # With branch
68
+ @config[:branch] = "origin/foo"
69
+ assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy origin/foo", @source.checkout('Not used', dest)
70
+ end
71
+
72
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
73
+ def test_command_should_default_to_default_command
74
+ assert_equal "git", @source.command
75
+ @source.local { assert_equal "git", @source.command }
76
+ end
77
+
78
+ def test_command_should_use_scm_command_if_available
79
+ @config[:scm_command] = "/opt/local/bin/git"
80
+ assert_equal "/opt/local/bin/git", @source.command
81
+ end
82
+
83
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
84
+ @config[:scm_command] = "/opt/local/bin/git"
85
+ @source.local { assert_equal "/opt/local/bin/git", @source.command }
86
+ end
87
+
88
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
89
+ @config[:scm_command] = "/opt/local/bin/git"
90
+ @config[:local_scm_command] = "/usr/local/bin/git"
91
+ assert_equal "/opt/local/bin/git", @source.command
92
+ @source.local { assert_equal "/usr/local/bin/git", @source.command }
93
+ end
94
+
95
+ def test_command_should_use_default_if_scm_command_is_default
96
+ @config[:scm_command] = :default
97
+ assert_equal "git", @source.command
98
+ end
99
+
100
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
101
+ @config[:scm_command] = "/foo/bar/git"
102
+ @config[:local_scm_command] = :default
103
+ @source.local { assert_equal "git", @source.command }
104
+ end
105
+
106
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
107
+ @config[:scm_command] = "/foo/bar/git"
108
+ @config[:local_scm_command] = :default
109
+ assert_equal "git", @source.local.command
110
+ assert_equal "/foo/bar/git", @source.command
111
+ end
112
+ end
@@ -1,6 +1,7 @@
1
1
  require "#{File.dirname(__FILE__)}/../../utils"
2
2
  require 'capistrano/logger'
3
3
  require 'capistrano/recipes/deploy/strategy/copy'
4
+ require 'stringio'
4
5
 
5
6
  class DeployStrategyCopyTest < Test::Unit::TestCase
6
7
  def setup
@@ -26,7 +27,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
26
27
  mock_file = mock("file")
27
28
  mock_file.expects(:puts).with("154")
28
29
  File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
29
- File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
30
+ File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
30
31
 
31
32
  FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
32
33
  FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
@@ -48,7 +49,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
48
49
  mock_file = mock("file")
49
50
  mock_file.expects(:puts).with("154")
50
51
  File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
51
- File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
52
+ File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
52
53
 
53
54
  FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
54
55
  FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
@@ -70,7 +71,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
70
71
  mock_file = mock("file")
71
72
  mock_file.expects(:puts).with("154")
72
73
  File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
73
- File.expects(:read).with("/temp/dir/1234567890.zip").returns(:mock_file_contents)
74
+ File.expects(:open).with("/temp/dir/1234567890.zip", "rb").yields(StringIO.new).returns(:mock_file_contents)
74
75
 
75
76
  FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
76
77
  FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
@@ -92,7 +93,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
92
93
  mock_file = mock("file")
93
94
  mock_file.expects(:puts).with("154")
94
95
  File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
95
- File.expects(:read).with("/temp/dir/1234567890.tar.bz2").returns(:mock_file_contents)
96
+ File.expects(:open).with("/temp/dir/1234567890.tar.bz2", "rb").yields(StringIO.new).returns(:mock_file_contents)
96
97
 
97
98
  FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
98
99
  FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
@@ -114,7 +115,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
114
115
  mock_file = mock("file")
115
116
  mock_file.expects(:puts).with("154")
116
117
  File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
117
- File.expects(:read).with("/other/path/1234567890.tar.gz").returns(:mock_file_contents)
118
+ File.expects(:open).with("/other/path/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
118
119
 
119
120
  FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
120
121
  FileUtils.expects(:rm_rf).with("/other/path/1234567890")
@@ -136,7 +137,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
136
137
  mock_file = mock("file")
137
138
  mock_file.expects(:puts).with("154")
138
139
  File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
139
- File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
140
+ File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
140
141
 
141
142
  FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
142
143
  FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
@@ -33,7 +33,7 @@ class UploadTest < Test::Unit::TestCase
33
33
 
34
34
  def test_process_when_sftp_open_fails_should_raise_error
35
35
  sftp = mock_sftp
36
- sftp.expects(:open).with("test.txt", @mode, 0660).yields(mock("status", :code => "bad status", :message => "bad status"), :file_handle)
36
+ sftp.expects(:open).with("test.txt", @mode, 0664).yields(mock("status", :code => "bad status", :message => "bad status"), :file_handle)
37
37
  session = mock("session", :sftp => sftp, :xserver => server("capistrano"))
38
38
  upload = Capistrano::Upload.new([session], "test.txt", :data => "data", :logger => stub_everything)
39
39
  assert_raises(Capistrano::UploadError) { upload.process! }
@@ -43,7 +43,7 @@ class UploadTest < Test::Unit::TestCase
43
43
 
44
44
  def test_process_when_sftp_write_fails_should_raise_error
45
45
  sftp = mock_sftp
46
- sftp.expects(:open).with("test.txt", @mode, 0660).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
46
+ sftp.expects(:open).with("test.txt", @mode, 0664).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
47
47
  sftp.expects(:write).with(:file_handle, "data").yields(mock("status2", :code => "bad status", :message => "bad status"))
48
48
  session = mock("session", :sftp => sftp, :xserver => server("capistrano"))
49
49
  upload = Capistrano::Upload.new([session], "test.txt", :data => "data", :logger => stub_everything)
@@ -54,7 +54,7 @@ class UploadTest < Test::Unit::TestCase
54
54
 
55
55
  def test_upload_error_should_include_accessor_with_host_array
56
56
  sftp = mock_sftp
57
- sftp.expects(:open).with("test.txt", @mode, 0660).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
57
+ sftp.expects(:open).with("test.txt", @mode, 0664).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
58
58
  sftp.expects(:write).with(:file_handle, "data").yields(mock("status2", :code => "bad status", :message => "bad status"))
59
59
  session = mock("session", :sftp => sftp, :xserver => server("capistrano"))
60
60
  upload = Capistrano::Upload.new([session], "test.txt", :data => "data", :logger => stub_everything)
@@ -70,7 +70,7 @@ class UploadTest < Test::Unit::TestCase
70
70
 
71
71
  def test_process_when_sftp_succeeds_should_raise_nothing
72
72
  sftp = mock_sftp
73
- sftp.expects(:open).with("test.txt", @mode, 0660).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
73
+ sftp.expects(:open).with("test.txt", @mode, 0664).yields(mock("status1", :code => Net::SFTP::Session::FX_OK), :file_handle)
74
74
  sftp.expects(:write).with(:file_handle, "data").yields(mock("status2", :code => Net::SFTP::Session::FX_OK))
75
75
  sftp.expects(:close_handle).with(:file_handle).yields
76
76
  session = mock("session", :sftp => sftp, :xserver => server("capistrano"))
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: capistrano
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.0.0
7
- date: 2007-07-21 00:00:00 -06:00
6
+ version: 2.1.0
7
+ date: 2007-10-14 00:00:00 -06:00
8
8
  summary: Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH.
9
9
  require_paths:
10
10
  - lib
@@ -66,10 +66,12 @@ files:
66
66
  - lib/capistrano/recipes/deploy/local_dependency.rb
67
67
  - lib/capistrano/recipes/deploy/remote_dependency.rb
68
68
  - lib/capistrano/recipes/deploy/scm
69
+ - lib/capistrano/recipes/deploy/scm/accurev.rb
69
70
  - lib/capistrano/recipes/deploy/scm/base.rb
70
71
  - lib/capistrano/recipes/deploy/scm/bzr.rb
71
72
  - lib/capistrano/recipes/deploy/scm/cvs.rb
72
73
  - lib/capistrano/recipes/deploy/scm/darcs.rb
74
+ - lib/capistrano/recipes/deploy/scm/git.rb
73
75
  - lib/capistrano/recipes/deploy/scm/mercurial.rb
74
76
  - lib/capistrano/recipes/deploy/scm/perforce.rb
75
77
  - lib/capistrano/recipes/deploy/scm/subversion.rb
@@ -120,7 +122,9 @@ files:
120
122
  - test/configuration_test.rb
121
123
  - test/deploy
122
124
  - test/deploy/scm
125
+ - test/deploy/scm/accurev_test.rb
123
126
  - test/deploy/scm/base_test.rb
127
+ - test/deploy/scm/git_test.rb
124
128
  - test/deploy/strategy
125
129
  - test/deploy/strategy/copy_test.rb
126
130
  - test/extensions_test.rb