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.
- checksums.yaml +4 -4
- data/bin/git-statistics +1 -1
- data/bin/git_statistics +1 -1
- data/lib/git_statistics.rb +33 -35
- data/lib/git_statistics/collector.rb +13 -16
- data/lib/git_statistics/commit_summary.rb +13 -16
- data/lib/git_statistics/commits.rb +34 -36
- data/lib/git_statistics/diff_summary.rb +13 -17
- data/lib/git_statistics/formatters/console.rb +22 -18
- data/lib/git_statistics/log.rb +3 -5
- data/lib/git_statistics/pipe.rb +1 -1
- data/lib/git_statistics/utilities.rb +7 -9
- data/lib/git_statistics/version.rb +1 -1
- data/spec/collector_spec.rb +107 -104
- data/spec/commit_summary_spec.rb +110 -84
- data/spec/commits_spec.rb +251 -218
- data/spec/formatters/console_spec.rb +141 -127
- data/spec/log_spec.rb +19 -21
- data/spec/pipe_spec.rb +30 -25
- data/spec/utilities_spec.rb +42 -40
- metadata +37 -37
@@ -3,174 +3,188 @@ include GitStatistics
|
|
3
3
|
include GitStatistics::Formatters
|
4
4
|
|
5
5
|
describe Console 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) {
|
15
|
-
let(:save_file) { File.join(collector.commits_path,
|
16
|
-
let(:email) {false}
|
17
|
-
let(:merge) {false}
|
18
|
-
let(:sort) {:commits}
|
19
|
-
let(:top_n) {0}
|
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
|
+
let(:top_n) { 0 }
|
20
20
|
|
21
|
-
let(:results)
|
21
|
+
let(:results) do
|
22
22
|
setup_commits(commits, fixture_file, save_file, pretty)
|
23
23
|
commits.calculate_statistics(email, merge)
|
24
24
|
commits.author_top_n_type(sort)
|
25
|
-
|
26
|
-
|
25
|
+
Console.new(commits)
|
26
|
+
end
|
27
27
|
|
28
|
-
let(:config)
|
28
|
+
let(:config) do
|
29
29
|
results.prepare_result_summary(sort, email, top_n)
|
30
|
-
|
30
|
+
end
|
31
31
|
|
32
32
|
before { config }
|
33
33
|
|
34
|
-
describe
|
35
|
-
context
|
36
|
-
context
|
37
|
-
let(:data) {config[:data]}
|
38
|
-
author =
|
39
|
-
subject {data[author]}
|
40
|
-
|
41
|
-
it
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
34
|
+
describe '#prepare_result_summary' do
|
35
|
+
context 'with email and sorting' do
|
36
|
+
context 'on first author' do
|
37
|
+
let(:data) { config[:data] }
|
38
|
+
author = 'Kevin Jalbert'
|
39
|
+
subject { data[author] }
|
40
|
+
|
41
|
+
it do
|
42
|
+
expect(data.key?(author)).to be true
|
43
|
+
|
44
|
+
expect(subject[:commits]).to eq(1)
|
45
|
+
expect(subject[:additions]).to eq(73)
|
46
|
+
expect(subject[:deletions]).to eq(0)
|
47
|
+
expect(subject[:added_files]).to eq(2)
|
48
|
+
|
49
|
+
expect(subject[:languages][:Ruby][:additions]).to eq(62)
|
50
|
+
expect(subject[:languages][:Ruby][:deletions]).to eq(0)
|
51
|
+
expect(subject[:languages][:Ruby][:added_files]).to eq(1)
|
52
|
+
expect(subject[:languages][:Markdown][:additions]).to eq(11)
|
53
|
+
expect(subject[:languages][:Markdown][:deletions]).to eq(0)
|
54
|
+
expect(subject[:languages][:Markdown][:added_files]).to eq(1)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
|
56
|
-
context
|
57
|
-
let(:data) {config[:data]}
|
58
|
-
author =
|
59
|
-
subject {data[author]}
|
58
|
+
context 'on second author' do
|
59
|
+
let(:data) { config[:data] }
|
60
|
+
author = 'John Smith'
|
61
|
+
subject { data[author] }
|
60
62
|
|
61
|
-
it
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
it do
|
64
|
+
expect(data.key?(author)).to be true
|
65
|
+
expect(subject[:commits]).to eq(1)
|
66
|
+
expect(subject[:additions]).to eq(64)
|
67
|
+
expect(subject[:deletions]).to eq(16)
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
expect(subject[:languages][:Ruby][:additions]).to eq(64)
|
70
|
+
expect(subject[:languages][:Ruby][:deletions]).to eq(16)
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
|
-
it
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
it do
|
75
|
+
expect(config[:sort]).to eq(sort)
|
76
|
+
expect(config[:email]).to eq(email)
|
77
|
+
expect(config[:top_n]).to eq(top_n)
|
78
|
+
expect(config[:author_length]).to eq(17)
|
79
|
+
expect(config[:language_length]).to eq(8)
|
80
|
+
end
|
75
81
|
end
|
76
82
|
|
77
|
-
context
|
78
|
-
let(:top_n) {-1}
|
83
|
+
context 'with negative top_n' do
|
84
|
+
let(:top_n) { -1 }
|
85
|
+
|
86
|
+
context 'on first author' do
|
87
|
+
let(:data) { config[:data] }
|
88
|
+
author = 'Kevin Jalbert'
|
89
|
+
subject { data[author] }
|
90
|
+
|
91
|
+
it do
|
92
|
+
expect(data.key?(author)).to be true
|
93
|
+
|
94
|
+
expect(subject[:commits]).to eq(1)
|
95
|
+
expect(subject[:additions]).to eq(73)
|
96
|
+
expect(subject[:deletions]).to eq(0)
|
97
|
+
expect(subject[:added_files]).to eq(2)
|
98
|
+
|
99
|
+
expect(subject[:languages][:Ruby][:additions]).to eq(62)
|
100
|
+
expect(subject[:languages][:Ruby][:deletions]).to eq(0)
|
101
|
+
expect(subject[:languages][:Ruby][:added_files]).to eq(1)
|
102
|
+
expect(subject[:languages][:Markdown][:additions]).to eq(11)
|
103
|
+
expect(subject[:languages][:Markdown][:deletions]).to eq(0)
|
104
|
+
expect(subject[:languages][:Markdown][:added_files]).to eq(1)
|
105
|
+
end
|
106
|
+
end
|
79
107
|
|
80
|
-
context
|
81
|
-
let(:data) {config[:data]}
|
82
|
-
author =
|
83
|
-
subject {data[author]}
|
108
|
+
context 'on second author' do
|
109
|
+
let(:data) { config[:data] }
|
110
|
+
author = 'John Smith'
|
111
|
+
subject { data[author] }
|
84
112
|
|
85
|
-
it
|
113
|
+
it do
|
114
|
+
expect(data.key?(author)).to be true
|
86
115
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
it {subject[:added_files].should == 2}
|
116
|
+
expect(subject[:commits]).to eq(1)
|
117
|
+
expect(subject[:additions]).to eq(64)
|
118
|
+
expect(subject[:deletions]).to eq(16)
|
91
119
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
it {subject[:languages][:Markdown][:additions].should == 11}
|
96
|
-
it {subject[:languages][:Markdown][:deletions].should == 0}
|
97
|
-
it {subject[:languages][:Markdown][:added_files].should == 1}
|
120
|
+
expect(subject[:languages][:Ruby][:additions]).to eq(64)
|
121
|
+
expect(subject[:languages][:Ruby][:deletions]).to eq(16)
|
122
|
+
end
|
98
123
|
end
|
99
124
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
it {subject[:commits].should == 1}
|
107
|
-
it {subject[:additions].should == 64}
|
108
|
-
it {subject[:deletions].should == 16}
|
109
|
-
|
110
|
-
it {subject[:languages][:Ruby][:additions].should == 64}
|
111
|
-
it {subject[:languages][:Ruby][:deletions].should == 16}
|
125
|
+
it do
|
126
|
+
expect(config[:sort]).to eq(sort)
|
127
|
+
expect(config[:email]).to eq(email)
|
128
|
+
expect(config[:top_n]).to eq(0)
|
129
|
+
expect(config[:author_length]).to eq(17)
|
130
|
+
expect(config[:language_length]).to eq(8)
|
112
131
|
end
|
113
|
-
|
114
|
-
it {config[:sort].should == sort}
|
115
|
-
it {config[:email].should == email}
|
116
|
-
it {config[:top_n].should == 0}
|
117
|
-
it {config[:author_length].should == 17}
|
118
|
-
it {config[:language_length].should == 8}
|
119
132
|
end
|
120
133
|
|
121
|
-
context
|
122
|
-
let(:top_n) {1}
|
123
|
-
let(:data) {config[:data]}
|
124
|
-
author =
|
125
|
-
subject {data[author]}
|
126
|
-
|
127
|
-
it
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
134
|
+
context 'with top_n that filters to one author' do
|
135
|
+
let(:top_n) { 1 }
|
136
|
+
let(:data) { config[:data] }
|
137
|
+
author = 'Kevin Jalbert'
|
138
|
+
subject { data[author] }
|
139
|
+
|
140
|
+
it do
|
141
|
+
expect(data.key?(author)).to be true
|
142
|
+
|
143
|
+
expect(subject[:commits]).to eq(1)
|
144
|
+
expect(subject[:additions]).to eq(73)
|
145
|
+
expect(subject[:deletions]).to eq(0)
|
146
|
+
expect(subject[:added_files]).to eq(2)
|
147
|
+
|
148
|
+
expect(subject[:languages][:Ruby][:additions]).to eq(62)
|
149
|
+
expect(subject[:languages][:Ruby][:deletions]).to eq(0)
|
150
|
+
expect(subject[:languages][:Ruby][:added_files]).to eq(1)
|
151
|
+
expect(subject[:languages][:Markdown][:additions]).to eq(11)
|
152
|
+
expect(subject[:languages][:Markdown][:deletions]).to eq(0)
|
153
|
+
expect(subject[:languages][:Markdown][:added_files]).to eq(1)
|
154
|
+
|
155
|
+
expect(config[:sort]).to eq(sort)
|
156
|
+
expect(config[:email]).to eq(email)
|
157
|
+
expect(config[:top_n]).to eq(top_n)
|
158
|
+
expect(config[:author_length]).to eq(17)
|
159
|
+
expect(config[:language_length]).to eq(8)
|
160
|
+
end
|
146
161
|
end
|
147
162
|
end
|
148
163
|
|
149
|
-
describe
|
164
|
+
describe 'output' do
|
150
165
|
let(:output) { fixture(file).file.read }
|
151
|
-
describe
|
152
|
-
context
|
153
|
-
let(:file) {
|
154
|
-
subject {results.print_summary(sort, email)}
|
155
|
-
it {
|
166
|
+
describe '#print_summary' do
|
167
|
+
context 'with valid data' do
|
168
|
+
let(:file) { 'summary_output.txt' }
|
169
|
+
subject { results.print_summary(sort, email) }
|
170
|
+
it { expect(subject).to eq(output.chomp) }
|
156
171
|
end
|
157
172
|
end
|
158
173
|
|
159
|
-
describe
|
160
|
-
context
|
161
|
-
let(:file) {
|
162
|
-
subject {results.print_language_data(config[:data][
|
163
|
-
it {
|
174
|
+
describe '#print_language_data' do
|
175
|
+
context 'with valid data' do
|
176
|
+
let(:file) { 'language_data_output.txt' }
|
177
|
+
subject { results.print_language_data(config[:data]['Kevin Jalbert']) }
|
178
|
+
it { expect(subject).to eq(output.split("\n")) }
|
164
179
|
end
|
165
180
|
end
|
166
181
|
|
167
|
-
describe
|
168
|
-
context
|
169
|
-
let(:file) {
|
182
|
+
describe '#print_header' do
|
183
|
+
context 'with valid data' do
|
184
|
+
let(:file) { 'header_output.txt' }
|
170
185
|
subject { results.print_header.join("\n") }
|
171
|
-
it {
|
186
|
+
it { expect(subject).to eq(output.chomp) }
|
172
187
|
end
|
173
188
|
end
|
174
189
|
end
|
175
|
-
|
176
190
|
end
|
data/spec/log_spec.rb
CHANGED
@@ -3,52 +3,50 @@ require 'spec_helper'
|
|
3
3
|
include GitStatistics
|
4
4
|
|
5
5
|
describe Log do
|
6
|
-
|
7
6
|
let(:log) { Class.new(Log) }
|
8
7
|
|
9
|
-
context
|
10
|
-
it
|
11
|
-
log.instance.
|
8
|
+
context 'initializes instance' do
|
9
|
+
it 'acts as singleton' do
|
10
|
+
expect(log.instance).to eq(log.instance)
|
12
11
|
end
|
13
12
|
|
14
|
-
it
|
15
|
-
log.instance.logger.
|
13
|
+
it 'has a logger' do
|
14
|
+
expect(log.instance.logger).to be_a(Logger)
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
19
|
-
log.class.
|
17
|
+
it 'is a Log (FakeLog)' do
|
18
|
+
expect(log.class).to eq(Log.class)
|
20
19
|
end
|
21
20
|
|
22
|
-
it
|
21
|
+
it 'reacts to Logger methods' do
|
23
22
|
Logger.public_instance_methods.each do |method|
|
24
|
-
log.valid_method?(method).
|
23
|
+
expect(log.valid_method?(method)).to be true
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
context
|
28
|
+
context '#use_debug' do
|
30
29
|
it "logger's progname before" do
|
31
|
-
log.progname.
|
30
|
+
expect(log.progname).to be nil
|
32
31
|
end
|
33
32
|
|
34
33
|
it "logger's progname after" do
|
35
34
|
log.use_debug
|
36
|
-
log.progname.
|
35
|
+
expect(log.progname).to_not be nil
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
context
|
41
|
-
context
|
42
|
-
it {log.parse_caller(nil).
|
39
|
+
context '#parse_caller' do
|
40
|
+
context 'with nothing' do
|
41
|
+
it { expect(log.parse_caller(nil)).to be nil }
|
43
42
|
end
|
44
43
|
|
45
|
-
context
|
46
|
-
it {log.parse_caller(
|
44
|
+
context 'with jumble (random text)' do
|
45
|
+
it { expect(log.parse_caller('asdaacsdc')).to be nil }
|
47
46
|
end
|
48
47
|
|
49
|
-
context
|
50
|
-
it {log.parse_caller("git_statistics/lib/git_statistics/log.rb:45:in `respond_to_missing?'").
|
48
|
+
context 'with valid caller' do
|
49
|
+
it { expect(log.parse_caller("git_statistics/lib/git_statistics/log.rb:45:in `respond_to_missing?'")).to eq('git_statistics/lib/git_statistics/log.rb:45') }
|
51
50
|
end
|
52
51
|
end
|
53
|
-
|
54
52
|
end
|
data/spec/pipe_spec.rb
CHANGED
@@ -4,56 +4,61 @@ include GitStatistics
|
|
4
4
|
|
5
5
|
describe Pipe do
|
6
6
|
let(:command) { 'git' }
|
7
|
-
let(:line) {
|
7
|
+
let(:line) { '' }
|
8
8
|
let(:pipe) { Pipe.new(command) }
|
9
9
|
|
10
|
-
context
|
11
|
-
context
|
10
|
+
context 'initializes correctly' do
|
11
|
+
context 'with pipe character' do
|
12
12
|
let(:command) { '|git log --oneline' }
|
13
|
-
it { expect(pipe.command).to eq
|
13
|
+
it { expect(pipe.command).to eq('git log --oneline') }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
|
+
context 'without pipe character' do
|
16
17
|
let(:command) { 'stat something else' }
|
17
|
-
it { expect(pipe.command).to eq
|
18
|
+
it { expect(pipe.command).to eq('stat something else') }
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
context
|
22
|
-
before { pipe.
|
23
|
-
|
22
|
+
context '#empty?' do
|
23
|
+
before { allow(pipe).to receive(:lines) { lines } }
|
24
|
+
|
25
|
+
context 'with empty lines' do
|
24
26
|
let(:lines) { [] }
|
25
|
-
it { pipe.
|
27
|
+
it { expect(pipe).to be_empty }
|
26
28
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
|
30
|
+
context 'with a single line' do
|
31
|
+
let(:lines) { [double] }
|
32
|
+
it { expect(pipe).to_not be_empty }
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
|
-
context
|
36
|
+
context '#each' do
|
34
37
|
before do
|
35
|
-
pipe.
|
38
|
+
allow(pipe).to receive(:lines) { [line, line] }
|
36
39
|
end
|
37
|
-
|
38
|
-
|
40
|
+
|
41
|
+
it 'should delegate to the lines' do
|
42
|
+
expect(line).to receive(:call).twice
|
39
43
|
pipe.each(&:call)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
context
|
47
|
+
context '#lines' do
|
44
48
|
before do
|
45
|
-
line.
|
46
|
-
pipe.
|
49
|
+
expect(line).to receive(:strip).twice.and_return('')
|
50
|
+
allow(pipe).to receive(:io) { [line, line] }
|
47
51
|
end
|
52
|
+
|
48
53
|
it { pipe.lines }
|
49
54
|
end
|
50
55
|
|
51
|
-
context
|
52
|
-
it
|
53
|
-
pipe.
|
56
|
+
context '#io' do
|
57
|
+
it 'should call #open and pass the command through' do
|
58
|
+
expect(pipe).to receive(:open).with(/\A|#{command}/)
|
54
59
|
pipe.io
|
55
60
|
end
|
56
|
-
it { pipe.io.should be_an IO }
|
57
|
-
end
|
58
61
|
|
62
|
+
it { expect(pipe.io).to be_an(IO) }
|
63
|
+
end
|
59
64
|
end
|