statistrano 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/changelog.md +161 -0
  3. data/doc/config/file-permissions.md +33 -0
  4. data/doc/config/log-files.md +32 -0
  5. data/doc/config/task-definitions.md +88 -0
  6. data/doc/getting-started.md +96 -0
  7. data/doc/strategies/base.md +38 -0
  8. data/doc/strategies/branches.md +82 -0
  9. data/doc/strategies/releases.md +110 -0
  10. data/doc/strategies.md +17 -0
  11. data/lib/statistrano/config/configurable.rb +53 -0
  12. data/lib/statistrano/config/rake_task_with_context_creation.rb +43 -0
  13. data/lib/statistrano/config.rb +52 -0
  14. data/lib/statistrano/deployment/log_file.rb +44 -0
  15. data/lib/statistrano/deployment/manifest.rb +88 -0
  16. data/lib/statistrano/deployment/rake_tasks.rb +74 -0
  17. data/lib/statistrano/deployment/registerable.rb +11 -0
  18. data/lib/statistrano/deployment/releaser/revisions.rb +163 -0
  19. data/lib/statistrano/deployment/releaser/single.rb +48 -0
  20. data/lib/statistrano/deployment/releaser.rb +2 -0
  21. data/lib/statistrano/deployment/strategy/base.rb +132 -0
  22. data/lib/statistrano/deployment/strategy/branches/index/template.html.erb +78 -0
  23. data/lib/statistrano/deployment/strategy/branches/index.rb +40 -0
  24. data/lib/statistrano/deployment/strategy/branches/release.rb +73 -0
  25. data/lib/statistrano/deployment/strategy/branches.rb +198 -0
  26. data/lib/statistrano/deployment/strategy/check_git.rb +43 -0
  27. data/lib/statistrano/deployment/strategy/invoke_tasks.rb +58 -0
  28. data/lib/statistrano/deployment/strategy/releases.rb +76 -0
  29. data/lib/statistrano/deployment/strategy.rb +37 -0
  30. data/lib/statistrano/deployment.rb +10 -0
  31. data/lib/statistrano/log/default_logger.rb +105 -0
  32. data/lib/statistrano/log.rb +33 -0
  33. data/lib/statistrano/remote/file.rb +79 -0
  34. data/lib/statistrano/remote.rb +111 -0
  35. data/lib/statistrano/shell.rb +17 -0
  36. data/lib/statistrano/util/file_permissions.rb +34 -0
  37. data/lib/statistrano/util.rb +27 -0
  38. data/lib/statistrano/version.rb +3 -0
  39. data/lib/statistrano.rb +55 -0
  40. data/readme.md +247 -0
  41. data/spec/integration_tests/base_integration_spec.rb +103 -0
  42. data/spec/integration_tests/branches_integration_spec.rb +189 -0
  43. data/spec/integration_tests/releases/deploy_integration_spec.rb +116 -0
  44. data/spec/integration_tests/releases/list_releases_integration_spec.rb +38 -0
  45. data/spec/integration_tests/releases/prune_releases_integration_spec.rb +86 -0
  46. data/spec/integration_tests/releases/rollback_release_integration_spec.rb +46 -0
  47. data/spec/lib/statistrano/config/configurable_spec.rb +88 -0
  48. data/spec/lib/statistrano/config/rake_task_with_context_creation_spec.rb +73 -0
  49. data/spec/lib/statistrano/config_spec.rb +34 -0
  50. data/spec/lib/statistrano/deployment/log_file_spec.rb +75 -0
  51. data/spec/lib/statistrano/deployment/manifest_spec.rb +171 -0
  52. data/spec/lib/statistrano/deployment/rake_tasks_spec.rb +107 -0
  53. data/spec/lib/statistrano/deployment/registerable_spec.rb +19 -0
  54. data/spec/lib/statistrano/deployment/releaser/revisions_spec.rb +486 -0
  55. data/spec/lib/statistrano/deployment/releaser/single_spec.rb +59 -0
  56. data/spec/lib/statistrano/deployment/strategy/base_spec.rb +158 -0
  57. data/spec/lib/statistrano/deployment/strategy/branches_spec.rb +19 -0
  58. data/spec/lib/statistrano/deployment/strategy/check_git_spec.rb +39 -0
  59. data/spec/lib/statistrano/deployment/strategy/invoke_tasks_spec.rb +66 -0
  60. data/spec/lib/statistrano/deployment/strategy/releases_spec.rb +257 -0
  61. data/spec/lib/statistrano/deployment/strategy_spec.rb +76 -0
  62. data/spec/lib/statistrano/deployment_spec.rb +4 -0
  63. data/spec/lib/statistrano/log/default_logger_spec.rb +172 -0
  64. data/spec/lib/statistrano/log_spec.rb +36 -0
  65. data/spec/lib/statistrano/remote/file_spec.rb +166 -0
  66. data/spec/lib/statistrano/remote_spec.rb +226 -0
  67. data/spec/lib/statistrano/util/file_permissions_spec.rb +25 -0
  68. data/spec/lib/statistrano/util_spec.rb +23 -0
  69. data/spec/lib/statistrano_spec.rb +52 -0
  70. data/spec/spec_helper.rb +86 -0
  71. data/spec/support/given.rb +39 -0
  72. metadata +223 -0
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy::Base do
4
+
5
+ it "is registered as :base" do
6
+ expect( Statistrano::Deployment::Strategy.find(:base) ).to eq described_class
7
+ end
8
+
9
+ describe "#initialize" do
10
+ it "sets name to given name" do
11
+ subject = described_class.new "hello"
12
+ expect( subject.name ).to eq "hello"
13
+ end
14
+ end
15
+
16
+ describe "#deploy" do
17
+
18
+ before :each do
19
+ @remote = instance_double("Statistrano::Remote").as_null_object
20
+ @releaser = instance_double("Statistrano::Deployment::Releaser::Revisions").as_null_object
21
+ allow( Statistrano::Remote ).to receive(:new)
22
+ .and_return(@remote)
23
+ allow( Statistrano::Deployment::Releaser::Single ).to receive(:new)
24
+ .and_return(@releaser)
25
+ @subject = define_deployment "base", :base do
26
+ remote_dir "/tmp"
27
+ local_dir "/tmp"
28
+ hostname "localhost"
29
+ build_task { "empty block" }
30
+ end
31
+ end
32
+
33
+ context "when check_git is set to true" do
34
+ it "runs `safe_to_deploy? (and exits if false)" do
35
+ subject = define_deployment "base", :base do
36
+ check_git true
37
+ git_branch 'master'
38
+ end
39
+
40
+ expect( subject ).to receive(:safe_to_deploy?)
41
+ .and_return( false )
42
+
43
+ expect{
44
+ subject.deploy
45
+ }.to raise_error SystemExit
46
+ end
47
+
48
+ it "will exit if build changes checked in files" do
49
+ subject = define_deployment "base", :base do
50
+ check_git true
51
+ git_branch 'master'
52
+
53
+ build_task do
54
+ # no-op
55
+ end
56
+ end
57
+
58
+ expect( subject ).to receive(:safe_to_deploy?)
59
+ .and_return( true, false ) # simulate git being clear
60
+ # before the build task, but not
61
+ # after
62
+
63
+ expect{
64
+ subject.deploy
65
+ }.to raise_error SystemExit
66
+ end
67
+ end
68
+
69
+ it "runs `invoke_build_task`" do
70
+ expect( @subject ).to receive(:invoke_build_task)
71
+ @subject.deploy
72
+ end
73
+
74
+ it "calls create_release for the releaser" do
75
+ expect( @releaser ).to receive(:create_release)
76
+ .with( @remote, {} )
77
+
78
+ @subject.deploy
79
+ end
80
+
81
+ it "calls the post_deploy_task" do
82
+ expect( @subject ).to receive(:invoke_post_deploy_task)
83
+ @subject.deploy
84
+ end
85
+
86
+ context "when log_file_path is set" do
87
+
88
+ before :each do
89
+ @subject = define_deployment "base", :base do
90
+ remote_dir "/tmp"
91
+ local_dir "/tmp"
92
+ hostname "localhost"
93
+ build_task do
94
+ { build_task: 'data' }
95
+ end
96
+ post_deploy_task do
97
+ { post_deploy_task: 'data' }
98
+ end
99
+
100
+ log_file_path '/log/path'
101
+ log_file_entry do |dep, rel, build_data, post_deploy_data|
102
+ {
103
+ log: 'entry',
104
+ }.merge( build_data ).merge( post_deploy_data )
105
+ end
106
+ end
107
+ end
108
+
109
+ it "should create a Remote::File for the log & append log_file_entry to it" do
110
+ log_file_double = instance_double("Statistrano::Remote::File")
111
+ expect( Statistrano::Remote::File ).to receive(:new)
112
+ .with('/log/path', @remote)
113
+ .and_return( log_file_double )
114
+ expect( log_file_double ).to receive(:append_content!)
115
+ .with('{"log":"entry","build_task":"data","post_deploy_task":"data"}')
116
+
117
+ @subject.deploy
118
+ end
119
+ end
120
+
121
+ context "when log_file_path isn't set" do
122
+ it "doesn't create a log file" do
123
+ expect( Statistrano::Remote::File ).not_to receive(:new)
124
+ @subject.deploy
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#persited_releaser" do
130
+ it "returns same object each time it's called" do
131
+ subject = define_deployment "base", :base do
132
+ remote_dir "/tmp"
133
+ local_dir "/tmp"
134
+ hostname "localhost"
135
+ build_task { "empty block" }
136
+ end
137
+
138
+ expect( subject.persisted_releaser ).to eq subject.persisted_releaser
139
+ end
140
+ end
141
+
142
+ describe "#flush_persisted_releaser!" do
143
+ it "removes the persisted_releaser" do
144
+ subject = define_deployment "base", :base do
145
+ remote_dir "/tmp"
146
+ local_dir "/tmp"
147
+ hostname "localhost"
148
+ build_task { "empty block" }
149
+ end
150
+
151
+ first_releaser = subject.persisted_releaser
152
+ subject.flush_persisted_releaser!
153
+
154
+ expect( subject.persisted_releaser ).not_to eq first_releaser
155
+ end
156
+ end
157
+
158
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy::Branches do
4
+
5
+ describe "#new" do
6
+ it "creates a deployment with a name" do
7
+ deployment = described_class.new("name")
8
+ expect( deployment.name ).to eq "name"
9
+ end
10
+
11
+ it "respects the default configs" do
12
+ allow( Asgit ).to receive(:current_branch).and_return('first_branch')
13
+ deployment = described_class.new("name")
14
+
15
+ expect( deployment.config.public_dir ).to eq "first_branch"
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy::CheckGit do
4
+
5
+ before :each do
6
+ class Subject
7
+ include Statistrano::Deployment::Strategy::CheckGit
8
+
9
+ def config
10
+ Struct.new(:check_git,:git_branch).new(true,'master')
11
+ end
12
+ end
13
+
14
+ allow( Asgit ).to receive(:working_tree_clean?).and_return(true)
15
+ allow( Asgit ).to receive(:current_branch).and_return('master')
16
+ allow( Asgit ).to receive(:remote_up_to_date?).and_return(true)
17
+ end
18
+
19
+ let(:subject) { Subject.new }
20
+
21
+ describe "#safe_to_deploy?" do
22
+ it "is false if the working_tree is dirty" do
23
+ allow( Asgit ).to receive(:working_tree_clean?).and_return(false)
24
+ expect( subject.safe_to_deploy? ).to be_falsy
25
+ end
26
+ it "is false if the current_branch does not match set branch" do
27
+ allow( Asgit ).to receive(:current_branch).and_return('not_master')
28
+ expect( subject.safe_to_deploy? ).to be_falsy
29
+ end
30
+ it "is false if out of sync with remote" do
31
+ allow( Asgit ).to receive(:remote_up_to_date?).and_return(false)
32
+ expect( subject.safe_to_deploy? ).to be_falsy
33
+ end
34
+ it "is true if working_tree is clean, on correct branch, and in sync with remote" do
35
+ expect( subject.safe_to_deploy? ).to be_truthy
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy::InvokeTasks do
4
+
5
+ before :each do
6
+ class InvokeTasksSubject
7
+ include Statistrano::Deployment::Strategy::InvokeTasks
8
+
9
+ def config; end
10
+ end
11
+ end
12
+
13
+ let(:subject) { InvokeTasksSubject.new }
14
+
15
+ describe "#invoke_post_deploy_task" do
16
+ it "calls_or_invokes the post_deploy_task" do
17
+ allow( subject ).to receive_message_chain(:config, :post_deploy_task)
18
+ .and_return "foo"
19
+ expect( subject ).to receive(:call_or_invoke_task).with "foo"
20
+ subject.invoke_post_deploy_task
21
+ end
22
+ end
23
+
24
+ describe "#invoke_build_task" do
25
+ it "calls_or_invokes the build_task" do
26
+ allow( subject ).to receive_message_chain(:config, :build_task)
27
+ .and_return "foo"
28
+ expect( subject ).to receive(:call_or_invoke_task).with "foo"
29
+ subject.invoke_build_task
30
+ end
31
+ end
32
+
33
+ describe "#call_or_invoke_task" do
34
+ it "calls the task if it is a proc" do
35
+ expect( subject.call_or_invoke_task( -> { "hello" } ) ).to eq "hello"
36
+ end
37
+
38
+ it "passes self as the arg if proc has arity of 1" do
39
+ task = Proc.new { |s| expect(s).to(eq(subject)) }
40
+ subject.call_or_invoke_task(task)
41
+ end
42
+
43
+ it "invokes a rake task if it is a string" do
44
+ rake_double = double("Rake::Task")
45
+ expect( Rake::Task ).to receive(:[])
46
+ .with("hello")
47
+ .and_return( rake_double )
48
+ expect( rake_double ).to receive(:invoke)
49
+
50
+ subject.call_or_invoke_task("hello")
51
+ end
52
+
53
+ it "catches exceptions and then aborts" do
54
+ proc_raises_exception = -> { raise Exception, "ermagerd" }
55
+
56
+ expect( Statistrano::Log ).to receive(:error)
57
+ .with "exiting due to error in task",
58
+ "Exception: ermagerd"
59
+
60
+ expect {
61
+ subject.call_or_invoke_task(proc_raises_exception)
62
+ }.to raise_error SystemExit
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,257 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy::Releases do
4
+
5
+ it "is registered as :releases" do
6
+ expect( Statistrano::Deployment::Strategy.find(:releases) ).to eq described_class
7
+ end
8
+
9
+ describe "#remotes" do
10
+
11
+ let(:default_options) do
12
+ {
13
+ remote_dir: nil,
14
+ local_dir: nil,
15
+ hostname: nil,
16
+ user: nil,
17
+ password: nil,
18
+ keys: nil,
19
+ forward_agent: nil,
20
+ verbose: false,
21
+ build_task: nil,
22
+ check_git: nil,
23
+ git_branch: nil,
24
+ repo_url: nil,
25
+ post_deploy_task: nil,
26
+ dir_permissions: 755,
27
+ file_permissions: 644,
28
+ rsync_flags: '-aqz --delete-after',
29
+ pre_symlink_task: nil,
30
+ release_count: 5,
31
+ release_dir: "releases",
32
+ public_dir: "current",
33
+ log_file_path: nil,
34
+ log_file_entry: nil
35
+ }
36
+ end
37
+
38
+ it "returns remotes cache if set" do
39
+ subject = described_class.new 'multi'
40
+ subject.instance_variable_set(:@_remotes, 'remotes')
41
+
42
+ expect( subject.remotes ).to eq 'remotes'
43
+ end
44
+
45
+ it "sets remote cache with results" do
46
+ allow( Statistrano::Remote ).to receive(:new)
47
+ subject = described_class.new 'multi'
48
+ remotes = subject.remotes
49
+
50
+ expect( remotes ).not_to be_nil
51
+ expect( subject.instance_variable_get(:@_remotes) ).to eq remotes
52
+ end
53
+
54
+ it "initializes a Remote with each remote" do
55
+ deployment = define_deployment "multi", :releases do
56
+ remotes [
57
+ { hostname: 'web01' },
58
+ { hostname: 'web02' }
59
+ ]
60
+ end
61
+
62
+ expect( Statistrano::Remote ).to receive(:new).exactly(2).times
63
+ deployment.remotes
64
+ end
65
+
66
+ it "merges remote data with global data" do
67
+ deployment = define_deployment "multi", :releases do
68
+ remote_dir "remote_dir"
69
+ remotes [
70
+ { hostname: 'web01', remote_dir: 'web01_remote_dir' }
71
+ ]
72
+ end
73
+
74
+ config_double = instance_double("Statistrano::Config")
75
+ expect( Statistrano::Config ).to receive(:new)
76
+ .with(default_options.merge({remotes: [{hostname: 'web01', remote_dir: 'web01_remote_dir'}]})
77
+ .merge(hostname: 'web01', remote_dir: 'web01_remote_dir'))
78
+ .and_return(config_double)
79
+ expect( Statistrano::Remote ).to receive(:new)
80
+ .with(config_double)
81
+ deployment.remotes
82
+ end
83
+ end
84
+
85
+ describe "#deploy" do
86
+ context "when check_git is set to true" do
87
+ it "runs `safe_to_deploy? (and exits if false)" do
88
+ subject = define_deployment "multi", :releases do
89
+ check_git true
90
+ git_branch 'master'
91
+ end
92
+
93
+ expect( subject ).to receive(:safe_to_deploy?)
94
+ .and_return( false )
95
+
96
+ expect{
97
+ subject.deploy
98
+ }.to raise_error SystemExit
99
+ end
100
+ end
101
+
102
+ context "when build task is defined as a Proc" do
103
+ context "when build task returns hash" do
104
+ it "passes hash to build" do
105
+ subject = define_deployment "multi", :releases do
106
+ build_task do
107
+ {foo: 'bar'}
108
+ end
109
+ remotes [{one: 'two'}]
110
+ end
111
+ remote = instance_double("Statistrano::Remote")
112
+ releaser = instance_double("Statistrano::Deployment::Releaser::Revisions")
113
+ allow( Statistrano::Remote ).to receive(:new)
114
+ .and_return(remote)
115
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
116
+ .and_return(releaser)
117
+
118
+ expect( releaser ).to receive(:create_release)
119
+ .with( remote, {foo: 'bar'} )
120
+
121
+ subject.deploy
122
+ end
123
+ end
124
+
125
+ context "when build task returns foo" do
126
+ it "passes a blank hash to create_release" do
127
+ subject = define_deployment "multi", :releases do
128
+ build_task do
129
+ 'foo'
130
+ end
131
+ remotes [{one: 'two'}]
132
+ end
133
+ remote = instance_double("Statistrano::Remote")
134
+ releaser = instance_double("Statistrano::Deployment::Releaser::Revisions")
135
+ allow( Statistrano::Remote ).to receive(:new)
136
+ .and_return(remote)
137
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
138
+ .and_return(releaser)
139
+
140
+ expect( releaser ).to receive(:create_release)
141
+ .with( remote, {} )
142
+
143
+ subject.deploy
144
+ end
145
+ end
146
+ end
147
+
148
+ it "runs create_release for each remote" do
149
+ @subject = define_deployment "multi", :releases do
150
+ build_task 'nil:bar'
151
+ post_deploy_task 'foo:bar'
152
+ remotes [{remote: 'one'},{remote: 'two'}]
153
+ end
154
+ task_double = double(invoke: nil)
155
+ allow( Rake::Task ).to receive(:[])
156
+ .and_return(task_double)
157
+
158
+ remote = instance_double("Statistrano::Remote")
159
+ releaser = instance_double("Statistrano::Deployment::Releaser::Revisions")
160
+ allow( Statistrano::Remote ).to receive(:new)
161
+ .and_return(remote)
162
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
163
+ .and_return(releaser)
164
+
165
+ expect( releaser ).to receive(:create_release)
166
+ .with(remote, {}).twice
167
+ @subject.deploy
168
+ end
169
+
170
+ context "when post_deploy_task is a proc" do
171
+ it "calls the post_deploy_task task" do
172
+ allow( Statistrano::Remote ).to receive(:new)
173
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
174
+ .and_return( double("Statistrano::Deployment::Releaser::Revisions").as_null_object )
175
+ subject = define_deployment "multi", :releases
176
+ task_double = -> {}
177
+ config = double("Statistrano::Config", build_task: -> {},
178
+ check_git: false,
179
+ options: { remotes: [] },
180
+ post_deploy_task: task_double,
181
+ log_file_path: nil)
182
+ allow( subject ).to receive(:config).and_return(config)
183
+
184
+ expect( task_double ).to receive(:call)
185
+ subject.deploy
186
+ end
187
+ end
188
+
189
+ context "when post_deploy_task is a string" do
190
+ it "invokes the post_deploy_task once" do
191
+ allow( Statistrano::Remote ).to receive(:new)
192
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
193
+ .and_return( double("Statistrano::Deployment::Releaser::Revisions").as_null_object )
194
+ @subject = define_deployment "multi", :releases do
195
+ build_task 'nil:bar'
196
+ post_deploy_task 'foo:bar'
197
+ end
198
+
199
+ task_double = double(invoke: nil)
200
+ post_task_double = double
201
+ allow( Rake::Task ).to receive(:[]).with('nil:bar')
202
+ .and_return(task_double)
203
+ expect( Rake::Task ).to receive(:[]).with('foo:bar')
204
+ .and_return(post_task_double)
205
+ expect( post_task_double ).to receive(:invoke).once
206
+
207
+ @subject.deploy
208
+ end
209
+ end
210
+ end
211
+
212
+ describe "#rollback_release" do
213
+ it "calls rollback_release on each remote" do
214
+ subject = define_deployment "multi", :releases do
215
+ build_task 'nil:bar'
216
+ post_deploy_task 'foo:bar'
217
+ remotes [{remote: 'one'},{remote: 'two'}]
218
+ end
219
+
220
+ remote = instance_double("Statistrano::Remote")
221
+ releaser = instance_double("Statistrano::Deployment::Releaser::Revisions")
222
+ allow( Statistrano::Remote ).to receive(:new)
223
+ .and_return(remote)
224
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
225
+ .and_return(releaser)
226
+
227
+ expect( releaser ).to receive(:rollback_release)
228
+ .with(remote).twice
229
+ subject.rollback_release
230
+ end
231
+ end
232
+
233
+ describe "#prune_releases" do
234
+ it "calls prune_releases on each remote" do
235
+ subject = define_deployment "multi", :releases do
236
+ build_task 'nil:bar'
237
+ post_deploy_task 'foo:bar'
238
+ remotes [{remote: 'one'},{remote: 'two'}]
239
+ end
240
+
241
+ remote = instance_double("Statistrano::Remote")
242
+ releaser = instance_double("Statistrano::Deployment::Releaser::Revisions")
243
+ allow( Statistrano::Remote ).to receive(:new)
244
+ .and_return(remote)
245
+ allow( Statistrano::Deployment::Releaser::Revisions ).to receive(:new)
246
+ .and_return(releaser)
247
+
248
+ expect( releaser ).to receive(:prune_releases)
249
+ .with(remote).twice
250
+ subject.prune_releases
251
+ end
252
+ end
253
+
254
+ describe "#list_releases" do
255
+ end
256
+
257
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment::Strategy do
4
+
5
+ def store_registered_cache
6
+ @registered_cache = described_class.instance_variable_get(:@_registered)
7
+ end
8
+
9
+ def restore_registered_cache
10
+ described_class.instance_variable_set(:@_registered, @registered_cache)
11
+ end
12
+
13
+ def remove_registered_cache
14
+ if described_class.instance_variable_defined?(:@_registered)
15
+ described_class.send(:remove_instance_variable, :@_registered)
16
+ end
17
+ end
18
+
19
+ before :all do
20
+ store_registered_cache
21
+ end
22
+
23
+ after :all do
24
+ restore_registered_cache
25
+ end
26
+
27
+ before :each do
28
+ class Foo; end
29
+ class Woo; end
30
+ remove_registered_cache
31
+ end
32
+
33
+ describe "::registered" do
34
+
35
+ it "returns the @_registered variable" do
36
+ described_class.instance_variable_set(:@_registered, 'foo')
37
+ expect( described_class.registered ).to eq 'foo'
38
+ end
39
+
40
+ it "defaults to a Hash if no registered are set" do
41
+ hash = {}
42
+ expect( described_class.registered ).to eq hash
43
+ end
44
+
45
+ end
46
+
47
+ describe "::register" do
48
+
49
+ it "adds the class to the strategy cache" do
50
+ described_class.register(Foo,:foo)
51
+ expect( described_class.registered[:foo] ).to eq Foo
52
+ end
53
+
54
+ it "symbolizes provided names" do
55
+ described_class.register(Woo,'woo')
56
+ expect( described_class.registered ).to have_key :woo
57
+ end
58
+
59
+ end
60
+
61
+ describe "::find" do
62
+
63
+ it "returns registered strategy" do
64
+ described_class.register(Foo,:foo)
65
+ expect( described_class.find(:foo) ).to eq Foo
66
+ end
67
+
68
+ it "raises an UndefinedStrategy error if no strategy defined" do
69
+ expect {
70
+ described_class.find(:missing)
71
+ }.to raise_error Statistrano::Deployment::Strategy::UndefinedStrategy
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistrano::Deployment do
4
+ end