Basic blob tests

This commit is contained in:
Joshua Peek
2011-05-13 12:43:16 -05:00
parent d07d457677
commit 0009cbab89
2 changed files with 54 additions and 0 deletions

2
test/fixtures/blob/foo.rb vendored Normal file
View File

@@ -0,0 +1,2 @@
module Foo
end

52
test/test_blob.rb Normal file
View File

@@ -0,0 +1,52 @@
require 'linguist/blob'
require 'test/unit'
require 'mime/types'
class TestBlob < Test::Unit::TestCase
include Linguist
class FixtureBlob
def initialize(name)
@name = name
@path = File.expand_path("../fixtures/blob/#{name}", __FILE__)
end
def name
@name
end
def mime_type
guesses = ::MIME::Types.type_for(name)
orginal_type = guesses.first ? guesses.first.simplified : 'text/plain'
end
def data
File.read(@path)
end
def size
File.size(@path)
end
end
def blob(name)
Blob.new(FixtureBlob.new(name))
end
def test_name
assert_equal Pathname.new("foo.rb"), blob("foo.rb").name
end
def test_mime_type
assert_equal "application/ruby", blob("foo.rb").mime_type
end
def test_data
assert_equal "module Foo\nend\n", blob("foo.rb").data
end
def test_size
assert_equal 15, blob("foo.rb").size
end
end