mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
command mocking refactored
This commit is contained in:
parent
d26c261a18
commit
0cb7b52591
3 changed files with 17 additions and 22 deletions
|
@ -9,12 +9,12 @@ module GitStats
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
result = in_repo { %x[#@command] }
|
result = run_in_repo { %x[#@command] }
|
||||||
repo.git_command_observer.try(:call, @command, result)
|
repo.git_command_observer.try(:call, @command, result)
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_repo
|
def run_in_repo
|
||||||
Dir.chdir(@repo.path) { yield }
|
Dir.chdir(@repo.path) { yield }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,30 +2,27 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe GitStats::GitData::Repo do
|
describe GitStats::GitData::Repo do
|
||||||
let(:repo) { build(:repo) }
|
let(:repo) { build(:repo) }
|
||||||
|
let(:expected_authors) { {
|
||||||
|
"john.doe@gmail.com" => build(:author, repo: repo, name: "John Doe", email: "john.doe@gmail.com"),
|
||||||
|
"joe.doe@gmail.com" => build(:author, repo: repo, name: "Joe Doe", email: "joe.doe@gmail.com")
|
||||||
|
} }
|
||||||
|
|
||||||
describe 'git output parsing' do
|
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 <john.doe@gmail.com>
|
|
||||||
53 Joe Doe <joe.doe@gmail.com>
|
|
||||||
"))
|
|
||||||
}
|
|
||||||
|
|
||||||
it 'should parse git shortlog output to authors hash' do
|
it 'should parse git shortlog output to authors hash' do
|
||||||
repo.authors.should == {
|
GitStats::GitData::Command.any_instance.should_receive(:run_in_repo).and_return(" 156 John Doe <john.doe@gmail.com>
|
||||||
"john.doe@gmail.com" => GitStats::GitData::Author.new(repo: repo, name: "John Doe", email: "john.doe@gmail.com"),
|
53 Joe Doe <joe.doe@gmail.com>
|
||||||
"joe.doe@gmail.com" => GitStats::GitData::Author.new(repo: repo, name: "Joe Doe", email: "joe.doe@gmail.com")
|
")
|
||||||
}
|
|
||||||
|
repo.authors.should == expected_authors
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should parse git revlist output to date sorted commits array' do
|
it 'should parse git revlist output to date sorted commits array' do
|
||||||
GitStats::GitData::Command.should_receive(:new).with(
|
GitStats::GitData::Command.any_instance.should_receive(:run_in_repo).and_return("e4412c3|1348603824|2012-09-25 22:10:24 +0200|john.doe@gmail.com
|
||||||
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
|
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
|
5eab339|1345835073|2012-08-24 21:04:33 +0200|john.doe@gmail.com
|
||||||
"))
|
")
|
||||||
|
|
||||||
|
repo.stub(authors: expected_authors)
|
||||||
|
|
||||||
repo.commits.should == [
|
repo.commits.should == [
|
||||||
GitStats::GitData::Commit.new(
|
GitStats::GitData::Commit.new(
|
||||||
|
|
|
@ -13,11 +13,9 @@ describe GitStats::GitData::ShortStat do
|
||||||
{content: '', expect: [0, 0, 0]},
|
{content: '', expect: [0, 0, 0]},
|
||||||
].each do |test|
|
].each do |test|
|
||||||
it "#{test[:content]} parsing" do
|
it "#{test[:content]} parsing" do
|
||||||
GitStats::GitData::Command.should_receive(:new).with(
|
GitStats::GitData::Command.any_instance.should_receive(:run_in_repo).and_return("abc some commit
|
||||||
commit.repo, 'git show --shortstat --oneline abc').and_return(
|
|
||||||
double(:run => "abc some commit
|
|
||||||
#{test[:content]}
|
#{test[:content]}
|
||||||
"))
|
")
|
||||||
|
|
||||||
|
|
||||||
commit.short_stat.should be_a(GitStats::GitData::ShortStat)
|
commit.short_stat.should be_a(GitStats::GitData::ShortStat)
|
||||||
|
|
Loading…
Reference in a new issue