-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgit_branch_spec.rb
158 lines (100 loc) · 3.71 KB
/
git_branch_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require 'git-process/git_lib'
require 'GitRepoHelper'
describe GitProc::GitBranch do
include GitRepoHelper
def log_level
Logger::ERROR
end
before(:each) do
create_files(%w(.gitignore))
gitlib.commit('initial')
end
after(:each) do
rm_rf(gitlib.workdir)
end
describe 'comparison' do
it 'should handle another branch' do
base_branch = gitlib.branches.current
current = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
fb = gitlib.branches['fb']
expect( current <=> fb ).to eq(1)
expect( fb <=> current ).to eq(-1)
end
it 'should handle a String' do
current = gitlib.branches.current
expect( current <=> 'fb' ).to eq(1)
expect( 'fb' <=> current ).to eq(-1)
end
it 'should handle a nil' do
current = gitlib.branches.current
expect( current <=> nil ).to be_nil
expect( nil <=> current ).to be_nil
end
it 'should handle an unknown' do
current = gitlib.branches.current
expect( current <=> {} ).to be_nil
expect( {} <=> current ).to be_nil
end
end
describe 'contains_all_of' do
it 'should handle the trivial case' do
current = gitlib.branches.current
current.contains_all_of(current.name).should == true
end
it 'should handle new branch containing base branch that did not change' do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
change_file_and_commit('a', 'hello')
current.contains_all_of(base_branch.name).should == true
end
it "should handle new branch containing base branch that did change" do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
gitlib.checkout(base_branch.name)
change_file_and_commit('a', 'goodbye')
current.contains_all_of(base_branch.name).should == false
end
it 'should handle containing in both branches' do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
change_file_and_commit('a', 'hello')
gitlib.checkout(base_branch.name)
change_file_and_commit('a', 'goodbye')
current.contains_all_of(base_branch.name).should == false
end
end
describe "is_ahead_of" do
it "should handle the trivial case" do
current = gitlib.branches.current
current.is_ahead_of(current.name).should == false # same is not "ahead of"
end
it "should handle new branch containing base branch that did not change" do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
change_file_and_commit('a', 'hello')
current.is_ahead_of(base_branch.name).should == true
end
it "should handle new branch containing base branch that did change" do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
gitlib.checkout(base_branch.name)
change_file_and_commit('a', 'goodbye')
current.is_ahead_of(base_branch.name).should == false
end
it "should handle containing in both branches" do
base_branch = gitlib.branches.current
gitlib.checkout('fb', :new_branch => base_branch.name)
current = gitlib.branches.current
change_file_and_commit('a', 'hello')
gitlib.checkout(base_branch.name)
change_file_and_commit('a', 'goodbye')
current.is_ahead_of(base_branch.name).should == false
end
end
end