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
|
class Test::Unit::TestCase
|
||||||
include RR::Adapters::TestUnit
|
include RR::Adapters::TestUnit
|
||||||
|
|
||||||
def dest_dir
|
def dest_dir(subdirs = [])
|
||||||
File.join(File.dirname(__FILE__), 'dest')
|
File.join(File.dirname(__FILE__), 'dest', *subdirs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def source_dir
|
def source_dir(subdirs = [])
|
||||||
File.join(File.dirname(__FILE__), 'source')
|
File.join(File.dirname(__FILE__), 'source', *subdirs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_dest
|
def clear_dest
|
||||||
|
|
|
@ -10,7 +10,7 @@ class TestGeneratedSite < Test::Unit::TestCase
|
||||||
|
|
||||||
@site = Site.new(Jekyll.configuration)
|
@site = Site.new(Jekyll.configuration)
|
||||||
@site.process
|
@site.process
|
||||||
@index = File.read(File.join(dest_dir, 'index.html'))
|
@index = File.read(dest_dir('index.html'))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "insert site.posts into the index" do
|
should "insert site.posts into the index" do
|
||||||
|
@ -18,21 +18,21 @@ class TestGeneratedSite < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render post.content" do
|
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 = Post.new(@site, source_dir, '', File.basename(latest_post))
|
||||||
post.transform
|
post.transform
|
||||||
assert @index.include?(post.content)
|
assert @index.include?(post.content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "hide unpublished posts" do
|
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 1, published.size
|
||||||
assert_equal "published.html", published.first
|
assert_equal "published.html", published.first
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not copy _posts directory" do
|
should "not copy _posts directory" do
|
||||||
assert !File.exist?(File.join(dest_dir, '_posts'))
|
assert !File.exist?(dest_dir('_posts'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/helper'
|
||||||
|
|
||||||
class TestPost < Test::Unit::TestCase
|
class TestPost < Test::Unit::TestCase
|
||||||
def setup_post(file)
|
def setup_post(file)
|
||||||
Post.new(@site, File.join(File.dirname(__FILE__), 'source'), '', file)
|
Post.new(@site, source_dir, '', file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_render(post)
|
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" => []}})
|
post.render(layouts, {"site" => {"posts" => []}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class TestPost < Test::Unit::TestCase
|
||||||
|
|
||||||
@real_file = "2008-10-18-foo-bar.textile"
|
@real_file = "2008-10-18-foo-bar.textile"
|
||||||
@fake_file = "2008-10-19-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
|
end
|
||||||
|
|
||||||
should "keep date, title, and markup type" do
|
should "keep date, title, and markup type" do
|
||||||
|
|
Loading…
Reference in New Issue