git_stats/spec/git_data/commit_spec.rb

47 lines
2.6 KiB
Ruby
Raw Normal View History

2012-10-16 22:03:25 +02:00
require 'spec_helper'
describe GitStats::GitData::Commit do
2012-10-20 22:38:11 +02:00
let(:commit) { build(:commit, sha: 'abc') }
2012-10-16 22:03:25 +02:00
describe 'git output parsing' do
2012-10-16 22:44:04 +02:00
context 'parsing git ls-tree output' do
before {
2012-10-19 16:57:49 +02:00
commit.repo.should_receive(:run).with('git ls-tree -r abc').and_return("100644 blob 5ade7ad51a75ee7db4eb06cecd3918d38134087d lib/git_stats/git_data/commit.rb
2012-10-16 22:03:25 +02:00
100644 blob db01e94677a8f72289848e507a52a43de2ea109a lib/git_stats/git_data/repo.rb
2012-10-22 19:50:31 +02:00
100644 blob 1463eacb3ac9f95f21f360f1eb935a84a9ee0895 templates/index.haml
2012-10-16 22:44:04 +02:00
100644 blob 31d8b960a67f195bdedaaf9e7aa70b2389f3f1a8 templates/assets/bootstrap/css/bootstrap.min.css
") }
2012-10-16 22:03:25 +02:00
2012-10-16 22:44:04 +02:00
it 'should be parsed to files' do
commit.files.should == [
2012-10-20 22:38:11 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "5ade7ad51a75ee7db4eb06cecd3918d38134087d", filename: "lib/git_stats/git_data/commit.rb"),
GitStats::GitData::Blob.new(repo: commit.repo, sha: "db01e94677a8f72289848e507a52a43de2ea109a", filename: "lib/git_stats/git_data/repo.rb"),
2012-10-22 19:50:31 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "1463eacb3ac9f95f21f360f1eb935a84a9ee0895", filename: "templates/index.haml"),
2012-10-20 22:38:11 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "31d8b960a67f195bdedaaf9e7aa70b2389f3f1a8", filename: "templates/assets/bootstrap/css/bootstrap.min.css"),
2012-10-16 22:44:04 +02:00
]
end
it 'should group files by extension' do
commit.files_by_extension.should == {'.rb' => [
2012-10-20 22:38:11 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "5ade7ad51a75ee7db4eb06cecd3918d38134087d", filename: "lib/git_stats/git_data/commit.rb"),
GitStats::GitData::Blob.new(repo: commit.repo, sha: "db01e94677a8f72289848e507a52a43de2ea109a", filename: "lib/git_stats/git_data/repo.rb")
2012-10-16 22:44:04 +02:00
], '.haml' => [
2012-10-22 19:50:31 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "1463eacb3ac9f95f21f360f1eb935a84a9ee0895", filename: "templates/index.haml")
2012-10-16 22:44:04 +02:00
], '.css' => [
2012-10-20 22:38:11 +02:00
GitStats::GitData::Blob.new(repo: commit.repo, sha: "31d8b960a67f195bdedaaf9e7aa70b2389f3f1a8", filename: "templates/assets/bootstrap/css/bootstrap.min.css")
2012-10-16 22:44:04 +02:00
]
}
end
2012-10-20 22:38:11 +02:00
it 'should count lines by extension excluding empty or binary files' do
2012-10-16 22:44:04 +02:00
GitStats::GitData::Blob.should_receive(:new).and_return(
double(lines_count: 40, extension: '.rb'),
double(lines_count: 60, extension: '.rb'),
2012-10-20 21:28:25 +02:00
double(lines_count: 0, extension: '.haml'),
2012-10-16 22:44:04 +02:00
double(lines_count: 20, extension: '.css'),
)
commit.lines_by_extension.should == {'.rb' => 100, '.css' => 20}
2012-10-16 22:44:04 +02:00
end
2012-10-16 22:03:25 +02:00
end
end
end