git_statistics 0.5.1 → 0.6.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,16 +3,15 @@ include GitStatistics
3
3
  include GitStatistics::Formatters
4
4
 
5
5
  describe Console do
6
- let(:verbose) {false}
7
6
  let(:limit) {100}
8
7
  let(:fresh) {true}
9
8
  let(:pretty) {false}
10
- let(:collector) {Collector.new(verbose, limit, fresh, pretty)}
9
+ let(:collector) {Collector.new(limit, fresh, pretty)}
11
10
 
12
11
  let(:commits) {collector.commits}
13
12
 
14
13
  let(:fixture_file) {"multiple_authors.json"}
15
- let(:save_file) {collector.commits_path + "0.json"}
14
+ let(:save_file) { File.join(collector.commits_path, "0.json") }
16
15
  let(:email) {false}
17
16
  let(:merge) {false}
18
17
  let(:sort) {:commits}
@@ -29,6 +28,8 @@ describe Console do
29
28
  results.prepare_result_summary(sort, email, top_n)
30
29
  }
31
30
 
31
+ before { config }
32
+
32
33
  describe "#prepare_result_summary" do
33
34
  context "with email and sorting" do
34
35
  context "on first author" do
@@ -36,7 +37,7 @@ describe Console do
36
37
  author = "Kevin Jalbert"
37
38
  subject {data[author]}
38
39
 
39
- it {data.has_key?(author).should be_true}
40
+ it {data.should have_key author}
40
41
 
41
42
  it {subject[:commits].should == 1}
42
43
  it {subject[:additions].should == 73}
@@ -144,24 +145,30 @@ describe Console do
144
145
  end
145
146
  end
146
147
 
147
- describe "#print_summary" do
148
- context "with valid data" do
149
- let(:language_data) {results.print_summary(sort, email)}
150
- it {language_data.should == fixture("summary_output.txt").read}
148
+ describe "output" do
149
+ let(:output) { fixture(file).file.read }
150
+ describe "#print_summary" do
151
+ context "with valid data" do
152
+ let(:file) { "summary_output.txt" }
153
+ subject {results.print_summary(sort, email)}
154
+ it { should == output.chomp }
155
+ end
151
156
  end
152
- end
153
157
 
154
- describe "#print_language_data" do
155
- context "with valid data" do
156
- let(:language_data) {results.print_language_data(config[:pattern], config[:data]["Kevin Jalbert"])}
157
- it {language_data.should == fixture("language_data_output.txt").read}
158
+ describe "#print_language_data" do
159
+ context "with valid data" do
160
+ let(:file) { "language_data_output.txt" }
161
+ subject {results.print_language_data(config[:data]["Kevin Jalbert"])}
162
+ it {should == output.split("\n")}
163
+ end
158
164
  end
159
- end
160
165
 
161
- describe "#print_header" do
162
- context "with valid data" do
163
- let(:header) {results.print_header(config)}
164
- it {header.should == fixture("header_output.txt").read}
166
+ describe "#print_header" do
167
+ context "with valid data" do
168
+ let(:file) { "header_output.txt" }
169
+ subject { results.print_header.join("\n") }
170
+ it {should == output.chomp}
171
+ end
165
172
  end
166
173
  end
167
174
 
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ include GitStatistics
4
+
5
+ describe Log do
6
+
7
+ let(:log) { Class.new(Log) }
8
+
9
+ context "initializes instance" do
10
+ it "should acts as singleton" do
11
+ log.instance.should == log.instance
12
+ end
13
+
14
+ it "should have a logger" do
15
+ log.instance.logger.should be_a Logger
16
+ end
17
+
18
+ it "should be a Log (FakeLog)" do
19
+ log.class.should eq Log.class
20
+ end
21
+
22
+ it "should react to Logger methods" do
23
+ Logger.public_instance_methods.each do |method|
24
+ log.valid_method?(method).should be_true
25
+ end
26
+ end
27
+ end
28
+
29
+ context "#use_debug" do
30
+ it "logger's progname before" do
31
+ log.progname.should be_nil
32
+ end
33
+
34
+ it "logger's progname after" do
35
+ log.use_debug
36
+ log.progname.should_not be_nil
37
+ end
38
+ end
39
+
40
+ context "#parse_caller" do
41
+ context "with nothing" do
42
+ it {log.parse_caller(nil).should be_nil}
43
+ end
44
+
45
+ context "with jumble (random text)" do
46
+ it {log.parse_caller("asdaacsdc").should be_nil}
47
+ end
48
+
49
+ context "with valid caller" do
50
+ it {log.parse_caller("git_statistics/lib/git_statistics/log.rb:45:in `respond_to_missing?'").should eq "git_statistics/lib/git_statistics/log.rb:45"}
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ include GitStatistics
4
+
5
+ describe Pipe do
6
+ let(:command) { 'git' }
7
+ let(:line) { "" }
8
+ let(:pipe) { Pipe.new(command) }
9
+
10
+ context "initializes correctly" do
11
+ context "with pipe character" do
12
+ let(:command) { '|git log --oneline' }
13
+ it { expect(pipe.command).to eq 'git log --oneline'}
14
+ end
15
+ context "without pipe character" do
16
+ let(:command) { 'stat something else' }
17
+ it { expect(pipe.command).to eq 'stat something else'}
18
+ end
19
+ end
20
+
21
+ context "#empty?" do
22
+ before { pipe.stub(:lines) { lines } }
23
+ context "with empty lines" do
24
+ let(:lines) { [] }
25
+ it { pipe.should be_empty }
26
+ end
27
+ context "with a single line" do
28
+ let(:lines) { [stub] }
29
+ it { pipe.should_not be_empty }
30
+ end
31
+ end
32
+
33
+ context "#each" do
34
+ before do
35
+ pipe.stub(:lines) { [line, line] }
36
+ end
37
+ it "should delegate to the lines" do
38
+ line.should_receive(:call).twice
39
+ pipe.each(&:call)
40
+ end
41
+ end
42
+
43
+ context "#lines" do
44
+ before do
45
+ line.should_receive(:strip).twice.and_call_original
46
+ pipe.stub(:io) { [line, line] }
47
+ end
48
+ it { pipe.lines }
49
+ end
50
+
51
+ context "#io" do
52
+ it "should call #open and pass the command through" do
53
+ pipe.should_receive(:open).with(/\A|#{command}/)
54
+ pipe.io
55
+ end
56
+ it { pipe.io.should be_an IO }
57
+ end
58
+
59
+ end
@@ -4,76 +4,74 @@ include GitStatistics
4
4
  describe Utilities do
5
5
 
6
6
  describe "#get_repository" do
7
- let(:repo) {Utilities.get_repository(dir)}
7
+ subject { Utilities.get_repository(dir) }
8
8
 
9
9
  context "with root directory" do
10
- let(:dir) {Dir.pwd} # git_statistics/
11
- it {repo.instance_of?(Grit::Repo).should be_true}
10
+ let(:dir) { Dir.pwd } # git_statistics/
11
+ it { should be_a Grit::Repo }
12
12
  end
13
13
 
14
14
  context "with sub directory" do
15
- let(:dir) {File.dirname(__FILE__)} # git_statistics/spec/
16
- it {repo.instance_of?(Grit::Repo).should be_true}
15
+ let(:dir) { File.dirname(__FILE__) } # git_statistics/spec/
16
+ it { should be_a Grit::Repo }
17
17
  end
18
18
 
19
19
  context "when not in a repository directory" do
20
- let(:dir) {Dir.pwd + "../"} # git_statistics/../
21
- it {repo.should.nil?}
20
+ before { Utilities.should_receive(:exit) }
21
+ let(:dir) { Dir.home } # /Users/username/
22
+ it { should be_nil }
22
23
  end
23
24
  end
24
25
 
25
26
  describe "#max_length_in_list" do
26
27
  let(:max) {nil}
27
28
  let(:list) {[]}
28
- let(:results) {Utilities.max_length_in_list(list, max)}
29
+ subject(:results) {Utilities.max_length_in_list(list, max)}
29
30
 
30
31
  context "with empty list" do
31
- it {results.should.nil?}
32
+ it { should be_nil }
32
33
  end
33
34
 
34
35
  context "with nil list" do
35
36
  let(:list) {nil}
36
- it {results.should.nil?}
37
+ it { should be_nil }
38
+ end
39
+
40
+ context "with empty list and zero max" do
41
+ let(:list) { [] }
42
+ let(:max) { 0 }
43
+ it { should == 0 }
37
44
  end
38
45
 
39
46
  context "with preset minimum length" do
40
47
  let(:max) {10}
41
- it {results.should == 10}
48
+ it { should == 10 }
42
49
  end
43
50
 
44
51
  context "with valid list" do
45
52
  let(:list) {["abc", "a", "ab"]}
46
- it {results.should == 3}
53
+ it { should == 3 }
47
54
  end
48
55
 
49
56
  context "with valid hash" do
50
57
  let(:list) {{"a" => "word_a", "ab" => "word_b", "abc" => "word_c"}}
51
- it {results.should == 3}
52
- end
53
- end
54
-
55
- describe "#clean_string" do
56
- let(:unclean) {" master "}
57
- let(:clean) {unclean.clean_for_authors}
58
-
59
- context "with trailling spaces" do
60
- it {clean.should == "master"}
58
+ it { should == 3 }
61
59
  end
62
60
  end
63
61
 
64
62
  describe "#get_modified_time" do
65
63
  let(:file) { 'file' }
66
- before do
67
- OS.stub(:mac?) { false }
68
- OS.stub(:linux?) { false }
69
- end
70
64
  after { Utilities.get_modified_time(file) }
71
65
  context "on a Mac" do
72
- before { OS.stub(:mac?) { true } }
66
+ before { Utilities.stub(:os) { :mac } }
73
67
  it { Utilities.should_receive(:time_at).with(%[stat -f %m file]) { 10 } }
74
68
  end
75
69
  context "on a Linux" do
76
- before { OS.stub(:linux?) { true } }
70
+ before { Utilities.stub(:os) { :linux } }
71
+ it { Utilities.should_receive(:time_at).with(%[stat -c %Y file]) { 10 } }
72
+ end
73
+ context "on a Unix" do
74
+ before { Utilities.stub(:os) { :unix } }
77
75
  it { Utilities.should_receive(:time_at).with(%[stat -c %Y file]) { 10 } }
78
76
  end
79
77
  end
@@ -120,48 +118,52 @@ describe Utilities do
120
118
  let(:tree) {Utilities.get_repository(Dir.pwd).tree(sha)}
121
119
  let(:file) {nil}
122
120
  let(:blob) {Utilities.find_blob_in_tree(tree, file.split(File::Separator))}
121
+ subject { blob }
123
122
 
124
123
  context "blob on root tree" do
125
124
  let(:file) {"Gemfile"}
126
- it {blob.instance_of?(Grit::Blob).should be_true}
127
- it {blob.name.should == file}
125
+ it { should be_instance_of Grit::Blob }
126
+ its(:name) { should == file }
128
127
  end
129
128
 
130
129
  context "blob down tree" do
131
130
  let(:file) {"lib/git_statistics/collector.rb"}
132
- it {blob.instance_of?(Grit::Blob).should be_true}
133
- it {blob.name.should == file.split(File::Separator).last}
131
+ it { should be_instance_of Grit::Blob }
132
+ its(:name) { should == File.basename(file) }
134
133
  end
135
134
 
136
135
  context "file is nil" do
137
- let(:blob) {Utilities.find_blob_in_tree(tree, nil)}
138
- it {blob.should.nil?}
136
+ subject {Utilities.find_blob_in_tree(tree, nil)}
137
+ it { should be_nil }
139
138
  end
140
139
 
141
140
  context "file is empty" do
142
141
  let(:file) {""}
143
- it {blob.should.nil?}
142
+ it { should be_nil }
144
143
  end
145
144
 
146
145
  context "file is submodule" do
147
146
  let(:sha) {"1940ef1c613a04f855d3867b874a4267d3e2c011"}
148
147
  let(:file) {"Spoon-Knife"}
149
- it {blob.instance_of?(Grit::Submodule).should be_true}
150
- it {blob.name.should == file}
148
+ it { should be_instance_of Grit::Submodule }
149
+ its(:name) { should == file }
151
150
  end
152
151
  end
153
152
 
154
153
  describe "#number_of_matching_files" do
155
- let(:files) {Utilities.number_of_matching_files(directory, pattern)}
156
- let(:pattern) {/\d+\.json/}
157
- let(:directory) {Dir.pwd + File::Separator + "tmp_dir_for_spec" + File::Separator}
154
+ let(:directory) { File.join(Dir.pwd, "tmp_dir_for_spec") }
155
+ let(:pattern) { (/\d+\.json/) }
156
+ subject {Utilities.number_of_matching_files(directory, pattern)}
158
157
 
159
- before(:each) do
158
+ around do |example|
160
159
  FileUtils.mkdir_p(directory)
160
+ Dir.chdir(directory) do
161
+ example.run
162
+ end
163
+ FileUtils.rmdir(directory)
161
164
  end
162
165
 
163
166
  context "with missing directory" do
164
- subject { files }
165
167
  before do
166
168
  subject.class.stub(:warn)
167
169
  FileUtils.rmdir(directory)
@@ -169,36 +171,36 @@ describe Utilities do
169
171
  it { should == 0 }
170
172
  end
171
173
 
172
- after(:each) do
173
- FileUtils.rmdir(directory)
174
- end
175
-
176
174
  context "with valid files" do
177
- it do
178
- FileUtils.touch(directory + "0.json")
179
- FileUtils.touch(directory + "1.json")
180
- FileUtils.touch(directory + "2.json")
181
- files.should == 3
182
- FileUtils.rm(directory + "0.json")
183
- FileUtils.rm(directory + "1.json")
184
- FileUtils.rm(directory + "2.json")
175
+ 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")
185
184
  end
185
+ it { should == 3 }
186
186
  end
187
187
 
188
188
  context "with invalid files" do
189
- it do
190
- FileUtils.touch(directory + "0.json")
191
- FileUtils.touch(directory + "incorrect.json")
192
- FileUtils.touch(directory + "1.json")
193
- files.should == 2
194
- FileUtils.rm(directory + "0.json")
195
- FileUtils.rm(directory + "incorrect.json")
196
- FileUtils.rm(directory + "1.json")
189
+ before do
190
+ FileUtils.touch("0.json")
191
+ FileUtils.touch("incorrect.json")
192
+ FileUtils.touch("1.json")
197
193
  end
194
+ after do
195
+ FileUtils.rm("0.json")
196
+ FileUtils.rm("incorrect.json")
197
+ FileUtils.rm("1.json")
198
+ end
199
+ it { should == 2 }
198
200
  end
199
201
 
200
202
  context "with no files" do
201
- it {files.should == 0}
203
+ it { should == 0 }
202
204
  end
203
205
  end
204
206
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: trollop
31
+ name: grit
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: grit
47
+ name: github-linguist
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -60,14 +60,30 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: github-linguist
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
67
83
  - - ! '>='
68
84
  - !ruby/object:Gem::Version
69
85
  version: '0'
70
- type: :runtime
86
+ type: :development
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
@@ -76,14 +92,30 @@ dependencies:
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
78
94
  - !ruby/object:Gem::Dependency
79
- name: os
95
+ name: simplecov
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
83
99
  - - ! '>='
84
100
  - !ruby/object:Gem::Version
85
101
  version: '0'
86
- type: :runtime
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: tailor
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
87
119
  prerelease: false
88
120
  version_requirements: !ruby/object:Gem::Requirement
89
121
  none: false
@@ -101,20 +133,25 @@ extensions: []
101
133
  extra_rdoc_files: []
102
134
  files:
103
135
  - lib/git_statistics/blob.rb
136
+ - lib/git_statistics/branches.rb
104
137
  - lib/git_statistics/collector.rb
105
138
  - lib/git_statistics/commit_line_extractor.rb
106
139
  - lib/git_statistics/commits.rb
107
- - lib/git_statistics/core_ext/string.rb
108
140
  - lib/git_statistics/formatters/console.rb
109
141
  - lib/git_statistics/initialize.rb
142
+ - lib/git_statistics/log.rb
143
+ - lib/git_statistics/pipe.rb
110
144
  - lib/git_statistics/regex_matcher.rb
111
145
  - lib/git_statistics/utilities.rb
112
146
  - lib/git_statistics/version.rb
113
147
  - lib/git_statistics.rb
148
+ - spec/branches_spec.rb
114
149
  - spec/collector_spec.rb
115
150
  - spec/commit_line_extractor_spec.rb
116
151
  - spec/commits_spec.rb
117
152
  - spec/formatters/console_spec.rb
153
+ - spec/log_spec.rb
154
+ - spec/pipe_spec.rb
118
155
  - spec/regex_matcher_spec.rb
119
156
  - spec/utilities_spec.rb
120
157
  - bin/git_statistics
@@ -137,6 +174,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
174
  - - ! '>='
138
175
  - !ruby/object:Gem::Version
139
176
  version: '0'
177
+ segments:
178
+ - 0
179
+ hash: 2745027118134232724
140
180
  requirements: []
141
181
  rubyforge_project:
142
182
  rubygems_version: 1.8.24
@@ -144,9 +184,12 @@ signing_key:
144
184
  specification_version: 3
145
185
  summary: Gem that provides the ability to gather detailed git statistics
146
186
  test_files:
187
+ - spec/branches_spec.rb
147
188
  - spec/collector_spec.rb
148
189
  - spec/commit_line_extractor_spec.rb
149
190
  - spec/commits_spec.rb
150
191
  - spec/formatters/console_spec.rb
192
+ - spec/log_spec.rb
193
+ - spec/pipe_spec.rb
151
194
  - spec/regex_matcher_spec.rb
152
195
  - spec/utilities_spec.rb