@@ -104,6 +104,59 @@ module Code
104104 end
105105 end
106106
107+ describe "#start" do
108+ it "should raise an error if branch already exists" do
109+ existing_branch = Branch . create "existing-branch"
110+
111+ expect { git . start "existing-branch" } . to raise_error Git ::FeatureExistsError
112+ end
113+
114+ it "should checkout the development branch, pull it, then create and switch to a new branch" do
115+ expect ( System ) . to receive ( :call ) . with ( "checkout development" )
116+ expect ( System ) . to receive ( :call ) . with ( "pull origin development:development" )
117+ expect ( System ) . to receive ( :call ) . with ( "branch new-feature" )
118+ expect ( System ) . to receive ( :call ) . with ( "checkout new-feature" )
119+
120+ git . start "new-feature"
121+ end
122+
123+ it "should not checkout the development branch if already on it" do
124+ dev_branch = Branch . create "development"
125+ allow ( git ) . to receive ( :current_branch ) . and_return ( dev_branch )
126+ expect ( System ) . not_to receive ( :call ) . with ( "checkout development" )
127+
128+ git . start "new-feature"
129+ end
130+ end
131+
132+ describe "#hotfix" do
133+ it "should raise an error if branch already exists" do
134+ existing_branch = Branch . create "hotfix-branch"
135+
136+ expect { git . hotfix "branch" } . to raise_error Git ::FeatureExistsError
137+ end
138+
139+ it "should checkout the master branch, pull it, then create and switch to a new branch" do
140+ some_other_branch = Branch . create "random-branch"
141+
142+ allow ( git ) . to receive ( :current_branch ) . and_return ( some_other_branch )
143+
144+ expect ( System ) . to receive ( :call ) . with ( "checkout master" )
145+ expect ( System ) . to receive ( :call ) . with ( "pull origin master:master" )
146+ expect ( System ) . to receive ( :call ) . with ( "branch hotfix-branch" )
147+ expect ( System ) . to receive ( :call ) . with ( "checkout hotfix-branch" )
148+
149+ git . hotfix "branch"
150+ end
151+
152+ it "should not checkout the master branch if already on it" do
153+ # NOTE: the default git repo is on "master" branch to begin
154+ expect ( System ) . not_to receive ( :call ) . with ( "checkout master" )
155+
156+ git . hotfix "branch"
157+ end
158+ end
159+
107160 describe "#finish" do
108161 it "should switch to development, perform a pull and delete the previous branch" do
109162 branch = Branch . create ( "test-branch" )
@@ -112,13 +165,11 @@ module Code
112165
113166 expect ( System ) . to receive ( :call ) . with ( "checkout development" ) . and_call_original
114167 expect ( System ) . to receive ( :call ) . with ( "pull origin development:development" )
115- expect ( System ) . to receive ( :call ) . with ( "branch -d test-branch" ) . and_call_original
168+ expect ( System ) . to receive ( :call ) . with ( "branch -d test-branch" )
116169
117170 allow ( git ) . to receive ( :fetch )
118171
119172 git . finish
120-
121- expect ( Branch . exists? "test-branch" ) . to eq false
122173 end
123174 end
124175
0 commit comments