diff --git a/lib/git.rb b/lib/git.rb index 5671cf6..49922d5 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -2,6 +2,8 @@ require 'rake/dsl_definition' module Git + class NoTagFoundError < Exception; end + include Rake::DSL def git_clone(repos, dir) @@ -34,7 +36,7 @@ def git_rev_parse(ref) def git_tag(glob) return nil if glob.nil? - %x{git tag -l '#{glob}'}.split("\n").last + %x{git tag -l '#{glob}'}.split("\n").last || (raise NoTagFoundError, "No tag found [#{glob}]") end def git_revision(repo) diff --git a/spec/git_spec.rb b/spec/git_spec.rb index a491e74..59faa0f 100644 --- a/spec/git_spec.rb +++ b/spec/git_spec.rb @@ -32,11 +32,13 @@ class GitTest; include Git; end subject.should_receive("`").with("git tag -l 'pattern*'") { "x\n\y\n\z\n" } subject.git_tag('pattern*').should == "z" end - it "returns nil if no tags match the pattern" do + it "raises exception if no tags match the pattern" do subject.should_receive("`").with("git tag -l 'pattern*'") { "\n" } - subject.git_tag('pattern*').should == nil + expect { + subject.git_tag('pattern*') + }.to raise_error(Git::NoTagFoundError) end - it "returns nil for a nil tag" do + it "returns nil for a nil glob" do subject.should_not_receive("`").with("git tag -l ''") { "\n" } subject.git_tag(nil).should == nil end diff --git a/spec/heroku_san/stage_spec.rb b/spec/heroku_san/stage_spec.rb index a9a74c5..95301f6 100644 --- a/spec/heroku_san/stage_spec.rb +++ b/spec/heroku_san/stage_spec.rb @@ -79,7 +79,8 @@ describe "#push" do it "deploys to heroku" do - subject.should_receive(:git_push).with(git_parsed_tag(subject.tag), subject.repo, []) + subject.should_receive(:git_parsed_tag).with(nil) {'tag'} + subject.should_receive(:git_push).with('tag', subject.repo, []) subject.push end @@ -89,7 +90,8 @@ end it "deploys with --force" do - subject.should_receive(:git_push).with(git_parsed_tag(subject.tag), subject.repo, %w[--force]) + subject.should_receive(:git_parsed_tag).with(nil) {'tag'} + subject.should_receive(:git_push).with('tag', subject.repo, %w[--force]) subject.push(nil, :force) end