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
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoTagger::CommandLine do
4
+
5
+ describe "#execute" do
6
+ it "runs the version command" do
7
+ command_line = AutoTagger::CommandLine.new ["version"]
8
+ command_line.execute.first.should be_true
9
+ command_line.execute.last.should include(AutoTagger.version)
10
+ end
11
+
12
+ it "runs the help command" do
13
+ command_line = AutoTagger::CommandLine.new ["help"]
14
+ command_line.execute.last.should include("USAGE")
15
+ end
16
+
17
+ describe "#cleanup" do
18
+ it "runs the cleanup command with a stage" do
19
+ command_line = AutoTagger::CommandLine.new ["cleanup"]
20
+ tagger = mock(AutoTagger::Base, :cleanup => 7)
21
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
22
+ command_line.execute.last.should include("7")
23
+ end
24
+
25
+ it "prints a friendly error message when no stage is provided" do
26
+ command_line = AutoTagger::CommandLine.new ["cleanup"]
27
+ AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
28
+ command_line.execute.last.should include("You must provide a stage")
29
+ end
30
+ end
31
+
32
+ describe "#delete_locally" do
33
+ it "runs the delete_locally command" do
34
+ command_line = AutoTagger::CommandLine.new ["delete_locally"]
35
+ tagger = mock(AutoTagger::Base, :delete_locally => 7)
36
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
37
+ command_line.execute.last.should include("7")
38
+ end
39
+
40
+ it "prints a friendly error message when no stage is provided" do
41
+ command_line = AutoTagger::CommandLine.new ["delete_locally"]
42
+ AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
43
+ command_line.execute.last.should include("You must provide a stage")
44
+ end
45
+ end
46
+
47
+ describe "#delete_on_remote" do
48
+ it "runs the delete_on_remote command" do
49
+ command_line = AutoTagger::CommandLine.new ["delete_on_remote"]
50
+ tagger = mock(AutoTagger::Base, :delete_on_remote => 7)
51
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
52
+ command_line.execute.last.should include("7")
53
+ end
54
+
55
+ it "prints a friendly error message when no stage is provided" do
56
+ command_line = AutoTagger::CommandLine.new ["delete_on_remote"]
57
+ AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
58
+ command_line.execute.last.should include("You must provide a stage")
59
+ end
60
+ end
61
+
62
+ describe "#list" do
63
+ it "runs the list command" do
64
+ command_line = AutoTagger::CommandLine.new ["list"]
65
+ tagger = mock(AutoTagger::Base, :list => ["foo", "bar"])
66
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
67
+ command_line.execute.last.should include("foo", "bar")
68
+ end
69
+
70
+ it "prints a friendly error message when no stage is provided" do
71
+ command_line = AutoTagger::CommandLine.new ["list"]
72
+ AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
73
+ command_line.execute.last.should include("You must provide a stage")
74
+ end
75
+ end
76
+
77
+ it "runs the config command" do
78
+ command_line = AutoTagger::CommandLine.new ["config"]
79
+ config = mock(AutoTagger::Configuration, :settings => {"foo" => "bar"})
80
+ AutoTagger::Configuration.should_receive(:new).and_return(config)
81
+ command_line.execute.last.should include("foo", "bar")
82
+ end
83
+
84
+ describe "#create" do
85
+ it "runs the create command" do
86
+ command_line = AutoTagger::CommandLine.new ["create"]
87
+ tagger = mock(AutoTagger::Base, :create_ref => mock(AutoTagger::Git::Ref, :name => "refs/tags"))
88
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
89
+ command_line.execute.last.should include("refs/tags")
90
+ end
91
+
92
+ it "includes a deprecation command when necessary" do
93
+ command_line = AutoTagger::CommandLine.new ["ci"]
94
+ tagger = mock(AutoTagger::Base, :create_ref => mock(AutoTagger::Git::Ref, :name => "refs/tags"))
95
+ AutoTagger::Base.should_receive(:new).and_return(tagger)
96
+ result = command_line.execute.last
97
+ result.should include("DEPRECATION")
98
+ result.should include("refs/tags")
99
+ end
100
+
101
+ it "prints a friendly error message when no stage is provided" do
102
+ command_line = AutoTagger::CommandLine.new ["create"]
103
+ AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
104
+ command_line.execute.last.should include("You must provide a stage")
105
+ end
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -1,17 +1,43 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe AutoTagger::Commander do
4
- describe ".execute" do
4
+
5
+ describe "#read" do
5
6
  it "execute the command and returns the results" do
6
- mock(AutoTagger::Commander).`("cd /foo && ls") { "" } #`
7
- AutoTagger::Commander.execute("/foo", "ls")
7
+ commander = AutoTagger::Commander.new("/foo", false)
8
+ commander.should_receive(:`).with("cd /foo && ls")
9
+ commander.read("ls")
10
+ end
11
+
12
+ it "puts the response when it's verbose" do
13
+ commander = AutoTagger::Commander.new("/foo", true)
14
+ commander.stub(:`)
15
+ commander.should_receive(:puts).with("cd /foo && ls")
16
+ commander.read("ls")
8
17
  end
9
18
  end
10
19
 
11
- describe "system" do
20
+ describe "#execute" do
12
21
  it "executes and doesn't return anything" do
13
- mock(AutoTagger::Commander).system("cd /foo && ls")
14
- AutoTagger::Commander.execute?("/foo", "ls")
22
+ commander = AutoTagger::Commander.new("/foo", false)
23
+ commander.should_receive(:system).with("cd /foo && ls")
24
+ commander.execute("ls")
25
+ end
26
+
27
+ it "puts the response when it's verbose" do
28
+ commander = AutoTagger::Commander.new("/foo", true)
29
+ commander.stub(:system)
30
+ commander.should_receive(:puts).with("cd /foo && ls")
31
+ commander.execute("ls")
15
32
  end
16
33
  end
34
+
35
+ describe "#print" do
36
+ it "returns the command to be run" do
37
+ commander = AutoTagger::Commander.new("/foo", false)
38
+ commander.should_receive(:puts).with("cd /foo && ls")
39
+ commander.print("ls")
40
+ end
41
+ end
42
+
17
43
  end
@@ -0,0 +1,275 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoTagger::Configuration do
4
+
5
+ before do
6
+ # make sure that the specs don't pick up this gem's .auto_tagger file
7
+ File.stub(:read) { nil }
8
+ end
9
+
10
+ describe "#working_directory" do
11
+ it "returns the current directory when path is nil" do
12
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
13
+ Dir.stub(:pwd) { dir }
14
+ config = AutoTagger::Configuration.new({})
15
+ config.working_directory.should == dir
16
+ end
17
+
18
+ it "expands path when path is set" do
19
+ dir = File.expand_path(".")
20
+ config = AutoTagger::Configuration.new :path => "."
21
+ config.working_directory.should == dir
22
+ end
23
+ end
24
+
25
+ describe "#opts_file" do
26
+ it "expands the passed in opts file path in reference to the working directory" do
27
+ config = AutoTagger::Configuration.new :opts_file => "../.foo_tagger", :path => "/foo/bar"
28
+ config.opts_file.should == "/foo/.foo_tagger"
29
+ end
30
+
31
+ it "defaults to looking in the working directories .auto_tagger file" do
32
+ config = AutoTagger::Configuration.new :path => "/foo"
33
+ config.opts_file.should == "/foo/.auto_tagger"
34
+ end
35
+ end
36
+
37
+ describe "#file_settings" do
38
+ it "return a hash representing the options specified in the opts file" do
39
+ config = AutoTagger::Configuration.new
40
+ config.stub(:opts_file) { "/foo/.auto_tagger" }
41
+ File.should_receive(:exists?) { true }
42
+ File.should_receive(:read).with("/foo/.auto_tagger").and_return("--offline=false\n--verbose=true")
43
+ config.file_settings.should == {:offline => false, :verbose => true}
44
+ end
45
+
46
+ it "ignores blank lines and whitespace" do
47
+ config = AutoTagger::Configuration.new
48
+ config.stub(:opts_file) { "/foo/.auto_tagger" }
49
+ File.should_receive(:exists?).with("/foo/.auto_tagger") { true }
50
+ File.should_receive(:read).with("/foo/.auto_tagger").and_return(" --offline=false \n\n--verbose=true\n")
51
+ config.file_settings.should == {:offline => false, :verbose => true}
52
+ end
53
+
54
+ it "returns an empty hash if the file doens't exist" do
55
+ File.stub(:exists?) { false }
56
+ config = AutoTagger::Configuration.new :path => "/foo"
57
+ config.file_settings.should == {}
58
+ end
59
+
60
+ # TODO: print warnings instead of blowing up??
61
+ it "doesn't parse options that are not valid for the opts file" do
62
+ File.stub(:exists?) { true }
63
+ File.should_receive(:read).with("/foo/.auto_tagger").and_return("--opts-file=/foo")
64
+ config = AutoTagger::Configuration.new :path => "/foo"
65
+ proc do
66
+ config.file_settings.should == {}
67
+ end.should raise_error(OptionParser::InvalidOption)
68
+ end
69
+ end
70
+
71
+ describe "#settings" do
72
+ it "should merge the passed in settings with the file settings" do
73
+ config = AutoTagger::Configuration.new :stage => "demo", :offline => true
74
+ config.stub(:file_settings).and_return({:stage => "ci", :verbose => false})
75
+ config.settings.should == {:stage => "demo", :offline => true, :verbose => false}
76
+ end
77
+ end
78
+
79
+ describe "#stages" do
80
+ it "splits on a comma if it's a string, ignoring whitespace" do
81
+ config = AutoTagger::Configuration.new :stages => ",ci,, demo , production,"
82
+ config.stages.should == ["ci", "demo", "production"]
83
+ end
84
+
85
+ it "returns the passed in stages if it's an array" do
86
+ config = AutoTagger::Configuration.new :stages => ["ci", "demo"]
87
+ config.stages.should == ["ci", "demo"]
88
+ end
89
+
90
+ it "removes blank items" do
91
+ config = AutoTagger::Configuration.new :stages => ["ci", ""]
92
+ config.stages.should == ["ci"]
93
+ end
94
+ end
95
+
96
+ describe "#stage" do
97
+ it "should use the stage passed in" do
98
+ config = AutoTagger::Configuration.new :stage => "demo"
99
+ config.stage.should == "demo"
100
+ end
101
+
102
+ it "defaults to the last stage if stages is passed in" do
103
+ config = AutoTagger::Configuration.new :stages => ["demo", "production"]
104
+ config.stage.should == "production"
105
+ end
106
+
107
+ it "returns nil if stage and stages are not passed in" do
108
+ config = AutoTagger::Configuration.new
109
+ config.stage.should be_nil
110
+ end
111
+ end
112
+
113
+ describe "#date_separator" do
114
+ it "returns the passed in option" do
115
+ config = AutoTagger::Configuration.new :date_separator => "-"
116
+ config.date_separator.should == "-"
117
+ end
118
+
119
+ it "defaults to an empty string" do
120
+ config = AutoTagger::Configuration.new
121
+ config.date_separator.should == ""
122
+ end
123
+ end
124
+
125
+ describe "#dry_run?" do
126
+ it "returns the passed in option" do
127
+ config = AutoTagger::Configuration.new :dry_run => true
128
+ config.dry_run?.should == true
129
+
130
+ config = AutoTagger::Configuration.new :dry_run => false
131
+ config.dry_run?.should == false
132
+ end
133
+
134
+ it "defaults to false" do
135
+ config = AutoTagger::Configuration.new
136
+ config.dry_run?.should == false
137
+ end
138
+ end
139
+
140
+ describe "#verbose?" do
141
+ it "returns the passed in option" do
142
+ config = AutoTagger::Configuration.new :verbose => true
143
+ config.verbose?.should == true
144
+
145
+ config = AutoTagger::Configuration.new :verbose => false
146
+ config.verbose?.should == false
147
+ end
148
+
149
+ it "defaults to false" do
150
+ config = AutoTagger::Configuration.new
151
+ config.verbose?.should == false
152
+ end
153
+ end
154
+
155
+ describe "#offline?" do
156
+ it "returns the passed in option" do
157
+ config = AutoTagger::Configuration.new :offline => true
158
+ config.offline?.should == true
159
+
160
+ config = AutoTagger::Configuration.new :offline => false
161
+ config.offline?.should == false
162
+ end
163
+
164
+ it "defaults to false" do
165
+ config = AutoTagger::Configuration.new
166
+ config.offline?.should == false
167
+ end
168
+ end
169
+
170
+ describe "#push_refs" do
171
+ it "defaults to true" do
172
+ config = AutoTagger::Configuration.new
173
+ config.push_refs?.should == true
174
+ end
175
+
176
+ it "respects the passed-in option" do
177
+ config = AutoTagger::Configuration.new :push_refs => true
178
+ config.push_refs?.should == true
179
+
180
+ config = AutoTagger::Configuration.new :push_refs => false
181
+ config.push_refs?.should == false
182
+ end
183
+
184
+ it "returns false if offline is true" do
185
+ config = AutoTagger::Configuration.new :offline => true, :push_refs => true
186
+ config.push_refs?.should == false
187
+ end
188
+ end
189
+
190
+ describe "#fetch_refs" do
191
+ it "defaults to true" do
192
+ config = AutoTagger::Configuration.new
193
+ config.fetch_refs?.should == true
194
+ end
195
+
196
+ it "respects the passed-in option" do
197
+ config = AutoTagger::Configuration.new :fetch_refs => true
198
+ config.fetch_refs?.should == true
199
+
200
+ config = AutoTagger::Configuration.new :fetch_refs => false
201
+ config.fetch_refs?.should == false
202
+ end
203
+
204
+ it "returns false if offline is true" do
205
+ config = AutoTagger::Configuration.new :offline => true, :fetch_refs => true
206
+ config.fetch_refs?.should == false
207
+ end
208
+ end
209
+
210
+ describe "#executable" do
211
+ it "returns the passed in executable" do
212
+ config = AutoTagger::Configuration.new :executable => "/usr/bin/git"
213
+ config.executable.should == "/usr/bin/git"
214
+ end
215
+
216
+ it "defaults to git" do
217
+ config = AutoTagger::Configuration.new
218
+ config.executable.should == "git"
219
+ end
220
+ end
221
+
222
+ describe "#refs_to_keep" do
223
+ it "return the refs to keep" do
224
+ config = AutoTagger::Configuration.new :refs_to_keep => 4
225
+ config.refs_to_keep.should == 4
226
+ end
227
+
228
+ it "defaults to 1" do
229
+ config = AutoTagger::Configuration.new
230
+ config.refs_to_keep.should == 1
231
+ end
232
+
233
+ it "always returns a FixNum" do
234
+ config = AutoTagger::Configuration.new :refs_to_keep => "4"
235
+ config.refs_to_keep.should == 4
236
+ end
237
+ end
238
+
239
+ describe "#remote" do
240
+ it "returns the passed in option" do
241
+ config = AutoTagger::Configuration.new :remote => "myorigin"
242
+ config.remote.should == "myorigin"
243
+ end
244
+
245
+ it "defaults to origin" do
246
+ config = AutoTagger::Configuration.new
247
+ config.remote.should == "origin"
248
+ end
249
+ end
250
+
251
+ describe "#ref_path" do
252
+ it "returns the passed in option" do
253
+ config = AutoTagger::Configuration.new :ref_path => "auto_tags"
254
+ config.ref_path.should == "auto_tags"
255
+ end
256
+
257
+ it "defaults to tags" do
258
+ config = AutoTagger::Configuration.new
259
+ config.ref_path.should == "tags"
260
+ end
261
+
262
+ it "raises an error if you pass in heads or remotes" do
263
+ proc do
264
+ config = AutoTagger::Configuration.new :ref_path => "heads"
265
+ config.ref_path.should == "tags"
266
+ end.should raise_error(AutoTagger::Configuration::InvalidRefPath)
267
+
268
+ proc do
269
+ config = AutoTagger::Configuration.new :ref_path => "heads"
270
+ config.ref_path.should == "tags"
271
+ end.should raise_error(AutoTagger::Configuration::InvalidRefPath)
272
+ end
273
+ end
274
+
275
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoTagger::Git::RefSet do
4
+
5
+ before do
6
+ @repo = mock(AutoTagger::Git::Repo, :exec => true)
7
+ @ref_set = AutoTagger::Git::RefSet.new(@repo)
8
+ @refstring = <<-LIST
9
+ 23087241c495773c8eece1c195cc453a8055c4eb refs/tags/200808080808
10
+ 23087241c495773c8eece1c195cc453a8055c4eb refs/tags/200808080809
11
+ LIST
12
+ end
13
+
14
+ describe "#all" do
15
+ it "returns an array of refs" do
16
+ @repo.should_receive(:read).with("show-ref").and_return(@refstring)
17
+ refs = @ref_set.all
18
+ refs.length.should == 2
19
+ refs.first.name.should == "refs/tags/200808080808"
20
+ refs.first.sha.should == "23087241c495773c8eece1c195cc453a8055c4eb"
21
+ end
22
+ end
23
+
24
+ describe "#create" do
25
+ it "instantiates and saves a ref" do
26
+ @repo.should_receive(:exec).with("update-ref refs/auto_tags/demo/2008 abc123")
27
+ @ref_set.create "abc123", "refs/auto_tags/demo/2008"
28
+ end
29
+
30
+ it "returns the ref" do
31
+ ref = @ref_set.create("abc123", "refs/auto_tags/demo/2008")
32
+ ref.sha.should == "abc123"
33
+ ref.name.should == "refs/auto_tags/demo/2008"
34
+ end
35
+ end
36
+
37
+ describe "#push" do
38
+ it "pushes all refs to the specified remote" do
39
+ @repo.should_receive(:exec).with("push myremote refs/auto_tags/*:refs/auto_tags/*")
40
+ @ref_set.push "refs/auto_tags/*", "myremote"
41
+ end
42
+
43
+ it "defaults to origin" do
44
+ @repo.should_receive(:exec).with("push origin refs/auto_tags/*:refs/auto_tags/*")
45
+ @ref_set.push "refs/auto_tags/*"
46
+ end
47
+ end
48
+
49
+ describe "#fetch" do
50
+ it "fetches all refs to the specified remote" do
51
+ @repo.should_receive(:exec).with("fetch myremote refs/auto_tags/*:refs/auto_tags/*")
52
+ @ref_set.fetch "refs/auto_tags/*", "myremote"
53
+ end
54
+
55
+ it "defaults to origin" do
56
+ @repo.should_receive(:exec).with("fetch origin refs/auto_tags/*:refs/auto_tags/*")
57
+ @ref_set.fetch "refs/auto_tags/*"
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoTagger::Git::Ref do
4
+
5
+ before do
6
+ @repo = mock(AutoTagger::Git::Repo, :exec => true)
7
+ @ref = AutoTagger::Git::Ref.new(@repo, "85af4e", "refs/auto_tags/ci")
8
+ end
9
+
10
+ describe "#to_s" do
11
+ it "returns the sha and the name" do
12
+ @ref.to_s.should == "85af4e refs/auto_tags/ci"
13
+ end
14
+ end
15
+
16
+ describe "#delete_locally" do
17
+ it "sends the update ref command" do
18
+ @repo.should_receive(:exec).with("update-ref -d refs/auto_tags/ci")
19
+ @ref.delete_locally
20
+ end
21
+ end
22
+
23
+ describe "#delete_on_remote" do
24
+ it "pushes nothing to the remote ref" do
25
+ @repo.should_receive(:exec).with("push myorigin :refs/auto_tags/ci")
26
+ @ref.delete_on_remote "myorigin"
27
+ end
28
+
29
+ it "defaults to origin" do
30
+ @repo.should_receive(:exec).with("push origin :refs/auto_tags/ci")
31
+ @ref.delete_on_remote
32
+ end
33
+ end
34
+
35
+ describe "#save" do
36
+ it "should send the correct update-ref command" do
37
+ @repo.should_receive(:exec).with("update-ref refs/auto_tags/ci 85af4e")
38
+ @ref.save
39
+ end
40
+
41
+ it "returns the ref" do
42
+ @ref.save.should == @ref
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoTagger::Git::Repo do
4
+
5
+ before do
6
+ File.stub(:exists?).and_return(true)
7
+ @commander = mock(AutoTagger::Commander)
8
+ end
9
+
10
+ describe "#path" do
11
+ it "raises an error if the path is blank" do
12
+ proc do
13
+ AutoTagger::Git::Repo.new(" ").path
14
+ end.should raise_error(AutoTagger::Git::Repo::NoPathProvidedError)
15
+
16
+ proc do
17
+ AutoTagger::Git::Repo.new(nil).path
18
+ end.should raise_error(AutoTagger::Git::Repo::NoPathProvidedError)
19
+ end
20
+
21
+ it "raises and error if the path does not exist" do
22
+ File.should_receive(:exists?).with("/foo").and_return(false)
23
+ proc do
24
+ AutoTagger::Git::Repo.new("/foo").path
25
+ end.should raise_error(AutoTagger::Git::Repo::NoSuchPathError)
26
+ end
27
+
28
+ it "raises and error if the path does not have a .git directory" do
29
+ File.should_receive(:exists?).with("/foo").and_return(true)
30
+ File.should_receive(:exists?).with("/foo/.git").and_return(false)
31
+ proc do
32
+ AutoTagger::Git::Repo.new("/foo").path
33
+ end.should raise_error(AutoTagger::Git::Repo::InvalidGitRepositoryError)
34
+ end
35
+
36
+ it "returns the path if it's a git directory" do
37
+ File.should_receive(:exists?).with("/foo").and_return(true)
38
+ File.should_receive(:exists?).with("/foo/.git").and_return(true)
39
+ AutoTagger::Git::Repo.new("/foo").path.should == "/foo"
40
+ end
41
+ end
42
+
43
+ describe "#refs" do
44
+ it "returns a new refset" do
45
+ AutoTagger::Git::Repo.new("/foo").refs.should be_kind_of(AutoTagger::Git::RefSet)
46
+ end
47
+ end
48
+
49
+ describe "#==" do
50
+ it "returns true if the path matches" do
51
+ AutoTagger::Git::Repo.new("/foo").should == AutoTagger::Git::Repo.new("/foo")
52
+ end
53
+
54
+ it "returns false if the path does not match" do
55
+ AutoTagger::Git::Repo.new("/foo").should_not == AutoTagger::Git::Repo.new("/bar")
56
+ end
57
+ end
58
+
59
+ describe "#latest_commit_sha" do
60
+ it "returns the latest sha from HEAD" do
61
+ repo = AutoTagger::Git::Repo.new("/foo")
62
+ repo.should_receive(:read).with("rev-parse HEAD").and_return(" abc123 ")
63
+ repo.latest_commit_sha.should == "abc123"
64
+ end
65
+ end
66
+
67
+ describe "#read" do
68
+ it "formats the command and sends it to the system" do
69
+ repo = AutoTagger::Git::Repo.new("/foo")
70
+ repo.stub(:commander).and_return(@commander)
71
+ @commander.should_receive(:read).with("git rev-parse HEAD").and_return("lkj")
72
+ repo.read("rev-parse HEAD").should == "lkj"
73
+ end
74
+
75
+ it "respects the passed in executable" do
76
+ repo = AutoTagger::Git::Repo.new("/foo", :executable => "/usr/bin/git")
77
+ repo.stub(:commander).and_return(@commander)
78
+ @commander.should_receive(:read).with("/usr/bin/git rev-parse HEAD").and_return("lkj")
79
+ repo.read("rev-parse HEAD").should == "lkj"
80
+ end
81
+ end
82
+
83
+ describe "#exec" do
84
+ it "sends the exec command to the commander" do
85
+ repo = AutoTagger::Git::Repo.new("/foo")
86
+ repo.stub(:commander).and_return(@commander)
87
+ @commander.should_receive(:execute).with("git push origin master").and_return(true)
88
+ repo.exec("push origin master")
89
+ end
90
+
91
+ it "raises an error if the command returns false" do
92
+ repo = AutoTagger::Git::Repo.new("/foo")
93
+ repo.stub(:commander).and_return(@commander)
94
+ @commander.should_receive(:execute).with("git push origin master").and_return(false)
95
+ proc do
96
+ repo.exec("push origin master")
97
+ end.should raise_error(AutoTagger::Git::Repo::GitCommandFailedError)
98
+ end
99
+
100
+ it "sends the print command to the commander if execute_commands is false" do
101
+ repo = AutoTagger::Git::Repo.new("/foo", :execute_commands => false)
102
+ repo.stub(:commander).and_return(@commander)
103
+ @commander.should_receive(:print).with("git push origin master")
104
+ repo.exec("push origin master")
105
+ end
106
+ end
107
+
108
+ end