git_stats/spec/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
let(:commit) { build(:commit) }
describe 'git output parsing' do
2012-10-16 22:44:04 +02:00
context 'parsing git ls-tree output' do
before {
GitStats::GitData::Command.any_instance.should_receive(:run_in_repo).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-16 22:44:04 +02:00
100644 blob 1463eacb3ac9f95f21f360f1eb935a84a9ee0895 templates/activity.haml
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 == [
GitStats::GitData::Blob.new(repo: commit.repo, hash: "5ade7ad51a75ee7db4eb06cecd3918d38134087d", filename: "lib/git_stats/git_data/commit.rb"),
GitStats::GitData::Blob.new(repo: commit.repo, hash: "db01e94677a8f72289848e507a52a43de2ea109a", filename: "lib/git_stats/git_data/repo.rb"),
GitStats::GitData::Blob.new(repo: commit.repo, hash: "1463eacb3ac9f95f21f360f1eb935a84a9ee0895", filename: "templates/activity.haml"),
GitStats::GitData::Blob.new(repo: commit.repo, hash: "31d8b960a67f195bdedaaf9e7aa70b2389f3f1a8", filename: "templates/assets/bootstrap/css/bootstrap.min.css"),
]
end
it 'should group files by extension' do
commit.files_by_extension.should == {'.rb' => [
GitStats::GitData::Blob.new(repo: commit.repo, hash: "5ade7ad51a75ee7db4eb06cecd3918d38134087d", filename: "lib/git_stats/git_data/commit.rb"),
GitStats::GitData::Blob.new(repo: commit.repo, hash: "db01e94677a8f72289848e507a52a43de2ea109a", filename: "lib/git_stats/git_data/repo.rb")
], '.haml' => [
GitStats::GitData::Blob.new(repo: commit.repo, hash: "1463eacb3ac9f95f21f360f1eb935a84a9ee0895", filename: "templates/activity.haml")
], '.css' => [
GitStats::GitData::Blob.new(repo: commit.repo, hash: "31d8b960a67f195bdedaaf9e7aa70b2389f3f1a8", filename: "templates/assets/bootstrap/css/bootstrap.min.css")
]
}
end
it 'should count lines by extension' do
GitStats::GitData::Blob.should_receive(:new).and_return(
double(lines_count: 40, extension: '.rb'),
double(lines_count: 60, extension: '.rb'),
double(lines_count: 10, extension: '.haml'),
double(lines_count: 20, extension: '.css'),
)
commit.lines_by_extension.should == {'.rb' => 100, '.haml' => 10, '.css' => 20}
end
2012-10-16 22:03:25 +02:00
end
end
end