auto_tagger 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +4 -1
  2. data/CHANGELOG +26 -2
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +60 -0
  5. data/README.md +90 -36
  6. data/Rakefile +1 -26
  7. data/VERSION +1 -1
  8. data/auto_tagger.gemspec +24 -14
  9. data/bin/autotag +14 -29
  10. data/features/autotag.feature +43 -2
  11. data/features/deployment.feature +4 -0
  12. data/features/step_definitions/autotag_steps.rb +27 -22
  13. data/features/step_definitions/deployment_steps.rb +41 -33
  14. data/features/support/env.rb +45 -2
  15. data/features/support/step_helpers.rb +36 -12
  16. data/features/templates/deploy.erb +1 -1
  17. data/lib/auto_tagger/base.rb +150 -19
  18. data/lib/auto_tagger/capistrano_helper.rb +38 -17
  19. data/lib/auto_tagger/command_line.rb +65 -0
  20. data/lib/auto_tagger/commander.rb +22 -11
  21. data/lib/auto_tagger/configuration.rb +88 -0
  22. data/lib/auto_tagger/deprecator.rb +11 -0
  23. data/lib/auto_tagger/git/ref.rb +34 -0
  24. data/lib/auto_tagger/git/ref_set.rb +35 -0
  25. data/lib/auto_tagger/git/repo.rb +76 -0
  26. data/lib/auto_tagger/options.rb +170 -0
  27. data/lib/auto_tagger/recipes.rb +67 -27
  28. data/lib/auto_tagger.rb +9 -4
  29. data/spec/auto_tagger/base_spec.rb +236 -52
  30. data/spec/auto_tagger/capistrano_helper_spec.rb +82 -112
  31. data/spec/auto_tagger/command_line_spec.rb +110 -0
  32. data/spec/auto_tagger/commander_spec.rb +33 -7
  33. data/spec/auto_tagger/configuration_spec.rb +275 -0
  34. data/spec/auto_tagger/git/ref_set_spec.rb +61 -0
  35. data/spec/auto_tagger/git/ref_spec.rb +46 -0
  36. data/spec/auto_tagger/git/repo_spec.rb +108 -0
  37. data/spec/auto_tagger/options_spec.rb +157 -0
  38. data/spec/spec_helper.rb +1 -6
  39. metadata +32 -15
  40. data/geminstaller.yml +0 -7
  41. data/lib/auto_tagger/repository.rb +0 -43
  42. data/lib/auto_tagger/stage_manager.rb +0 -23
  43. data/lib/auto_tagger/tag.rb +0 -43
  44. data/spec/auto_tagger/repository_spec.rb +0 -72
  45. data/spec/auto_tagger/stage_manager_spec.rb +0 -34
  46. data/spec/auto_tagger/tag_spec.rb +0 -66
@@ -1,85 +1,269 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe AutoTagger::Runner do
4
- before(:each) do
5
- stub(Dir).pwd { File.join(File.dirname(__FILE__), '..', '..') }
3
+ describe AutoTagger::Base do
4
+
5
+ describe "#repo" do
6
+ it "returns a repo with the correct options" do
7
+ base = AutoTagger::Base.new :path => "/foo",
8
+ :dry_run => true,
9
+ :verbose => true,
10
+ :executable => "/usr/bin/git"
11
+ AutoTagger::Git::Repo.should_receive(:new).with "/foo",
12
+ :execute_commands => false,
13
+ :verbose => true,
14
+ :executable => "/usr/bin/git"
15
+ base.repo
16
+ end
17
+ end
18
+
19
+ describe "#last_ref_from_previous_stage" do
20
+ it "returns nil if there is no previous stage" do
21
+ refs = "0f7324495f06e2b refs/tags/ci/2001"
22
+ base = AutoTagger::Base.new :stages => ["ci", "demo", "production"], :stage => "ci"
23
+ base.repo.stub(:read).and_return(refs)
24
+ base.last_ref_from_previous_stage.should be_nil
25
+ end
26
+
27
+ it "returns nil if there are no matching refs" do
28
+ refs = "0f7324495f06e2b refs/tags-ci/2001"
29
+ base = AutoTagger::Base.new :stages => ["ci", "demo", "production"], :stage => "ci"
30
+ base.repo.stub(:read).and_return(refs)
31
+ base.last_ref_from_previous_stage.should be_nil
32
+ end
33
+
34
+ it "should return the last ref from the previous stage" do
35
+ refs = %Q{
36
+ 41dee06050450ac refs/tags/ci/2003
37
+ 41dee06050450a5 refs/tags/ci/2003
38
+ 61c6627d766c1be refs/tags/demo/2001
39
+ }
40
+ base = AutoTagger::Base.new :stages => ["ci", "demo", "production"], :stage => "demo"
41
+ base.repo.stub(:read).and_return(refs)
42
+ ref = AutoTagger::Git::Ref.new(base.repo, "41dee06050450ac", "refs/tags/ci/2003")
43
+ base.last_ref_from_previous_stage.name.should == "refs/tags/ci/2003"
44
+ end
6
45
  end
7
46
 
8
- describe ".new" do
9
- it "blows up if you don't pass an stage" do
47
+ describe "#create_ref" do
48
+ it "creates a ref with the given sha and returns the ref" do
49
+ base = AutoTagger::Base.new :stage => "demo"
50
+ base.stub(:timestamp).and_return("20081010")
51
+
52
+ base.repo.stub(:exec) { true }
53
+ base.repo.should_receive(:exec).with("update-ref refs/tags/demo/20081010 abc123")
54
+
55
+ ref = base.create_ref "abc123"
56
+ ref.name.should == "refs/tags/demo/20081010"
57
+ ref.sha.should == "abc123"
58
+ end
59
+
60
+ it "defaults to the latest commit sha" do
61
+ base = AutoTagger::Base.new :stage => "demo"
62
+ base.stub(:timestamp).and_return("20081010")
63
+
64
+ base.repo.should_receive(:latest_commit_sha).and_return("abc123")
65
+ base.repo.stub(:exec) { true }
66
+ base.repo.should_receive(:exec).with("update-ref refs/tags/demo/20081010 abc123")
67
+
68
+ ref = base.create_ref
69
+ ref.name.should == "refs/tags/demo/20081010"
70
+ ref.sha.should == "abc123"
71
+ end
72
+
73
+ it "respects the passed in date separator" do
74
+ time = Time.now.utc
75
+ timestamp = time.strftime("%Y-%m-%d-%H-%M-%S")
76
+ base = AutoTagger::Base.new :stage => "ci", :date_separator => "-"
77
+ base.repo.stub(:exec) { true }
78
+ base.repo.should_receive(:exec).with("update-ref refs/tags/ci/#{timestamp} abc123")
79
+ base.create_ref "abc123"
80
+ end
81
+
82
+ it "raises an error if the stage is not set" do
10
83
  proc do
11
- AutoTagger::Runner.new(nil)
12
- end.should raise_error(AutoTagger::EnvironmentCannotBeBlankError)
84
+ AutoTagger::Base.new({}).create_ref
85
+ end.should raise_error(AutoTagger::Base::StageCannotBeBlankError)
13
86
  end
14
87
 
15
- it "sets the stage when it's passed" do
16
- AutoTagger::Runner.new("ci").stage.should == "ci"
88
+ it "fetches tags before creating tags" do
89
+ base = AutoTagger::Base.new :stage => "ci"
90
+ base.repo.stub(:exec) { true }
91
+ base.repo.should_receive(:exec).with("fetch origin refs/tags/*:refs/tags/*")
92
+ base.create_ref "abc123"
17
93
  end
18
94
 
19
- it "sets the path to Dir.pwd when nil" do
20
- mock(Dir).pwd { "/foo" }
21
- mock(AutoTagger::Repository).new("/foo")
22
- AutoTagger::Runner.new("ci")
95
+ it "does not fetch tags before creating tags if fetch tags is false" do
96
+ base = AutoTagger::Base.new :stage => "ci", :fetch_tags => false
97
+ base.repo.stub(:exec) { true }
98
+ base.repo.should_receive(:exec).with("push origin refs/tags/*:refs/tags/*")
99
+ base.create_ref "abc123"
23
100
  end
24
101
 
25
- it "expands the path when the path is passed" do
26
- mock(AutoTagger::Repository).new(File.expand_path("."))
27
- AutoTagger::Runner.new("ci", ".")
102
+ it "pushes tags before creating tags" do
103
+ base = AutoTagger::Base.new :stage => "ci"
104
+ base.repo.stub(:exec) { true }
105
+ base.repo.should_receive(:exec).with("push origin refs/tags/*:refs/tags/*")
106
+ base.create_ref "abc123"
28
107
  end
29
108
 
30
- it "exposes the working directory" do
31
- mock(AutoTagger::Repository).new(File.expand_path("."))
32
- AutoTagger::Runner.new("ci", ".").working_directory.should == File.expand_path(".")
109
+ it "does not push tags before creating tags if push tags is false" do
110
+ base = AutoTagger::Base.new :stage => "ci", :push_tags => false
111
+ base.repo.stub(:exec) { true }
112
+ base.repo.should_receive(:exec).with("push origin refs/tags/*:refs/tags/*")
113
+ base.create_ref "abc123"
33
114
  end
34
115
  end
35
116
 
36
- describe "#create_tag" do
37
- it "generates the correct commands" do
38
- time = Time.local(2001,1,1)
39
- mock(Time).now.once {time}
40
- timestamp = time.utc.strftime('%Y%m%d%H%M%S')
41
- mock(File).exists?(anything).twice { true }
117
+ describe "#delete_locally" do
118
+ it "blows up if you don't enter a stage" do
119
+ base = AutoTagger::Base.new({})
120
+ proc do
121
+ base.delete_locally
122
+ end.should raise_error(AutoTagger::Base::StageCannotBeBlankError)
123
+ end
42
124
 
43
- mock(AutoTagger::Commander).execute?("/foo", "git fetch origin --tags") {true}
44
- mock(AutoTagger::Commander).execute?("/foo", "git tag ci/#{timestamp}") {true}
45
- mock(AutoTagger::Commander).execute?("/foo", "git push origin --tags") {true}
125
+ it "executes the local delete commands for all the refs that match" do
126
+ base = AutoTagger::Base.new :stage => "ci"
127
+ base.repo.stub(:exec) { true }
128
+ base.stub(:refs_for_stage) do
129
+ [
130
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008"),
131
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009"),
132
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2010")
133
+ ]
134
+ end
135
+ base.repo.should_receive(:exec).with("update-ref -d refs/tags/ci/2008")
136
+ base.repo.should_receive(:exec).with("update-ref -d refs/tags/ci/2009")
137
+ base.repo.should_not_receive(:exec).with("update-ref -d refs/tags/ci/2010")
138
+ base.delete_locally
139
+ end
140
+ end
46
141
 
47
- AutoTagger::Runner.new("ci", "/foo").create_tag
142
+ describe "#delete_on_remote" do
143
+ it "blows up if you don't enter a stage" do
144
+ base = AutoTagger::Base.new({})
145
+ proc do
146
+ base.delete_on_remote
147
+ end.should raise_error(AutoTagger::Base::StageCannotBeBlankError)
48
148
  end
49
149
 
50
- it "allows you to base it off an existing tag or commit" do
51
- time = Time.local(2001,1,1)
52
- mock(Time).now.once {time}
53
- timestamp = time.utc.strftime('%Y%m%d%H%M%S')
54
- mock(File).exists?(anything).twice { true }
150
+ it "does not push if there are no tags" do
151
+ base = AutoTagger::Base.new :stage => "ci"
152
+ base.stub(:refs_for_stage).with("ci") {[]}
153
+ base.repo.should_not_receive(:exec)
154
+ base.delete_on_remote
155
+ end
55
156
 
56
- mock(AutoTagger::Commander).execute?("/foo", "git fetch origin --tags") {true}
57
- mock(AutoTagger::Commander).execute?("/foo", "git tag ci/#{timestamp} guid") {true}
58
- mock(AutoTagger::Commander).execute?("/foo", "git push origin --tags") {true}
157
+ it "executes the remote delete commands in a batch" do
158
+ base = AutoTagger::Base.new :stage => "ci"
159
+ base.repo.stub(:exec) { true }
160
+ base.stub(:refs_for_stage).with("ci") do
161
+ [
162
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008"),
163
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009"),
164
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2010")
165
+ ]
166
+ end
167
+ base.repo.should_receive(:exec).with("push origin :refs/tags/ci/2008 :refs/tags/ci/2009")
168
+ base.delete_on_remote
169
+ end
170
+ end
59
171
 
60
- AutoTagger::Runner.new("ci", "/foo").create_tag("guid")
172
+ describe "#cleanup" do
173
+ it "blows up if you don't enter a stage" do
174
+ base = AutoTagger::Base.new({})
175
+ proc do
176
+ base.cleanup
177
+ end.should raise_error(AutoTagger::Base::StageCannotBeBlankError)
61
178
  end
62
179
 
63
- it "returns the tag that was created" do
64
- time = Time.local(2001,1,1)
65
- mock(Time).now.once {time}
66
- timestamp = time.utc.strftime('%Y%m%d%H%M%S')
67
- mock(File).exists?(anything).twice { true }
68
- mock(AutoTagger::Commander).execute?(anything, anything).times(any_times) {true}
180
+ it "executes delete locally" do
181
+ base = AutoTagger::Base.new :stage => "ci"
182
+ base.repo.stub(:exec) { true }
183
+ base.stub(:refs_for_stage).with("ci") { [AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008")] }
184
+ base.should_receive(:delete_local_refs)
185
+ base.cleanup
186
+ end
69
187
 
70
- AutoTagger::Runner.new("ci", "/foo").create_tag.should == "ci/#{timestamp}"
188
+ it "executes delete on remote if push refs is true" do
189
+ base = AutoTagger::Base.new :stage => "ci"
190
+ base.repo.stub(:exec) { true }
191
+ base.stub(:refs_for_stage).with("ci") { [AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008")] }
192
+ base.should_receive(:delete_remote_refs)
193
+ base.cleanup
194
+ end
195
+
196
+ it "does not execute delete on remote if push refs is false" do
197
+ base = AutoTagger::Base.new :stage => "ci", :offline => true
198
+ base.repo.stub(:exec) { true }
199
+ base.stub(:refs_for_stage).with("ci") { [AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008")] }
200
+ base.should_not_receive(:delete_remote_refs)
201
+ base.cleanup
71
202
  end
72
203
  end
73
204
 
74
- describe "#latest_tag" do
75
- it "generates the correct commands" do
76
- mock(File).exists?(anything).twice { true }
205
+ describe ".items_to_remove" do
206
+ it "returns the items that can be removed from an array, based on the keep value passed in" do
207
+ AutoTagger::Base.items_to_remove(["2008"], 0).should == ["2008"]
208
+ AutoTagger::Base.items_to_remove(["2008"], 1).should == []
209
+ AutoTagger::Base.items_to_remove(["2008", "2009"], 0).should == ["2008", "2009"]
210
+ AutoTagger::Base.items_to_remove(["2008", "2009"], 1).should == ["2008"]
211
+ AutoTagger::Base.items_to_remove(["2008", "2009"], 2).should == []
212
+ AutoTagger::Base.items_to_remove(["2008", "2009"], 3).should == []
213
+ AutoTagger::Base.items_to_remove(["2008", "2009", "2010"], 0).should == ["2008", "2009", "2010"]
214
+ AutoTagger::Base.items_to_remove(["2008", "2009", "2010"], 1).should == ["2008", "2009"]
215
+ AutoTagger::Base.items_to_remove(["2008", "2009", "2010"], 2).should == ["2008"]
216
+ AutoTagger::Base.items_to_remove(["2008", "2009", "2010"], 3).should == []
217
+ end
218
+ end
77
219
 
78
- mock(AutoTagger::Commander).execute?("/foo", "git fetch origin --tags") {true}
79
- mock(AutoTagger::Commander).execute("/foo", "git tag") { "ci_01" }
220
+ describe "#refs_for_stage" do
221
+ it "returns refs that match the given stage" do
222
+ base = AutoTagger::Base.new :stage => "ci"
223
+ base.repo.stub(:exec) { true }
224
+ refs = [
225
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/auto_tags/ci/2008"),
226
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009"),
227
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/2009"),
228
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags-ci/2009"),
229
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/heads/master")
230
+ ]
231
+ base.repo.stub(:refs) { mock("RefSet", :all => refs) }
232
+ base.refs_for_stage("ci").should == [
233
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009")
234
+ ]
235
+ end
236
+ end
80
237
 
81
- AutoTagger::Runner.new("ci", "/foo").latest_tag
238
+ describe "#list" do
239
+ it "return a list of refs for the given stage" do
240
+ base = AutoTagger::Base.new :stage => "ci"
241
+ base.should_receive(:fetch)
242
+ base.should_receive(:refs_for_stage).with("ci")
243
+ base.list
82
244
  end
83
245
  end
84
246
 
247
+ describe "#release_tag_entries" do
248
+ it "lists the last ref from each stage" do
249
+ base = AutoTagger::Base.new :stage => "ci", :stages => ["ci", "demo", "production"]
250
+ base.repo.stub(:exec) { true }
251
+ refs = [
252
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2008"),
253
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009"),
254
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/demo/2008"),
255
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/demo/2009"),
256
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/production/2008"),
257
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/production/2009")
258
+ ]
259
+ base.repo.stub(:refs) { mock("RefSet", :all => refs) }
260
+ base.release_tag_entries.should == [
261
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009"),
262
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/demo/2009"),
263
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/production/2009")
264
+ ]
265
+ end
266
+ end
267
+
268
+
85
269
  end
@@ -1,145 +1,115 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe AutoTagger::CapistranoHelper do
4
4
 
5
- describe ".new" do
6
- it "blows up if there are no stages" do
7
- proc do
8
- AutoTagger::CapistranoHelper.new({})
9
- end.should raise_error(AutoTagger::StageManager::NoStagesSpecifiedError)
5
+ describe "#ref" do
6
+ it "returns the specified branch when passed the :head variable" do
7
+ helper = AutoTagger::CapistranoHelper.new :branch => "release", :head => nil
8
+ helper.ref.should == "release"
10
9
  end
11
- end
12
10
 
13
- describe "#variables" do
14
- it "returns all variables" do
15
- AutoTagger::CapistranoHelper.new({:autotagger_stages => [:bar]}).variables.should == {:autotagger_stages => [:bar]}
11
+ it "returns the specified tag" do
12
+ helper = AutoTagger::CapistranoHelper.new :tag => "v0.1.7"
13
+ helper.ref.should == "v0.1.7"
14
+ end
15
+
16
+ it "returns the specified ref" do
17
+ helper = AutoTagger::CapistranoHelper.new :ref => "refs/auto_tags/ci"
18
+ helper.ref.should == "refs/auto_tags/ci"
16
19
  end
17
- end
18
20
 
19
- describe "#working_directory" do
20
- it "returns the hashes' working directory value" do
21
- AutoTagger::CapistranoHelper.new({:autotagger_stages => [:bar], :working_directory => "/foo"}).working_directory.should == "/foo"
21
+ it "returns the sha of the last ref from that stage" do
22
+ helper = AutoTagger::CapistranoHelper.new({})
23
+ ref = mock(AutoTagger::Git::Ref, :sha => "abc123")
24
+ auto_tagger = mock AutoTagger::Base, :last_ref_from_previous_stage => ref
25
+ helper.stub(:auto_tagger) { auto_tagger }
26
+ helper.ref.should == "abc123"
22
27
  end
23
28
 
24
- it "defaults to Dir.pwd if it's not set, or it's nil" do
25
- mock(Dir).pwd { "/bar" }
26
- AutoTagger::CapistranoHelper.new({:autotagger_stages => [:bar]}).working_directory.should == "/bar"
29
+ it "returns the branch when specified" do
30
+ helper = AutoTagger::CapistranoHelper.new :branch => "release"
31
+ helper.ref.should == "release"
27
32
  end
28
33
  end
29
34
 
30
- describe "#stage" do
31
- it "returns the hashes' current stage value" do
32
- AutoTagger::CapistranoHelper.new({:autotagger_stages => [:bar], :stage => :bar}).stage.should == :bar
33
- AutoTagger::CapistranoHelper.new({:autotagger_stages => [:bar]}).stage.should be_nil
35
+ describe "#auto_tagger" do
36
+ it "returns an AutoTagger::Base object with the correct options" do
37
+ helper = AutoTagger::CapistranoHelper.new({})
38
+ helper.stub(:auto_tagger_options).and_return({:foo => "bar"})
39
+ AutoTagger::Base.should_receive(:new).with({:foo => "bar"})
40
+ helper.auto_tagger
34
41
  end
35
42
  end
36
43
 
37
- describe "#release_tag_entries" do
38
- it "returns a column-justifed version of all the commits" do
39
- mock(AutoTagger::Commander).execute("/foo", "git tag").times(any_times) { "ci/01\nstaging/01\nproduction/01" }
40
- mock(AutoTagger::Commander).execute("/foo", "git --no-pager log ci/01 --pretty=oneline -1") { "guid1" }
41
- mock(AutoTagger::Commander).execute("/foo", "git --no-pager log staging/01 --pretty=oneline -1") { "guid2" }
42
- mock(AutoTagger::Commander).execute("/foo", "git --no-pager log production/01 --pretty=oneline -1") { "guid3" }
43
- mock(AutoTagger::Commander).execute?("/foo", "git fetch origin --tags").times(any_times) { true }
44
- mock(File).exists?(anything).times(any_times) {true}
45
-
46
- variables = {
47
- :working_directory => "/foo",
48
- :autotagger_stages => [:ci, :staging, :production]
49
- }
50
- histories = AutoTagger::CapistranoHelper.new(variables).release_tag_entries
51
- histories.length.should == 3
52
- histories[0].should include("ci/01", "guid1")
53
- histories[1].should include("staging/01", "guid2")
54
- histories[2].should include("production/01", "guid3")
44
+ describe "#auto_tagger_options" do
45
+ it "includes :stage from :auto_tagger_stage, :stage" do
46
+ helper = AutoTagger::CapistranoHelper.new :stage => "demo"
47
+ helper.auto_tagger_options[:stage].should == "demo"
48
+
49
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_stage => "demo"
50
+ helper.auto_tagger_options[:stage].should == "demo"
51
+
52
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_stage => "demo", :stage => "ci"
53
+ helper.auto_tagger_options[:stage].should == "demo"
55
54
  end
56
55
 
57
- it "ignores tags delimited with '_'" do
58
- mock(AutoTagger::Commander).execute("/foo", "git tag").times(any_times) { "ci/01\nci_02" }
59
- mock(AutoTagger::Commander).execute("/foo", "git --no-pager log ci/01 --pretty=oneline -1") { "guid1" }
60
- mock(AutoTagger::Commander).execute?("/foo", "git fetch origin --tags").times(any_times) { true }
61
- mock(File).exists?(anything).times(any_times) {true}
62
-
63
- variables = {
64
- :working_directory => "/foo",
65
- :autotagger_stages => [:ci]
66
- }
67
- histories = AutoTagger::CapistranoHelper.new(variables).release_tag_entries
68
- histories.length.should == 1
69
- histories[0].should include("ci/01", "guid1")
56
+ it "includes stages" do
57
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => ["demo"]
58
+ helper.auto_tagger_options[:stages].should == ["demo"]
70
59
  end
71
- end
72
60
 
73
- describe "#branch" do
74
- describe "with :head and :branch specified" do
75
- it "returns master" do
76
- variables = {
77
- :autotagger_stages => [:bar],
78
- :head => nil,
79
- :branch => "foo"
80
- }
81
- AutoTagger::CapistranoHelper.new(variables).branch.should == "foo"
82
- end
61
+ it "includes :auto_tagger_working_directory" do
62
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_working_directory => "/foo"
63
+ helper.auto_tagger_options[:path].should == "/foo"
83
64
  end
84
65
 
85
- describe "with :head specified, but no branch specified" do
86
- it "returns master" do
87
- variables = {
88
- :autotagger_stages => [:bar],
89
- :head => nil
90
- }
91
- AutoTagger::CapistranoHelper.new(variables).branch.should == nil
92
- end
66
+ it "includes and deprecates :working_directory" do
67
+ AutoTagger::Deprecator.should_receive(:warn)
68
+ helper = AutoTagger::CapistranoHelper.new :working_directory => "/foo"
69
+ helper.auto_tagger_options[:path].should == "/foo"
93
70
  end
94
71
 
95
- describe "with :branch specified" do
96
- it "returns the value of branch" do
97
- variables = {
98
- :autotagger_stages => [:bar],
99
- :branch => "foo"
100
- }
101
- AutoTagger::CapistranoHelper.new(variables).branch.should == "foo"
72
+ [
73
+ :date_separator,
74
+ :push_refs,
75
+ :fetch_refs,
76
+ :remote,
77
+ :ref_path,
78
+ :offline,
79
+ :dry_run,
80
+ :verbose,
81
+ :refs_to_keep,
82
+ :executable,
83
+ :opts_file
84
+ ].each do |key|
85
+ it "incudes :#{key}" do
86
+ helper = AutoTagger::CapistranoHelper.new :"auto_tagger_#{key}" => "value"
87
+ helper.auto_tagger_options[key].should == "value"
102
88
  end
103
89
  end
104
90
 
105
- describe "with a previous stage with a tag" do
106
- it "returns the latest tag for the previous stage" do
107
- variables = {
108
- :autotagger_stages => [:foo, :bar],
109
- :stage => :bar,
110
- :branch => "master",
111
- :working_directory => "/foo"
112
- }
113
- tagger = Object.new
114
- mock(tagger).latest_tag { "foo_01" }
115
- mock(AutoTagger::Runner).new("foo", "/foo") { tagger }
116
- AutoTagger::CapistranoHelper.new(variables).branch.should == "foo_01"
117
- end
91
+ end
92
+
93
+ describe "#stages" do
94
+ it "understands :stages" do
95
+ helper = AutoTagger::CapistranoHelper.new :stages => ["demo"]
96
+ helper.stages.should == ["demo"]
118
97
  end
119
98
 
120
- describe "with no branch and a previous stage with no tag" do
121
- it "returns nil" do
122
- variables = {
123
- :autotagger_stages => [:foo, :bar],
124
- :stage => :bar,
125
- :working_directory => "/foo"
126
- }
127
- tagger = Object.new
128
- mock(tagger).latest_tag { nil }
129
- mock(AutoTagger::Runner).new("foo", "/foo") { tagger }
130
- AutoTagger::CapistranoHelper.new(variables).branch.should == nil
131
- end
99
+ it "understands :auto_tagger_stages" do
100
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => ["demo"]
101
+ helper.auto_tagger_options[:stages].should == ["demo"]
132
102
  end
133
103
 
134
- describe "with no branch and previous stage" do
135
- it "returns nil" do
136
- variables = {
137
- :autotagger_stages => [:bar],
138
- :stage => :bar
139
- }
140
- AutoTagger::CapistranoHelper.new(variables).previous_stage.should be_nil
141
- AutoTagger::CapistranoHelper.new(variables).branch.should == nil
142
- end
104
+ it "understands and deprecates :autotagger_stages" do
105
+ AutoTagger::Deprecator.should_receive(:warn)
106
+ helper = AutoTagger::CapistranoHelper.new :autotagger_stages => ["demo"]
107
+ helper.stages.should == ["demo"]
108
+ end
109
+
110
+ it "makes all stages strings" do
111
+ helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => [:demo]
112
+ helper.stages.should == ["demo"]
143
113
  end
144
114
  end
145
115