git_statistics 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/CHANGELOG.md +1 -0
- data/lib/git_statistics.rb +22 -19
- data/lib/git_statistics/collector.rb +11 -4
- data/lib/git_statistics/commits.rb +64 -24
- data/lib/git_statistics/results.rb +4 -4
- data/lib/git_statistics/utilities.rb +13 -2
- data/lib/git_statistics/version.rb +1 -1
- data/spec/collector_spec.rb +101 -114
- data/spec/commits_spec.rb +222 -171
- data/spec/results_spec.rb +113 -89
- data/spec/spec_helper.rb +6 -0
- data/spec/utilities_spec.rb +97 -55
- metadata +2 -2
data/spec/commits_spec.rb
CHANGED
@@ -2,237 +2,288 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
include GitStatistics
|
3
3
|
|
4
4
|
describe Commits do
|
5
|
-
|
5
|
+
let(:verbose) {false}
|
6
|
+
let(:limit) {100}
|
7
|
+
let(:fresh) {true}
|
8
|
+
let(:pretty) {false}
|
9
|
+
let(:collector) {Collector.new(verbose, limit, fresh, pretty)}
|
10
|
+
|
11
|
+
let(:commits) {collector.commits}
|
12
|
+
|
13
|
+
let(:fixture_file) {"multiple_authors.json"}
|
14
|
+
let(:save_file) {collector.commits_path + "0.json"}
|
15
|
+
let(:email) {false}
|
16
|
+
let(:merge) {false}
|
17
|
+
let(:sort) {:commits}
|
18
|
+
let(:stats) do
|
19
|
+
setup_commits(commits, fixture_file, save_file, pretty)
|
20
|
+
commits.calculate_statistics(email, merge)
|
21
|
+
commits.author_top_n_type(sort)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#flush_commits" do
|
25
|
+
let(:commits) {collector.commits.load(fixture(fixture_file))}
|
26
|
+
|
27
|
+
context "with commits exceeding limit" do
|
28
|
+
let(:limit) {2}
|
29
|
+
it do
|
30
|
+
commits.size.should == 3
|
31
|
+
commits.flush_commits
|
32
|
+
commits.size.should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with commits equal to limit" do
|
37
|
+
let(:limit) {3}
|
38
|
+
it do
|
39
|
+
commits.size.should == 3
|
40
|
+
commits.flush_commits
|
41
|
+
commits.size.should == 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with commits less than limit" do
|
46
|
+
let(:limit) {5}
|
47
|
+
it do
|
48
|
+
commits.size.should == 3
|
49
|
+
commits.flush_commits
|
50
|
+
commits.size.should == 3
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with commits less than limit but forced" do
|
55
|
+
let(:limit) {5}
|
56
|
+
it do
|
57
|
+
commits.size.should == 3
|
58
|
+
commits.flush_commits(true)
|
59
|
+
commits.size.should == 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
6
63
|
|
7
64
|
describe "#author_top_n_type" do
|
65
|
+
let(:sort) {:deletions}
|
66
|
+
|
8
67
|
context "with valid data" do
|
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
|
-
it {stats[author_2][:languages][:Ruby][:deletions].should == 0}
|
38
|
-
it {stats[author_2][:languages][:Ruby][:create].should == 1}
|
68
|
+
context "on first author" do
|
69
|
+
author = "John Smith"
|
70
|
+
subject {stats[author]}
|
71
|
+
it {stats.has_key?(author).should be_true}
|
72
|
+
it {subject[:commits].should == 1}
|
73
|
+
it {subject[:deletions].should == 16}
|
74
|
+
it {subject[:additions].should == 64}
|
75
|
+
|
76
|
+
it {subject[:languages][:Ruby][:additions].should == 64}
|
77
|
+
it {subject[:languages][:Ruby][:deletions].should == 16}
|
78
|
+
end
|
79
|
+
|
80
|
+
context "on second author" do
|
81
|
+
author = "Kevin Jalbert"
|
82
|
+
subject {stats[author]}
|
83
|
+
it {stats.has_key?(author).should be_true}
|
84
|
+
it {subject[:commits].should == 1}
|
85
|
+
it {subject[:additions].should == 73}
|
86
|
+
it {subject[:deletions].should == 0}
|
87
|
+
it {subject[:create].should == 2}
|
88
|
+
|
89
|
+
it {subject[:languages][:Markdown][:additions].should == 11}
|
90
|
+
it {subject[:languages][:Markdown][:deletions].should == 0}
|
91
|
+
it {subject[:languages][:Markdown][:create].should== 1}
|
92
|
+
it {subject[:languages][:Ruby][:additions].should == 62}
|
93
|
+
it {subject[:languages][:Ruby][:deletions].should == 0}
|
94
|
+
it {subject[:languages][:Ruby][:create].should == 1}
|
95
|
+
end
|
39
96
|
end
|
40
97
|
|
41
98
|
context "with invalid type" do
|
42
|
-
|
43
|
-
commits.load(fixture("multiple_authors.json"))
|
44
|
-
|
45
|
-
commits.calculate_statistics(false, false)
|
46
|
-
stats = commits.author_top_n_type(:wrong)
|
47
|
-
|
99
|
+
let(:sort) {:wrong}
|
48
100
|
it {stats.should == nil}
|
49
101
|
end
|
50
102
|
|
51
103
|
context "with invalid data" do
|
52
|
-
|
53
|
-
|
54
|
-
commits.calculate_statistics(false, false)
|
55
|
-
stats = commits.author_top_n_type(:deletions)
|
56
|
-
|
104
|
+
let(:fixture_file) {nil}
|
57
105
|
it {stats.should == nil}
|
58
106
|
end
|
59
107
|
end
|
60
108
|
|
61
109
|
describe "#calculate_statistics" do
|
62
|
-
|
63
|
-
commits = Commits.new
|
64
|
-
commits.load(fixture("single_author_pretty.json"))
|
65
|
-
|
66
|
-
commits.calculate_statistics(true, false)
|
67
|
-
stats = commits.author_top_n_type(:commits)
|
110
|
+
let(:fixture_file) {"single_author_pretty.json"}
|
68
111
|
|
112
|
+
context "with email" do
|
113
|
+
let(:email) {true}
|
69
114
|
author = "kevin.j.jalbert@gmail.com"
|
70
|
-
|
71
|
-
it {stats[author][:commits].should == 1}
|
72
|
-
it {stats[author][:additions].should == 73}
|
73
|
-
it {stats[author][:deletions].should == 0}
|
74
|
-
it {stats[author][:create].should == 2}
|
115
|
+
subject {stats[author]}
|
75
116
|
|
76
|
-
it {stats
|
77
|
-
it {
|
78
|
-
it {
|
79
|
-
it {
|
80
|
-
it {
|
117
|
+
it {stats.has_key?(author).should be_true}
|
118
|
+
it {subject[:commits].should == 1}
|
119
|
+
it {subject[:additions].should == 73}
|
120
|
+
it {subject[:deletions].should == 0}
|
121
|
+
it {subject[:create].should == 2}
|
122
|
+
|
123
|
+
it {subject[:languages][:Markdown][:additions].should == 11}
|
124
|
+
it {subject[:languages][:Markdown][:deletions].should == 0}
|
125
|
+
it {subject[:languages][:Ruby][:additions].should == 62}
|
126
|
+
it {subject[:languages][:Ruby][:deletions].should == 0}
|
127
|
+
it {subject[:languages][:Ruby][:create].should == 1}
|
81
128
|
end
|
82
129
|
|
83
130
|
context "with merge" do
|
84
|
-
|
85
|
-
commits.load(fixture("single_author_pretty.json"))
|
86
|
-
|
87
|
-
commits.calculate_statistics(false, true)
|
88
|
-
stats = commits.author_top_n_type(:commits)
|
89
|
-
|
131
|
+
let(:merge) {true}
|
90
132
|
author = "Kevin Jalbert"
|
133
|
+
subject {stats[author]}
|
134
|
+
|
91
135
|
it {stats.has_key?(author).should be_true}
|
92
|
-
it {
|
93
|
-
it {
|
94
|
-
it {
|
95
|
-
it {
|
96
|
-
it {
|
97
|
-
|
98
|
-
it {
|
99
|
-
it {
|
100
|
-
it {
|
101
|
-
it {
|
102
|
-
it {
|
136
|
+
it {subject[:commits].should == 2}
|
137
|
+
it {subject[:additions].should == 153}
|
138
|
+
it {subject[:deletions].should == 5}
|
139
|
+
it {subject[:create].should == 3}
|
140
|
+
it {subject[:merges].should == 1}
|
141
|
+
|
142
|
+
it {subject[:languages][:Markdown][:additions].should == 18}
|
143
|
+
it {subject[:languages][:Markdown][:deletions].should == 1}
|
144
|
+
it {subject[:languages][:Ruby][:additions].should == 135}
|
145
|
+
it {subject[:languages][:Ruby][:deletions].should == 4}
|
146
|
+
it {subject[:languages][:Ruby][:create].should == 2}
|
103
147
|
end
|
104
148
|
end
|
105
149
|
|
106
150
|
describe "#add_language_stats" do
|
107
|
-
file = {:additions => 10,
|
108
|
-
:deletions => 5}
|
109
151
|
|
110
152
|
context "with file language" do
|
111
|
-
|
112
|
-
|
113
|
-
|
153
|
+
let(:data) {
|
154
|
+
data = Hash.new(0)
|
155
|
+
data[:languages] = {}
|
114
156
|
|
115
|
-
|
157
|
+
file = {:additions => 10,
|
158
|
+
:deletions => 5}
|
116
159
|
|
117
|
-
|
160
|
+
file[:language] = "Ruby"
|
118
161
|
|
119
|
-
|
120
|
-
|
162
|
+
data = commits.add_language_stats(data, file)
|
163
|
+
}
|
164
|
+
|
165
|
+
it {data[:languages][:Ruby][:additions].should == 10}
|
166
|
+
it {data[:languages][:Ruby][:deletions].should == 5}
|
121
167
|
end
|
122
168
|
|
123
169
|
context "with multiple files" do
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
170
|
+
let(:data) {
|
171
|
+
data = Hash.new(0)
|
172
|
+
data[:languages] = {}
|
173
|
+
|
174
|
+
file = {:additions => 10,
|
175
|
+
:deletions => 5}
|
176
|
+
|
177
|
+
# First file is "Ruby"
|
178
|
+
file[:language] = "Ruby"
|
179
|
+
data = commits.add_language_stats(data, file)
|
180
|
+
|
181
|
+
# Second file is "Java"
|
182
|
+
file[:language] = "Java"
|
183
|
+
data = commits.add_language_stats(data, file)
|
184
|
+
|
185
|
+
# Third file is "Ruby"
|
186
|
+
file[:language] = "Ruby"
|
187
|
+
data = commits.add_language_stats(data, file)
|
188
|
+
}
|
189
|
+
|
190
|
+
it {data[:languages][:Ruby][:additions].should == 20}
|
191
|
+
it {data[:languages][:Ruby][:deletions].should == 10}
|
192
|
+
it {data[:languages][:Java][:additions].should == 10}
|
193
|
+
it {data[:languages][:Java][:deletions].should == 5}
|
144
194
|
end
|
145
195
|
end
|
146
196
|
|
147
197
|
describe "#add_commit_stats" do
|
148
|
-
commit = {:additions => 10,
|
149
|
-
:deletions => 5,
|
150
|
-
:merge => false}
|
151
|
-
|
152
198
|
context "with valid commit" do
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
199
|
+
let(:data) {
|
200
|
+
commit = {:additions => 10,
|
201
|
+
:deletions => 5,
|
202
|
+
:merge => false}
|
203
|
+
|
204
|
+
data = Hash.new(0)
|
205
|
+
data = commits.add_commit_stats(data, commit)
|
206
|
+
}
|
207
|
+
|
208
|
+
it {data[:commits].should == 1}
|
209
|
+
it {data[:additions].should == 10}
|
210
|
+
it {data[:deletions].should == 5}
|
211
|
+
it {data[:merges].should == 0}
|
162
212
|
end
|
163
213
|
|
164
|
-
context "with multiple commits" do
|
165
|
-
|
166
|
-
|
214
|
+
context "with multiple commits (one merge commit)" do
|
215
|
+
let(:data) {
|
216
|
+
commit = {:additions => 10,
|
217
|
+
:deletions => 5,
|
218
|
+
:merge => false}
|
167
219
|
|
168
|
-
|
220
|
+
data = Hash.new(0)
|
221
|
+
data = commits.add_commit_stats(data, commit)
|
169
222
|
|
170
|
-
|
171
|
-
|
223
|
+
# Second commit has merge status
|
224
|
+
commit[:merge] = true
|
225
|
+
data = commits.add_commit_stats(data, commit)
|
226
|
+
}
|
172
227
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
it {data[:deletions].should == 10}
|
178
|
-
it {data[:merges].should == 1}
|
228
|
+
it {data[:commits].should == 2}
|
229
|
+
it {data[:additions].should == 20}
|
230
|
+
it {data[:deletions].should == 10}
|
231
|
+
it {data[:merges].should == 1}
|
179
232
|
end
|
180
233
|
|
181
234
|
context "with commit that has file status changes" do
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
data = Hash.new(0)
|
203
|
-
commit[:merge] = true
|
204
|
-
|
205
|
-
data = commits.add_commit_stats(data, commit)
|
206
|
-
|
207
|
-
it {data[:commits].should == 1}
|
208
|
-
it {data[:additions].should == 10}
|
209
|
-
it {data[:deletions].should == 5}
|
210
|
-
it {data[:merges].should == 1}
|
235
|
+
let(:data) {
|
236
|
+
commit = {:additions => 10,
|
237
|
+
:deletions => 5,
|
238
|
+
:create => 1,
|
239
|
+
:delete => 2,
|
240
|
+
:rename => 3,
|
241
|
+
:copy => 4,
|
242
|
+
:merge => false}
|
243
|
+
|
244
|
+
data = Hash.new(0)
|
245
|
+
data = commits.add_commit_stats(data, commit)
|
246
|
+
}
|
247
|
+
|
248
|
+
it {data[:commits].should == 1}
|
249
|
+
it {data[:additions].should == 10}
|
250
|
+
it {data[:deletions].should == 5}
|
251
|
+
it {data[:create].should == 1}
|
252
|
+
it {data[:delete].should == 2}
|
253
|
+
it {data[:rename].should == 3}
|
254
|
+
it {data[:copy].should == 4}
|
211
255
|
end
|
212
256
|
end
|
213
257
|
|
214
258
|
describe "#save and #load" do
|
215
259
|
context "with pretty" do
|
216
|
-
|
217
|
-
|
218
|
-
|
260
|
+
let(:fixture_file) {"single_author_pretty.json"}
|
261
|
+
let(:pretty) {true}
|
262
|
+
|
263
|
+
it do
|
264
|
+
commits.load(fixture(fixture_file))
|
265
|
+
commits.save("tmp.json", pretty)
|
219
266
|
|
220
|
-
|
221
|
-
|
267
|
+
same = FileUtils.compare_file("tmp.json", fixture(fixture_file))
|
268
|
+
FileUtils.remove_file("tmp.json")
|
222
269
|
|
223
|
-
|
270
|
+
same.should be_true
|
271
|
+
end
|
224
272
|
end
|
225
273
|
|
226
274
|
context "with no pretty" do
|
227
|
-
|
228
|
-
|
229
|
-
commits.save("tmp.json", false)
|
275
|
+
let(:fixture_file) {"multiple_authors.json"}
|
276
|
+
let(:pretty) {false}
|
230
277
|
|
231
|
-
|
232
|
-
|
278
|
+
it do
|
279
|
+
commits.load(fixture(fixture_file))
|
280
|
+
commits.save("tmp.json", pretty)
|
233
281
|
|
234
|
-
|
282
|
+
same = FileUtils.compare_file("tmp.json", fixture(fixture_file))
|
283
|
+
FileUtils.remove_file("tmp.json")
|
284
|
+
|
285
|
+
same.should be_true
|
286
|
+
end
|
235
287
|
end
|
236
288
|
end
|
237
|
-
|
238
289
|
end
|