diff --git a/lib/git_stats/git_data/author.rb b/lib/git_stats/git_data/author.rb index 58cb0c0f0..a964efb7e 100644 --- a/lib/git_stats/git_data/author.rb +++ b/lib/git_stats/git_data/author.rb @@ -19,6 +19,10 @@ module GitStats "#{self.class} #@name <#@email>" end + def ==(other) + [self.repo, self.name, self.email] == [other.repo, other.name, other.email] + end + end end end \ No newline at end of file diff --git a/lib/git_stats/git_data/commit.rb b/lib/git_stats/git_data/commit.rb index 18a06ddb6..b1e948d45 100644 --- a/lib/git_stats/git_data/commit.rb +++ b/lib/git_stats/git_data/commit.rb @@ -18,6 +18,11 @@ module GitStats def to_s "#{self.class} #@hash" end + + def ==(other) + [self.repo, self.hash, self.stamp, self.date, self.author] == + [other.repo, other.hash, other.stamp, other.date, other.author] + end end end end \ No newline at end of file diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index d8dadb39e..208434ffc 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -42,6 +42,10 @@ module GitStats "#{self.class} #@path" end + def ==(other) + self.path == other.path + end + end end end \ No newline at end of file diff --git a/spec/activity_spec.rb b/spec/activity_spec.rb index 4ba6baad0..68fe0253e 100644 --- a/spec/activity_spec.rb +++ b/spec/activity_spec.rb @@ -8,7 +8,7 @@ describe GitStats::GitData::Activity do '15.06.2011 15:02', '27.09.2011 15:34' ] } - let(:commits) { dates.map { |d| double(:date => DateTime.parse(d)) } } + let(:commits) { dates.map { |d| GitStats::GitData::Commit.new(:date => DateTime.parse(d)) } } let(:activity) { GitStats::GitData::Activity.new(commits) } it 'by_hour should count commits by hour' do diff --git a/spec/author_spec.rb b/spec/author_spec.rb index 598f3a462..e73ba4611 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' describe GitStats::GitData::Author do + let(:repo) { GitStats::GitData::Repo.new(path: "repo_path") } + let(:author) { GitStats::GitData::Author.new(repo: repo, name: "author1", email: "author1@gmail.com") } + let(:other_author) { GitStats::GitData::Author.new(repo: repo, name: "author2", email: "author2@gmail.com") } let(:my_commits) { Hash[10.times.map { |i| ["my #{i}", double("my_commit #{i}", :author => author)] }] } - let(:other_commits) { Hash[10.times.map { |i| ["other #{i}", double("other_commit #{i}", :author => 42)] }] } - let(:repo) { double("repo") } - let(:author) { GitStats::GitData::Author.new(repo: repo) } + let(:other_commits) { Hash[10.times.map { |i| ["other #{i}", double("other_commit #{i}", :author => other_author)] }] } + before { repo.stub(:commits => my_commits.merge(other_commits)) } it 'commits should give repo commits filtered to this author' do diff --git a/spec/repo_spec.rb b/spec/repo_spec.rb new file mode 100644 index 000000000..70a0c149b --- /dev/null +++ b/spec/repo_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe GitStats::GitData::Repo do + let(:repo) { GitStats::GitData::Repo.new("repo_path") } + + describe 'git output parsing' do + before { + GitStats::GitData::Command.should_receive(:new).with( + repo, 'git shortlog -se HEAD').and_return( + double(:run => " 156 John Doe + 53 Joe Doe +")) + } + + it 'should parse git shortlog output to authors hash' do + repo.authors.should == { + "john.doe@gmail.com" => GitStats::GitData::Author.new(repo: repo, name: "John Doe", email: "john.doe@gmail.com"), + "joe.doe@gmail.com" => GitStats::GitData::Author.new(repo: repo, name: "Joe Doe", email: "joe.doe@gmail.com") + } + end + + it 'should parse git revlist output to commits hash' do + GitStats::GitData::Command.should_receive(:new).with( + repo, 'git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').and_return( + double(:run => "e4412c3|1348603824|2012-09-25 22:10:24 +0200|john.doe@gmail.com +ce34874|1347482927|2012-09-12 22:48:47 +0200|joe.doe@gmail.com +5eab339|1345835073|2012-08-24 21:04:33 +0200|john.doe@gmail.com +")) + + repo.commits.should == { + "e4412c3" => GitStats::GitData::Commit.new( + repo: repo, hash: "e4412c3", stamp: "1348603824", date: DateTime.parse("2012-09-25 22:10:24 +0200"), + author: repo.authors["john.doe@gmail.com"]), + "ce34874" => GitStats::GitData::Commit.new( + repo: repo, hash: "ce34874", stamp: "1347482927", date: DateTime.parse("2012-09-12 22:48:47 +0200"), + author: repo.authors["joe.doe@gmail.com"]), + "5eab339" => GitStats::GitData::Commit.new( + repo: repo, hash: "5eab339", stamp: "1345835073", date: DateTime.parse("2012-08-24 21:04:33 +0200"), + author: repo.authors["john.doe@gmail.com"]) + } + end + end +end \ No newline at end of file