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,143 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/configuration/roles'
|
3
|
+
require 'capistrano/server_definition'
|
4
|
+
|
5
|
+
class ConfigurationRolesTest < Test::Unit::TestCase
|
6
|
+
class MockConfig
|
7
|
+
attr_reader :original_initialize_called
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@original_initialize_called = true
|
11
|
+
end
|
12
|
+
|
13
|
+
include Capistrano::Configuration::Roles
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@config = MockConfig.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize_should_initialize_roles_collection
|
21
|
+
assert @config.original_initialize_called
|
22
|
+
assert @config.roles.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_role_should_allow_empty_list
|
26
|
+
@config.role :app
|
27
|
+
assert @config.roles[:app].empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_role_with_one_argument_should_add_to_roles_collection
|
31
|
+
@config.role :app, "app1.capistrano.test"
|
32
|
+
assert_equal [:app], @config.roles.keys
|
33
|
+
assert_role_equals %w(app1.capistrano.test)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_role_block_returning_single_string_is_added_to_roles_collection
|
37
|
+
@config.role :app do
|
38
|
+
'app1.capistrano.test'
|
39
|
+
end
|
40
|
+
assert_role_equals %w(app1.capistrano.test)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_role_with_multiple_arguments_should_add_each_to_roles_collection
|
44
|
+
@config.role :app, "app1.capistrano.test", "app2.capistrano.test"
|
45
|
+
assert_equal [:app], @config.roles.keys
|
46
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_role_with_block_and_strings_should_add_both_to_roles_collection
|
50
|
+
@config.role :app, 'app1.capistrano.test' do
|
51
|
+
'app2.capistrano.test'
|
52
|
+
end
|
53
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_role_block_returning_array_should_add_each_to_roles_collection
|
57
|
+
@config.role :app do
|
58
|
+
['app1.capistrano.test', 'app2.capistrano.test']
|
59
|
+
end
|
60
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_role_with_options_should_apply_options_to_each_argument
|
64
|
+
@config.role :app, "app1.capistrano.test", "app2.capistrano.test", :extra => :value
|
65
|
+
@config.roles[:app].each do |server|
|
66
|
+
assert_equal({:extra => :value}, server.options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_role_with_options_should_apply_options_to_block_results
|
71
|
+
@config.role :app, :extra => :value do
|
72
|
+
['app1.capistrano.test', 'app2.capistrano.test']
|
73
|
+
end
|
74
|
+
@config.roles[:app].each do |server|
|
75
|
+
assert_equal({:extra => :value}, server.options)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_options_should_apply_only_to_this_argument_set
|
80
|
+
@config.role :app, 'app1.capistrano.test', 'app2.capistrano.test' do
|
81
|
+
['app3.capistrano.test', 'app4.capistrano.test']
|
82
|
+
end
|
83
|
+
@config.role :app, 'app5.capistrano.test', 'app6.capistrano.test', :extra => :value do
|
84
|
+
['app7.capistrano.test', 'app8.capistrano.test']
|
85
|
+
end
|
86
|
+
@config.role :app, 'app9.capistrano.test'
|
87
|
+
|
88
|
+
option_hosts = ['app5.capistrano.test', 'app6.capistrano.test', 'app7.capistrano.test', 'app8.capistrano.test']
|
89
|
+
@config.roles[:app].each do |server|
|
90
|
+
if (option_hosts.include? server.host)
|
91
|
+
assert_equal({:extra => :value}, server.options)
|
92
|
+
else
|
93
|
+
assert_not_equal({:extra => :value}, server.options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Here, the source should be more readable than the method name
|
99
|
+
def test_role_block_returns_options_hash_is_merged_with_role_options_argument
|
100
|
+
@config.role :app, :first => :one, :second => :two do
|
101
|
+
['app1.capistrano.test', 'app2.capistrano.test', {:second => :please, :third => :three}]
|
102
|
+
end
|
103
|
+
@config.roles[:app].each do |server|
|
104
|
+
assert_equal({:first => :one, :second => :please, :third => :three}, server.options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_role_block_can_override_role_options_argument
|
109
|
+
@config.role :app, :value => :wrong do
|
110
|
+
Capistrano::ServerDefinition.new('app.capistrano.test')
|
111
|
+
end
|
112
|
+
@config.roles[:app].servers
|
113
|
+
@config.roles[:app].servers.each do |server|
|
114
|
+
assert_not_equal({:value => :wrong}, server.options)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_role_block_can_return_nil
|
119
|
+
@config.role :app do
|
120
|
+
nil
|
121
|
+
end
|
122
|
+
assert_role_equals ([])
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_role_block_can_return_empty_array
|
126
|
+
@config.role :app do
|
127
|
+
[]
|
128
|
+
end
|
129
|
+
assert_role_equals ([])
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_role_definitions_via_server_should_associate_server_with_roles
|
133
|
+
@config.server "www.capistrano.test", :web, :app
|
134
|
+
assert_equal %w(www.capistrano.test), @config.roles[:app].map { |s| s.host }
|
135
|
+
assert_equal %w(www.capistrano.test), @config.roles[:web].map { |s| s.host }
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def assert_role_equals(list)
|
141
|
+
assert_equal list, @config.roles[:app].map { |s| s.host }
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/task_definition'
|
3
|
+
require 'capistrano/configuration/servers'
|
4
|
+
|
5
|
+
class ConfigurationServersTest < Test::Unit::TestCase
|
6
|
+
class MockConfig
|
7
|
+
attr_reader :roles
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@roles = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
include Capistrano::Configuration::Servers
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@config = MockConfig.new
|
18
|
+
role(@config, :app, "app1", :primary => true)
|
19
|
+
role(@config, :app, "app2", "app3")
|
20
|
+
role(@config, :web, "web1", "web2")
|
21
|
+
role(@config, :report, "app2", :no_deploy => true)
|
22
|
+
role(@config, :file, "file", :no_deploy => true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_task_without_roles_should_apply_to_all_defined_hosts
|
26
|
+
task = new_task(:testing)
|
27
|
+
assert_equal %w(app1 app2 app3 web1 web2 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_task_with_explicit_role_list_should_apply_only_to_those_roles
|
31
|
+
task = new_task(:testing, @config, :roles => %w(app web))
|
32
|
+
assert_equal %w(app1 app2 app3 web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_task_with_single_role_should_apply_only_to_that_role
|
36
|
+
task = new_task(:testing, @config, :roles => :web)
|
37
|
+
assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_task_with_unknown_role_should_raise_exception
|
41
|
+
task = new_task(:testing, @config, :roles => :bogus)
|
42
|
+
assert_raises(ArgumentError) do
|
43
|
+
@config.find_servers_for_task(task)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_task_with_hosts_option_should_apply_only_to_those_hosts
|
48
|
+
task = new_task(:testing, @config, :hosts => %w(foo bar))
|
49
|
+
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_task_with_single_hosts_option_should_apply_only_to_that_host
|
53
|
+
task = new_task(:testing, @config, :hosts => "foo")
|
54
|
+
assert_equal %w(foo).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_task_with_roles_as_environment_variable_should_apply_only_to_that_role
|
58
|
+
ENV['ROLES'] = "app,file"
|
59
|
+
task = new_task(:testing)
|
60
|
+
assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
61
|
+
ensure
|
62
|
+
ENV.delete('ROLES')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_task_with_hosts_as_environment_variable_should_apply_only_to_those_hosts
|
66
|
+
ENV['HOSTS'] = "foo,bar"
|
67
|
+
task = new_task(:testing)
|
68
|
+
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
69
|
+
ensure
|
70
|
+
ENV.delete('HOSTS')
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_task_with_hosts_as_environment_variable_should_not_inspect_roles_at_all
|
74
|
+
ENV['HOSTS'] = "foo,bar"
|
75
|
+
task = new_task(:testing, @config, :roles => :bogus)
|
76
|
+
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
77
|
+
ensure
|
78
|
+
ENV.delete('HOSTS')
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_task_with_onlyhosts_environment_variable_should_apply_only_to_those_hosts
|
82
|
+
ENV['HOSTFILTER'] = "app1,web1"
|
83
|
+
task = new_task(:testing)
|
84
|
+
assert_equal %w(app1 web1).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
85
|
+
ensure
|
86
|
+
ENV.delete('HOSTFILTER')
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_task_with_onlyhosts_environment_variable_should_filter_hosts_option
|
90
|
+
ENV['HOSTFILTER'] = "foo"
|
91
|
+
task = new_task(:testing, @config, :hosts => %w(foo bar))
|
92
|
+
assert_equal %w(foo).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
93
|
+
ensure
|
94
|
+
ENV.delete('HOSTFILTER')
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_task_with_only_should_apply_only_to_matching_tasks
|
98
|
+
task = new_task(:testing, @config, :roles => :app, :only => { :primary => true })
|
99
|
+
assert_equal %w(app1), @config.find_servers_for_task(task).map { |s| s.host }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_task_with_except_should_apply_only_to_matching_tasks
|
103
|
+
task = new_task(:testing, @config, :except => { :no_deploy => true })
|
104
|
+
assert_equal %w(app1 app2 app3 web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_options_to_find_servers_for_task_should_override_options_in_task
|
108
|
+
task = new_task(:testing, @config, :roles => :web)
|
109
|
+
assert_equal %w(app1 app2 app3).sort, @config.find_servers_for_task(task, :roles => :app).map { |s| s.host }.sort
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_find_servers_with_lambda_for_hosts_should_be_evaluated
|
113
|
+
assert_equal %w(foo), @config.find_servers(:hosts => lambda { "foo" }).map { |s| s.host }.sort
|
114
|
+
assert_equal %w(bar foo), @config.find_servers(:hosts => lambda { %w(foo bar) }).map { |s| s.host }.sort
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_find_servers_with_lambda_for_roles_should_be_evaluated
|
118
|
+
assert_equal %w(app1 app2 app3), @config.find_servers(:roles => lambda { :app }).map { |s| s.host }.sort
|
119
|
+
assert_equal %w(app2 file), @config.find_servers(:roles => lambda { [:report, :file] }).map { |s| s.host }.sort
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/configuration/variables'
|
3
|
+
|
4
|
+
class ConfigurationVariablesTest < Test::Unit::TestCase
|
5
|
+
class MockConfig
|
6
|
+
attr_reader :original_initialize_called
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@original_initialize_called = true
|
10
|
+
end
|
11
|
+
|
12
|
+
include Capistrano::Configuration::Variables
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
MockConfig.any_instance.stubs(:logger).returns(stub_everything)
|
17
|
+
@config = MockConfig.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize_should_initialize_variables_hash
|
21
|
+
assert @config.original_initialize_called
|
22
|
+
assert_equal({:ssh_options => {}, :logger => @config.logger}, @config.variables)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_set_should_add_variable_to_hash
|
26
|
+
@config.set :sample, :value
|
27
|
+
assert_equal :value, @config.variables[:sample]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_set_should_convert_variable_name_to_symbol
|
31
|
+
@config.set "sample", :value
|
32
|
+
assert_equal :value, @config.variables[:sample]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_set_should_be_aliased_to_square_brackets
|
36
|
+
@config[:sample] = :value
|
37
|
+
assert_equal :value, @config.variables[:sample]
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_variables_should_be_accessible_as_read_accessors
|
41
|
+
@config[:sample] = :value
|
42
|
+
assert_equal :value, @config.sample
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_method_missing_should_raise_error_if_no_variable_matches
|
46
|
+
assert_raises(NoMethodError) do
|
47
|
+
@config.sample
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_respond_to_should_look_for_variables
|
52
|
+
assert !@config.respond_to?(:sample)
|
53
|
+
@config[:sample] = :value
|
54
|
+
assert @config.respond_to?(:sample)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_set_should_require_value
|
58
|
+
assert_raises(ArgumentError) do
|
59
|
+
@config.set(:sample)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_set_should_allow_value_to_be_omitted_if_block_is_given
|
64
|
+
assert_nothing_raised do
|
65
|
+
@config.set(:sample) { :value }
|
66
|
+
end
|
67
|
+
assert_instance_of Proc, @config.variables[:sample]
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_set_should_not_allow_multiple_values
|
71
|
+
assert_raises(ArgumentError) do
|
72
|
+
@config.set(:sample, :value, :another)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_set_should_not_allow_both_a_value_and_a_block
|
77
|
+
assert_raises(ArgumentError) do
|
78
|
+
@config.set(:sample, :value) { :block }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_set_should_not_allow_capitalized_variables
|
83
|
+
assert_raises(ArgumentError) do
|
84
|
+
@config.set :Sample, :value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_unset_should_remove_variable_from_hash
|
89
|
+
@config.set :sample, :value
|
90
|
+
assert @config.variables.key?(:sample)
|
91
|
+
@config.unset :sample
|
92
|
+
assert !@config.variables.key?(:sample)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_unset_should_clear_memory_of_original_proc
|
96
|
+
@config.set(:sample) { :value }
|
97
|
+
@config.fetch(:sample)
|
98
|
+
@config.unset(:sample)
|
99
|
+
assert_equal false, @config.reset!(:sample)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_exists_should_report_existance_of_variable_in_hash
|
103
|
+
assert !@config.exists?(:sample)
|
104
|
+
@config[:sample] = :value
|
105
|
+
assert @config.exists?(:sample)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_reset_should_do_nothing_if_variable_does_not_exist
|
109
|
+
assert_equal false, @config.reset!(:sample)
|
110
|
+
assert !@config.variables.key?(:sample)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_reset_should_do_nothing_if_variable_is_not_a_proc
|
114
|
+
@config.set(:sample, :value)
|
115
|
+
assert_equal false, @config.reset!(:sample)
|
116
|
+
assert_equal :value, @config.variables[:sample]
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_reset_should_do_nothing_if_proc_variable_has_not_been_dereferenced
|
120
|
+
@config.set(:sample) { :value }
|
121
|
+
assert_equal false, @config.reset!(:sample)
|
122
|
+
assert_instance_of Proc, @config.variables[:sample]
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_reset_should_restore_variable_to_original_proc_value
|
126
|
+
@config.set(:sample) { :value }
|
127
|
+
assert_instance_of Proc, @config.variables[:sample]
|
128
|
+
@config.fetch(:sample)
|
129
|
+
assert_instance_of Symbol, @config.variables[:sample]
|
130
|
+
assert @config.reset!(:sample)
|
131
|
+
assert_instance_of Proc, @config.variables[:sample]
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_fetch_should_return_stored_non_proc_value
|
135
|
+
@config.set(:sample, :value)
|
136
|
+
assert_equal :value, @config.fetch(:sample)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_fetch_should_raise_index_error_if_variable_does_not_exist
|
140
|
+
assert_raises(IndexError) do
|
141
|
+
@config.fetch(:sample)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_fetch_should_return_default_if_variable_does_not_exist_and_default_is_given
|
146
|
+
assert_nothing_raised do
|
147
|
+
assert_equal :default_value, @config.fetch(:sample, :default_value)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_fetch_should_invoke_block_if_variable_does_not_exist_and_block_is_given
|
152
|
+
assert_nothing_raised do
|
153
|
+
assert_equal :default_value, @config.fetch(:sample) { :default_value }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_fetch_should_raise_argument_error_if_both_default_and_block_are_given
|
158
|
+
assert_raises(ArgumentError) do
|
159
|
+
@config.fetch(:sample, :default1) { :default2 }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_fetch_should_dereference_proc_values
|
164
|
+
@config.set(:sample) { :value }
|
165
|
+
assert_instance_of Proc, @config.variables[:sample]
|
166
|
+
assert_equal :value, @config.fetch(:sample)
|
167
|
+
assert_instance_of Symbol, @config.variables[:sample]
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_square_brackets_should_alias_fetch
|
171
|
+
@config.set(:sample, :value)
|
172
|
+
assert_equal :value, @config[:sample]
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_square_brackets_should_return_nil_for_non_existant_variable
|
176
|
+
assert_nothing_raised do
|
177
|
+
assert_nil @config[:sample]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/configuration'
|
3
|
+
|
4
|
+
# These tests are only for testing the integration of the various components
|
5
|
+
# of the Configuration class. To test specific features, please look at the
|
6
|
+
# tests under test/configuration.
|
7
|
+
|
8
|
+
class ConfigurationTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@config = Capistrano::Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
|
14
|
+
Capistrano::SSH.expects(:connect).with { |s,c| s.host == "www.capistrano.test" && c == @config }.returns(:session)
|
15
|
+
|
16
|
+
process_args = Proc.new do |tree, session, opts|
|
17
|
+
tree.fallback.command == "echo 'hello world'" &&
|
18
|
+
session == [:session] &&
|
19
|
+
opts == { :logger => @config.logger }
|
20
|
+
end
|
21
|
+
|
22
|
+
Capistrano::Command.expects(:process).with(&process_args)
|
23
|
+
|
24
|
+
@config.load do
|
25
|
+
role :test, "www.capistrano.test"
|
26
|
+
set :message, "hello world"
|
27
|
+
namespace :testing do
|
28
|
+
task :example, :roles => :test do
|
29
|
+
run "echo '#{message}'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@config.testing.example
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_same_namespace
|
38
|
+
@config.namespace(:outer) do
|
39
|
+
task(:first) { set :called_first, true }
|
40
|
+
namespace(:inner) do
|
41
|
+
task(:first) { set :called_inner_first, true }
|
42
|
+
task(:second) { first }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
@config.outer.inner.second
|
47
|
+
assert !@config[:called_first]
|
48
|
+
assert @config[:called_inner_first]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_parent_namespace
|
52
|
+
@config.namespace(:outer) do
|
53
|
+
task(:first) { set :called_first, true }
|
54
|
+
namespace(:inner) do
|
55
|
+
task(:second) { first }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
@config.outer.inner.second
|
60
|
+
assert @config[:called_first]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_tasks_in_nested_namespace_should_be_able_to_call_shadowed_tasks_in_parent_namespace
|
64
|
+
@config.namespace(:outer) do
|
65
|
+
task(:first) { set :called_first, true }
|
66
|
+
namespace(:inner) do
|
67
|
+
task(:first) { set :called_inner_first, true }
|
68
|
+
task(:second) { parent.first }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@config.outer.inner.second
|
73
|
+
assert @config[:called_first]
|
74
|
+
assert !@config[:called_inner_first]
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
|
78
|
+
@config.namespace(:outer) do
|
79
|
+
task(:default) { set :called_default, true }
|
80
|
+
task(:before_outer) { set :called_before_outer, true }
|
81
|
+
task(:after_outer) { set :called_after_outer, true }
|
82
|
+
end
|
83
|
+
@config.outer.default
|
84
|
+
assert @config[:called_before_outer]
|
85
|
+
assert @config[:called_default]
|
86
|
+
assert @config[:called_after_outer]
|
87
|
+
end
|
88
|
+
end
|