Skip to content

Commit d402336

Browse files
committed
Cover #177 with a test
1 parent 314826c commit d402336

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/code_climate/test_reporter/git.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def info
1010
}
1111
end
1212

13+
def head_from_git_or_ci
14+
head_from_git || head_from_ci
15+
end
16+
1317
def branch_from_git_or_ci
1418
clean_service_branch || clean_git_branch || "master"
1519
end
@@ -34,10 +38,6 @@ def clean_git_branch
3438

3539
private
3640

37-
def head_from_git_or_ci
38-
head_from_git || head_from_ci
39-
end
40-
4141
def head_from_git
4242
commit_hash = git("log -1 --pretty=format:'%H'")
4343
!commit_hash.empty? ? commit_hash : nil

spec/code_climate/test_reporter/git_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ def self.root
7979
end
8080
end
8181

82+
describe 'head_from_git_or_ci' do
83+
it 'returns the head sha from git' do
84+
expect(Git).to receive(:git).with("log -1 --pretty=format:'%H'").and_return("1234")
85+
86+
expect(Git.head_from_git_or_ci).to eq '1234'
87+
end
88+
89+
it 'returns the head sha from ci if git is not available' do
90+
expect(Git).to receive(:git).with("log -1 --pretty=format:'%H'").and_return("")
91+
expect(Ci).to receive(:service_data).and_return({commit_sha: "4567"})
92+
93+
expect(Git.head_from_git_or_ci).to eq '4567'
94+
end
95+
end
96+
8297
describe 'committed_at_from_git_or_ci' do
8398
it 'returns the committed_at from git' do
8499
expect(Git.committed_at_from_git_or_ci).to eq Git.send(:committed_at_from_git)

0 commit comments

Comments
 (0)