minmb-capistrano 2.15.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +1170 -0
  4. data/Gemfile +13 -0
  5. data/README.md +94 -0
  6. data/Rakefile +11 -0
  7. data/bin/cap +4 -0
  8. data/bin/capify +92 -0
  9. data/capistrano.gemspec +40 -0
  10. data/lib/capistrano.rb +5 -0
  11. data/lib/capistrano/callback.rb +45 -0
  12. data/lib/capistrano/cli.rb +47 -0
  13. data/lib/capistrano/cli/execute.rb +85 -0
  14. data/lib/capistrano/cli/help.rb +125 -0
  15. data/lib/capistrano/cli/help.txt +81 -0
  16. data/lib/capistrano/cli/options.rb +243 -0
  17. data/lib/capistrano/cli/ui.rb +40 -0
  18. data/lib/capistrano/command.rb +303 -0
  19. data/lib/capistrano/configuration.rb +57 -0
  20. data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
  21. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  22. data/lib/capistrano/configuration/actions/invocation.rb +329 -0
  23. data/lib/capistrano/configuration/alias_task.rb +26 -0
  24. data/lib/capistrano/configuration/callbacks.rb +147 -0
  25. data/lib/capistrano/configuration/connections.rb +237 -0
  26. data/lib/capistrano/configuration/execution.rb +142 -0
  27. data/lib/capistrano/configuration/loading.rb +205 -0
  28. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  29. data/lib/capistrano/configuration/namespaces.rb +223 -0
  30. data/lib/capistrano/configuration/roles.rb +77 -0
  31. data/lib/capistrano/configuration/servers.rb +116 -0
  32. data/lib/capistrano/configuration/variables.rb +127 -0
  33. data/lib/capistrano/errors.rb +19 -0
  34. data/lib/capistrano/ext/multistage.rb +64 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +57 -0
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +166 -0
  39. data/lib/capistrano/processable.rb +57 -0
  40. data/lib/capistrano/recipes/compat.rb +32 -0
  41. data/lib/capistrano/recipes/deploy.rb +625 -0
  42. data/lib/capistrano/recipes/deploy/assets.rb +201 -0
  43. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  44. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  45. data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
  46. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  47. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  48. data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
  49. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  50. data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
  51. data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
  52. data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
  53. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  54. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  55. data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
  56. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  57. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  58. data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
  59. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  60. data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
  61. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  62. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  63. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
  64. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  65. data/lib/capistrano/recipes/standard.rb +37 -0
  66. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  67. data/lib/capistrano/role.rb +102 -0
  68. data/lib/capistrano/server_definition.rb +56 -0
  69. data/lib/capistrano/shell.rb +265 -0
  70. data/lib/capistrano/ssh.rb +95 -0
  71. data/lib/capistrano/task_definition.rb +77 -0
  72. data/lib/capistrano/transfer.rb +218 -0
  73. data/lib/capistrano/version.rb +11 -0
  74. data/test/cli/execute_test.rb +132 -0
  75. data/test/cli/help_test.rb +165 -0
  76. data/test/cli/options_test.rb +329 -0
  77. data/test/cli/ui_test.rb +28 -0
  78. data/test/cli_test.rb +17 -0
  79. data/test/command_test.rb +322 -0
  80. data/test/configuration/actions/file_transfer_test.rb +61 -0
  81. data/test/configuration/actions/inspect_test.rb +76 -0
  82. data/test/configuration/actions/invocation_test.rb +288 -0
  83. data/test/configuration/alias_task_test.rb +118 -0
  84. data/test/configuration/callbacks_test.rb +201 -0
  85. data/test/configuration/connections_test.rb +439 -0
  86. data/test/configuration/execution_test.rb +175 -0
  87. data/test/configuration/loading_test.rb +148 -0
  88. data/test/configuration/namespace_dsl_test.rb +332 -0
  89. data/test/configuration/roles_test.rb +157 -0
  90. data/test/configuration/servers_test.rb +183 -0
  91. data/test/configuration/variables_test.rb +190 -0
  92. data/test/configuration_test.rb +77 -0
  93. data/test/deploy/local_dependency_test.rb +76 -0
  94. data/test/deploy/remote_dependency_test.rb +146 -0
  95. data/test/deploy/scm/accurev_test.rb +23 -0
  96. data/test/deploy/scm/base_test.rb +55 -0
  97. data/test/deploy/scm/bzr_test.rb +51 -0
  98. data/test/deploy/scm/darcs_test.rb +37 -0
  99. data/test/deploy/scm/git_test.rb +221 -0
  100. data/test/deploy/scm/mercurial_test.rb +134 -0
  101. data/test/deploy/scm/none_test.rb +35 -0
  102. data/test/deploy/scm/perforce_test.rb +23 -0
  103. data/test/deploy/scm/subversion_test.rb +40 -0
  104. data/test/deploy/strategy/copy_test.rb +360 -0
  105. data/test/extensions_test.rb +69 -0
  106. data/test/fixtures/cli_integration.rb +5 -0
  107. data/test/fixtures/config.rb +5 -0
  108. data/test/fixtures/custom.rb +3 -0
  109. data/test/logger_formatting_test.rb +149 -0
  110. data/test/logger_test.rb +134 -0
  111. data/test/recipes_test.rb +25 -0
  112. data/test/role_test.rb +11 -0
  113. data/test/server_definition_test.rb +121 -0
  114. data/test/shell_test.rb +96 -0
  115. data/test/ssh_test.rb +113 -0
  116. data/test/task_definition_test.rb +117 -0
  117. data/test/transfer_test.rb +168 -0
  118. data/test/utils.rb +37 -0
  119. metadata +316 -0
@@ -0,0 +1,157 @@
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_roles_for_host_with_one_role
26
+ @config.role :app, "app1.capistrano.test"
27
+ @config.role :not_app, "not-app.capistrano.test"
28
+ app_server = @config.roles[:app].servers.first
29
+ assert @config.role_names_for_host(app_server)==[ :app ]
30
+ end
31
+
32
+ def test_roles_for_host_with_multiple_roles
33
+ @config.server "www.capistrano.test", :db, :worker
34
+ db_server = @config.roles[:db].servers.first
35
+ assert_equal @config.role_names_for_host(db_server).map(&:to_s).sort, [ 'db', 'worker' ]
36
+ end
37
+
38
+ def test_role_should_allow_empty_list
39
+ @config.role :app
40
+ assert @config.roles.keys.include?(:app)
41
+ assert @config.roles[:app].empty?
42
+ end
43
+
44
+ def test_role_with_one_argument_should_add_to_roles_collection
45
+ @config.role :app, "app1.capistrano.test"
46
+ assert_equal [:app], @config.roles.keys
47
+ assert_role_equals %w(app1.capistrano.test)
48
+ end
49
+
50
+ def test_role_block_returning_single_string_is_added_to_roles_collection
51
+ @config.role :app do
52
+ 'app1.capistrano.test'
53
+ end
54
+ assert_role_equals %w(app1.capistrano.test)
55
+ end
56
+
57
+ def test_role_with_multiple_arguments_should_add_each_to_roles_collection
58
+ @config.role :app, "app1.capistrano.test", "app2.capistrano.test"
59
+ assert_equal [:app], @config.roles.keys
60
+ assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
61
+ end
62
+
63
+ def test_role_with_block_and_strings_should_add_both_to_roles_collection
64
+ @config.role :app, 'app1.capistrano.test' do
65
+ 'app2.capistrano.test'
66
+ end
67
+ assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
68
+ end
69
+
70
+ def test_role_block_returning_array_should_add_each_to_roles_collection
71
+ @config.role :app do
72
+ ['app1.capistrano.test', 'app2.capistrano.test']
73
+ end
74
+ assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
75
+ end
76
+
77
+ def test_role_with_options_should_apply_options_to_each_argument
78
+ @config.role :app, "app1.capistrano.test", "app2.capistrano.test", :extra => :value
79
+ @config.roles[:app].each do |server|
80
+ assert_equal({:extra => :value}, server.options)
81
+ end
82
+ end
83
+
84
+ def test_role_with_options_should_apply_options_to_block_results
85
+ @config.role :app, :extra => :value do
86
+ ['app1.capistrano.test', 'app2.capistrano.test']
87
+ end
88
+ @config.roles[:app].each do |server|
89
+ assert_equal({:extra => :value}, server.options)
90
+ end
91
+ end
92
+
93
+ def test_options_should_apply_only_to_this_argument_set
94
+ @config.role :app, 'app1.capistrano.test', 'app2.capistrano.test' do
95
+ ['app3.capistrano.test', 'app4.capistrano.test']
96
+ end
97
+ @config.role :app, 'app5.capistrano.test', 'app6.capistrano.test', :extra => :value do
98
+ ['app7.capistrano.test', 'app8.capistrano.test']
99
+ end
100
+ @config.role :app, 'app9.capistrano.test'
101
+
102
+ option_hosts = ['app5.capistrano.test', 'app6.capistrano.test', 'app7.capistrano.test', 'app8.capistrano.test']
103
+ @config.roles[:app].each do |server|
104
+ if (option_hosts.include? server.host)
105
+ assert_equal({:extra => :value}, server.options)
106
+ else
107
+ assert_not_equal({:extra => :value}, server.options)
108
+ end
109
+ end
110
+ end
111
+
112
+ # Here, the source should be more readable than the method name
113
+ def test_role_block_returns_options_hash_is_merged_with_role_options_argument
114
+ @config.role :app, :first => :one, :second => :two do
115
+ ['app1.capistrano.test', 'app2.capistrano.test', {:second => :please, :third => :three}]
116
+ end
117
+ @config.roles[:app].each do |server|
118
+ assert_equal({:first => :one, :second => :please, :third => :three}, server.options)
119
+ end
120
+ end
121
+
122
+ def test_role_block_can_override_role_options_argument
123
+ @config.role :app, :value => :wrong do
124
+ Capistrano::ServerDefinition.new('app.capistrano.test')
125
+ end
126
+ @config.roles[:app].servers
127
+ @config.roles[:app].servers.each do |server|
128
+ assert_not_equal({:value => :wrong}, server.options)
129
+ end
130
+ end
131
+
132
+ def test_role_block_can_return_nil
133
+ @config.role :app do
134
+ nil
135
+ end
136
+ assert_role_equals ([])
137
+ end
138
+
139
+ def test_role_block_can_return_empty_array
140
+ @config.role :app do
141
+ []
142
+ end
143
+ assert_role_equals ([])
144
+ end
145
+
146
+ def test_role_definitions_via_server_should_associate_server_with_roles
147
+ @config.server "www.capistrano.test", :web, :app
148
+ assert_equal %w(www.capistrano.test), @config.roles[:app].map { |s| s.host }
149
+ assert_equal %w(www.capistrano.test), @config.roles[:web].map { |s| s.host }
150
+ end
151
+
152
+ private
153
+
154
+ def assert_role_equals(list)
155
+ assert_equal list, @config.roles[:app].map { |s| s.host }
156
+ end
157
+ end
@@ -0,0 +1,183 @@
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
+ attr_accessor :preserve_roles
9
+
10
+ def initialize
11
+ @roles = {}
12
+ @preserve_roles = false
13
+ end
14
+
15
+ include Capistrano::Configuration::Servers
16
+ end
17
+
18
+ def setup
19
+ @config = MockConfig.new
20
+ role(@config, :app, "app1", :primary => true)
21
+ role(@config, :app, "app2", "app3")
22
+ role(@config, :web, "web1", "web2")
23
+ role(@config, :report, "app2", :no_deploy => true)
24
+ role(@config, :file, "file", :no_deploy => true)
25
+ end
26
+
27
+ def test_task_without_roles_should_apply_to_all_defined_hosts
28
+ task = new_task(:testing)
29
+ assert_equal %w(app1 app2 app3 web1 web2 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
30
+ end
31
+
32
+ def test_task_with_explicit_role_list_should_apply_only_to_those_roles
33
+ task = new_task(:testing, @config, :roles => %w(app web))
34
+ assert_equal %w(app1 app2 app3 web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
35
+ end
36
+
37
+ def test_task_with_single_role_should_apply_only_to_that_role
38
+ task = new_task(:testing, @config, :roles => :web)
39
+ assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
40
+ end
41
+
42
+ # NOTE Rather than throw an error, as it used to, we return an
43
+ # empty array so that if a task is okay with a missing role it can continue on
44
+ def test_task_with_unknown_role_should_return_empty_array
45
+ task = new_task(:testing, @config, :roles => :bogus)
46
+ assert_equal [], @config.find_servers_for_task(task)
47
+ end
48
+
49
+ def test_task_with_hosts_option_should_apply_only_to_those_hosts
50
+ task = new_task(:testing, @config, :hosts => %w(foo bar))
51
+ assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
52
+ end
53
+
54
+ def test_task_with_single_hosts_option_should_apply_only_to_that_host
55
+ task = new_task(:testing, @config, :hosts => "foo")
56
+ assert_equal %w(foo).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
57
+ end
58
+
59
+ def test_task_with_roles_as_environment_variable_should_apply_only_to_that_role
60
+ ENV['ROLES'] = "app,file"
61
+ task = new_task(:testing)
62
+ assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
63
+ ensure
64
+ ENV.delete('ROLES')
65
+ end
66
+
67
+ def test_task_with_roles_as_environment_variable_and_preserve_roles_should_apply_only_to_existant_task_role
68
+ ENV['ROLES'] = "app,file"
69
+ @config.preserve_roles = true
70
+ task = new_task(:testing,@config, :roles => :app)
71
+ assert_equal %w(app1 app2 app3).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
72
+ ensure
73
+ ENV.delete('ROLES')
74
+ end
75
+
76
+ def test_task_with_roles_as_environment_variable_and_preserve_roles_should_apply_only_to_existant_task_roles
77
+ ENV['ROLES'] = "app,file,web"
78
+ @config.preserve_roles = true
79
+ task = new_task(:testing,@config, :roles => [ :app,:file ])
80
+ assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
81
+ ensure
82
+ ENV.delete('ROLES')
83
+ end
84
+
85
+ def test_task_with_roles_as_environment_variable_and_preserve_roles_should_not_apply_if_not_exists_those_task_roles
86
+ ENV['ROLES'] = "file,web"
87
+ @config.preserve_roles = true
88
+ task = new_task(:testing,@config, :roles => [ :app ])
89
+ assert_equal [], @config.find_servers_for_task(task).map { |s| s.host }.sort
90
+ ensure
91
+ ENV.delete('ROLES')
92
+ end
93
+
94
+ def test_task_with_hosts_as_environment_variable_should_apply_only_to_those_hosts
95
+ ENV['HOSTS'] = "foo,bar"
96
+ task = new_task(:testing)
97
+ assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
98
+ ensure
99
+ ENV.delete('HOSTS')
100
+ end
101
+
102
+ def test_task_with_hosts_as_environment_variable_should_not_inspect_roles_at_all
103
+ ENV['HOSTS'] = "foo,bar"
104
+ task = new_task(:testing, @config, :roles => :bogus)
105
+ assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
106
+ ensure
107
+ ENV.delete('HOSTS')
108
+ end
109
+
110
+ def test_task_with_hostfilter_environment_variable_should_apply_only_to_those_hosts
111
+ ENV['HOSTFILTER'] = "app1,web1"
112
+ task = new_task(:testing)
113
+ assert_equal %w(app1 web1).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
114
+ ensure
115
+ ENV.delete('HOSTFILTER')
116
+ end
117
+
118
+ def test_task_with_hostfilter_environment_variable_should_filter_hosts_option
119
+ ENV['HOSTFILTER'] = "foo"
120
+ task = new_task(:testing, @config, :hosts => %w(foo bar))
121
+ assert_equal %w(foo).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
122
+ ensure
123
+ ENV.delete('HOSTFILTER')
124
+ end
125
+
126
+ def test_task_with_hostfilter_environment_variable_and_skip_hostfilter_should_not_filter_hosts_option
127
+ ENV['HOSTFILTER'] = "foo"
128
+ task = new_task(:testing, @config, :hosts => %w(foo bar), :skip_hostfilter => true)
129
+ assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
130
+ ensure
131
+ ENV.delete('HOSTFILTER')
132
+ end
133
+
134
+ def test_task_with_hostrolefilter_environment_variable_should_apply_only_to_those_hosts
135
+ ENV['HOSTROLEFILTER'] = "web"
136
+ task = new_task(:testing)
137
+ assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
138
+ ensure
139
+ ENV.delete('HOSTROLEFILTER')
140
+ end
141
+
142
+ def test_task_with_only_should_apply_only_to_matching_tasks
143
+ task = new_task(:testing, @config, :roles => :app, :only => { :primary => true })
144
+ assert_equal %w(app1), @config.find_servers_for_task(task).map { |s| s.host }
145
+ end
146
+
147
+ def test_task_with_except_should_apply_only_to_matching_tasks
148
+ task = new_task(:testing, @config, :except => { :no_deploy => true })
149
+ assert_equal %w(app1 app2 app3 web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
150
+ end
151
+
152
+ def test_options_to_find_servers_for_task_should_override_options_in_task
153
+ task = new_task(:testing, @config, :roles => :web)
154
+ assert_equal %w(app1 app2 app3).sort, @config.find_servers_for_task(task, :roles => :app).map { |s| s.host }.sort
155
+ end
156
+
157
+ def test_find_servers_with_lambda_for_hosts_should_be_evaluated
158
+ assert_equal %w(foo), @config.find_servers(:hosts => lambda { "foo" }).map { |s| s.host }.sort
159
+ assert_equal %w(bar foo), @config.find_servers(:hosts => lambda { %w(foo bar) }).map { |s| s.host }.sort
160
+ end
161
+
162
+ def test_find_servers_with_lambda_for_roles_should_be_evaluated
163
+ assert_equal %w(app1 app2 app3), @config.find_servers(:roles => lambda { :app }).map { |s| s.host }.sort
164
+ assert_equal %w(app2 file), @config.find_servers(:roles => lambda { [:report, :file] }).map { |s| s.host }.sort
165
+ end
166
+
167
+ def test_find_servers_with_hosts_nil_or_empty
168
+ assert_equal [], @config.find_servers(:hosts => nil)
169
+ assert_equal [], @config.find_servers(:hosts => [])
170
+ result = @config.find_servers(:hosts => @config.find_servers(:roles => :report)[0])
171
+ assert_equal 1, result.size
172
+ result = @config.find_servers(:hosts => "app1")
173
+ assert_equal 1, result.size
174
+ end
175
+
176
+ def test_find_servers_with_rolees_nil_or_empty
177
+ assert_equal [], @config.find_servers(:roles => nil)
178
+ assert_equal [], @config.find_servers(:roles => [])
179
+ result = @config.find_servers(:roles => :report)
180
+ assert_equal 1, result.size
181
+ end
182
+
183
+ end
@@ -0,0 +1,190 @@
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_respond_to_should_be_true_when_passed_a_string
58
+ assert !@config.respond_to?('sample')
59
+ @config[:sample] = :value
60
+ assert @config.respond_to?('sample')
61
+ end
62
+
63
+ def test_respond_to_with_include_priv_paramter
64
+ assert !@config.respond_to?(:sample, true)
65
+ end
66
+
67
+ def test_set_should_require_value
68
+ assert_raises(ArgumentError) do
69
+ @config.set(:sample)
70
+ end
71
+ end
72
+
73
+ def test_set_should_allow_value_to_be_omitted_if_block_is_given
74
+ assert_nothing_raised do
75
+ @config.set(:sample) { :value }
76
+ end
77
+ assert_instance_of Proc, @config.variables[:sample]
78
+ end
79
+
80
+ def test_set_should_not_allow_multiple_values
81
+ assert_raises(ArgumentError) do
82
+ @config.set(:sample, :value, :another)
83
+ end
84
+ end
85
+
86
+ def test_set_should_not_allow_both_a_value_and_a_block
87
+ assert_raises(ArgumentError) do
88
+ @config.set(:sample, :value) { :block }
89
+ end
90
+ end
91
+
92
+ def test_set_should_not_allow_capitalized_variables
93
+ assert_raises(ArgumentError) do
94
+ @config.set :Sample, :value
95
+ end
96
+ end
97
+
98
+ def test_unset_should_remove_variable_from_hash
99
+ @config.set :sample, :value
100
+ assert @config.variables.key?(:sample)
101
+ @config.unset :sample
102
+ assert !@config.variables.key?(:sample)
103
+ end
104
+
105
+ def test_unset_should_clear_memory_of_original_proc
106
+ @config.set(:sample) { :value }
107
+ @config.fetch(:sample)
108
+ @config.unset(:sample)
109
+ assert_equal false, @config.reset!(:sample)
110
+ end
111
+
112
+ def test_exists_should_report_existance_of_variable_in_hash
113
+ assert !@config.exists?(:sample)
114
+ @config[:sample] = :value
115
+ assert @config.exists?(:sample)
116
+ end
117
+
118
+ def test_reset_should_do_nothing_if_variable_does_not_exist
119
+ assert_equal false, @config.reset!(:sample)
120
+ assert !@config.variables.key?(:sample)
121
+ end
122
+
123
+ def test_reset_should_do_nothing_if_variable_is_not_a_proc
124
+ @config.set(:sample, :value)
125
+ assert_equal false, @config.reset!(:sample)
126
+ assert_equal :value, @config.variables[:sample]
127
+ end
128
+
129
+ def test_reset_should_do_nothing_if_proc_variable_has_not_been_dereferenced
130
+ @config.set(:sample) { :value }
131
+ assert_equal false, @config.reset!(:sample)
132
+ assert_instance_of Proc, @config.variables[:sample]
133
+ end
134
+
135
+ def test_reset_should_restore_variable_to_original_proc_value
136
+ @config.set(:sample) { :value }
137
+ assert_instance_of Proc, @config.variables[:sample]
138
+ @config.fetch(:sample)
139
+ assert_instance_of Symbol, @config.variables[:sample]
140
+ assert @config.reset!(:sample)
141
+ assert_instance_of Proc, @config.variables[:sample]
142
+ end
143
+
144
+ def test_fetch_should_return_stored_non_proc_value
145
+ @config.set(:sample, :value)
146
+ assert_equal :value, @config.fetch(:sample)
147
+ end
148
+
149
+ def test_fetch_should_raise_index_error_if_variable_does_not_exist
150
+ assert_raises(IndexError) do
151
+ @config.fetch(:sample)
152
+ end
153
+ end
154
+
155
+ def test_fetch_should_return_default_if_variable_does_not_exist_and_default_is_given
156
+ assert_nothing_raised do
157
+ assert_equal :default_value, @config.fetch(:sample, :default_value)
158
+ end
159
+ end
160
+
161
+ def test_fetch_should_invoke_block_if_variable_does_not_exist_and_block_is_given
162
+ assert_nothing_raised do
163
+ assert_equal :default_value, @config.fetch(:sample) { :default_value }
164
+ end
165
+ end
166
+
167
+ def test_fetch_should_raise_argument_error_if_both_default_and_block_are_given
168
+ assert_raises(ArgumentError) do
169
+ @config.fetch(:sample, :default1) { :default2 }
170
+ end
171
+ end
172
+
173
+ def test_fetch_should_dereference_proc_values
174
+ @config.set(:sample) { :value }
175
+ assert_instance_of Proc, @config.variables[:sample]
176
+ assert_equal :value, @config.fetch(:sample)
177
+ assert_instance_of Symbol, @config.variables[:sample]
178
+ end
179
+
180
+ def test_square_brackets_should_alias_fetch
181
+ @config.set(:sample, :value)
182
+ assert_equal :value, @config[:sample]
183
+ end
184
+
185
+ def test_square_brackets_should_return_nil_for_non_existant_variable
186
+ assert_nothing_raised do
187
+ assert_nil @config[:sample]
188
+ end
189
+ end
190
+ end