fotonauts-capistrano 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +728 -0
- data/Manifest +104 -0
- data/README.rdoc +66 -0
- data/Rakefile +34 -0
- data/bin/cap +4 -0
- data/bin/capify +78 -0
- data/capistrano.gemspec +49 -0
- data/examples/sample.rb +14 -0
- data/lib/capistrano.rb +2 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +84 -0
- data/lib/capistrano/cli/help.rb +118 -0
- data/lib/capistrano/cli/help.txt +62 -0
- data/lib/capistrano/cli/options.rb +224 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +283 -0
- data/lib/capistrano/configuration.rb +43 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +193 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +196 -0
- data/lib/capistrano/configuration/execution.rb +132 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +65 -0
- data/lib/capistrano/configuration/servers.rb +85 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +15 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +555 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +271 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/upgrade.rb +33 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +79 -0
- data/lib/capistrano/task_definition.rb +70 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/setup.rb +1346 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +317 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +210 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +348 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +305 -0
- data/test/configuration/roles_test.rb +143 -0
- data/test/configuration/servers_test.rb +121 -0
- data/test/configuration/variables_test.rb +180 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/git_test.rb +159 -0
- data/test/deploy/scm/mercurial_test.rb +129 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/strategy/copy_test.rb +258 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +102 -0
- data/test/task_definition_test.rb +101 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +38 -0
- metadata +310 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/cli/execute'
|
3
|
+
|
4
|
+
class CLIExecuteTest < Test::Unit::TestCase
|
5
|
+
class MockCLI
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@options = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
include Capistrano::CLI::Execute
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@cli = MockCLI.new
|
17
|
+
@logger = stub_everything
|
18
|
+
@config = stub(:logger => @logger, :debug= => nil, :dry_run= => nil)
|
19
|
+
@config.stubs(:set)
|
20
|
+
@config.stubs(:load)
|
21
|
+
@config.stubs(:trigger)
|
22
|
+
@cli.stubs(:instantiate_configuration).returns(@config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_execute_should_set_logger_verbosity
|
26
|
+
@cli.options[:verbose] = 7
|
27
|
+
@logger.expects(:level=).with(7)
|
28
|
+
@cli.execute!
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_execute_should_set_password
|
32
|
+
@cli.options[:password] = "nosoup4u"
|
33
|
+
@config.expects(:set).with(:password, "nosoup4u")
|
34
|
+
@cli.execute!
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_execute_should_set_prevars_before_loading
|
38
|
+
@config.expects(:load).never
|
39
|
+
@config.expects(:set).with(:stage, "foobar")
|
40
|
+
@config.expects(:load).with("standard")
|
41
|
+
@cli.options[:pre_vars] = { :stage => "foobar" }
|
42
|
+
@cli.execute!
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_execute_should_load_sysconf_if_sysconf_set_and_exists
|
46
|
+
@cli.options[:sysconf] = "/etc/capistrano.conf"
|
47
|
+
@config.expects(:load).with("/etc/capistrano.conf")
|
48
|
+
File.expects(:file?).with("/etc/capistrano.conf").returns(true)
|
49
|
+
@cli.execute!
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_execute_should_not_load_sysconf_when_sysconf_set_and_not_exists
|
53
|
+
@cli.options[:sysconf] = "/etc/capistrano.conf"
|
54
|
+
File.expects(:file?).with("/etc/capistrano.conf").returns(false)
|
55
|
+
@cli.execute!
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_execute_should_load_dotfile_if_dotfile_set_and_exists
|
59
|
+
@cli.options[:dotfile] = "/home/jamis/.caprc"
|
60
|
+
@config.expects(:load).with("/home/jamis/.caprc")
|
61
|
+
File.expects(:file?).with("/home/jamis/.caprc").returns(true)
|
62
|
+
@cli.execute!
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_execute_should_not_load_dotfile_when_dotfile_set_and_not_exists
|
66
|
+
@cli.options[:dotfile] = "/home/jamis/.caprc"
|
67
|
+
File.expects(:file?).with("/home/jamis/.caprc").returns(false)
|
68
|
+
@cli.execute!
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_execute_should_load_recipes_when_recipes_are_given
|
72
|
+
@cli.options[:recipes] = %w(config/deploy path/to/extra)
|
73
|
+
@config.expects(:load).with("config/deploy")
|
74
|
+
@config.expects(:load).with("path/to/extra")
|
75
|
+
@cli.execute!
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_execute_should_set_vars_and_execute_tasks
|
79
|
+
@cli.options[:vars] = { :foo => "bar", :baz => "bang" }
|
80
|
+
@cli.options[:actions] = %w(first second)
|
81
|
+
@config.expects(:set).with(:foo, "bar")
|
82
|
+
@config.expects(:set).with(:baz, "bang")
|
83
|
+
@config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
|
84
|
+
@config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
|
85
|
+
@cli.execute!
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_execute_should_call_load_and_exit_triggers
|
89
|
+
@cli.options[:actions] = %w(first second)
|
90
|
+
@config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
|
91
|
+
@config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
|
92
|
+
@config.expects(:trigger).never
|
93
|
+
@config.expects(:trigger).with(:load)
|
94
|
+
@config.expects(:trigger).with(:exit)
|
95
|
+
@cli.execute!
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_execute_should_call_handle_error_when_exceptions_occur
|
99
|
+
@config.expects(:load).raises(Exception, "boom")
|
100
|
+
@cli.expects(:handle_error).with { |e,| Exception === e }
|
101
|
+
@cli.execute!
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_execute_should_return_config_instance
|
105
|
+
assert_equal @config, @cli.execute!
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_instantiate_configuration_should_return_new_configuration_instance
|
109
|
+
assert_instance_of Capistrano::Configuration, MockCLI.new.instantiate_configuration
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_handle_error_with_auth_error_should_abort_with_message_including_user_name
|
113
|
+
@cli.expects(:abort).with { |s| s.include?("jamis") }
|
114
|
+
@cli.handle_error(Net::SSH::AuthenticationFailed.new("jamis"))
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_handle_error_with_cap_error_should_abort_with_message
|
118
|
+
@cli.expects(:abort).with("Wish you were here")
|
119
|
+
@cli.handle_error(Capistrano::Error.new("Wish you were here"))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_handle_error_with_other_errors_should_reraise_error
|
123
|
+
other_error = Class.new(RuntimeError)
|
124
|
+
assert_raises(other_error) { @cli.handle_error(other_error.new("boom")) }
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_class_execute_method_should_call_parse_and_execute_with_ARGV
|
128
|
+
cli = mock(:execute! => nil)
|
129
|
+
MockCLI.expects(:parse).with(ARGV).returns(cli)
|
130
|
+
MockCLI.execute
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/cli/help'
|
3
|
+
|
4
|
+
class CLIHelpTest < Test::Unit::TestCase
|
5
|
+
class MockCLI
|
6
|
+
attr_reader :options, :called_original
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@options = {}
|
10
|
+
@called_original = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute_requested_actions(config)
|
14
|
+
@called_original = config
|
15
|
+
end
|
16
|
+
|
17
|
+
include Capistrano::CLI::Help
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@cli = MockCLI.new
|
22
|
+
@cli.options[:verbose] = 0
|
23
|
+
@ui = stub("ui", :output_cols => 80, :output_rows => 20, :page_at= => nil)
|
24
|
+
MockCLI.stubs(:ui).returns(@ui)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_execute_requested_actions_without_tasks_or_explain_should_call_original
|
28
|
+
@cli.execute_requested_actions(:config)
|
29
|
+
@cli.expects(:task_list).never
|
30
|
+
@cli.expects(:explain_task).never
|
31
|
+
assert_equal :config, @cli.called_original
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_execute_requested_actions_with_tasks_should_call_task_list
|
35
|
+
@cli.options[:tasks] = true
|
36
|
+
@cli.expects(:task_list).with(:config, true)
|
37
|
+
@cli.expects(:explain_task).never
|
38
|
+
@cli.execute_requested_actions(:config)
|
39
|
+
assert !@cli.called_original
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_execute_requested_actions_with_explain_should_call_explain_task
|
43
|
+
@cli.options[:explain] = "deploy_with_niftiness"
|
44
|
+
@cli.expects(:task_list).never
|
45
|
+
@cli.expects(:explain_task).with(:config, "deploy_with_niftiness")
|
46
|
+
@cli.execute_requested_actions(:config)
|
47
|
+
assert !@cli.called_original
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_task_list_with_no_tasks_should_emit_warning
|
51
|
+
config = mock("config", :task_list => [])
|
52
|
+
@cli.expects(:warn)
|
53
|
+
@cli.task_list(config)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_task_list_should_query_all_tasks_in_all_namespaces
|
57
|
+
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
|
58
|
+
task_list = [task("c"), task("g", "c:g"), task("b", "c:b"), task("a")]
|
59
|
+
task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
|
60
|
+
|
61
|
+
config = mock("config")
|
62
|
+
config.expects(:task_list).with(:all).returns(task_list)
|
63
|
+
@cli.stubs(:puts)
|
64
|
+
@cli.task_list(config)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_task_list_should_query_tasks_with_pattern
|
68
|
+
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
|
69
|
+
task_list = [task("g", "c:g"), task("b", "c:b")]
|
70
|
+
task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name)}
|
71
|
+
|
72
|
+
config = mock("config")
|
73
|
+
config.expects(:task_list).with(:all).once.returns(task_list)
|
74
|
+
|
75
|
+
@cli.stubs(:puts)
|
76
|
+
@cli.task_list(config, "c")
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_task_list_should_query_for_all_tasks_when_pattern_doesnt_match
|
80
|
+
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
|
81
|
+
task_list = [task("g", "c:g"), task("b", "c:b")]
|
82
|
+
task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
|
83
|
+
|
84
|
+
config = mock("config")
|
85
|
+
config.expects(:task_list).with(:all).times(2).returns(task_list)
|
86
|
+
|
87
|
+
@cli.stubs(:warn)
|
88
|
+
@cli.stubs(:puts)
|
89
|
+
@cli.task_list(config, "z")
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_task_list_should_never_use_less_than_MIN_MAX_LEN_chars_for_descriptions
|
93
|
+
@ui.stubs(:output_cols).returns(20)
|
94
|
+
t = task("c")
|
95
|
+
t.expects(:brief_description).with(30).returns("hello")
|
96
|
+
config = mock("config", :task_list => [t])
|
97
|
+
@cli.stubs(:puts)
|
98
|
+
@cli.task_list(config)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_task_list_should_not_include_tasks_with_blank_description_or_internal_by_default
|
102
|
+
t1 = task("c")
|
103
|
+
t1.expects(:brief_description).returns("hello")
|
104
|
+
t2 = task("d", "d", "[internal] howdy")
|
105
|
+
t2.expects(:brief_description).never
|
106
|
+
t3 = task("e", "e", "")
|
107
|
+
t3.expects(:brief_description).never
|
108
|
+
|
109
|
+
config = mock("config", :task_list => [t1, t2, t3])
|
110
|
+
@cli.stubs(:puts)
|
111
|
+
@cli.expects(:puts).never.with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }
|
112
|
+
@cli.task_list(config)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_task_list_should_include_tasks_with_blank_descriptions_and_internal_when_verbose
|
116
|
+
t1 = task("c")
|
117
|
+
t1.expects(:brief_description).returns("hello")
|
118
|
+
t2 = task("d", "d", "[internal] howdy")
|
119
|
+
t2.expects(:brief_description).returns("[internal] howdy")
|
120
|
+
t3 = task("e", "e", "")
|
121
|
+
t3.expects(:brief_description).returns("")
|
122
|
+
|
123
|
+
config = mock("config", :task_list => [t1, t2, t3])
|
124
|
+
@cli.options[:verbose] = 1
|
125
|
+
@cli.stubs(:puts)
|
126
|
+
@cli.expects(:puts).with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }.at_least_once
|
127
|
+
@cli.task_list(config)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_explain_task_should_warn_if_task_does_not_exist
|
131
|
+
config = mock("config", :find_task => nil)
|
132
|
+
@cli.expects(:warn).with { |s,| s =~ /`deploy_with_niftiness'/ }
|
133
|
+
@cli.explain_task(config, "deploy_with_niftiness")
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_explain_task_with_task_that_has_no_description_should_emit_stub
|
137
|
+
t = mock("task", :description => "")
|
138
|
+
config = mock("config")
|
139
|
+
config.expects(:find_task).with("deploy_with_niftiness").returns(t)
|
140
|
+
@cli.stubs(:puts)
|
141
|
+
@cli.expects(:puts).with("There is no description for this task.")
|
142
|
+
@cli.explain_task(config, "deploy_with_niftiness")
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_explain_task_with_task_should_format_description
|
146
|
+
t = stub("task", :description => "line1\nline2\n\nline3")
|
147
|
+
config = mock("config", :find_task => t)
|
148
|
+
@cli.stubs(:puts)
|
149
|
+
@cli.explain_task(config, "deploy_with_niftiness")
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_long_help_should_load_and_format_help_txt_file
|
153
|
+
File.expects(:dirname).returns "a/b/c"
|
154
|
+
File.expects(:read).with("a/b/c/help.txt").returns("text")
|
155
|
+
@ui.expects(:say).with("text\n")
|
156
|
+
@cli.long_help
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def task(name, fqn=name, desc="a description")
|
162
|
+
stub("task", :name => name, :fully_qualified_name => fqn, :description => desc)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/cli/options'
|
3
|
+
|
4
|
+
class CLIOptionsTest < Test::Unit::TestCase
|
5
|
+
class ExitException < Exception; end
|
6
|
+
|
7
|
+
class MockCLI
|
8
|
+
def initialize
|
9
|
+
@args = []
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :args
|
13
|
+
|
14
|
+
include Capistrano::CLI::Options
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@cli = MockCLI.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parse_options_should_require_non_empty_args_list
|
22
|
+
@cli.stubs(:warn)
|
23
|
+
@cli.expects(:exit).raises(ExitException)
|
24
|
+
assert_raises(ExitException) { @cli.parse_options! }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_parse_options_with_d_should_set_debug_option
|
28
|
+
@cli.args << "-d"
|
29
|
+
@cli.parse_options!
|
30
|
+
assert @cli.options[:debug]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_parse_options_with_n_should_set_dry_run_option
|
34
|
+
@cli.args << "-n"
|
35
|
+
@cli.parse_options!
|
36
|
+
assert @cli.options[:dry_run]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parse_options_with_dry_run_should_set_dry_run_option
|
40
|
+
@cli.args << "--dry-run"
|
41
|
+
@cli.parse_options!
|
42
|
+
assert @cli.options[:dry_run]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_parse_options_with_e_should_set_explain_option
|
46
|
+
@cli.args << "-e" << "sample"
|
47
|
+
@cli.parse_options!
|
48
|
+
assert_equal "sample", @cli.options[:explain]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_parse_options_with_f_should_add_recipe_file
|
52
|
+
@cli.args << "-f" << "deploy"
|
53
|
+
@cli.parse_options!
|
54
|
+
assert_equal %w(deploy), @cli.options[:recipes]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_parse_options_with_multiple_f_should_add_each_as_recipe_file
|
58
|
+
@cli.args << "-f" << "deploy" << "-f" << "monitor"
|
59
|
+
@cli.parse_options!
|
60
|
+
assert_equal %w(deploy monitor), @cli.options[:recipes]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_parse_options_with_H_should_show_verbose_help_and_exit
|
64
|
+
@cli.expects(:exit).raises(ExitException)
|
65
|
+
@cli.expects(:long_help)
|
66
|
+
@cli.args << "-H"
|
67
|
+
assert_raises(ExitException) { @cli.parse_options! }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_parse_options_with_h_should_show_options_and_exit
|
71
|
+
@cli.expects(:puts).with(@cli.option_parser)
|
72
|
+
@cli.expects(:exit).raises(ExitException)
|
73
|
+
@cli.args << "-h"
|
74
|
+
assert_raises(ExitException) { @cli.parse_options! }
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_parse_options_with_p_should_prompt_for_password
|
78
|
+
MockCLI.expects(:password_prompt).returns(:the_password)
|
79
|
+
@cli.args << "-p"
|
80
|
+
@cli.parse_options!
|
81
|
+
assert_equal :the_password, @cli.options[:password]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_parse_options_without_p_should_set_proc_for_password
|
85
|
+
@cli.args << "-e" << "sample"
|
86
|
+
@cli.parse_options!
|
87
|
+
assert_instance_of Proc, @cli.options[:password]
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_parse_options_with_q_should_set_verbose_to_0
|
91
|
+
@cli.args << "-q"
|
92
|
+
@cli.parse_options!
|
93
|
+
assert_equal 0, @cli.options[:verbose]
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_parse_options_with_S_should_set_pre_vars
|
97
|
+
@cli.args << "-S" << "foo=bar"
|
98
|
+
@cli.parse_options!
|
99
|
+
assert_equal "bar", @cli.options[:pre_vars][:foo]
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_S_should_coerce_digits_to_integers
|
103
|
+
@cli.args << "-S" << "foo=1234"
|
104
|
+
@cli.parse_options!
|
105
|
+
assert_equal 1234, @cli.options[:pre_vars][:foo]
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_S_should_treat_quoted_integers_as_string
|
109
|
+
@cli.args << "-S" << "foo=\"1234\""
|
110
|
+
@cli.parse_options!
|
111
|
+
assert_equal "1234", @cli.options[:pre_vars][:foo]
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_S_should_treat_digits_with_dot_as_floating_point
|
115
|
+
@cli.args << "-S" << "foo=3.1415"
|
116
|
+
@cli.parse_options!
|
117
|
+
assert_equal 3.1415, @cli.options[:pre_vars][:foo]
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_S_should_treat_true_as_boolean_true
|
121
|
+
@cli.args << "-S" << "foo=true"
|
122
|
+
@cli.parse_options!
|
123
|
+
assert_equal true, @cli.options[:pre_vars][:foo]
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_S_should_treat_false_as_boolean_false
|
127
|
+
@cli.args << "-S" << "foo=false"
|
128
|
+
@cli.parse_options!
|
129
|
+
assert_equal false, @cli.options[:pre_vars][:foo]
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_S_should_treat_nil_as_nil
|
133
|
+
@cli.args << "-S" << "foo=nil"
|
134
|
+
@cli.parse_options!
|
135
|
+
assert_equal nil, @cli.options[:pre_vars][:foo]
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_parse_options_with_s_should_set_vars
|
139
|
+
@cli.args << "-s" << "foo=bar"
|
140
|
+
@cli.parse_options!
|
141
|
+
assert_equal "bar", @cli.options[:vars][:foo]
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_s_should_coerce_digits_to_integers
|
145
|
+
@cli.args << "-s" << "foo=1234"
|
146
|
+
@cli.parse_options!
|
147
|
+
assert_equal 1234, @cli.options[:vars][:foo]
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_s_should_treat_quoted_integers_as_string
|
151
|
+
@cli.args << "-s" << "foo=\"1234\""
|
152
|
+
@cli.parse_options!
|
153
|
+
assert_equal "1234", @cli.options[:vars][:foo]
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_s_should_treat_digits_with_dot_as_floating_point
|
157
|
+
@cli.args << "-s" << "foo=3.1415"
|
158
|
+
@cli.parse_options!
|
159
|
+
assert_equal 3.1415, @cli.options[:vars][:foo]
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_s_should_treat_true_as_boolean_true
|
163
|
+
@cli.args << "-s" << "foo=true"
|
164
|
+
@cli.parse_options!
|
165
|
+
assert_equal true, @cli.options[:vars][:foo]
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_s_should_treat_false_as_boolean_false
|
169
|
+
@cli.args << "-s" << "foo=false"
|
170
|
+
@cli.parse_options!
|
171
|
+
assert_equal false, @cli.options[:vars][:foo]
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_s_should_treat_nil_as_nil
|
175
|
+
@cli.args << "-s" << "foo=nil"
|
176
|
+
@cli.parse_options!
|
177
|
+
assert_equal nil, @cli.options[:vars][:foo]
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_parse_options_with_T_should_set_tasks_option_and_set_verbose_off
|
181
|
+
@cli.args << "-T"
|
182
|
+
@cli.parse_options!
|
183
|
+
assert @cli.options[:tasks]
|
184
|
+
assert_equal 0, @cli.options[:verbose]
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_parse_options_with_V_should_show_version_and_exit
|
188
|
+
@cli.args << "-V"
|
189
|
+
@cli.expects(:puts).with { |s| s.include?(Capistrano::Version::STRING) }
|
190
|
+
@cli.expects(:exit).raises(ExitException)
|
191
|
+
assert_raises(ExitException) { @cli.parse_options! }
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_parse_options_with_v_should_set_verbose_to_1
|
195
|
+
@cli.args << "-v"
|
196
|
+
@cli.parse_options!
|
197
|
+
assert_equal 1, @cli.options[:verbose]
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_parse_options_with_multiple_v_should_set_verbose_accordingly
|
201
|
+
@cli.args << "-vvvvvvv"
|
202
|
+
@cli.parse_options!
|
203
|
+
assert_equal 7, @cli.options[:verbose]
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_parse_options_without_X_should_set_sysconf
|
207
|
+
@cli.args << "-v"
|
208
|
+
@cli.parse_options!
|
209
|
+
assert @cli.options.key?(:sysconf)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_parse_options_with_X_should_unset_sysconf
|
213
|
+
@cli.args << "-X"
|
214
|
+
@cli.parse_options!
|
215
|
+
assert !@cli.options.key?(:sysconf)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_parse_options_without_x_should_set_dotfile
|
219
|
+
@cli.args << "-v"
|
220
|
+
@cli.parse_options!
|
221
|
+
assert @cli.options.key?(:dotfile)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_parse_options_with_x_should_unset_dotfile
|
225
|
+
@cli.args << "-x"
|
226
|
+
@cli.parse_options!
|
227
|
+
assert !@cli.options.key?(:dotfile)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_parse_options_without_q_or_v_should_set_verbose_to_3
|
231
|
+
@cli.args << "-x"
|
232
|
+
@cli.parse_options!
|
233
|
+
assert_equal 3, @cli.options[:verbose]
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_should_search_for_default_recipes_if_f_not_given
|
237
|
+
@cli.expects(:look_for_default_recipe_file!)
|
238
|
+
@cli.args << "-v"
|
239
|
+
@cli.parse_options!
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_should_not_search_for_default_recipes_if_f_given
|
243
|
+
@cli.expects(:look_for_default_recipe_file!).never
|
244
|
+
@cli.args << "-f" << "hello"
|
245
|
+
@cli.parse_options!
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_F_should_search_for_default_recipes_even_if_f_is_given
|
249
|
+
@cli.expects(:look_for_default_recipe_file!)
|
250
|
+
@cli.args << "-Ff" << "hello"
|
251
|
+
@cli.parse_options!
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_should_extract_env_vars_from_command_line
|
255
|
+
assert_nil ENV["HELLO"]
|
256
|
+
assert_nil ENV["ANOTHER"]
|
257
|
+
|
258
|
+
@cli.args << "HELLO=world" << "hello" << "ANOTHER=value"
|
259
|
+
@cli.parse_options!
|
260
|
+
|
261
|
+
assert_equal "world", ENV["HELLO"]
|
262
|
+
assert_equal "value", ENV["ANOTHER"]
|
263
|
+
ensure
|
264
|
+
ENV.delete("HELLO")
|
265
|
+
ENV.delete("ANOTHER")
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_remaining_args_should_be_added_to_actions_list
|
269
|
+
@cli.args << "-v" << "HELLO=world" << "-f" << "foo" << "something" << "else"
|
270
|
+
@cli.parse_options!
|
271
|
+
assert_equal %w(something else), @cli.args
|
272
|
+
ensure
|
273
|
+
ENV.delete("HELLO")
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_search_for_default_recipe_file_should_look_for_Capfile
|
277
|
+
File.stubs(:file?).returns(false)
|
278
|
+
File.expects(:file?).with("Capfile").returns(true)
|
279
|
+
@cli.args << "-v"
|
280
|
+
@cli.parse_options!
|
281
|
+
assert_equal %w(Capfile), @cli.options[:recipes]
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_search_for_default_recipe_file_should_look_for_capfile
|
285
|
+
File.stubs(:file?).returns(false)
|
286
|
+
File.expects(:file?).with("capfile").returns(true)
|
287
|
+
@cli.args << "-v"
|
288
|
+
@cli.parse_options!
|
289
|
+
assert_equal %w(capfile), @cli.options[:recipes]
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_search_for_default_recipe_should_hike_up_the_directory_tree_until_it_finds_default_recipe
|
293
|
+
File.stubs(:file?).returns(false)
|
294
|
+
File.expects(:file?).with("capfile").times(2).returns(false,true)
|
295
|
+
Dir.expects(:pwd).times(3).returns(*%w(/bar/baz /bar/baz /bar))
|
296
|
+
Dir.expects(:chdir).with("..")
|
297
|
+
@cli.args << "-v"
|
298
|
+
@cli.parse_options!
|
299
|
+
assert_equal %w(capfile), @cli.options[:recipes]
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_search_for_default_recipe_should_halt_at_root_directory
|
303
|
+
File.stubs(:file?).returns(false)
|
304
|
+
Dir.expects(:pwd).times(7).returns(*%w(/bar/baz /bar/baz /bar /bar / / /))
|
305
|
+
Dir.expects(:chdir).with("..").times(3)
|
306
|
+
Dir.expects(:chdir).with("/bar/baz")
|
307
|
+
@cli.args << "-v"
|
308
|
+
@cli.parse_options!
|
309
|
+
assert @cli.options[:recipes].empty?
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_parse_should_instantiate_new_cli_and_call_parse_options
|
313
|
+
cli = mock("cli", :parse_options! => nil)
|
314
|
+
MockCLI.expects(:new).with(%w(a b c)).returns(cli)
|
315
|
+
assert_equal cli, MockCLI.parse(%w(a b c))
|
316
|
+
end
|
317
|
+
end
|