forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitting_spec.rb
102 lines (84 loc) · 2.08 KB
/
committing_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'spec_helper'
describe 'commiting' do
subject { shell(%w[git commit --allow-empty -m Test]) }
let(:config) { <<-YML }
CommitMsg:
ALL:
enabled: false
PreCommit:
ALL:
enabled: false
AuthorName:
enabled: true
YML
around do |example|
repo do
File.open('.overcommit.yml', 'w') { |f| f.write(config) }
`overcommit --install > #{File::NULL}`
example.run
end
end
context 'when a hook fails' do
before do
`git config --local user.name "John"`
end
it 'exits with a non-zero status' do
subject.status.should_not == 0
end
end
context 'when no hooks fail' do
before do
`git config --local user.name "John Doe"`
end
it 'exits successfully' do
subject.status.should == 0
end
end
end
describe 'commiting to an empty repo' do
subject { shell(%w[git commit -m Test]) }
let(:config) { <<-YML }
CommitMsg:
ALL:
enabled: false
PreCommit:
ALL:
enabled: false
HardTabs:
enabled: true
YML
around do |example|
repo do
`overcommit --install > #{File::NULL}`
File.open('.overcommit.yml', 'w') { |f| f.write(config) }
File.open('test.txt', 'w') { |f| f.write(file_contents) }
`git add test.txt`
example.run
end
end
context 'when a hook fails' do
let(:file_contents) { "\t\tFile with some hard tabs" }
it 'exits with a non-zero status' do
subject.status.should_not == 0
end
it 'does not complain about missing HEAD' do
subject.stderr.should_not include 'HEAD'
end
it 'does not lose changes' do
File.open('test.txt').read.should == file_contents
end
end
context 'when no hooks fail' do
let(:file_contents) { 'File without hard tabs' }
it 'exits successfully' do
subject.status.should == 0
end
it 'does not complain about missing HEAD' do
subject.stderr.should_not include 'HEAD'
end
it 'does not lose changes' do
subject
File.open('test.txt').read.should == file_contents
end
end
end