whiskey_disk 0.6.22 → 0.6.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +25 -15
  2. data/README.integration_specs +24 -36
  3. data/README.markdown +112 -96
  4. data/Rakefile +79 -5
  5. data/VERSION +1 -1
  6. data/lib/whiskey_disk.rb +297 -294
  7. data/lib/whiskey_disk/config.rb +99 -168
  8. data/lib/whiskey_disk/config/abstract_filter.rb +19 -0
  9. data/lib/whiskey_disk/config/filter.rb +48 -0
  10. data/lib/whiskey_disk/config/filters/add_environment_name_filter.rb +11 -0
  11. data/lib/whiskey_disk/config/filters/add_project_name_filter.rb +11 -0
  12. data/lib/whiskey_disk/config/filters/check_for_duplicate_domains_filter.rb +21 -0
  13. data/lib/whiskey_disk/config/filters/convert_role_strings_to_list_filter.rb +20 -0
  14. data/lib/whiskey_disk/config/filters/default_config_target_filter.rb +12 -0
  15. data/lib/whiskey_disk/config/filters/default_domain_filter.rb +12 -0
  16. data/lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb +32 -0
  17. data/lib/whiskey_disk/config/filters/environment_scope_filter.rb +20 -0
  18. data/lib/whiskey_disk/config/filters/hashify_domain_entries_filter.rb +29 -0
  19. data/lib/whiskey_disk/config/filters/localize_domains_filter.rb +24 -0
  20. data/lib/whiskey_disk/config/filters/modules/scope_helper.rb +11 -0
  21. data/lib/whiskey_disk/config/filters/normalize_ssh_options_filter.rb +29 -0
  22. data/lib/whiskey_disk/config/filters/project_scope_filter.rb +34 -0
  23. data/lib/whiskey_disk/config/filters/select_project_and_environment_filter.rb +12 -0
  24. data/lib/whiskey_disk/config/filters/stringify_hash_keys_filter.rb +25 -0
  25. data/lib/whiskey_disk/helpers.rb +1 -1
  26. data/lib/whiskey_disk/rake.rb +25 -22
  27. data/scenarios/git_repositories/config.git/HEAD +1 -0
  28. data/scenarios/git_repositories/config.git/config +5 -0
  29. data/scenarios/git_repositories/config.git/description +1 -0
  30. data/scenarios/git_repositories/config.git/git-daemon-export-ok +0 -0
  31. data/scenarios/git_repositories/config.git/hooks/applypatch-msg.sample +15 -0
  32. data/scenarios/git_repositories/config.git/hooks/commit-msg.sample +24 -0
  33. data/scenarios/git_repositories/config.git/hooks/post-commit.sample +8 -0
  34. data/scenarios/git_repositories/config.git/hooks/post-receive.sample +15 -0
  35. data/scenarios/git_repositories/config.git/hooks/post-update.sample +8 -0
  36. data/scenarios/git_repositories/config.git/hooks/pre-applypatch.sample +14 -0
  37. data/scenarios/git_repositories/config.git/hooks/pre-commit.sample +46 -0
  38. data/scenarios/git_repositories/config.git/hooks/pre-rebase.sample +169 -0
  39. data/scenarios/git_repositories/config.git/hooks/prepare-commit-msg.sample +36 -0
  40. data/scenarios/git_repositories/config.git/hooks/update.sample +128 -0
  41. data/scenarios/git_repositories/config.git/info/exclude +6 -0
  42. data/scenarios/git_repositories/config.git/objects/0d/b14dd6ddc54017c0a11960dcda82ed802cde69 +0 -0
  43. data/scenarios/git_repositories/config.git/objects/0e/e781f5ce80d64db32a74a7aae7b5248dafe112 +3 -0
  44. data/scenarios/git_repositories/config.git/objects/17/6bf54cf17d1d1c24556dc059c4144a5df230e8 +0 -0
  45. data/scenarios/git_repositories/config.git/objects/20/e9ff3feaa8ede30f707e5f1b4356e3c02bb7ec +0 -0
  46. data/scenarios/git_repositories/config.git/objects/45/117b1c775f0de415478dbf08ed9d667ab17d13 +0 -0
  47. data/scenarios/git_repositories/config.git/objects/51/3954c9aca090e6ce40359f0e9fde30ea78eb8c +0 -0
  48. data/scenarios/git_repositories/config.git/objects/66/947a7a11a6f5d3d561fe95de284ced3010819a +0 -0
  49. data/scenarios/git_repositories/config.git/objects/6b/bc79311bfac47d3ed724aa82a4814e0dda4c67 +0 -0
  50. data/scenarios/git_repositories/config.git/objects/71/eb5df52676e8e6efba471050b46978173af110 +1 -0
  51. data/scenarios/git_repositories/config.git/objects/84/17d2fe3e8fcc0825249c517b29b0f9ea8b8b31 +2 -0
  52. data/scenarios/git_repositories/config.git/objects/8b/384fcfcf7c0dee7c3c1d5636bee9e645d9cf38 +0 -0
  53. data/scenarios/git_repositories/config.git/objects/bb/59da633ba74296b0c2f9ff70784ac155ddb599 +0 -0
  54. data/scenarios/git_repositories/config.git/objects/cc/b86b26189afbf45d8eb9165812ab86dbdfca63 +0 -0
  55. data/scenarios/git_repositories/config.git/objects/d1/0bcd51fec41f854001e4d61f99d9e282a695d3 +0 -0
  56. data/scenarios/git_repositories/config.git/objects/d8/a8b0f5b1fd66844efb141d9544965ea0065f2d +0 -0
  57. data/scenarios/git_repositories/config.git/objects/e6/b02c66ad632e6b8535c4630cb8fe07732a72fc +0 -0
  58. data/scenarios/git_repositories/config.git/objects/e8/b8bfeeba735c0a1a873082554cb4d7256ac125 +0 -0
  59. data/scenarios/git_repositories/config.git/objects/f9/0181466a1a60b793ca9cc9abd584c18d4e3887 +0 -0
  60. data/scenarios/git_repositories/config.git/objects/f9/49d5d8a4f12c91471e34d4e277239c35ebd10d +0 -0
  61. data/scenarios/git_repositories/config.git/refs/heads/master +1 -0
  62. data/scenarios/git_repositories/project.git/HEAD +1 -0
  63. data/scenarios/git_repositories/project.git/config +5 -0
  64. data/scenarios/git_repositories/project.git/description +1 -0
  65. data/scenarios/git_repositories/project.git/git-daemon-export-ok +0 -0
  66. data/scenarios/git_repositories/project.git/hooks/applypatch-msg.sample +15 -0
  67. data/scenarios/git_repositories/project.git/hooks/commit-msg.sample +24 -0
  68. data/scenarios/git_repositories/project.git/hooks/post-commit.sample +8 -0
  69. data/scenarios/git_repositories/project.git/hooks/post-receive.sample +15 -0
  70. data/scenarios/git_repositories/project.git/hooks/post-update.sample +8 -0
  71. data/scenarios/git_repositories/project.git/hooks/pre-applypatch.sample +14 -0
  72. data/scenarios/git_repositories/project.git/hooks/pre-commit.sample +46 -0
  73. data/scenarios/git_repositories/project.git/hooks/pre-rebase.sample +169 -0
  74. data/scenarios/git_repositories/project.git/hooks/prepare-commit-msg.sample +36 -0
  75. data/scenarios/git_repositories/project.git/hooks/update.sample +128 -0
  76. data/scenarios/git_repositories/project.git/info/exclude +6 -0
  77. data/scenarios/git_repositories/project.git/objects/04/26e152e66c8cd42974279bdcae09be9839c172 +0 -0
  78. data/scenarios/git_repositories/project.git/objects/04/f4de85eaf72ef1631dc6d7424045c0a749b757 +1 -0
  79. data/scenarios/git_repositories/project.git/objects/06/13fe277280cbcdb2856e1eefc70bdaff011b20 +0 -0
  80. data/scenarios/git_repositories/project.git/objects/06/7aca89b86265eee211387434c3e50f37ccf009 +0 -0
  81. data/scenarios/git_repositories/project.git/objects/09/445dacc4822722612d60833c9948219ecdd8f5 +0 -0
  82. data/scenarios/git_repositories/project.git/objects/11/c4ec64326de35462f4e79d0f4229bf8e26e0c5 +0 -0
  83. data/scenarios/git_repositories/project.git/objects/20/1c7641c2e42b0b904e5c1f793489d8b858e4da +2 -0
  84. data/scenarios/git_repositories/project.git/objects/23/979639da60d2d31e9744468df1c1221b101e64 +0 -0
  85. data/scenarios/git_repositories/project.git/objects/27/a3fff2c4c45ab5513a405f694c0a042cb5d417 +1 -0
  86. data/scenarios/git_repositories/project.git/objects/2c/0c33cfba8e1af15df88522c0db2b10a6a94138 +2 -0
  87. data/scenarios/git_repositories/project.git/objects/38/b574660305ecb5fec6b2daa7ee1e0dbf1b6003 +0 -0
  88. data/scenarios/git_repositories/project.git/objects/4a/57abb5e4e426cfc9101b3af22ac83ccbd8e2ad +0 -0
  89. data/scenarios/git_repositories/project.git/objects/4c/77ebdd985e57afe7988480720c5dc77ec525c9 +0 -0
  90. data/scenarios/git_repositories/project.git/objects/51/c94da6f1b8aa9d2346088d3d362475b60c7f32 +0 -0
  91. data/scenarios/git_repositories/project.git/objects/5b/a96acf9cc9b87babe37c032676f53bf1ba9ae7 +2 -0
  92. data/scenarios/git_repositories/project.git/objects/5d/f555601d60f1c2a84d2364af0ad640612c3ba5 +0 -0
  93. data/scenarios/git_repositories/project.git/objects/71/03b5ac94940d596c2160a5cfcd55ca4ccac41f +0 -0
  94. data/scenarios/git_repositories/project.git/objects/73/3fc331098b03523f414f3509b9ae6e637c6866 +0 -0
  95. data/scenarios/git_repositories/project.git/objects/80/26076649ceccbe96a6292f2432652f08483035 +0 -0
  96. data/scenarios/git_repositories/project.git/objects/86/d1ef0976be4567de562224e1b51fbf9820c53a +1 -0
  97. data/scenarios/git_repositories/project.git/objects/87/a9d8b09b3401d21b23d90253332d6b28b47db2 +0 -0
  98. data/scenarios/git_repositories/project.git/objects/8b/030ba688255c917d189ae3f87d7c5ccd226bc2 +0 -0
  99. data/scenarios/git_repositories/project.git/objects/95/c9d5ad9b1c90e4c805516783105fc2037dedeb +2 -0
  100. data/scenarios/git_repositories/project.git/objects/95/d82d043af35a80eabfd56c0d705abfa3488787 +2 -0
  101. data/scenarios/git_repositories/project.git/objects/96/0bf34bb0b46d0aeb0be87f688f4ef06a4b35e1 +0 -0
  102. data/scenarios/git_repositories/project.git/objects/a3/860106dc1d148c7831cd45ae38829b4ed47702 +2 -0
  103. data/scenarios/git_repositories/project.git/objects/a8/506d6439b71784a72ac72d284b2ad53088f573 +0 -0
  104. data/scenarios/git_repositories/project.git/objects/ad/22ea6c7563777936ecfbe50d8e2cf8120fd525 +0 -0
  105. data/scenarios/git_repositories/project.git/objects/ae/3900de54aff557c61c81146d00f9d38e55a265 +1 -0
  106. data/scenarios/git_repositories/project.git/objects/bf/5e3740d52b80abb0378b3f85f93a53b1294521 +1 -0
  107. data/scenarios/git_repositories/project.git/objects/bf/b59811cdbc069418dee14b171e6e7e979784b7 +0 -0
  108. data/scenarios/git_repositories/project.git/objects/cc/5ac0afb24e727d5de344cc26a425f4fb7fd17d +3 -0
  109. data/scenarios/git_repositories/project.git/objects/d1/091aa2dd76885108461110c639e6b33a297fce +0 -0
  110. data/scenarios/git_repositories/project.git/objects/d8/913f6650eb2b7bf2a633732d8452008ca23dcb +0 -0
  111. data/scenarios/git_repositories/project.git/objects/db/d1b9667f1b26b13331ac0c321dced8be1aeab0 +3 -0
  112. data/scenarios/git_repositories/project.git/objects/e4/3b9107e9b1908ce415025e64eb83a493d329b7 +0 -0
  113. data/scenarios/git_repositories/project.git/objects/ef/2a88894d5421920b9dfe67a9a4d8043830e62e +0 -0
  114. data/scenarios/git_repositories/project.git/objects/f4/0123a1ff20c65d8dc15a38a83222647908e6f7 +0 -0
  115. data/scenarios/git_repositories/project.git/objects/f5/0af315b75ca0b12c720dec6d916b76b968c319 +0 -0
  116. data/scenarios/git_repositories/project.git/objects/f6/0215709b7b23f3738e9cbaf634b1c86bbd376a +0 -0
  117. data/scenarios/git_repositories/project.git/refs/heads/bad_rakefile +1 -0
  118. data/scenarios/git_repositories/project.git/refs/heads/hook_with_changed +1 -0
  119. data/scenarios/git_repositories/project.git/refs/heads/master +1 -0
  120. data/scenarios/git_repositories/project.git/refs/heads/no_rake_hooks +1 -0
  121. data/scenarios/git_repositories/project.git/refs/heads/post_rake_tasks +1 -0
  122. data/scenarios/invalid/deploy.yml +1 -0
  123. data/scenarios/local/deploy.yml.erb +17 -0
  124. data/scenarios/remote/deploy.yml +119 -0
  125. data/scenarios/setup/vagrant/.gitignore +3 -0
  126. data/scenarios/setup/vagrant/Vagrantfile +10 -0
  127. data/scenarios/setup/vagrant/manifests/integration.pp +32 -0
  128. data/scenarios/setup/vagrant/pids/.gitignore +1 -0
  129. data/spec/init_spec.rb +1 -1
  130. data/spec/install_spec.rb +4 -4
  131. data/spec/integration/branch_switching_spec.rb +41 -0
  132. data/spec/integration/deployment_failures_spec.rb +106 -0
  133. data/spec/integration/helper_spec.rb +90 -0
  134. data/spec/integration/invalid_configuration_spec.rb +39 -0
  135. data/spec/integration/local_deployments_spec.rb +230 -0
  136. data/spec/integration/post_rake_tasks_spec.rb +226 -0
  137. data/spec/integration/post_scripts_spec.rb +246 -0
  138. data/spec/integration/remote_deployments_spec.rb +166 -0
  139. data/spec/integration/staleness_checks_spec.rb +72 -0
  140. data/spec/spec_helper.rb +30 -2
  141. data/spec/wd_command_spec.rb +136 -136
  142. data/spec/wd_role_command_spec.rb +5 -5
  143. data/spec/whiskey_disk/config/filter_spec.rb +77 -0
  144. data/spec/whiskey_disk/config/filters/add_environment_name_filter_spec.rb +20 -0
  145. data/spec/whiskey_disk/config/filters/add_project_name_filter_spec.rb +19 -0
  146. data/spec/whiskey_disk/config/filters/check_for_duplicate_domains_filter_spec.rb +29 -0
  147. data/spec/whiskey_disk/config/filters/convert_role_strings_to_list_filter_spec.rb +48 -0
  148. data/spec/whiskey_disk/config/filters/default_config_target_filter_spec.rb +19 -0
  149. data/spec/whiskey_disk/config/filters/default_domain_filter_spec.rb +18 -0
  150. data/spec/whiskey_disk/config/filters/drop_empty_domain_roles_filter_spec.rb +60 -0
  151. data/spec/whiskey_disk/config/filters/environment_scope_filter_spec.rb +32 -0
  152. data/spec/whiskey_disk/config/filters/hashify_domain_entries_filter_spec.rb +41 -0
  153. data/spec/whiskey_disk/config/filters/localize_domains_filter_spec.rb +30 -0
  154. data/spec/whiskey_disk/config/filters/normalize_ssh_options_filter_spec.rb +56 -0
  155. data/spec/whiskey_disk/config/filters/project_scope_filter_spec.rb +75 -0
  156. data/spec/whiskey_disk/config/filters/select_project_and_environment_filter_spec.rb +30 -0
  157. data/spec/whiskey_disk/config/filters/stringify_hash_keys_filter_spec.rb +40 -0
  158. data/spec/whiskey_disk/config_spec.rb +259 -446
  159. data/spec/whiskey_disk/helpers_spec.rb +51 -51
  160. data/spec/whiskey_disk/rake_spec.rb +80 -80
  161. data/spec/whiskey_disk_spec.rb +591 -562
  162. data/whiskey_disk.gemspec +151 -20
  163. metadata +151 -18
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config', 'filters', 'normalize_ssh_options_filter'))
4
+
5
+ describe 'normalizing SSH options' do
6
+ before do
7
+ @config = WhiskeyDisk::Config.new
8
+ @filter = WhiskeyDisk::Config::NormalizeSshOptionsFilter.new(@config)
9
+ end
10
+
11
+ it 'eliminates ssh options with nil, or empty values' do
12
+ @data = {
13
+ 'domain' => [
14
+ { 'name' => 'foo', 'ssh_options' => nil },
15
+ { 'name' => 'bar', 'ssh_options' => '' },
16
+ { 'name' => 'baz', 'ssh_options' => [] },
17
+ { 'name' => 'xyzzy', 'ssh_options' => ['', ''] },
18
+ { 'name' => 'quux', 'ssh_options' => [nil, '', nil] },
19
+ ]
20
+ }
21
+
22
+ @filter.filter(@data).should == {
23
+ 'domain' => [
24
+ { 'name' => 'foo' },
25
+ { 'name' => 'bar' },
26
+ { 'name' => 'baz' },
27
+ { 'name' => 'xyzzy' },
28
+ { 'name' => 'quux' }
29
+ ]
30
+ }
31
+ end
32
+
33
+ it 'preserves non-empty ssh options' do
34
+ @data = {
35
+ 'domain' => [
36
+ { 'name' => 'foo', 'ssh_options' => nil },
37
+ { 'name' => 'bar', 'ssh_options' => 'c' },
38
+ { 'name' => 'baz', 'ssh_options' => [] },
39
+ { 'name' => 'xyzzy', 'ssh_options' => ['', 'c'] },
40
+ { 'name' => 'quux', 'ssh_options' => [nil, '', 'a', nil, 'b' ] },
41
+ { 'name' => 'wut', 'ssh_options' => [nil, '', 'x', 'a', 'a', nil, 'b' ] },
42
+ ]
43
+ }
44
+
45
+ @filter.filter(@data).should == {
46
+ 'domain' => [
47
+ { 'name' => 'foo' },
48
+ { 'name' => 'bar', 'ssh_options' => [ 'c' ] },
49
+ { 'name' => 'baz' },
50
+ { 'name' => 'xyzzy', 'ssh_options' => [ 'c' ] },
51
+ { 'name' => 'quux', 'ssh_options' => [ 'a', 'b' ] },
52
+ { 'name' => 'wut', 'ssh_options' => [ 'x', 'a', 'a', 'b' ] }
53
+ ]
54
+ }
55
+ end
56
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config', 'filters', 'project_scope_filter'))
4
+
5
+ describe 'filtering configuration data by adding project scoping' do
6
+ before do
7
+ ENV['to'] = @env = 'foo:staging'
8
+
9
+ @config = WhiskeyDisk::Config.new
10
+ @filter = WhiskeyDisk::Config::ProjectScopeFilter.new(@config)
11
+
12
+ @bare_data = { 'staging' => { 'repository' => 'git://foo/bar.git', 'domain' => [ { :name => 'ogc@ogtastic.com' } ] } }
13
+ @proj_data = { 'foo' => @bare_data }
14
+ end
15
+
16
+ it 'fails if the configuration data is not a hash' do
17
+ lambda { @filter.filter([]) }.should.raise
18
+ end
19
+
20
+ describe 'when no project name is specified via ENV["to"]' do
21
+ before do
22
+ ENV['to'] = @env = 'staging'
23
+ end
24
+
25
+ it 'returns the original data if it has both project and environment scoping' do
26
+ @filter.filter(@proj_data).should == @proj_data
27
+ end
28
+
29
+ describe 'when no project name is specified in the bare config hash' do
30
+ it 'returns the original data wrapped in project scope, using a dummy project, if it has environment scoping but no project scoping' do
31
+ @filter.filter(@bare_data).should == { 'unnamed_project' => @bare_data }
32
+ end
33
+ end
34
+
35
+ describe 'when a project name is specified in the bare config hash' do
36
+ before do
37
+ @bare_data['staging']['project'] = 'whiskey_disk'
38
+ end
39
+
40
+ it 'returns the original data wrapped in project scope if it has environment scoping but no project scoping' do
41
+ @filter.filter(@bare_data).should == { 'whiskey_disk' => @bare_data }
42
+ end
43
+ end
44
+ end
45
+
46
+ describe 'when a project name is specified via ENV["to"]' do
47
+ before do
48
+ ENV['to'] = @env = 'whiskey_disk:staging'
49
+ end
50
+
51
+ describe 'when a project name is not specified in the bare config hash' do
52
+ it 'returns the original data if it has both project and environment scoping' do
53
+ @filter.filter(@proj_data).should == @proj_data
54
+ end
55
+
56
+ it 'returns the original data wrapped in project scope if it has environment scoping but no project scoping' do
57
+ @filter.filter(@bare_data).should == { 'whiskey_disk' => @bare_data }
58
+ end
59
+ end
60
+
61
+ describe 'when a project name is specified in the bare config hash' do
62
+ before do
63
+ @bare_data['staging']['project'] = 'whiskey_disk'
64
+ end
65
+
66
+ it 'returns the original data if it has both project and environment scoping' do
67
+ @filter.filter(@proj_data).should == @proj_data
68
+ end
69
+
70
+ it 'returns the original data wrapped in project scope if it has environment scoping but no project scoping' do
71
+ @filter.filter(@bare_data).should == { 'whiskey_disk' => @bare_data }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config', 'filters', 'select_project_and_environment_filter'))
4
+
5
+ describe 'filtering configuration data by selecting the data for the project and environment' do
6
+ before do
7
+ @config = WhiskeyDisk::Config.new
8
+ @filter = WhiskeyDisk::Config::SelectProjectAndEnvironmentFilter.new(@config)
9
+
10
+ @data = {
11
+ 'project' => { 'environment' => { 'a' => 'b' } },
12
+ 'other' => { 'missing' => { 'c' => 'd' } },
13
+ }
14
+ end
15
+
16
+ it 'fails when the specified project cannot be found' do
17
+ ENV['to'] = @env = 'something:environment'
18
+ lambda { @filter.filter(@data) }.should.raise
19
+ end
20
+
21
+ it 'fails when the specified environment cannot be found for the specified project' do
22
+ ENV['to'] = @env = 'other:environment'
23
+ lambda { @filter.filter(@data) }.should.raise
24
+ end
25
+
26
+ it 'returns only the data for the specified project and environment' do
27
+ ENV['to'] = @env = 'project:environment'
28
+ @filter.filter(@data).should == @data['project']['environment']
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'whiskey_disk', 'config', 'filters', 'stringify_hash_keys_filter'))
4
+
5
+ describe 'filtering configuration data to only have symbol hash keys' do
6
+ before do
7
+ @config = WhiskeyDisk::Config.new
8
+ @filter = WhiskeyDisk::Config::StringifyHashKeysFilter.new(@config)
9
+ @data = {
10
+ 'a' => {
11
+ :x => 'y',
12
+ 'c' => 'd',
13
+ :e => {
14
+ 'f' => ['a', 'b', 'c']
15
+ }
16
+ },
17
+ :b => [ '1', '2', '3' ]
18
+ }
19
+ end
20
+
21
+ it 'recursively stringifies hash keys in the provided data structure' do
22
+ @filter.filter(@data).should == {
23
+ 'a' => {
24
+ 'x' => 'y',
25
+ 'c' => 'd',
26
+ 'e' => {
27
+ 'f' => [ 'a', 'b', 'c' ]
28
+ }
29
+ },
30
+ 'b' => [ '1', '2', '3' ]
31
+ }
32
+ end
33
+
34
+ it 'clones value data so that the original data structure is not shared' do
35
+ original = @data.clone
36
+ result = @filter.filter(@data)
37
+ result['a']['e']['f'] << 'd'
38
+ @data.should == original
39
+ end
40
+ end
@@ -21,126 +21,130 @@ end
21
21
 
22
22
  # class for testing .open calls -- for use with URL config paths
23
23
  class TestURLConfig < WhiskeyDisk::Config
24
- def self.open
25
- raise
24
+ def set_response(data)
25
+ @fake_response = YAML.dump(data)
26
26
  end
27
- end
28
27
 
29
- def set_config_url_response(data)
30
- TestURLConfig.stub!(:open).and_return(YAML.dump(data))
28
+ def open(path)
29
+ @fake_response || raise
30
+ end
31
31
  end
32
32
 
33
33
  describe WhiskeyDisk::Config do
34
+ before do
35
+ @config = WhiskeyDisk::Config.new
36
+ end
37
+
34
38
  describe 'when computing the environment name' do
35
- it 'should return false when there is no ENV["to"] setting' do
39
+ it 'returns false when there is no ENV["to"] setting' do
36
40
  ENV['to'] = nil
37
- WhiskeyDisk::Config.environment_name.should == false
41
+ @config.environment_name.should == false
38
42
  end
39
43
 
40
- it 'should return false when the ENV["to"] setting is blank' do
44
+ it 'returns false when the ENV["to"] setting is blank' do
41
45
  ENV['to'] = ''
42
- WhiskeyDisk::Config.environment_name.should == false
46
+ @config.environment_name.should == false
43
47
  end
44
48
 
45
- it 'should return the ENV["to"] setting when it is non-blank' do
49
+ it 'returns the ENV["to"] setting when it is non-blank' do
46
50
  ENV['to'] = 'staging'
47
- WhiskeyDisk::Config.environment_name.should == 'staging'
51
+ @config.environment_name.should == 'staging'
48
52
  end
49
53
 
50
- it 'should return the environment portion of the ENV["to"] setting when a project is specified' do
54
+ it 'returns the environment portion of the ENV["to"] setting when a project is specified' do
51
55
  ENV['to'] = 'project:staging'
52
- WhiskeyDisk::Config.environment_name.should == 'staging'
56
+ @config.environment_name.should == 'staging'
53
57
  end
54
58
  end
55
59
 
56
60
  describe 'when determining whether to do a staleness check before updating' do
57
- it 'should return false when there is no ENV["check"] setting' do
61
+ it 'returns false when there is no ENV["check"] setting' do
58
62
  ENV['check'] = nil
59
- WhiskeyDisk::Config.check_staleness?.should == false
63
+ @config.check_staleness?.should == false
60
64
  end
61
65
 
62
- it 'should return false when the ENV["check"] setting is blank' do
66
+ it 'returns false when the ENV["check"] setting is blank' do
63
67
  ENV['check'] = ''
64
- WhiskeyDisk::Config.check_staleness?.should == false
68
+ @config.check_staleness?.should == false
65
69
  end
66
70
 
67
- it 'should return true if the ENV["check"] setting is "t"' do
71
+ it 'returns true if the ENV["check"] setting is "t"' do
68
72
  ENV['check'] = 't'
69
- WhiskeyDisk::Config.check_staleness?.should == true
73
+ @config.check_staleness?.should == true
70
74
  end
71
75
 
72
- it 'should return true if the ENV["check"] setting is "true"' do
76
+ it 'returns true if the ENV["check"] setting is "true"' do
73
77
  ENV['check'] = 'true'
74
- WhiskeyDisk::Config.check_staleness?.should == true
78
+ @config.check_staleness?.should == true
75
79
  end
76
80
 
77
- it 'should return true if the ENV["check"] setting is "y"' do
81
+ it 'returns true if the ENV["check"] setting is "y"' do
78
82
  ENV['check'] = 'y'
79
- WhiskeyDisk::Config.check_staleness?.should == true
83
+ @config.check_staleness?.should == true
80
84
  end
81
85
 
82
- it 'should return true if the ENV["check"] setting is "yes"' do
86
+ it 'returns true if the ENV["check"] setting is "yes"' do
83
87
  ENV['check'] = 'yes'
84
- WhiskeyDisk::Config.check_staleness?.should == true
88
+ @config.check_staleness?.should == true
85
89
  end
86
90
 
87
- it 'should return true if the ENV["check"] setting is "1"' do
91
+ it 'returns true if the ENV["check"] setting is "1"' do
88
92
  ENV['check'] = '1'
89
- WhiskeyDisk::Config.check_staleness?.should == true
93
+ @config.check_staleness?.should == true
90
94
  end
91
95
  end
92
96
 
93
97
  describe 'when determining whether there is a domain limit set' do
94
- it 'should return false when ENV["only"] is nil' do
98
+ it 'returns false when ENV["only"] is nil' do
95
99
  ENV['only'] = nil
96
- WhiskeyDisk::Config.domain_limit.should == false
100
+ @config.domain_limit.should == false
97
101
  end
98
102
 
99
- it 'should return false when ENV["only"] is empty' do
103
+ it 'returns false when ENV["only"] is empty' do
100
104
  ENV['only'] = ''
101
- WhiskeyDisk::Config.domain_limit.should == false
105
+ @config.domain_limit.should == false
102
106
  end
103
107
 
104
- it 'should return the value in ENV["only"] when it is non-empty' do
108
+ it 'returns the value in ENV["only"] when it is non-empty' do
105
109
  ENV['only'] = 'somedomain'
106
- WhiskeyDisk::Config.domain_limit.should == 'somedomain'
110
+ @config.domain_limit.should == 'somedomain'
107
111
  end
108
112
  end
109
113
 
110
114
  describe 'when determining whether to turn debug mode on' do
111
- it 'should return false when there is no ENV["debug"] setting' do
115
+ it 'returns false when there is no ENV["debug"] setting' do
112
116
  ENV['debug'] = nil
113
- WhiskeyDisk::Config.debug?.should == false
117
+ @config.debug?.should == false
114
118
  end
115
119
 
116
- it 'should return false when the ENV["debug"] setting is blank' do
120
+ it 'returns false when the ENV["debug"] setting is blank' do
117
121
  ENV['debug'] = ''
118
- WhiskeyDisk::Config.debug?.should == false
122
+ @config.debug?.should == false
119
123
  end
120
124
 
121
- it 'should return true if the ENV["debug"] setting is "t"' do
125
+ it 'returns true if the ENV["debug"] setting is "t"' do
122
126
  ENV['debug'] = 't'
123
- WhiskeyDisk::Config.debug?.should == true
127
+ @config.debug?.should == true
124
128
  end
125
129
 
126
- it 'should return true if the ENV["debug"] setting is "true"' do
130
+ it 'returns true if the ENV["debug"] setting is "true"' do
127
131
  ENV['debug'] = 'true'
128
- WhiskeyDisk::Config.debug?.should == true
132
+ @config.debug?.should == true
129
133
  end
130
134
 
131
- it 'should return true if the ENV["debug"] setting is "y"' do
135
+ it 'returns true if the ENV["debug"] setting is "y"' do
132
136
  ENV['debug'] = 'y'
133
- WhiskeyDisk::Config.debug?.should == true
137
+ @config.debug?.should == true
134
138
  end
135
139
 
136
- it 'should return true if the ENV["debug"] setting is "yes"' do
140
+ it 'returns true if the ENV["debug"] setting is "yes"' do
137
141
  ENV['debug'] = 'yes'
138
- WhiskeyDisk::Config.debug?.should == true
142
+ @config.debug?.should == true
139
143
  end
140
144
 
141
- it 'should return true if the ENV["debug"] setting is "1"' do
145
+ it 'returns true if the ENV["debug"] setting is "1"' do
142
146
  ENV['debug'] = '1'
143
- WhiskeyDisk::Config.debug?.should == true
147
+ @config.debug?.should == true
144
148
  end
145
149
  end
146
150
 
@@ -149,89 +153,90 @@ describe WhiskeyDisk::Config do
149
153
  before do
150
154
  ENV['to'] = @env = 'foo:staging'
151
155
  ENV['path'] = 'https://www.example.com/foo/bar/deploy.yml'
156
+ @config = TestURLConfig.new
152
157
  end
153
158
 
154
- it 'should fail if the current environment cannot be determined' do
159
+ it 'fails if the current environment cannot be determined' do
155
160
  ENV['to'] = nil
156
- lambda { TestURLConfig.fetch }.should.raise
161
+ lambda { @config.fetch }.should.raise
157
162
  end
158
163
 
159
- it 'should fail if the configuration data cannot be retrieved' do
160
- TestURLConfig.stub!(:open).and_raise(RuntimeError)
161
- lambda { TestURLConfig.fetch }.should.raise
164
+ it 'fails if the configuration data cannot be retrieved' do
165
+ @config.stub!(:open).and_raise(RuntimeError)
166
+ lambda { @config.fetch }.should.raise
162
167
  end
163
168
 
164
- it 'should fail if the retrieved configuration data is invalid' do
165
- TestURLConfig.stub!(:open).and_return("}")
166
- lambda { TestURLConfig.fetch }.should.raise
169
+ it 'fails if the retrieved configuration data is invalid' do
170
+ @config.stub!(:open).and_return("}")
171
+ lambda { @config.fetch }.should.raise
167
172
  end
168
173
 
169
- it 'should fail if the retrieved configuration data does not define data for this environment' do
170
- set_config_url_response('foo' => { 'production' => { 'a' => 'b'} })
171
- lambda { TestURLConfig.fetch }.should.raise
174
+ it 'fails if the retrieved configuration data does not define data for this environment' do
175
+ @config.set_response('foo' => { 'production' => { 'a' => 'b'} })
176
+ lambda { @config.fetch }.should.raise
172
177
  end
173
178
 
174
- it 'should return the retrieved configuration yaml data for this environment as a hash' do
179
+ it 'returns the retrieved configuration yaml data for this environment as a hash' do
175
180
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
176
- set_config_url_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
177
- result = TestURLConfig.fetch
181
+ @config.set_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
182
+ result = @config.fetch
178
183
  staging.each_pair do |k,v|
179
184
  result[k].should == v
180
185
  end
181
186
  end
182
187
 
183
- it 'should not include configuration information for other environments in the returned hash' do
188
+ it 'does not include configuration information for other environments in the returned hash' do
184
189
  staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
185
- set_config_url_response('production' => { 'repository' => 'c', 'a' => 'b'}, 'staging' => staging)
186
- TestURLConfig.fetch['a'].should.be.nil
190
+ @config.set_response('production' => { 'repository' => 'c', 'a' => 'b'}, 'staging' => staging)
191
+ @config.fetch['a'].should.be.nil
187
192
  end
188
193
 
189
- it 'should include the environment in the hash' do
194
+ it 'includes the environment in the hash' do
190
195
  staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
191
- set_config_url_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
192
- TestURLConfig.fetch['environment'].should == 'staging'
196
+ @config.set_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
197
+ @config.fetch['environment'].should == 'staging'
193
198
  end
194
199
 
195
- it 'should not allow overriding the environment in the configuration file' do
200
+ it 'does not allow overriding the environment in the configuration file' do
196
201
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'environment' => 'production' }
197
- set_config_url_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
198
- TestURLConfig.fetch['environment'].should == 'staging'
202
+ @config.set_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
203
+ @config.fetch['environment'].should == 'staging'
199
204
  end
200
205
 
201
- it 'should include the project handle in the hash' do
206
+ it 'includes the project handle in the hash' do
202
207
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
203
- set_config_url_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
204
- TestURLConfig.fetch['project'].should == 'foo'
208
+ @config.set_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
209
+ @config.fetch['project'].should == 'foo'
205
210
  end
206
211
 
207
- it 'should not allow overriding the project handle in the configuration file when a project root is specified' do
212
+ it 'does not allow overriding the project handle in the configuration file when a project root is specified' do
208
213
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
209
- set_config_url_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
210
- TestURLConfig.fetch['project'].should == 'foo'
214
+ @config.set_response('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
215
+ @config.fetch['project'].should == 'foo'
211
216
  end
212
217
 
213
- it 'should allow overriding the project handle in the configuration file when a project root is not specified' do
218
+ it 'allows overriding the project handle in the configuration file when a project root is not specified' do
214
219
  ENV['to'] = @env = 'staging'
215
220
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
216
- set_config_url_response('production' => { 'repository' => 'b'}, 'staging' => staging)
217
- TestURLConfig.fetch['project'].should == 'diskey_whisk'
221
+ @config.set_response('production' => { 'repository' => 'b'}, 'staging' => staging)
222
+ @config.fetch['project'].should == 'diskey_whisk'
218
223
  end
219
224
 
220
- it 'should include the environment name as the config_target setting when no config_target is specified' do
225
+ it 'includes the environment name as the config_target setting when no config_target is specified' do
221
226
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
222
- set_config_url_response('production' => { 'repository' => 'b'}, 'staging' => staging)
223
- TestURLConfig.fetch['config_target'].should == 'staging'
227
+ @config.set_response('production' => { 'repository' => 'b'}, 'staging' => staging)
228
+ @config.fetch['config_target'].should == 'staging'
224
229
  end
225
230
 
226
- it 'should include the config_target setting when a config_target is specified' do
231
+ it 'includes the config_target setting when a config_target is specified' do
227
232
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk', 'config_target' => 'testing' }
228
- set_config_url_response('production' => { 'repository' => 'b'}, 'staging' => staging)
229
- TestURLConfig.fetch['config_target'].should == 'testing'
233
+ @config.set_response('production' => { 'repository' => 'b'}, 'staging' => staging)
234
+ @config.fetch['config_target'].should == 'testing'
230
235
  end
231
236
 
232
- it 'should fail if the named target cannot be found' do
237
+ it 'fails if the named target cannot be found' do
233
238
  ENV['to'] = @env = 'bogus:thing'
234
- lambda { TestURLConfig.fetch }.should.raise
239
+ lambda { @config.fetch }.should.raise
235
240
  end
236
241
  end
237
242
 
@@ -246,91 +251,91 @@ describe WhiskeyDisk::Config do
246
251
  FileUtils.rm_rf(@path)
247
252
  end
248
253
 
249
- it 'should fail if the current environment cannot be determined' do
254
+ it 'fails if the current environment cannot be determined' do
250
255
  ENV['to'] = nil
251
- lambda { WhiskeyDisk::Config.fetch }.should.raise
256
+ lambda { @config.fetch }.should.raise
252
257
  end
253
258
 
254
- it 'should fail if the configuration file does not exist' do
255
- lambda { WhiskeyDisk::Config.fetch }.should.raise
259
+ it 'fails if the configuration file does not exist' do
260
+ lambda { @config.fetch }.should.raise
256
261
  end
257
262
 
258
- it 'should fail if the configuration file cannot be read' do
263
+ it 'fails if the configuration file cannot be read' do
259
264
  Dir.mkdir(File.join(@path, 'tmp'))
260
- lambda { WhiskeyDisk::Config.fetch }.should.raise
265
+ lambda { @config.fetch }.should.raise
261
266
  end
262
267
 
263
- it 'should fail if the configuration file is invalid' do
268
+ it 'fails if the configuration file is invalid' do
264
269
  File.open(@config_file, 'w') {|f| f.puts "}" }
265
- lambda { WhiskeyDisk::Config.fetch }.should.raise
270
+ lambda { @config.fetch }.should.raise
266
271
  end
267
272
 
268
- it 'should fail if the configuration file does not define data for this environment' do
273
+ it 'fails if the configuration file does not define data for this environment' do
269
274
  write_config_file('foo' => { 'production' => { 'a' => 'b'} })
270
- lambda { WhiskeyDisk::Config.fetch }.should.raise
275
+ lambda { @config.fetch }.should.raise
271
276
  end
272
277
 
273
- it 'should return the configuration yaml file data for this environment as a hash' do
278
+ it 'returns the configuration yaml file data for this environment as a hash' do
274
279
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
275
280
  write_config_file('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
276
- result = WhiskeyDisk::Config.fetch
281
+ result = @config.fetch
277
282
  staging.each_pair do |k,v|
278
283
  result[k].should == v
279
284
  end
280
285
  end
281
286
 
282
- it 'should not include configuration information for other environments in the returned hash' do
287
+ it 'does not include configuration information for other environments in the returned hash' do
283
288
  staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
284
289
  write_config_file('production' => { 'repository' => 'c', 'a' => 'b'}, 'staging' => staging)
285
- WhiskeyDisk::Config.fetch['a'].should.be.nil
290
+ @config.fetch['a'].should.be.nil
286
291
  end
287
292
 
288
- it 'should include the environment in the hash' do
293
+ it 'includes the environment in the hash' do
289
294
  staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
290
295
  write_config_file('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
291
- WhiskeyDisk::Config.fetch['environment'].should == 'staging'
296
+ @config.fetch['environment'].should == 'staging'
292
297
  end
293
298
 
294
- it 'should not allow overriding the environment in the configuration file' do
299
+ it 'does not allow overriding the environment in the configuration file' do
295
300
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'environment' => 'production' }
296
301
  write_config_file('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
297
- WhiskeyDisk::Config.fetch['environment'].should == 'staging'
302
+ @config.fetch['environment'].should == 'staging'
298
303
  end
299
304
 
300
- it 'should include the project handle in the hash' do
305
+ it 'includes the project handle in the hash' do
301
306
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
302
307
  write_config_file('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
303
- WhiskeyDisk::Config.fetch['project'].should == 'foo'
308
+ @config.fetch['project'].should == 'foo'
304
309
  end
305
310
 
306
- it 'should not allow overriding the project handle in the configuration file when a project root is specified' do
311
+ it 'does not allow overriding the project handle in the configuration file when a project root is specified' do
307
312
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
308
313
  write_config_file('foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging })
309
- WhiskeyDisk::Config.fetch['project'].should == 'foo'
314
+ @config.fetch['project'].should == 'foo'
310
315
  end
311
316
 
312
- it 'should allow overriding the project handle in the configuration file when a project root is not specified' do
317
+ it 'allows overriding the project handle in the configuration file when a project root is not specified' do
313
318
  ENV['to'] = @env = 'staging'
314
319
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
315
320
  write_config_file('production' => { 'repository' => 'b'}, 'staging' => staging)
316
- WhiskeyDisk::Config.fetch['project'].should == 'diskey_whisk'
321
+ @config.fetch['project'].should == 'diskey_whisk'
317
322
  end
318
323
 
319
- it 'should include the environment name as the config_target setting when no config_target is specified' do
324
+ it 'includes the environment name as the config_target setting when no config_target is specified' do
320
325
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
321
326
  write_config_file('production' => { 'repository' => 'b'}, 'staging' => staging)
322
- WhiskeyDisk::Config.fetch['config_target'].should == 'staging'
327
+ @config.fetch['config_target'].should == 'staging'
323
328
  end
324
329
 
325
- it 'should include the config_target setting when a config_target is specified' do
330
+ it 'includes the config_target setting when a config_target is specified' do
326
331
  staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk', 'config_target' => 'testing' }
327
332
  write_config_file('production' => { 'repository' => 'b'}, 'staging' => staging)
328
- WhiskeyDisk::Config.fetch['config_target'].should == 'testing'
333
+ @config.fetch['config_target'].should == 'testing'
329
334
  end
330
335
 
331
- it 'should fail if the named target cannot be found' do
336
+ it 'fails if the named target cannot be found' do
332
337
  ENV['to'] = @env = 'bogus:thing'
333
- lambda { WhiskeyDisk::Config.fetch }.should.raise
338
+ lambda { @config.fetch }.should.raise
334
339
  end
335
340
  end
336
341
  end
@@ -345,17 +350,17 @@ describe WhiskeyDisk::Config do
345
350
  FileUtils.rm_rf(@path)
346
351
  end
347
352
 
348
- it 'should fail if the configuration file does not exist' do
349
- lambda { WhiskeyDisk::Config.configuration_data }.should.raise
353
+ it 'fails if the configuration file does not exist' do
354
+ lambda { @config.configuration_data }.should.raise
350
355
  end
351
356
 
352
- it 'should return the contents of the configuration file' do
357
+ it 'returns the contents of the configuration file' do
353
358
  File.open(@config_file, 'w') { |f| f.puts "file contents" }
354
- WhiskeyDisk::Config.configuration_data.should == "file contents\n"
359
+ @config.configuration_data.should == "file contents\n"
355
360
  end
356
361
  end
357
362
 
358
- describe 'transforming data from the configuration file' do
363
+ describe 'loading data from the configuration file' do
359
364
  before do
360
365
  ENV['to'] = 'foo:bar'
361
366
  @path = build_temp_dir
@@ -366,290 +371,35 @@ describe WhiskeyDisk::Config do
366
371
  FileUtils.rm_rf(@path)
367
372
  end
368
373
 
369
- it 'should fail if the configuration data cannot be loaded' do
370
- lambda { WhiskeyDisk::Config.load_data }.should.raise
374
+ it 'fails if the configuration data cannot be loaded' do
375
+ lambda { @config.load_data }.should.raise
371
376
  end
372
377
 
373
- it 'should fail if converting the configuration data from YAML fails' do
378
+ it 'fails if converting the configuration data from YAML fails' do
374
379
  File.open(@config_file, 'w') { |f| f.puts "}" }
375
- lambda { WhiskeyDisk::Config.load_data }.should.raise
380
+ lambda { @config.load_data }.should.raise
376
381
  end
377
382
 
378
- it 'should return a normalized version of the un-YAMLized configuration data' do
383
+ it 'returns the un-YAMLized configuration data' do
379
384
  write_config_file('repository' => 'x')
380
- WhiskeyDisk::Config.load_data.should == { 'foo' => { 'bar' => { 'repository' => 'x', 'domain' => [{ :name => 'local' } ] } } }
381
- end
382
-
383
- describe 'normalizing domains' do
384
- before do
385
- write_config_file(
386
- 'foo' => {
387
- 'xyz' => { 'repository' => 'x' },
388
- 'eee' => { 'repository' => 'x', 'domain' => '' },
389
- 'abc' => { 'repository' => 'x', 'domain' => 'what@example.com' },
390
- 'baz' => { 'repository' => 'x', 'domain' => [ 'bar@example.com', 'baz@domain.com' ]},
391
- 'bar' => { 'repository' => 'x', 'domain' => [ 'user@example.com', nil, 'foo@domain.com' ]},
392
- 'bat' => { 'repository' => 'x', 'domain' => [ 'user@example.com', 'foo@domain.com', '' ]},
393
- 'hsh' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, { 'name' => 'baz@domain.com' } ]},
394
- 'mix' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, 'baz@domain.com' ]},
395
- 'erl' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => nil },
396
- { 'name' => 'baz@domain.com', 'roles' => '' },
397
- { 'name' => 'aok@domain.com', 'roles' => [] } ]},
398
- 'rol' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
399
- { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
400
- { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
401
- 'wow' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
402
- { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
403
- '', 'foo@bar.example.com',
404
- { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
405
- },
406
-
407
- 'zyx' => {
408
- 'xyz' => { 'repository' => 'x' },
409
- 'eee' => { 'repository' => 'x', 'domain' => '' },
410
- 'abc' => { 'repository' => 'x', 'domain' => 'what@example.com' },
411
- 'hij' => { 'repository' => 'x', 'domain' => [ 'bar@example.com', 'baz@domain.com' ]},
412
- 'def' => { 'repository' => 'x', 'domain' => [ 'user@example.com', nil, 'foo@domain.com' ]},
413
- 'dex' => { 'repository' => 'x', 'domain' => [ 'user@example.com', 'foo@domain.com', '' ]},
414
- 'hsh' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, { 'name' => 'baz@domain.com' } ]},
415
- 'mix' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, 'baz@domain.com' ]},
416
- 'erl' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => nil },
417
- { 'name' => 'baz@domain.com', 'roles' => '' },
418
- { 'name' => 'aok@domain.com', 'roles' => [] } ]},
419
- 'rol' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
420
- { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
421
- { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
422
- 'wow' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
423
- { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
424
- '', 'foo@bar.example.com',
425
- { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
426
- }
427
- )
428
- end
429
-
430
- it 'should set the domain to "local" when no domain is specified' do
431
- WhiskeyDisk::Config.load_data['foo']['xyz']['domain'].should == [ { :name => 'local' } ]
432
- end
433
-
434
- it 'should handle nil domains across all projects and targets' do
435
- WhiskeyDisk::Config.load_data['zyx']['xyz']['domain'].should == [ { :name => 'local' } ]
436
- end
437
-
438
- it 'should return domain as "local" if a single empty domain was specified' do
439
- WhiskeyDisk::Config.load_data['foo']['eee']['domain'].should == [ { :name => 'local' } ]
440
- end
441
-
442
- it 'should handle single empty specified domains across all projects and targets' do
443
- WhiskeyDisk::Config.load_data['zyx']['eee']['domain'].should == [ { :name => 'local' } ]
444
- end
445
-
446
- it 'should return domain as a single element list with a name if a single non-empty domain was specified' do
447
- WhiskeyDisk::Config.load_data['foo']['abc']['domain'].should == [ { :name => 'what@example.com' } ]
448
- end
449
-
450
- it 'should handle single specified domains across all projects and targets' do
451
- WhiskeyDisk::Config.load_data['zyx']['abc']['domain'].should == [ { :name => 'what@example.com' } ]
452
- end
453
-
454
- it 'should return the list of domain name hashes when a list of domains is specified' do
455
- WhiskeyDisk::Config.load_data['foo']['baz']['domain'].should == [
456
- { :name => 'bar@example.com' }, { :name => 'baz@domain.com' }
457
- ]
458
- end
459
-
460
- it 'should handle lists of domains across all projects and targets' do
461
- WhiskeyDisk::Config.load_data['zyx']['hij']['domain'].should == [
462
- { :name => 'bar@example.com' }, { :name => 'baz@domain.com' }
463
- ]
464
- end
465
-
466
- it 'should replace any nil domains with "local" domains in a domain list' do
467
- WhiskeyDisk::Config.load_data['foo']['bar']['domain'].should == [
468
- { :name => 'user@example.com' }, { :name => 'local' }, { :name => 'foo@domain.com' }
469
- ]
470
- end
471
-
472
- it 'should handle localizing nils across all projects and targets' do
473
- WhiskeyDisk::Config.load_data['zyx']['def']['domain'].should == [
474
- { :name => 'user@example.com' }, { :name => 'local' }, { :name => 'foo@domain.com' }
475
- ]
476
- end
477
-
478
- it 'should replace any blank domains with "local" domains in a domain list' do
479
- WhiskeyDisk::Config.load_data['foo']['bat']['domain'].should == [
480
- { :name => 'user@example.com' }, { :name => 'foo@domain.com' }, { :name => 'local' }
481
- ]
482
- end
483
-
484
- it 'should handle localizing blanks across all projects and targets' do
485
- WhiskeyDisk::Config.load_data['zyx']['dex']['domain'].should == [
486
- { :name => 'user@example.com' }, { :name => 'foo@domain.com' }, { :name => 'local' }
487
- ]
488
- end
489
-
490
- it 'should not include roles when only nil, blank or empty roles lists are specified' do
491
- WhiskeyDisk::Config.load_data['foo']['erl']['domain'].should == [
492
- { :name => 'bar@example.com' }, { :name => 'baz@domain.com' }, { :name => 'aok@domain.com' }
493
- ]
494
- end
495
-
496
- it 'should handle filtering empty roles across all projects and targets ' do
497
- WhiskeyDisk::Config.load_data['zyx']['erl']['domain'].should == [
498
- { :name => 'bar@example.com' }, { :name => 'baz@domain.com' }, { :name => 'aok@domain.com' }
499
- ]
500
- end
501
-
502
- it 'should include and normalize roles when specified as strings or lists' do
503
- WhiskeyDisk::Config.load_data['foo']['rol']['domain'].should == [
504
- { :name => 'bar@example.com', :roles => [ 'web', 'db' ] },
505
- { :name => 'baz@domain.com', :roles => [ 'db' ] },
506
- { :name => 'aok@domain.com', :roles => [ 'app' ] }
507
- ]
508
- end
509
-
510
- it 'should handle normalizing roles across all projects and targets ' do
511
- WhiskeyDisk::Config.load_data['zyx']['rol']['domain'].should == [
512
- { :name => 'bar@example.com', :roles => [ 'web', 'db' ] },
513
- { :name => 'baz@domain.com', :roles => [ 'db' ] },
514
- { :name => 'aok@domain.com', :roles => [ 'app' ] }
515
- ]
516
- end
517
-
518
- it 'should respect empty domains among role data' do
519
- WhiskeyDisk::Config.load_data['foo']['wow']['domain'].should == [
520
- { :name => 'bar@example.com', :roles => [ 'web', 'db' ] },
521
- { :name => 'baz@domain.com', :roles => [ 'db' ] },
522
- { :name => 'local' },
523
- { :name => 'foo@bar.example.com' },
524
- { :name => 'aok@domain.com', :roles => [ 'app' ] }
525
- ]
526
- end
527
-
528
- it 'should handle empty domain filtering among roles across all projects and targets' do
529
- WhiskeyDisk::Config.load_data['zyx']['wow']['domain'].should == [
530
- { :name => 'bar@example.com', :roles => [ 'web', 'db' ] },
531
- { :name => 'baz@domain.com', :roles => [ 'db' ] },
532
- { :name => 'local' },
533
- { :name => 'foo@bar.example.com' },
534
- { :name => 'aok@domain.com', :roles => [ 'app' ] }
535
- ]
536
- end
537
-
538
- it 'should raise an exception if a domain appears more than once in a target' do
539
- write_config_file(
540
- 'foo' => {
541
- 'erl' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => nil },
542
- { 'name' => 'baz@domain.com', 'roles' => '' },
543
- { 'name' => 'bar@example.com', 'roles' => [] } ]},
544
- }
545
- )
546
-
547
- lambda { WhiskeyDisk::Config.load_data }.should.raise
548
-
549
- end
550
- end
551
- end
552
-
553
- describe 'normalizing YAML data from the configuration file' do
554
- before do
555
- ENV['to'] = @env = 'foo:staging'
556
-
557
- @bare_data = { 'repository' => 'git://foo/bar.git', 'domain' => [ { :name => 'ogc@ogtastic.com' } ] }
558
- @env_data = { 'staging' => @bare_data }
559
- @proj_data = { 'foo' => @env_data }
560
- end
561
-
562
- it 'should fail if the configuration data is not a hash' do
563
- lambda { WhiskeyDisk::Config.normalize_data([]) }.should.raise
564
- end
565
-
566
- describe 'when no project name is specified via ENV["to"]' do
567
- before do
568
- ENV['to'] = @env = 'staging'
569
- end
570
-
571
- it 'should return the original data if it has both project and environment scoping' do
572
- WhiskeyDisk::Config.normalize_data(@proj_data).should == @proj_data
573
- end
574
-
575
- describe 'when no project name is specified in the bare config hash' do
576
- it 'should return the original data wrapped in project scope, using a dummy project, if it has environment scoping but no project scoping' do
577
- WhiskeyDisk::Config.normalize_data(@env_data).should == { 'unnamed_project' => @env_data }
578
- end
579
-
580
- it 'should return the original data wrapped in a project scope, using a dummy project, and an environment scope if it has neither scoping' do
581
- WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'unnamed_project' => { 'staging' => @bare_data } }
582
- end
583
- end
584
-
585
- describe 'when a project name is specified in the bare config hash' do
586
- before do
587
- @bare_data['project'] = 'whiskey_disk'
588
- end
589
-
590
- it 'should return the original data wrapped in project scope if it has environment scoping but no project scoping' do
591
- WhiskeyDisk::Config.normalize_data(@env_data).should == { 'whiskey_disk' => @env_data }
592
- end
593
-
594
- it 'should return the original data wrapped in a project scope and an environment scope if it has neither scoping' do
595
- WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'whiskey_disk' => { 'staging' => @bare_data } }
596
- end
597
- end
598
- end
599
-
600
- describe 'when a project name is specified via ENV["to"]' do
601
- before do
602
- ENV['to'] = @env = 'whiskey_disk:staging'
603
- end
604
-
605
- describe 'when a project name is not specified in the bare config hash' do
606
- it 'should return the original data if it has both project and environment scoping' do
607
- WhiskeyDisk::Config.normalize_data(@proj_data).should == @proj_data
608
- end
609
-
610
- it 'should return the original data wrapped in project scope if it has environment scoping but no project scoping' do
611
- WhiskeyDisk::Config.normalize_data(@env_data).should == { 'whiskey_disk' => @env_data }
612
- end
613
-
614
- it 'should return the original data wrapped in a project scope and an environment scope if it has neither scoping' do
615
- WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'whiskey_disk' => { 'staging' => @bare_data } }
616
- end
617
- end
618
-
619
- describe 'when a project name is specified in the bare config hash' do
620
- before do
621
- @bare_data['project'] = 'whiskey_disk'
622
- end
623
-
624
- it 'should return the original data if it has both project and environment scoping' do
625
- WhiskeyDisk::Config.normalize_data(@proj_data).should == @proj_data
626
- end
627
-
628
- it 'should return the original data wrapped in project scope if it has environment scoping but no project scoping' do
629
- WhiskeyDisk::Config.normalize_data(@env_data).should == { 'whiskey_disk' => @env_data }
630
- end
631
-
632
- it 'should return the original data wrapped in a project scope and an environment scope if it has neither scoping' do
633
- WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'whiskey_disk' => { 'staging' => @bare_data } }
634
- end
635
- end
636
- end
385
+ @config.load_data.should == { 'repository' => 'x' }
386
+ end
637
387
  end
638
388
 
639
- describe 'computing the project name from a configuration hash' do
640
- it 'should return the project name from the ENV["to"] setting when it is available' do
389
+ describe 'computing the project name' do
390
+ it 'returns the project name from the ENV["to"] setting when it is available' do
641
391
  ENV['to'] = 'foo:staging'
642
- WhiskeyDisk::Config.project_name.should == 'foo'
392
+ @config.project_name.should == 'foo'
643
393
  end
644
394
 
645
- it 'should return "unnamed_project" when ENV["to"] is unset' do
395
+ it 'returns "unnamed_project" when ENV["to"] is unset' do
646
396
  ENV['to'] = ''
647
- WhiskeyDisk::Config.project_name.should == 'unnamed_project'
397
+ @config.project_name.should == 'unnamed_project'
648
398
  end
649
399
 
650
- it 'should return "unnamed_project" when no ENV["to"] project setting is available' do
400
+ it 'returns "unnamed_project" when no ENV["to"] project setting is available' do
651
401
  ENV['to'] = 'staging'
652
- WhiskeyDisk::Config.project_name.should == 'unnamed_project'
402
+ @config.project_name.should == 'unnamed_project'
653
403
  end
654
404
  end
655
405
 
@@ -687,67 +437,67 @@ describe WhiskeyDisk::Config do
687
437
  ENV['to'] = @env = 'foo:staging'
688
438
  end
689
439
 
690
- it 'should return the path to deploy/foo/<environment>.yml under the project base path if it exists' do
691
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy/foo/staging.yml"
440
+ it 'returns the path to deploy/foo/<environment>.yml under the project base path if it exists' do
441
+ @config.configuration_file.should == "#{@dir}/deploy/foo/staging.yml"
692
442
  end
693
443
 
694
- it 'should return the path to deploy/foo.yml under the project base path if it exists' do
444
+ it 'returns the path to deploy/foo.yml under the project base path if it exists' do
695
445
  File.unlink("#{@dir}/deploy/foo/staging.yml")
696
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy/foo.yml"
446
+ @config.configuration_file.should == "#{@dir}/deploy/foo.yml"
697
447
  end
698
448
 
699
- it 'should return the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
449
+ it 'returns the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
700
450
  File.unlink("#{@dir}/deploy/foo/staging.yml")
701
451
  File.unlink("#{@dir}/deploy/foo.yml")
702
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy/staging.yml"
452
+ @config.configuration_file.should == "#{@dir}/deploy/staging.yml"
703
453
  end
704
454
 
705
- it 'should return the path to a per-environment configuration file under the project base path if it exists' do
455
+ it 'returns the path to a per-environment configuration file under the project base path if it exists' do
706
456
  File.unlink("#{@dir}/deploy/foo/staging.yml")
707
457
  File.unlink("#{@dir}/deploy/foo.yml")
708
458
  File.unlink("#{@dir}/deploy/staging.yml")
709
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/staging.yml"
459
+ @config.configuration_file.should == "#{@dir}/staging.yml"
710
460
  end
711
461
 
712
- it 'should return the path to deploy.yml under the project base path' do
462
+ it 'returns the path to deploy.yml under the project base path' do
713
463
  File.unlink("#{@dir}/deploy/foo/staging.yml")
714
464
  File.unlink("#{@dir}/deploy/foo.yml")
715
465
  File.unlink("#{@dir}/deploy/staging.yml")
716
466
  File.unlink("#{@dir}/staging.yml")
717
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy.yml"
467
+ @config.configuration_file.should == "#{@dir}/deploy.yml"
718
468
  end
719
469
 
720
- it 'should fail if no per-environment config file nor deploy.yml exists under the project base path' do
470
+ it 'fails if no per-environment config file nor deploy.yml exists under the project base path' do
721
471
  File.unlink("#{@dir}/deploy/foo/staging.yml")
722
472
  File.unlink("#{@dir}/deploy/foo.yml")
723
473
  File.unlink("#{@dir}/deploy/staging.yml")
724
474
  File.unlink("#{@dir}/staging.yml")
725
475
  File.unlink("#{@dir}/deploy.yml")
726
- lambda { WhiskeyDisk::Config.configuration_file }.should.raise
476
+ lambda { @config.configuration_file }.should.raise
727
477
  end
728
478
  end
729
479
 
730
480
  describe 'and no project name is specified in ENV["to"]' do
731
- it 'should return the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
732
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy/staging.yml"
481
+ it 'returns the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
482
+ @config.configuration_file.should == "#{@dir}/deploy/staging.yml"
733
483
  end
734
484
 
735
- it 'should return the path to a per-environment configuration file under the project base path if it exists' do
485
+ it 'returns the path to a per-environment configuration file under the project base path if it exists' do
736
486
  File.unlink("#{@dir}/deploy/staging.yml")
737
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/staging.yml"
487
+ @config.configuration_file.should == "#{@dir}/staging.yml"
738
488
  end
739
489
 
740
- it 'should return the path to deploy.yml under the project base path' do
490
+ it 'returns the path to deploy.yml under the project base path' do
741
491
  File.unlink("#{@dir}/deploy/staging.yml")
742
492
  File.unlink("#{@dir}/staging.yml")
743
- WhiskeyDisk::Config.configuration_file.should == "#{@dir}/deploy.yml"
493
+ @config.configuration_file.should == "#{@dir}/deploy.yml"
744
494
  end
745
495
 
746
- it 'should fail if no per-environment config file nor deploy.yml exists under the project base path' do
496
+ it 'fails if no per-environment config file nor deploy.yml exists under the project base path' do
747
497
  File.unlink("#{@dir}/deploy/staging.yml")
748
498
  File.unlink("#{@dir}/staging.yml")
749
499
  File.unlink("#{@dir}/deploy.yml")
750
- lambda { WhiskeyDisk::Config.configuration_file }.should.raise
500
+ lambda { @config.configuration_file }.should.raise
751
501
  end
752
502
  end
753
503
  end
@@ -762,13 +512,13 @@ describe WhiskeyDisk::Config do
762
512
  FileUtils.rm_rf(@path)
763
513
  end
764
514
 
765
- it 'should fail if a path is specified which does not exist' do
766
- lambda { WhiskeyDisk::Config.configuration_file }.should.raise
515
+ it 'fails if a path is specified which does not exist' do
516
+ lambda { @config.configuration_file }.should.raise
767
517
  end
768
518
 
769
- it 'should return the file path when a path which points to an existing file is specified' do
519
+ it 'returns the file path when a path which points to an existing file is specified' do
770
520
  FileUtils.touch(@config_file)
771
- WhiskeyDisk::Config.configuration_file.should == @config_file
521
+ @config.configuration_file.should == @config_file
772
522
  end
773
523
  end
774
524
 
@@ -794,72 +544,135 @@ describe WhiskeyDisk::Config do
794
544
  ENV['to'] = @env = 'foo:staging'
795
545
  end
796
546
 
797
- it 'should return the path to deploy/foo/<environment>.yml under the project base path if it exists' do
798
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'foo' ,'staging.yml')
547
+ it 'returns the path to deploy/foo/<environment>.yml under the project base path if it exists' do
548
+ @config.configuration_file.should == File.join(@path, 'deploy', 'foo' ,'staging.yml')
799
549
  end
800
550
 
801
- it 'should return the path to deploy/foo.yml under the project base path if it exists' do
551
+ it 'returns the path to deploy/foo.yml under the project base path if it exists' do
802
552
  File.unlink(File.join(@path, 'deploy', 'foo', 'staging.yml'))
803
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'foo.yml')
553
+ @config.configuration_file.should == File.join(@path, 'deploy', 'foo.yml')
804
554
  end
805
555
 
806
- it 'should return the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
556
+ it 'returns the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
807
557
  File.unlink(File.join(@path, 'deploy', 'foo', 'staging.yml'))
808
558
  File.unlink(File.join(@path, 'deploy', 'foo.yml'))
809
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
559
+ @config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
810
560
  end
811
561
 
812
- it 'should return the path to a per-environment configuration file in the path specified if that file exists' do
562
+ it 'returns the path to a per-environment configuration file in the path specified if that file exists' do
813
563
  File.unlink(File.join(@path, 'deploy', 'foo', 'staging.yml'))
814
564
  File.unlink(File.join(@path, 'deploy', 'foo.yml'))
815
565
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
816
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'staging.yml')
566
+ @config.configuration_file.should == File.join(@path, 'staging.yml')
817
567
  end
818
568
 
819
- it 'should return the path to deploy.yaml in the path specified if deploy.yml exists' do
569
+ it 'returns the path to deploy.yaml in the path specified if deploy.yml exists' do
820
570
  File.unlink(File.join(@path, 'deploy', 'foo', 'staging.yml'))
821
571
  File.unlink(File.join(@path, 'deploy', 'foo.yml'))
822
572
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
823
573
  File.unlink(File.join(@path, 'staging.yml'))
824
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy.yml')
574
+ @config.configuration_file.should == File.join(@path, 'deploy.yml')
825
575
  end
826
576
 
827
- it 'should fail if no per-environment configuration file nor deploy.yml exists in the path specified' do
577
+ it 'fails if no per-environment configuration file nor deploy.yml exists in the path specified' do
828
578
  File.unlink(File.join(@path, 'deploy', 'foo', 'staging.yml'))
829
579
  File.unlink(File.join(@path, 'deploy', 'foo.yml'))
830
580
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
831
581
  File.unlink(File.join(@path, 'staging.yml'))
832
582
  File.unlink(File.join(@path, 'deploy.yml'))
833
- lambda { WhiskeyDisk::Config.configuration_file }.should.raise
583
+ lambda { @config.configuration_file }.should.raise
834
584
  end
835
585
  end
836
586
 
837
587
  describe 'and no project name is specified in ENV["to"]' do
838
- it 'should return the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
839
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
588
+ it 'returns the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
589
+ @config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
840
590
  end
841
591
 
842
- it 'should return the path to a per-environment configuration file in the path specified if that file exists' do
592
+ it 'returns the path to a per-environment configuration file in the path specified if that file exists' do
843
593
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
844
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'staging.yml')
594
+ @config.configuration_file.should == File.join(@path, 'staging.yml')
845
595
  end
846
596
 
847
- it 'should return the path to deploy.yaml in the path specified if deploy.yml exists' do
597
+ it 'returns the path to deploy.yaml in the path specified if deploy.yml exists' do
848
598
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
849
599
  File.unlink(File.join(@path, 'staging.yml'))
850
- WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy.yml')
600
+ @config.configuration_file.should == File.join(@path, 'deploy.yml')
851
601
  end
852
602
 
853
- it 'should fail if no per-environment configuration file nor deploy.yml exists in the path specified' do
603
+ it 'fails if no per-environment configuration file nor deploy.yml exists in the path specified' do
854
604
  File.unlink(File.join(@path, 'deploy', 'staging.yml'))
855
605
  File.unlink(File.join(@path, 'staging.yml'))
856
606
  File.unlink(File.join(@path, 'deploy.yml'))
857
- lambda { WhiskeyDisk::Config.configuration_file }.should.raise
607
+ lambda { @config.configuration_file }.should.raise
858
608
  end
859
609
  end
860
610
  end
861
611
  end
862
612
 
613
+ describe 'filtering configuration data' do
614
+ before do
615
+ ENV['to'] = @env = 'foo:erl'
616
+ @data = {
617
+ 'foo' => {
618
+ 'xyz' => { 'repository' => 'x' },
619
+ 'eee' => { 'repository' => 'x', 'domain' => '' },
620
+ 'abc' => { 'repository' => 'x', 'domain' => 'what@example.com' },
621
+ 'baz' => { 'repository' => 'x', 'domain' => [ 'bar@example.com', 'baz@domain.com' ]},
622
+ 'bar' => { 'repository' => 'x', 'domain' => [ 'user@example.com', nil, 'foo@domain.com' ]},
623
+ 'bat' => { 'repository' => 'x', 'domain' => [ 'user@example.com', 'foo@domain.com', '' ]},
624
+ 'hsh' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, { 'name' => 'baz@domain.com' } ]},
625
+ 'mix' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, 'baz@domain.com' ]},
626
+ 'erl' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => nil },
627
+ { 'name' => 'baz@domain.com', 'roles' => '' },
628
+ { 'name' => 'aok@domain.com', 'roles' => [] } ]},
629
+ 'rol' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
630
+ { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
631
+ { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
632
+ 'wow' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
633
+ { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
634
+ '', 'foo@bar.example.com',
635
+ { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
636
+ },
637
+
638
+ 'zyx' => {
639
+ 'xyz' => { 'repository' => 'x' },
640
+ 'eee' => { 'repository' => 'x', 'domain' => '' },
641
+ 'abc' => { 'repository' => 'x', 'domain' => 'what@example.com' },
642
+ 'hij' => { 'repository' => 'x', 'domain' => [ 'bar@example.com', 'baz@domain.com' ]},
643
+ 'def' => { 'repository' => 'x', 'domain' => [ 'user@example.com', nil, 'foo@domain.com' ]},
644
+ 'dex' => { 'repository' => 'x', 'domain' => [ 'user@example.com', 'foo@domain.com', '' ]},
645
+ 'hsh' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, { 'name' => 'baz@domain.com' } ]},
646
+ 'mix' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com' }, 'baz@domain.com' ]},
647
+ 'erl' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => nil },
648
+ { 'name' => 'baz@domain.com', 'roles' => '' },
649
+ { 'name' => 'aok@domain.com', 'roles' => [] } ]},
650
+ 'rol' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
651
+ { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
652
+ { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
653
+ 'wow' => { 'repository' => 'x', 'domain' => [ { 'name' => 'bar@example.com', 'roles' => [ 'web', 'db' ] },
654
+ { 'name' => 'baz@domain.com', 'roles' => [ 'db' ] },
655
+ '', 'foo@bar.example.com',
656
+ { 'name' => 'aok@domain.com', 'roles' => 'app' } ]},
657
+ }
658
+ }
659
+ end
660
+
661
+ it 'should apply all available filters' do
662
+ @config.filter_data(@data).should == {
663
+ "repository" => "x",
664
+ "project" => "foo",
665
+ "config_target" => "erl",
666
+ "environment" => "erl",
667
+ "domain" => [
668
+ { 'name' => "bar@example.com" },
669
+ { 'name' => "baz@domain.com" },
670
+ { 'name' => "aok@domain.com" }
671
+ ]
672
+ }
673
+ end
674
+ end
675
+
863
676
  describe 'computing the base path for the project' do
864
677
  before do
865
678
  @original_path = Dir.pwd
@@ -881,12 +694,12 @@ describe WhiskeyDisk::Config do
881
694
  Dir.chdir(@original_path)
882
695
  end
883
696
 
884
- it 'should return the path set in the "path" environment variable' do
885
- WhiskeyDisk::Config.base_path.should == @path
697
+ it 'returns the path set in the "path" environment variable' do
698
+ @config.base_path.should == @path
886
699
  end
887
700
 
888
- it 'should leave the current working path the same as when the base path lookup started' do
889
- WhiskeyDisk::Config.base_path
701
+ it 'leaves the current working path the same as when the base path lookup started' do
702
+ @config.base_path
890
703
  Dir.pwd.should == @original_path
891
704
  end
892
705
  end
@@ -903,13 +716,13 @@ describe WhiskeyDisk::Config do
903
716
  FileUtils.rm_rf(@path)
904
717
  end
905
718
 
906
- it 'should return the config directory under the current directory if there is no Rakefile along the root path to the current directory' do
907
- WhiskeyDisk::Config.base_path.should == File.join(@path, 'config')
719
+ it 'returns the config directory under the current directory if there is no Rakefile along the root path to the current directory' do
720
+ @config.base_path.should == File.join(@path, 'config')
908
721
  end
909
722
 
910
- it 'should leave the current working path the same as when the base path lookup started' do
723
+ it 'leaves the current working path the same as when the base path lookup started' do
911
724
  prior = Dir.pwd
912
- WhiskeyDisk::Config.base_path
725
+ @config.base_path
913
726
  Dir.pwd.should == prior
914
727
  end
915
728
  end
@@ -928,12 +741,12 @@ describe WhiskeyDisk::Config do
928
741
  end
929
742
 
930
743
  it 'return the config directory in the nearest enclosing path with a Rakefile along the root path to the current directory' do
931
- WhiskeyDisk::Config.base_path.should == File.join(@path, 'config')
744
+ @config.base_path.should == File.join(@path, 'config')
932
745
  end
933
746
 
934
- it 'should leave the current working path the same as when the base path lookup started' do
747
+ it 'leaves the current working path the same as when the base path lookup started' do
935
748
  prior = Dir.pwd
936
- WhiskeyDisk::Config.base_path
749
+ @config.base_path
937
750
  Dir.pwd.should == prior
938
751
  end
939
752
  end