git_statistics 0.7.0 → 0.8.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.
@@ -3,357 +3,390 @@ require 'fileutils'
3
3
  include GitStatistics
4
4
 
5
5
  describe Commits do
6
- let(:limit) {100}
7
- let(:fresh) {true}
8
- let(:pretty) {false}
6
+ let(:limit) { 100 }
7
+ let(:fresh) { true }
8
+ let(:pretty) { false }
9
9
  let(:repo) { GIT_REPO }
10
- let(:collector) {Collector.new(repo, limit, fresh, pretty)}
10
+ let(:collector) { Collector.new(repo, limit, fresh, pretty) }
11
11
 
12
- let(:commits) {collector.commits}
12
+ let(:commits) { collector.commits }
13
13
 
14
- let(:fixture_file) {"multiple_authors.json"}
15
- let(:save_file) { File.join(collector.commits_path, "0.json") }
16
- let(:email) {false}
17
- let(:merge) {false}
18
- let(:sort) {:commits}
14
+ let(:fixture_file) { 'multiple_authors.json' }
15
+ let(:save_file) { File.join(collector.commits_path, '0.json') }
16
+ let(:email) { false }
17
+ let(:merge) { false }
18
+ let(:sort) { :commits }
19
19
  let(:stats) do
20
20
  setup_commits(commits, fixture_file, save_file, pretty)
21
21
  commits.calculate_statistics(email, merge)
22
22
  commits.author_top_n_type(sort)
23
23
  end
24
24
 
25
- describe "#files_in_path" do
25
+ describe '#files_in_path' do
26
26
  let(:path) { '/tmp/example' }
27
27
  subject { commits.files_in_path }
28
- around do |example|
28
+
29
+ it do
29
30
  Dir.mktmpdir do |dir|
30
31
  Dir.chdir(dir) do
31
32
  FileUtils.touch '0.json'
32
33
  FileUtils.touch '1.json'
33
- commits.stub(:path) { dir }
34
- example.run
34
+ allow(commits).to receive(:path) { dir }
35
+
36
+ expect(subject.count).to eq(2)
37
+ expect(subject).to_not include('.')
38
+ expect(subject).to_not include('..')
35
39
  end
36
40
  end
37
41
  end
38
- its(:count) { should == 2 }
39
- it { should_not include '.' }
40
- it { should_not include '..' }
41
42
  end
42
43
 
43
- describe "#flush_commits" do
44
- let(:commits) {collector.commits.load(fixture(fixture_file).file)}
44
+ describe '#flush_commits' do
45
+ let(:commits) { collector.commits.load(fixture(fixture_file).file) }
45
46
 
46
47
  def commit_size_changes_from(beginning, opts = {})
47
- commits.size.should == beginning
48
+ expect(commits.size).to eq(beginning)
48
49
  commits.flush_commits
49
- commits.size.should == opts[:to]
50
+ expect(commits.size).to eq(opts[:to])
50
51
  end
51
52
 
52
- context "with commits exceeding limit" do
53
- let(:limit) {2}
53
+ context 'with commits exceeding limit' do
54
+ let(:limit) { 2 }
54
55
  it { commit_size_changes_from(3, to: 0) }
55
56
  end
56
57
 
57
- context "with commits equal to limit" do
58
- let(:limit) {3}
58
+ context 'with commits equal to limit' do
59
+ let(:limit) { 3 }
59
60
  it { commit_size_changes_from(3, to: 0) }
60
61
  end
61
62
 
62
- context "with commits less than limit" do
63
- let(:limit) {5}
63
+ context 'with commits less than limit' do
64
+ let(:limit) { 5 }
64
65
  it { commit_size_changes_from(3, to: 3) }
65
66
  end
66
67
  end
67
68
 
68
- describe "#process_commits" do
69
- let(:commits) {collector.commits.load(fixture(fixture_file).file)}
70
- let(:type) {:author}
69
+ describe '#process_commits' do
70
+ let(:commits) { collector.commits.load(fixture(fixture_file).file) }
71
+ let(:type) { :author }
71
72
  subject { commits.stats[author_name] }
72
73
 
73
74
  before do
74
75
  commits.process_commits(type, merge)
75
76
  end
76
77
 
77
- context "with merge" do
78
- let(:merge) {true}
79
-
80
- context "on first author" do
81
- let(:author_name) {"Kevin Jalbert"}
82
- it {subject[:additions].should == 153}
83
- it {subject[:deletions].should == 5}
84
- it {subject[:commits].should == 2}
85
- it {subject[:added_files].should == 3}
86
- it {subject[:merges].should == 1}
87
-
88
- it {subject[:languages][:Markdown][:additions].should == 18}
89
- it {subject[:languages][:Markdown][:deletions].should == 1}
90
- it {subject[:languages][:Markdown][:added_files].should == 1}
91
- it {subject[:languages][:Ruby][:additions].should == 135}
92
- it {subject[:languages][:Ruby][:deletions].should == 4}
93
- it {subject[:languages][:Ruby][:added_files].should == 2}
78
+ context 'with merge' do
79
+ let(:merge) { true }
80
+
81
+ context 'on first author' do
82
+ let(:author_name) { 'Kevin Jalbert' }
83
+
84
+ it do
85
+ expect(subject[:additions]).to eq(153)
86
+ expect(subject[:deletions]).to eq(5)
87
+ expect(subject[:commits]).to eq(2)
88
+ expect(subject[:added_files]).to eq(3)
89
+ expect(subject[:merges]).to eq(1)
90
+
91
+ expect(subject[:languages][:Markdown][:additions]).to eq(18)
92
+ expect(subject[:languages][:Markdown][:deletions]).to eq(1)
93
+ expect(subject[:languages][:Markdown][:added_files]).to eq(1)
94
+ expect(subject[:languages][:Ruby][:additions]).to eq(135)
95
+ expect(subject[:languages][:Ruby][:deletions]).to eq(4)
96
+ expect(subject[:languages][:Ruby][:added_files]).to eq(2)
97
+ end
94
98
  end
95
99
 
96
- context "on second author" do
97
- let(:author_name) {"John Smith"}
98
- it {subject[:additions].should == 64}
99
- it {subject[:deletions].should == 16}
100
- it {subject[:commits].should == 1}
100
+ context 'on second author' do
101
+ let(:author_name) { 'John Smith' }
101
102
 
102
- it {subject[:languages][:Ruby][:additions].should == 64}
103
- it {subject[:languages][:Ruby][:deletions].should == 16}
104
- it {subject[:languages][:Ruby][:added_files].should == 0}
103
+ it do
104
+ expect(subject[:additions]).to eq(64)
105
+ expect(subject[:deletions]).to eq(16)
106
+ expect(subject[:commits]).to eq(1)
107
+
108
+ expect(subject[:languages][:Ruby][:additions]).to eq(64)
109
+ expect(subject[:languages][:Ruby][:deletions]).to eq(16)
110
+ expect(subject[:languages][:Ruby][:added_files]).to eq(0)
111
+ end
105
112
  end
106
113
  end
107
114
 
108
- context "without merge" do
109
- let(:merge) {false}
110
-
111
- context "on first author" do
112
- let(:author_name) {"Kevin Jalbert"}
113
- it {subject[:additions].should == 73}
114
- it {subject[:deletions].should == 0}
115
- it {subject[:commits].should == 1}
116
- it {subject[:added_files].should == 2}
117
-
118
- it {subject[:languages][:Markdown][:additions].should == 11}
119
- it {subject[:languages][:Markdown][:deletions].should == 0}
120
- it {subject[:languages][:Markdown][:added_files].should == 1}
121
- it {subject[:languages][:Ruby][:additions].should == 62}
122
- it {subject[:languages][:Ruby][:deletions].should == 0}
123
- it {subject[:languages][:Ruby][:added_files].should == 1}
115
+ context 'without merge' do
116
+ let(:merge) { false }
117
+
118
+ context 'on first author' do
119
+ let(:author_name) { 'Kevin Jalbert' }
120
+
121
+ it do
122
+ expect(subject[:additions]).to eq(73)
123
+ expect(subject[:deletions]).to eq(0)
124
+ expect(subject[:commits]).to eq(1)
125
+ expect(subject[:added_files]).to eq(2)
126
+
127
+ expect(subject[:languages][:Markdown][:additions]).to eq(11)
128
+ expect(subject[:languages][:Markdown][:deletions]).to eq(0)
129
+ expect(subject[:languages][:Markdown][:added_files]).to eq(1)
130
+ expect(subject[:languages][:Ruby][:additions]).to eq(62)
131
+ expect(subject[:languages][:Ruby][:deletions]).to eq(0)
132
+ expect(subject[:languages][:Ruby][:added_files]).to eq(1)
133
+ end
124
134
  end
125
135
 
126
- context "on second author" do
127
- let(:author_name) {"John Smith"}
128
- it {subject[:additions].should == 64}
129
- it {subject[:deletions].should == 16}
130
- it {subject[:commits].should == 1}
136
+ context 'on second author' do
137
+ let(:author_name) { 'John Smith' }
131
138
 
132
- it {subject[:languages][:Ruby][:additions].should == 64}
133
- it {subject[:languages][:Ruby][:deletions].should == 16}
139
+ it do
140
+ expect(subject[:additions]).to eq(64)
141
+ expect(subject[:deletions]).to eq(16)
142
+ expect(subject[:commits]).to eq(1)
143
+
144
+ expect(subject[:languages][:Ruby][:additions]).to eq(64)
145
+ expect(subject[:languages][:Ruby][:deletions]).to eq(16)
146
+ end
134
147
  end
135
148
  end
136
149
  end
137
150
 
138
- describe "#author_top_n_type" do
139
- let(:sort) {:deletions}
140
- subject {stats[author]}
151
+ describe '#author_top_n_type' do
152
+ let(:sort) { :deletions }
153
+ subject { stats[author] }
141
154
 
142
- context "with valid data" do
143
- context "on first author" do
155
+ context 'with valid data' do
156
+ context 'on first author' do
144
157
  let(:author) { 'John Smith' }
145
- it {stats.has_key?(author).should be_true}
146
- it {subject[:commits].should == 1}
147
- it {subject[:deletions].should == 16}
148
- it {subject[:additions].should == 64}
149
158
 
150
- it {subject[:languages][:Ruby][:additions].should == 64}
151
- it {subject[:languages][:Ruby][:deletions].should == 16}
159
+ it do
160
+ expect(stats.key?(author)).to be true
161
+ expect(subject[:commits]).to eq(1)
162
+ expect(subject[:deletions]).to eq(16)
163
+ expect(subject[:additions]).to eq(64)
164
+
165
+ expect(subject[:languages][:Ruby][:additions]).to eq(64)
166
+ expect(subject[:languages][:Ruby][:deletions]).to eq(16)
167
+ end
152
168
  end
153
169
 
154
- context "on second author" do
155
- let(:author) { "Kevin Jalbert" }
156
- it {stats.has_key?(author).should be_true}
157
- it {subject[:commits].should == 1}
158
- it {subject[:additions].should == 73}
159
- it {subject[:deletions].should == 0}
160
- it {subject[:added_files].should == 2}
161
-
162
- it {subject[:languages][:Markdown][:additions].should == 11}
163
- it {subject[:languages][:Markdown][:deletions].should == 0}
164
- it {subject[:languages][:Markdown][:added_files].should== 1}
165
- it {subject[:languages][:Ruby][:additions].should == 62}
166
- it {subject[:languages][:Ruby][:deletions].should == 0}
167
- it {subject[:languages][:Ruby][:added_files].should == 1}
170
+ context 'on second author' do
171
+ let(:author) { 'Kevin Jalbert' }
172
+
173
+ it do
174
+ expect(stats.key?(author)).to be true
175
+ expect(subject[:commits]).to eq(1)
176
+ expect(subject[:additions]).to eq(73)
177
+ expect(subject[:deletions]).to eq(0)
178
+ expect(subject[:added_files]).to eq(2)
179
+
180
+ expect(subject[:languages][:Markdown][:additions]).to eq(11)
181
+ expect(subject[:languages][:Markdown][:deletions]).to eq(0)
182
+ expect(subject[:languages][:Markdown][:added_files]).to eq(1)
183
+ expect(subject[:languages][:Ruby][:additions]).to eq(62)
184
+ expect(subject[:languages][:Ruby][:deletions]).to eq(0)
185
+ expect(subject[:languages][:Ruby][:added_files]).to eq(1)
186
+ end
168
187
  end
169
188
  end
170
189
 
171
- context "with invalid type" do
172
- let(:sort) {:wrong}
173
- it { stats.should be_nil }
190
+ context 'with invalid type' do
191
+ let(:sort) { :wrong }
192
+ it { expect(stats).to be nil }
174
193
  end
175
194
 
176
- context "with invalid data" do
177
- let(:fixture_file) {nil}
178
- it { stats.should be_nil }
195
+ context 'with invalid data' do
196
+ let(:fixture_file) { nil }
197
+ it { expect(stats).to be nil }
179
198
  end
180
199
  end
181
200
 
182
- describe "#calculate_statistics" do
183
- let(:fixture_file) {"single_author_pretty.json"}
184
- subject {stats[author]}
185
-
186
- context "with email" do
187
- let(:email) {true}
188
- let(:author) { "kevin.j.jalbert@gmail.com" }
189
-
190
- it {stats.has_key?(author).should be_true}
191
- it {subject[:commits].should == 1}
192
- it {subject[:additions].should == 73}
193
- it {subject[:deletions].should == 0}
194
- it {subject[:added_files].should == 2}
195
-
196
- it {subject[:languages][:Markdown][:additions].should == 11}
197
- it {subject[:languages][:Markdown][:deletions].should == 0}
198
- it {subject[:languages][:Ruby][:additions].should == 62}
199
- it {subject[:languages][:Ruby][:deletions].should == 0}
200
- it {subject[:languages][:Ruby][:added_files].should == 1}
201
+ describe '#calculate_statistics' do
202
+ let(:fixture_file) { 'single_author_pretty.json' }
203
+ subject { stats[author] }
204
+
205
+ context 'with email' do
206
+ let(:email) { true }
207
+ let(:author) { 'kevin.j.jalbert@gmail.com' }
208
+
209
+ it do
210
+ expect(stats.key?(author)).to be true
211
+ expect(subject[:commits]).to eq(1)
212
+ expect(subject[:additions]).to eq(73)
213
+ expect(subject[:deletions]).to eq(0)
214
+ expect(subject[:added_files]).to eq(2)
215
+
216
+ expect(subject[:languages][:Markdown][:additions]).to eq(11)
217
+ expect(subject[:languages][:Markdown][:deletions]).to eq(0)
218
+ expect(subject[:languages][:Ruby][:additions]).to eq(62)
219
+ expect(subject[:languages][:Ruby][:deletions]).to eq(0)
220
+ expect(subject[:languages][:Ruby][:added_files]).to eq(1)
221
+ end
201
222
  end
202
223
 
203
- context "with merge" do
204
- let(:merge) {true}
205
- let(:author) { "Kevin Jalbert" }
206
-
207
- it {stats.has_key?(author).should be_true}
208
- it {subject[:commits].should == 2}
209
- it {subject[:additions].should == 153}
210
- it {subject[:deletions].should == 5}
211
- it {subject[:added_files].should == 3}
212
- it {subject[:merges].should == 1}
213
-
214
- it {subject[:languages][:Markdown][:additions].should == 18}
215
- it {subject[:languages][:Markdown][:deletions].should == 1}
216
- it {subject[:languages][:Ruby][:additions].should == 135}
217
- it {subject[:languages][:Ruby][:deletions].should == 4}
218
- it {subject[:languages][:Ruby][:added_files].should == 2}
224
+ context 'with merge' do
225
+ let(:merge) { true }
226
+ let(:author) { 'Kevin Jalbert' }
227
+
228
+ it do
229
+ expect(stats.key?(author)).to be true
230
+ expect(subject[:commits]).to eq(2)
231
+ expect(subject[:additions]).to eq(153)
232
+ expect(subject[:deletions]).to eq(5)
233
+ expect(subject[:added_files]).to eq(3)
234
+ expect(subject[:merges]).to eq(1)
235
+
236
+ expect(subject[:languages][:Markdown][:additions]).to eq(18)
237
+ expect(subject[:languages][:Markdown][:deletions]).to eq(1)
238
+ expect(subject[:languages][:Ruby][:additions]).to eq(135)
239
+ expect(subject[:languages][:Ruby][:deletions]).to eq(4)
240
+ expect(subject[:languages][:Ruby][:added_files]).to eq(2)
241
+ end
219
242
  end
220
243
  end
221
244
 
222
- describe "#add_language_stats" do
223
- context "with file language" do
224
- let(:data) {
245
+ describe '#add_language_stats' do
246
+ context 'with file language' do
247
+ let(:data) do
225
248
  data = Hash.new(0)
226
249
  data[:languages] = {}
227
250
 
228
- file = {:additions => 10,
229
- :deletions => 5}
251
+ file = { additions: 10,
252
+ deletions: 5 }
230
253
 
231
- file[:language] = "Ruby"
254
+ file[:language] = 'Ruby'
232
255
 
233
- data = commits.add_language_stats(data, file)
234
- }
256
+ commits.add_language_stats(data, file)
257
+ end
235
258
 
236
- it {data[:languages][:Ruby][:additions].should == 10}
237
- it {data[:languages][:Ruby][:deletions].should == 5}
259
+ it do
260
+ expect(data[:languages][:Ruby][:additions]).to eq(10)
261
+ expect(data[:languages][:Ruby][:deletions]).to eq(5)
262
+ end
238
263
  end
239
264
 
240
- context "with multiple files" do
241
- let(:data) {
265
+ context 'with multiple files' do
266
+ let(:data) do
242
267
  data = Hash.new(0)
243
268
  data[:languages] = {}
244
269
 
245
- file = {:additions => 10,
246
- :deletions => 5}
270
+ file = { additions: 10,
271
+ deletions: 5 }
247
272
 
248
273
  # First file is "Ruby"
249
- file[:language] = "Ruby"
274
+ file[:language] = 'Ruby'
250
275
  data = commits.add_language_stats(data, file)
251
276
 
252
277
  # Second file is "Java"
253
- file[:language] = "Java"
278
+ file[:language] = 'Java'
254
279
  data = commits.add_language_stats(data, file)
255
280
 
256
281
  # Third file is "Ruby"
257
- file[:language] = "Ruby"
258
- data = commits.add_language_stats(data, file)
259
- }
282
+ file[:language] = 'Ruby'
283
+ commits.add_language_stats(data, file)
284
+ end
260
285
 
261
- it {data[:languages][:Ruby][:additions].should == 20}
262
- it {data[:languages][:Ruby][:deletions].should == 10}
263
- it {data[:languages][:Java][:additions].should == 10}
264
- it {data[:languages][:Java][:deletions].should == 5}
286
+ it do
287
+ expect(data[:languages][:Ruby][:additions]).to eq(20)
288
+ expect(data[:languages][:Ruby][:deletions]).to eq(10)
289
+ expect(data[:languages][:Java][:additions]).to eq(10)
290
+ expect(data[:languages][:Java][:deletions]).to eq(5)
291
+ end
265
292
  end
266
293
  end
267
294
 
268
- describe "#add_commit_stats" do
269
- context "with valid commit" do
270
- let(:data) {
271
- commit = {:additions => 10,
272
- :deletions => 5,
273
- :new_files => 0,
274
- :removed_files => 0,
275
- :merge => false}
295
+ describe '#add_commit_stats' do
296
+ context 'with valid commit' do
297
+ let(:data) do
298
+ commit = { additions: 10,
299
+ deletions: 5,
300
+ new_files: 0,
301
+ removed_files: 0,
302
+ merge: false }
276
303
 
277
304
  data = Hash.new(0)
278
- data = commits.add_commit_stats(data, commit)
279
- }
305
+ commits.add_commit_stats(data, commit)
306
+ end
280
307
 
281
- it {data[:commits].should == 1}
282
- it {data[:additions].should == 10}
283
- it {data[:deletions].should == 5}
284
- it {data[:merges].should == 0}
308
+ it do
309
+ expect(data[:commits]).to eq(1)
310
+ expect(data[:additions]).to eq(10)
311
+ expect(data[:deletions]).to eq(5)
312
+ expect(data[:merges]).to eq(0)
313
+ end
285
314
  end
286
315
 
287
- context "with multiple commits (one merge commit)" do
288
- let(:data) {
289
- commit = {:additions => 10,
290
- :deletions => 5,
291
- :new_files => 0,
292
- :removed_files => 0,
293
- :merge => false}
316
+ context 'with multiple commits (one merge commit)' do
317
+ let(:data) do
318
+ commit = { additions: 10,
319
+ deletions: 5,
320
+ new_files: 0,
321
+ removed_files: 0,
322
+ merge: false }
294
323
 
295
324
  data = Hash.new(0)
296
325
  data = commits.add_commit_stats(data, commit)
297
326
 
298
327
  # Second commit has merge status
299
328
  commit[:merge] = true
300
- data = commits.add_commit_stats(data, commit)
301
- }
329
+ commits.add_commit_stats(data, commit)
330
+ end
302
331
 
303
- it {data[:commits].should == 2}
304
- it {data[:additions].should == 20}
305
- it {data[:deletions].should == 10}
306
- it {data[:merges].should == 1}
332
+ it do
333
+ expect(data[:commits]).to eq(2)
334
+ expect(data[:additions]).to eq(20)
335
+ expect(data[:deletions]).to eq(10)
336
+ expect(data[:merges]).to eq(1)
337
+ end
307
338
  end
308
339
 
309
- context "with commit that has file status changes" do
310
- let(:data) {
311
- commit = {:additions => 10,
312
- :deletions => 5,
313
- :added_files => 1,
314
- :deleted_files => 2,
315
- :merge => false}
340
+ context 'with commit that has file status changes' do
341
+ let(:data) do
342
+ commit = { additions: 10,
343
+ deletions: 5,
344
+ added_files: 1,
345
+ deleted_files: 2,
346
+ merge: false }
316
347
 
317
348
  data = Hash.new(0)
318
- data = commits.add_commit_stats(data, commit)
319
- }
349
+ commits.add_commit_stats(data, commit)
350
+ end
320
351
 
321
- it {data[:commits].should == 1}
322
- it {data[:additions].should == 10}
323
- it {data[:deletions].should == 5}
324
- it {data[:added_files].should == 1}
325
- it {data[:deleted_files].should == 2}
352
+ it do
353
+ expect(data[:commits]).to eq(1)
354
+ expect(data[:additions]).to eq(10)
355
+ expect(data[:deletions]).to eq(5)
356
+ expect(data[:added_files]).to eq(1)
357
+ expect(data[:deleted_files]).to eq(2)
358
+ end
326
359
  end
327
360
  end
328
361
 
329
- describe "#save and #load" do
362
+ describe '#save and #load' do
330
363
  let(:fixture_contents) { fixture(fixture_file).io.join("\n") }
331
- let(:tmpfile_contents) { File.read("tmp.json") }
364
+ let(:tmpfile_contents) { File.read('tmp.json') }
332
365
 
333
366
  before do
334
367
  commits.load(fixture(fixture_file).file)
335
- commits.save("tmp.json", pretty)
368
+ commits.save('tmp.json', pretty)
336
369
  end
337
370
 
338
371
  after do
339
- FileUtils.remove_file("tmp.json")
372
+ FileUtils.remove_file('tmp.json')
340
373
  end
341
374
 
342
- context "with pretty" do
343
- let(:fixture_file) { "single_author_pretty.json" }
375
+ context 'with pretty' do
376
+ let(:fixture_file) { 'single_author_pretty.json' }
344
377
  let(:pretty) { true }
345
378
 
346
379
  it do
347
- JSON.parse(fixture_contents).should == JSON.parse(tmpfile_contents)
380
+ expect(JSON.parse(fixture_contents)).to eq(JSON.parse(tmpfile_contents))
348
381
  end
349
382
  end
350
383
 
351
- context "with no pretty" do
352
- let(:fixture_file) { "multiple_authors.json" }
384
+ context 'with no pretty' do
385
+ let(:fixture_file) { 'multiple_authors.json' }
353
386
  let(:pretty) { false }
354
387
 
355
388
  it do
356
- JSON.parse(fixture_contents).should == JSON.parse(tmpfile_contents)
389
+ expect(JSON.parse(fixture_contents)).to eq(JSON.parse(tmpfile_contents))
357
390
  end
358
391
  end
359
392
  end