Permalink
Browse files

Allowing the dest_dir and source_dir helpers to take arguments so tes…

…ts aren't littered with File.joins
  • Loading branch information...
1 parent c60be9c commit 479d8c757265f44525853d63bd54435d2f7cf66f @qrush qrush committed Mar 18, 2009
Showing with 11 additions and 11 deletions.
  1. +4 −4 test/helper.rb
  2. +4 −4 test/test_generated_site.rb
  3. +3 −3 test/test_post.rb
View
8 test/helper.rb
@@ -10,12 +10,12 @@
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
View
8 test/test_generated_site.rb
@@ -10,29 +10,29 @@ 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
assert @index.include?("#{@site.posts.size} Posts")
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
View
6 test/test_post.rb
@@ -2,11 +2,11 @@
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 @@ def do_render(post)
@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

0 comments on commit 479d8c7

Please sign in to comment.