DEM TESTS

This commit is contained in:
Parker Moore 2014-04-01 23:10:17 -04:00
parent 08162dbb50
commit 90807ac6e7
5 changed files with 55 additions and 12 deletions

View File

@ -15,6 +15,7 @@ module Jekyll
Dir.glob(File.join(directory, "**", "*.*")).each do |file_path|
if allowed_document?(file_path)
doc = Jekyll::Document.new(file_path, { site: site, collection: self })
doc.read
docs << doc
end
end

View File

@ -28,6 +28,10 @@ module Jekyll
Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
end
def basename(suffix = "")
File.basename(path, suffix)
end
def extname
File.extname(path)
end
@ -56,7 +60,7 @@ module Jekyll
# Read in the file and assign the content and data based on the file contents.
#
# Returns nothing.
def read
def read(opts = {})
if yaml_file?
@data = SafeYAML.load_file(path)
else

View File

@ -175,16 +175,9 @@ module Jekyll
entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
entries.delete_if { |e| File.directory?(File.join(base, e)) }
data_collection = Jekyll::Collection.new(self, "data")
entries.each do |entry|
path = File.join(source, dir, entry)
next if File.symlink?(path) && safe
key = sanitize_filename(File.basename(entry, '.*'))
doc = Jekyll::Document.new(path, { site: self, collection: data_collection })
doc.read
data_collection.read
data_collection.docs.each do |doc|
key = sanitize_filename(doc.basename(".*"))
self.data[key] = doc.data
end
end

View File

@ -1 +1 @@
test/source/_methods/sanitized_path.md
./site/generate.md

45
test/test_document.rb Normal file
View File

@ -0,0 +1,45 @@
require 'helper'
class TestDocument < Test::Unit::TestCase
context "" do
setup do
@site = Site.new(Jekyll.configuration({
"collections" => ["methods"],
"source" => source_dir,
"destination" => dest_dir
}))
@site.process
@document = @site.collections["methods"].docs.first
end
should "know its relative path" do
assert_equal "_methods/configuration.md", @document.relative_path
end
should "knows its extname" do
assert_equal ".md", @document.extname
end
should "know its basename" do
assert_equal "configuration.md", @document.basename
end
should "allow the suffix to be specified for the basename" do
assert_equal "configuration", @document.basename(".*")
end
should "know whether its a yaml file" do
assert_equal false, @document.yaml_file?
end
should "know its data" do
assert_equal({
"title" => "Jekyll.configuration",
"whatever" => "foo.bar"
}, @document.data)
end
end
end