Allowing the dest_dir and source_dir helpers to take arguments so tests aren't littered with File.joins
This commit is contained in:
parent
c60be9c571
commit
479d8c7572
|
@ -10,12 +10,12 @@ include Jekyll
|
|||
class Test::Unit::TestCase
|
||||
include RR::Adapters::TestUnit
|
||||
|
||||
def dest_dir
|
||||
File.join(File.dirname(__FILE__), 'dest')
|
||||
def dest_dir(subdirs = [])
|
||||
File.join(File.dirname(__FILE__), 'dest', *subdirs)
|
||||
end
|
||||
|
||||
def source_dir
|
||||
File.join(File.dirname(__FILE__), 'source')
|
||||
def source_dir(subdirs = [])
|
||||
File.join(File.dirname(__FILE__), 'source', *subdirs)
|
||||
end
|
||||
|
||||
def clear_dest
|
||||
|
|
|
@ -10,7 +10,7 @@ class TestGeneratedSite < Test::Unit::TestCase
|
|||
|
||||
@site = Site.new(Jekyll.configuration)
|
||||
@site.process
|
||||
@index = File.read(File.join(dest_dir, 'index.html'))
|
||||
@index = File.read(dest_dir('index.html'))
|
||||
end
|
||||
|
||||
should "insert site.posts into the index" do
|
||||
|
@ -18,21 +18,21 @@ class TestGeneratedSite < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "render post.content" do
|
||||
latest_post = Dir[File.join(source_dir, '_posts/*')].last
|
||||
latest_post = Dir[source_dir('_posts/*')].last
|
||||
post = Post.new(@site, source_dir, '', File.basename(latest_post))
|
||||
post.transform
|
||||
assert @index.include?(post.content)
|
||||
end
|
||||
|
||||
should "hide unpublished posts" do
|
||||
published = Dir[File.join(dest_dir, 'publish_test/2008/02/02/*.html')].map {|f| File.basename(f)}
|
||||
published = Dir[dest_dir('publish_test/2008/02/02/*.html')].map {|f| File.basename(f)}
|
||||
|
||||
assert_equal 1, published.size
|
||||
assert_equal "published.html", published.first
|
||||
end
|
||||
|
||||
should "not copy _posts directory" do
|
||||
assert !File.exist?(File.join(dest_dir, '_posts'))
|
||||
assert !File.exist?(dest_dir('_posts'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/helper'
|
|||
|
||||
class TestPost < Test::Unit::TestCase
|
||||
def setup_post(file)
|
||||
Post.new(@site, File.join(File.dirname(__FILE__), 'source'), '', file)
|
||||
Post.new(@site, source_dir, '', file)
|
||||
end
|
||||
|
||||
def do_render(post)
|
||||
layouts = {"default" => Layout.new(@site, File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
|
||||
layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")}
|
||||
post.render(layouts, {"site" => {"posts" => []}})
|
||||
end
|
||||
|
||||
|
@ -32,7 +32,7 @@ class TestPost < Test::Unit::TestCase
|
|||
|
||||
@real_file = "2008-10-18-foo-bar.textile"
|
||||
@fake_file = "2008-10-19-foo-bar.textile"
|
||||
@source = File.join(File.dirname(__FILE__), *%w[source _posts])
|
||||
@source = source_dir('_posts')
|
||||
end
|
||||
|
||||
should "keep date, title, and markup type" do
|
||||
|
|
Loading…
Reference in New Issue