git_statistics 0.6.0 → 0.7.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.
- checksums.yaml +7 -0
- data/bin/git-statistics +1 -1
- data/bin/git_statistics +1 -1
- data/lib/git_statistics.rb +48 -32
- data/lib/git_statistics/collector.rb +40 -187
- data/lib/git_statistics/commit_summary.rb +86 -0
- data/lib/git_statistics/commits.rb +18 -14
- data/lib/git_statistics/diff_summary.rb +79 -0
- data/lib/git_statistics/formatters/console.rb +31 -26
- data/lib/git_statistics/initialize.rb +7 -6
- data/lib/git_statistics/pipe.rb +1 -1
- data/lib/git_statistics/utilities.rb +28 -91
- data/lib/git_statistics/version.rb +1 -1
- data/spec/collector_spec.rb +41 -235
- data/spec/commit_summary_spec.rb +126 -0
- data/spec/commits_spec.rb +52 -58
- data/spec/formatters/console_spec.rb +11 -10
- data/spec/utilities_spec.rb +15 -128
- metadata +22 -75
- data/lib/git_statistics/blob.rb +0 -5
- data/lib/git_statistics/branches.rb +0 -35
- data/lib/git_statistics/commit_line_extractor.rb +0 -50
- data/lib/git_statistics/regex_matcher.rb +0 -23
- data/spec/branches_spec.rb +0 -44
- data/spec/commit_line_extractor_spec.rb +0 -70
- data/spec/regex_matcher_spec.rb +0 -35
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include GitStatistics
|
3
|
+
|
4
|
+
describe CommitSummary do
|
5
|
+
|
6
|
+
let(:sha) { "bf09a64b0e0f801d3e7fe4e002cbd1bf517340a7" }
|
7
|
+
let(:repo) { GIT_REPO }
|
8
|
+
subject(:commit) { CommitSummary.new(repo, repo.lookup(sha)) }
|
9
|
+
|
10
|
+
its(:__getobj__) { should be_a Rugged::Commit }
|
11
|
+
|
12
|
+
context "understands its files and languages" do
|
13
|
+
its(:filenames) { should have(3).items }
|
14
|
+
its(:languages) { should have(1).items }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "language-specific changes" do
|
18
|
+
let(:name) { "Ruby" }
|
19
|
+
subject(:language) { commit.languages.detect { |lang| lang.name == name } }
|
20
|
+
context "for commit 2aa45e4ff23c1a558b127c06e95d313a56cc6890" do
|
21
|
+
let(:sha) { "2aa45e4ff23c1a558b127c06e95d313a56cc6890" }
|
22
|
+
context "language count" do
|
23
|
+
subject { commit }
|
24
|
+
its(:languages) { should have(2).items }
|
25
|
+
end
|
26
|
+
context "Ruby" do
|
27
|
+
let(:name) { "Ruby" }
|
28
|
+
its(:additions) { should == 14 }
|
29
|
+
its(:deletions) { should == 13 }
|
30
|
+
its(:net) { should == 1 }
|
31
|
+
end
|
32
|
+
context "Text" do
|
33
|
+
let(:name) { "Text" }
|
34
|
+
its(:additions) { should == 7 }
|
35
|
+
its(:deletions) { should == 11 }
|
36
|
+
its(:net) { should == -4 }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context "for commit bf09a64b" do
|
40
|
+
subject { commit.languages.first }
|
41
|
+
its(:name) { should == "Ruby" }
|
42
|
+
its(:additions) { should == 10 }
|
43
|
+
its(:deletions) { should == 27 }
|
44
|
+
its(:net) { should == -17 }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "file-specific changes" do
|
49
|
+
let(:name) { "lib/git_statistics/formatters/console.rb" }
|
50
|
+
subject(:file) { commit.file_stats.detect { |file| file.filename == name } }
|
51
|
+
context "for commit ef9292a92467430e0061e1b1ad4cbbc3ad7da6fd" do
|
52
|
+
let(:sha) { "ef9292a92467430e0061e1b1ad4cbbc3ad7da6fd" }
|
53
|
+
context "file count" do
|
54
|
+
subject { commit }
|
55
|
+
its(:filenames) { should have(12).items }
|
56
|
+
end
|
57
|
+
context "bin/git_statistics (new)" do
|
58
|
+
let(:name) { "bin/git_statistics" }
|
59
|
+
its(:language) { should == "Ruby" }
|
60
|
+
its(:additions) { should == 5 }
|
61
|
+
its(:deletions) { should == 0 }
|
62
|
+
its(:net) { should == 5 }
|
63
|
+
its(:status) { should == :added }
|
64
|
+
end
|
65
|
+
context "lib/initialize.rb (deleted)" do
|
66
|
+
let(:name) { "lib/initialize.rb" }
|
67
|
+
its(:language) { should == "Ruby" }
|
68
|
+
its(:additions) { should == 0 }
|
69
|
+
its(:deletions) { should == 4 }
|
70
|
+
its(:net) { should == -4 }
|
71
|
+
its(:status) { should == :deleted }
|
72
|
+
end
|
73
|
+
context "lib/git_statistics.rb (modified)" do
|
74
|
+
let(:name) { "lib/git_statistics.rb" }
|
75
|
+
its(:language) { should == "Ruby" }
|
76
|
+
its(:additions) { should == 37 }
|
77
|
+
its(:deletions) { should == 30 }
|
78
|
+
its(:net) { should == 7 }
|
79
|
+
its(:status) { should == :modified }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with a removed file" do
|
85
|
+
let(:sha) { "4ce86b844458a1fd77c6066c9297576b9520f97e" }
|
86
|
+
its(:deleted_files) { should == 2 }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "without a removed file" do
|
90
|
+
let(:sha) { "b808b3a9d4ce2d8a1d850f2c24d2d1fb00e67727" }
|
91
|
+
its(:deleted_files) { should == 0 }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with a new file" do
|
95
|
+
let(:sha) { "8b1941437a0ff8cf6a35a46d4f5df8b6587c346f" }
|
96
|
+
its(:added_files) { should == 19 }
|
97
|
+
end
|
98
|
+
|
99
|
+
context "without a new file" do
|
100
|
+
let(:sha) { "52f9f38cbe4ba90edd607298cb2f9b1aec26bcf1" }
|
101
|
+
its(:added_files) { should == 0 }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with a merge" do
|
105
|
+
let(:sha) { "9d31467f6759c92f8535038c470d24a37ae93a9d" }
|
106
|
+
it { should be_a_merge }
|
107
|
+
context "statistics" do
|
108
|
+
its(:filenames) { should have(11).items }
|
109
|
+
its(:languages) { should have(1).items }
|
110
|
+
its(:additions) { should == 69 }
|
111
|
+
its(:deletions) { should == 68 }
|
112
|
+
its(:net) { should == 1 }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "without a merge" do
|
117
|
+
it { should_not be_a_merge }
|
118
|
+
end
|
119
|
+
|
120
|
+
context "net, additions, and deletions" do
|
121
|
+
its(:additions) { should == 10 }
|
122
|
+
its(:deletions) { should == 27 }
|
123
|
+
its(:net) { should == -17 }
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
data/spec/commits_spec.rb
CHANGED
@@ -6,7 +6,8 @@ describe Commits do
|
|
6
6
|
let(:limit) {100}
|
7
7
|
let(:fresh) {true}
|
8
8
|
let(:pretty) {false}
|
9
|
-
let(:
|
9
|
+
let(:repo) { GIT_REPO }
|
10
|
+
let(:collector) {Collector.new(repo, limit, fresh, pretty)}
|
10
11
|
|
11
12
|
let(:commits) {collector.commits}
|
12
13
|
|
@@ -24,16 +25,15 @@ describe Commits do
|
|
24
25
|
describe "#files_in_path" do
|
25
26
|
let(:path) { '/tmp/example' }
|
26
27
|
subject { commits.files_in_path }
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
around do |example|
|
29
|
+
Dir.mktmpdir do |dir|
|
30
|
+
Dir.chdir(dir) do
|
31
|
+
FileUtils.touch '0.json'
|
32
|
+
FileUtils.touch '1.json'
|
33
|
+
commits.stub(:path) { dir }
|
34
|
+
example.run
|
35
|
+
end
|
32
36
|
end
|
33
|
-
commits.stub(:path) { path }
|
34
|
-
end
|
35
|
-
after do
|
36
|
-
FileUtils.rm_rf(path)
|
37
37
|
end
|
38
38
|
its(:count) { should == 2 }
|
39
39
|
it { should_not include '.' }
|
@@ -45,7 +45,7 @@ describe Commits do
|
|
45
45
|
|
46
46
|
def commit_size_changes_from(beginning, opts = {})
|
47
47
|
commits.size.should == beginning
|
48
|
-
commits.flush_commits
|
48
|
+
commits.flush_commits
|
49
49
|
commits.size.should == opts[:to]
|
50
50
|
end
|
51
51
|
|
@@ -63,11 +63,6 @@ describe Commits do
|
|
63
63
|
let(:limit) {5}
|
64
64
|
it { commit_size_changes_from(3, to: 3) }
|
65
65
|
end
|
66
|
-
|
67
|
-
context "with commits less than limit but forced" do
|
68
|
-
let(:limit) {5}
|
69
|
-
it { commit_size_changes_from(3, to: 0, force: true) }
|
70
|
-
end
|
71
66
|
end
|
72
67
|
|
73
68
|
describe "#process_commits" do
|
@@ -87,15 +82,15 @@ describe Commits do
|
|
87
82
|
it {subject[:additions].should == 153}
|
88
83
|
it {subject[:deletions].should == 5}
|
89
84
|
it {subject[:commits].should == 2}
|
90
|
-
it {subject[:
|
85
|
+
it {subject[:added_files].should == 3}
|
91
86
|
it {subject[:merges].should == 1}
|
92
87
|
|
93
88
|
it {subject[:languages][:Markdown][:additions].should == 18}
|
94
89
|
it {subject[:languages][:Markdown][:deletions].should == 1}
|
95
|
-
it {subject[:languages][:Markdown][:
|
90
|
+
it {subject[:languages][:Markdown][:added_files].should == 1}
|
96
91
|
it {subject[:languages][:Ruby][:additions].should == 135}
|
97
92
|
it {subject[:languages][:Ruby][:deletions].should == 4}
|
98
|
-
it {subject[:languages][:Ruby][:
|
93
|
+
it {subject[:languages][:Ruby][:added_files].should == 2}
|
99
94
|
end
|
100
95
|
|
101
96
|
context "on second author" do
|
@@ -106,7 +101,7 @@ describe Commits do
|
|
106
101
|
|
107
102
|
it {subject[:languages][:Ruby][:additions].should == 64}
|
108
103
|
it {subject[:languages][:Ruby][:deletions].should == 16}
|
109
|
-
it {subject[:languages][:Ruby][:
|
104
|
+
it {subject[:languages][:Ruby][:added_files].should == 0}
|
110
105
|
end
|
111
106
|
end
|
112
107
|
|
@@ -118,14 +113,14 @@ describe Commits do
|
|
118
113
|
it {subject[:additions].should == 73}
|
119
114
|
it {subject[:deletions].should == 0}
|
120
115
|
it {subject[:commits].should == 1}
|
121
|
-
it {subject[:
|
116
|
+
it {subject[:added_files].should == 2}
|
122
117
|
|
123
118
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
124
119
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
125
|
-
it {subject[:languages][:Markdown][:
|
120
|
+
it {subject[:languages][:Markdown][:added_files].should == 1}
|
126
121
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
127
122
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
128
|
-
it {subject[:languages][:Ruby][:
|
123
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
129
124
|
end
|
130
125
|
|
131
126
|
context "on second author" do
|
@@ -162,14 +157,14 @@ describe Commits do
|
|
162
157
|
it {subject[:commits].should == 1}
|
163
158
|
it {subject[:additions].should == 73}
|
164
159
|
it {subject[:deletions].should == 0}
|
165
|
-
it {subject[:
|
160
|
+
it {subject[:added_files].should == 2}
|
166
161
|
|
167
162
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
168
163
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
169
|
-
it {subject[:languages][:Markdown][:
|
164
|
+
it {subject[:languages][:Markdown][:added_files].should== 1}
|
170
165
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
171
166
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
172
|
-
it {subject[:languages][:Ruby][:
|
167
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
173
168
|
end
|
174
169
|
end
|
175
170
|
|
@@ -196,36 +191,35 @@ describe Commits do
|
|
196
191
|
it {subject[:commits].should == 1}
|
197
192
|
it {subject[:additions].should == 73}
|
198
193
|
it {subject[:deletions].should == 0}
|
199
|
-
it {subject[:
|
194
|
+
it {subject[:added_files].should == 2}
|
200
195
|
|
201
196
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
202
197
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
203
198
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
204
199
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
205
|
-
it {subject[:languages][:Ruby][:
|
200
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
206
201
|
end
|
207
202
|
|
208
203
|
context "with merge" do
|
209
204
|
let(:merge) {true}
|
210
|
-
let(:author) {
|
205
|
+
let(:author) { "Kevin Jalbert" }
|
211
206
|
|
212
207
|
it {stats.has_key?(author).should be_true}
|
213
208
|
it {subject[:commits].should == 2}
|
214
209
|
it {subject[:additions].should == 153}
|
215
210
|
it {subject[:deletions].should == 5}
|
216
|
-
it {subject[:
|
211
|
+
it {subject[:added_files].should == 3}
|
217
212
|
it {subject[:merges].should == 1}
|
218
213
|
|
219
214
|
it {subject[:languages][:Markdown][:additions].should == 18}
|
220
215
|
it {subject[:languages][:Markdown][:deletions].should == 1}
|
221
216
|
it {subject[:languages][:Ruby][:additions].should == 135}
|
222
217
|
it {subject[:languages][:Ruby][:deletions].should == 4}
|
223
|
-
it {subject[:languages][:Ruby][:
|
218
|
+
it {subject[:languages][:Ruby][:added_files].should == 2}
|
224
219
|
end
|
225
220
|
end
|
226
221
|
|
227
222
|
describe "#add_language_stats" do
|
228
|
-
|
229
223
|
context "with file language" do
|
230
224
|
let(:data) {
|
231
225
|
data = Hash.new(0)
|
@@ -276,6 +270,8 @@ describe Commits do
|
|
276
270
|
let(:data) {
|
277
271
|
commit = {:additions => 10,
|
278
272
|
:deletions => 5,
|
273
|
+
:new_files => 0,
|
274
|
+
:removed_files => 0,
|
279
275
|
:merge => false}
|
280
276
|
|
281
277
|
data = Hash.new(0)
|
@@ -292,6 +288,8 @@ describe Commits do
|
|
292
288
|
let(:data) {
|
293
289
|
commit = {:additions => 10,
|
294
290
|
:deletions => 5,
|
291
|
+
:new_files => 0,
|
292
|
+
:removed_files => 0,
|
295
293
|
:merge => false}
|
296
294
|
|
297
295
|
data = Hash.new(0)
|
@@ -312,10 +310,8 @@ describe Commits do
|
|
312
310
|
let(:data) {
|
313
311
|
commit = {:additions => 10,
|
314
312
|
:deletions => 5,
|
315
|
-
:
|
316
|
-
:
|
317
|
-
:rename => 3,
|
318
|
-
:copy => 4,
|
313
|
+
:added_files => 1,
|
314
|
+
:deleted_files => 2,
|
319
315
|
:merge => false}
|
320
316
|
|
321
317
|
data = Hash.new(0)
|
@@ -325,41 +321,39 @@ describe Commits do
|
|
325
321
|
it {data[:commits].should == 1}
|
326
322
|
it {data[:additions].should == 10}
|
327
323
|
it {data[:deletions].should == 5}
|
328
|
-
it {data[:
|
329
|
-
it {data[:
|
330
|
-
it {data[:rename].should == 3}
|
331
|
-
it {data[:copy].should == 4}
|
324
|
+
it {data[:added_files].should == 1}
|
325
|
+
it {data[:deleted_files].should == 2}
|
332
326
|
end
|
333
327
|
end
|
334
328
|
|
335
329
|
describe "#save and #load" do
|
336
|
-
|
337
|
-
|
338
|
-
let(:pretty) {true}
|
330
|
+
let(:fixture_contents) { fixture(fixture_file).io.join("\n") }
|
331
|
+
let(:tmpfile_contents) { File.read("tmp.json") }
|
339
332
|
|
340
|
-
|
341
|
-
|
342
|
-
|
333
|
+
before do
|
334
|
+
commits.load(fixture(fixture_file).file)
|
335
|
+
commits.save("tmp.json", pretty)
|
336
|
+
end
|
343
337
|
|
344
|
-
|
345
|
-
|
338
|
+
after do
|
339
|
+
FileUtils.remove_file("tmp.json")
|
340
|
+
end
|
346
341
|
|
347
|
-
|
342
|
+
context "with pretty" do
|
343
|
+
let(:fixture_file) { "single_author_pretty.json" }
|
344
|
+
let(:pretty) { true }
|
345
|
+
|
346
|
+
it do
|
347
|
+
JSON.parse(fixture_contents).should == JSON.parse(tmpfile_contents)
|
348
348
|
end
|
349
349
|
end
|
350
350
|
|
351
351
|
context "with no pretty" do
|
352
|
-
let(:fixture_file) {"multiple_authors.json"}
|
353
|
-
let(:pretty) {false}
|
352
|
+
let(:fixture_file) { "multiple_authors.json" }
|
353
|
+
let(:pretty) { false }
|
354
354
|
|
355
355
|
it do
|
356
|
-
|
357
|
-
commits.save("tmp.json", pretty)
|
358
|
-
|
359
|
-
same = FileUtils.compare_file("tmp.json", fixture(fixture_file).file)
|
360
|
-
FileUtils.remove_file("tmp.json")
|
361
|
-
|
362
|
-
same.should be_true
|
356
|
+
JSON.parse(fixture_contents).should == JSON.parse(tmpfile_contents)
|
363
357
|
end
|
364
358
|
end
|
365
359
|
end
|
@@ -6,7 +6,8 @@ describe Console do
|
|
6
6
|
let(:limit) {100}
|
7
7
|
let(:fresh) {true}
|
8
8
|
let(:pretty) {false}
|
9
|
-
let(:
|
9
|
+
let(:repo) { GIT_REPO }
|
10
|
+
let(:collector) {Collector.new(repo, limit, fresh, pretty)}
|
10
11
|
|
11
12
|
let(:commits) {collector.commits}
|
12
13
|
|
@@ -42,14 +43,14 @@ describe Console do
|
|
42
43
|
it {subject[:commits].should == 1}
|
43
44
|
it {subject[:additions].should == 73}
|
44
45
|
it {subject[:deletions].should == 0}
|
45
|
-
it {subject[:
|
46
|
+
it {subject[:added_files].should == 2}
|
46
47
|
|
47
48
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
48
49
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
49
|
-
it {subject[:languages][:Ruby][:
|
50
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
50
51
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
51
52
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
52
|
-
it {subject[:languages][:Markdown][:
|
53
|
+
it {subject[:languages][:Markdown][:added_files].should == 1}
|
53
54
|
end
|
54
55
|
|
55
56
|
context "on second author" do
|
@@ -86,14 +87,14 @@ describe Console do
|
|
86
87
|
it {subject[:commits].should == 1}
|
87
88
|
it {subject[:additions].should == 73}
|
88
89
|
it {subject[:deletions].should == 0}
|
89
|
-
it {subject[:
|
90
|
+
it {subject[:added_files].should == 2}
|
90
91
|
|
91
92
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
92
93
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
93
|
-
it {subject[:languages][:Ruby][:
|
94
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
94
95
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
95
96
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
96
|
-
it {subject[:languages][:Markdown][:
|
97
|
+
it {subject[:languages][:Markdown][:added_files].should == 1}
|
97
98
|
end
|
98
99
|
|
99
100
|
context "on second author" do
|
@@ -128,14 +129,14 @@ describe Console do
|
|
128
129
|
it {subject[:commits].should == 1}
|
129
130
|
it {subject[:additions].should == 73}
|
130
131
|
it {subject[:deletions].should == 0}
|
131
|
-
it {subject[:
|
132
|
+
it {subject[:added_files].should == 2}
|
132
133
|
|
133
134
|
it {subject[:languages][:Ruby][:additions].should == 62}
|
134
135
|
it {subject[:languages][:Ruby][:deletions].should == 0}
|
135
|
-
it {subject[:languages][:Ruby][:
|
136
|
+
it {subject[:languages][:Ruby][:added_files].should == 1}
|
136
137
|
it {subject[:languages][:Markdown][:additions].should == 11}
|
137
138
|
it {subject[:languages][:Markdown][:deletions].should == 0}
|
138
|
-
it {subject[:languages][:Markdown][:
|
139
|
+
it {subject[:languages][:Markdown][:added_files].should == 1}
|
139
140
|
|
140
141
|
it {config[:sort].should == sort}
|
141
142
|
it {config[:email].should == email}
|
data/spec/utilities_spec.rb
CHANGED
@@ -3,38 +3,18 @@ include GitStatistics
|
|
3
3
|
|
4
4
|
describe Utilities do
|
5
5
|
|
6
|
-
describe "#get_repository" do
|
7
|
-
subject { Utilities.get_repository(dir) }
|
8
|
-
|
9
|
-
context "with root directory" do
|
10
|
-
let(:dir) { Dir.pwd } # git_statistics/
|
11
|
-
it { should be_a Grit::Repo }
|
12
|
-
end
|
13
|
-
|
14
|
-
context "with sub directory" do
|
15
|
-
let(:dir) { File.dirname(__FILE__) } # git_statistics/spec/
|
16
|
-
it { should be_a Grit::Repo }
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when not in a repository directory" do
|
20
|
-
before { Utilities.should_receive(:exit) }
|
21
|
-
let(:dir) { Dir.home } # /Users/username/
|
22
|
-
it { should be_nil }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
6
|
describe "#max_length_in_list" do
|
27
|
-
let(:max) {nil}
|
28
|
-
let(:list) {[]}
|
7
|
+
let(:max) { nil }
|
8
|
+
let(:list) { [] }
|
29
9
|
subject(:results) {Utilities.max_length_in_list(list, max)}
|
30
10
|
|
31
11
|
context "with empty list" do
|
32
|
-
it { should
|
12
|
+
it { should == 0 }
|
33
13
|
end
|
34
14
|
|
35
15
|
context "with nil list" do
|
36
|
-
let(:list) {nil}
|
37
|
-
it { should
|
16
|
+
let(:list) { nil }
|
17
|
+
it { should == 0 }
|
38
18
|
end
|
39
19
|
|
40
20
|
context "with empty list and zero max" do
|
@@ -44,17 +24,17 @@ describe Utilities do
|
|
44
24
|
end
|
45
25
|
|
46
26
|
context "with preset minimum length" do
|
47
|
-
let(:max) {10}
|
27
|
+
let(:max) { 10 }
|
48
28
|
it { should == 10 }
|
49
29
|
end
|
50
30
|
|
51
31
|
context "with valid list" do
|
52
|
-
let(:list) {["abc", "a", "ab"]}
|
32
|
+
let(:list) { ["abc", "a", "ab"] }
|
53
33
|
it { should == 3 }
|
54
34
|
end
|
55
35
|
|
56
36
|
context "with valid hash" do
|
57
|
-
let(:list) {{"a" => "word_a", "ab" => "word_b", "abc" => "word_c"}}
|
37
|
+
let(:list) { {"a" => "word_a", "ab" => "word_b", "abc" => "word_c"} }
|
58
38
|
it { should == 3 }
|
59
39
|
end
|
60
40
|
end
|
@@ -76,125 +56,32 @@ describe Utilities do
|
|
76
56
|
end
|
77
57
|
end
|
78
58
|
|
79
|
-
describe "#split_old_new_file" do
|
80
|
-
let(:files) {Utilities.split_old_new_file(old, new)}
|
81
|
-
context "with a change in middle" do
|
82
|
-
let(:old) {"lib/{old_dir"}
|
83
|
-
let(:new) {"new_dir}/file.rb"}
|
84
|
-
it {files[:new_file].should == "lib/new_dir/file.rb"}
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with a change at beginning" do
|
88
|
-
let(:old) {"{src/dir/lib"}
|
89
|
-
let(:new) {"lib/dir}/file.rb"}
|
90
|
-
it {files[:old_file].should == "src/dir/lib/file.rb"}
|
91
|
-
it {files[:new_file].should == "lib/dir/file.rb"}
|
92
|
-
end
|
93
|
-
|
94
|
-
context "with a change at beginning, alternative" do
|
95
|
-
let(:old) {"src/{"}
|
96
|
-
let(:new) {"dir}/file.rb"}
|
97
|
-
it {files[:old_file].should == "src/file.rb"}
|
98
|
-
it {files[:new_file].should == "src/dir/file.rb"}
|
99
|
-
end
|
100
|
-
|
101
|
-
context "with a change at ending" do
|
102
|
-
let(:old) {"lib/dir/{old_file.rb"}
|
103
|
-
let(:new) {"new_file.rb}"}
|
104
|
-
it {files[:old_file].should == "lib/dir/old_file.rb"}
|
105
|
-
it {files[:new_file].should == "lib/dir/new_file.rb"}
|
106
|
-
end
|
107
|
-
|
108
|
-
context "with a simple complete change" do
|
109
|
-
let(:old) {"file.rb"}
|
110
|
-
let(:new) {"lib/dir/file.rb}"}
|
111
|
-
it {files[:old_file].should == "file.rb"}
|
112
|
-
it {files[:new_file].should == "lib/dir/file.rb"}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "#find_blob_in_tree" do
|
117
|
-
let(:sha) {"7d6c29f0ad5860d3238debbaaf696e361bf8c541"} # Commit within repository
|
118
|
-
let(:tree) {Utilities.get_repository(Dir.pwd).tree(sha)}
|
119
|
-
let(:file) {nil}
|
120
|
-
let(:blob) {Utilities.find_blob_in_tree(tree, file.split(File::Separator))}
|
121
|
-
subject { blob }
|
122
|
-
|
123
|
-
context "blob on root tree" do
|
124
|
-
let(:file) {"Gemfile"}
|
125
|
-
it { should be_instance_of Grit::Blob }
|
126
|
-
its(:name) { should == file }
|
127
|
-
end
|
128
|
-
|
129
|
-
context "blob down tree" do
|
130
|
-
let(:file) {"lib/git_statistics/collector.rb"}
|
131
|
-
it { should be_instance_of Grit::Blob }
|
132
|
-
its(:name) { should == File.basename(file) }
|
133
|
-
end
|
134
|
-
|
135
|
-
context "file is nil" do
|
136
|
-
subject {Utilities.find_blob_in_tree(tree, nil)}
|
137
|
-
it { should be_nil }
|
138
|
-
end
|
139
|
-
|
140
|
-
context "file is empty" do
|
141
|
-
let(:file) {""}
|
142
|
-
it { should be_nil }
|
143
|
-
end
|
144
|
-
|
145
|
-
context "file is submodule" do
|
146
|
-
let(:sha) {"1940ef1c613a04f855d3867b874a4267d3e2c011"}
|
147
|
-
let(:file) {"Spoon-Knife"}
|
148
|
-
it { should be_instance_of Grit::Submodule }
|
149
|
-
its(:name) { should == file }
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
59
|
describe "#number_of_matching_files" do
|
154
|
-
let(:directory) { File.join(Dir.pwd, "tmp_dir_for_spec") }
|
155
60
|
let(:pattern) { (/\d+\.json/) }
|
156
|
-
subject {Utilities.number_of_matching_files(
|
61
|
+
subject {Utilities.number_of_matching_files(Dir.pwd, pattern)}
|
157
62
|
|
158
63
|
around do |example|
|
159
|
-
|
160
|
-
|
161
|
-
|
64
|
+
Dir.mktmpdir do |dir|
|
65
|
+
Dir.chdir(dir) do
|
66
|
+
example.run
|
67
|
+
end
|
162
68
|
end
|
163
|
-
FileUtils.rmdir(directory)
|
164
69
|
end
|
165
70
|
|
166
71
|
context "with missing directory" do
|
167
|
-
before do
|
168
|
-
subject.class.stub(:warn)
|
169
|
-
FileUtils.rmdir(directory)
|
170
|
-
end
|
171
72
|
it { should == 0 }
|
172
73
|
end
|
173
74
|
|
174
75
|
context "with valid files" do
|
175
76
|
before do
|
176
|
-
FileUtils.touch("0.json")
|
177
|
-
FileUtils.touch("1.json")
|
178
|
-
FileUtils.touch("2.json")
|
179
|
-
end
|
180
|
-
after do
|
181
|
-
FileUtils.rm("0.json")
|
182
|
-
FileUtils.rm("1.json")
|
183
|
-
FileUtils.rm("2.json")
|
77
|
+
FileUtils.touch(["0.json", "1.json", "2.json"])
|
184
78
|
end
|
185
79
|
it { should == 3 }
|
186
80
|
end
|
187
81
|
|
188
82
|
context "with invalid files" do
|
189
83
|
before do
|
190
|
-
FileUtils.touch("0.json")
|
191
|
-
FileUtils.touch("incorrect.json")
|
192
|
-
FileUtils.touch("1.json")
|
193
|
-
end
|
194
|
-
after do
|
195
|
-
FileUtils.rm("0.json")
|
196
|
-
FileUtils.rm("incorrect.json")
|
197
|
-
FileUtils.rm("1.json")
|
84
|
+
FileUtils.touch(["0.json", "incorrect.json", "1.json"])
|
198
85
|
end
|
199
86
|
it { should == 2 }
|
200
87
|
end
|