Stubbing git attributes (for now)

This commit is contained in:
Arfon Smith
2014-09-25 13:37:20 -05:00
parent ea2c7d8b27
commit 5284608942
2 changed files with 23 additions and 3 deletions

View File

@@ -47,7 +47,7 @@ module Linguist
def result_for_key(keyname) def result_for_key(keyname)
key = git_attributes[keyname] key = git_attributes[keyname]
if key == "false" if key == "false" || key.nil?
return false return false
else else
return true return true

View File

@@ -1,7 +1,7 @@
require 'linguist/repository' require 'linguist/repository'
require 'linguist/lazy_blob' require 'linguist/lazy_blob'
require 'test/unit' require 'test/unit'
require 'pry'
class TestRepository < Test::Unit::TestCase class TestRepository < Test::Unit::TestCase
def rugged_repository def rugged_repository
@rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__)) @rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__))
@@ -58,7 +58,6 @@ class TestRepository < Test::Unit::TestCase
# Rakefile linguist-generated # Rakefile linguist-generated
# test/fixtures/* linguist-vendored=false # test/fixtures/* linguist-vendored=false
attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33'
repo = linguist_repo(attr_commit) repo = linguist_repo(attr_commit)
@@ -72,8 +71,15 @@ class TestRepository < Test::Unit::TestCase
def test_linguist_generated? def test_linguist_generated?
attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33'
file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile')
git_attrs = { "linguist-language" => nil,
"linguist-vendored" => nil,
"linguist-generated"=> true }
# TODO: get rid of this (would like this to come from git data)
file.stubs(:git_attributes).returns(git_attrs)
# check we're getting the correct assignment back from .gitattributes # check we're getting the correct assignment back from .gitattributes
assert file.result_for_key('linguist-generated') assert file.result_for_key('linguist-generated')
@@ -87,6 +93,13 @@ class TestRepository < Test::Unit::TestCase
attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33'
override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile')
git_attrs = { "linguist-language" => nil,
"linguist-vendored" => true,
"linguist-generated"=> nil }
# TODO: get rid of this (would like this to come from git data)
override_vendored.stubs(:git_attributes).returns(git_attrs)
# check we're getting the correct assignment back from .gitattributes # check we're getting the correct assignment back from .gitattributes
assert override_vendored.result_for_key('linguist-vendored') assert override_vendored.result_for_key('linguist-vendored')
# overridden .gitattributes # overridden .gitattributes
@@ -101,6 +114,13 @@ class TestRepository < Test::Unit::TestCase
# lib/linguist/vendor.yml defines this as vendored. # lib/linguist/vendor.yml defines this as vendored.
override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb') override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb')
git_attrs = { "linguist-language" => nil,
"linguist-vendored" => "false",
"linguist-generated"=> nil }
# TODO: get rid of this (would like this to come from git data)
override_unvendored.stubs(:git_attributes).returns(git_attrs)
# check we're getting the correct assignment back from .gitattributes # check we're getting the correct assignment back from .gitattributes
assert !override_unvendored.result_for_key('linguist-vendored') assert !override_unvendored.result_for_key('linguist-vendored')
# overridden .gitattributes # overridden .gitattributes