Upgrading the rest of the tests to shoulda

This commit is contained in:
Nick Quaranto 2009-03-05 21:43:59 -05:00
parent 0d05f27fe4
commit 0e132bf2cb
5 changed files with 96 additions and 98 deletions

View File

@ -1,41 +1,41 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
class TestFilters < Test::Unit::TestCase class TestFilters < Test::Unit::TestCase
class JekyllFilter class JekyllFilter
include Jekyll::Filters include Jekyll::Filters
end end
def setup context "filters" do
setup do
@filter = JekyllFilter.new @filter = JekyllFilter.new
end end
def test_textilize_with_simple_string should "textilize with simple string" do
assert_equal "<p>something <strong>really</strong> simple</p>", @filter.textilize("something *really* simple") assert_equal "<p>something <strong>really</strong> simple</p>", @filter.textilize("something *really* simple")
end end
def test_array_to_sentence_string_with_no_args should "convert array to sentence string with no args" do
assert_equal "", @filter.array_to_sentence_string([]) assert_equal "", @filter.array_to_sentence_string([])
end end
def test_array_to_sentence_string_with_one_arg should "convert array to sentence string with one arg" do
assert_equal "1", @filter.array_to_sentence_string([1]) assert_equal "1", @filter.array_to_sentence_string([1])
assert_equal "chunky", @filter.array_to_sentence_string(["chunky"]) assert_equal "chunky", @filter.array_to_sentence_string(["chunky"])
end end
def test_array_to_sentence_string_with_two_args should "convert array to sentence string with two args" do
assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2]) assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2])
assert_equal "chunky and bacon", @filter.array_to_sentence_string(["chunky", "bacon"]) assert_equal "chunky and bacon", @filter.array_to_sentence_string(["chunky", "bacon"])
end end
def test_array_to_sentence_string_with_multiple_args should "convert array to sentence string with multiple args" do
assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4]) assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4])
assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"]) assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"])
end end
def test_xml_escape_with_ampersands should "escape xml with ampersands" do
assert_equal "AT&amp;T", @filter.xml_escape("AT&T") assert_equal "AT&amp;T", @filter.xml_escape("AT&T")
assert_equal "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>") assert_equal "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>")
end end
end
end end

View File

@ -1,7 +1,8 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
class TestGeneratedSite < Test::Unit::TestCase class TestGeneratedSite < Test::Unit::TestCase
def setup context "generated sites" do
setup do
clear_dest clear_dest
@source = File.join(File.dirname(__FILE__), *%w[source]) @source = File.join(File.dirname(__FILE__), *%w[source])
@s = Site.new(@source, dest_dir) @s = Site.new(@source, dest_dir)
@ -9,13 +10,11 @@ class TestGeneratedSite < Test::Unit::TestCase
@index = File.read(File.join(dest_dir, 'index.html')) @index = File.read(File.join(dest_dir, 'index.html'))
end end
def test_site_posts_in_index should "insert site.posts into the index" do
# confirm that {{ site.posts }} is working
assert @index.include?("#{@s.posts.size} Posts") assert @index.include?("#{@s.posts.size} Posts")
end end
def test_post_content_in_index should "render post.content" do
# confirm that the {{ post.content }} is rendered OK
latest_post = Dir[File.join(@source, '_posts/*')].last latest_post = Dir[File.join(@source, '_posts/*')].last
post = Post.new(@source, '', File.basename(latest_post)) post = Post.new(@source, '', File.basename(latest_post))
Jekyll.content_type = post.determine_content_type Jekyll.content_type = post.determine_content_type
@ -23,10 +22,12 @@ class TestGeneratedSite < Test::Unit::TestCase
assert @index.include?(post.content) assert @index.include?(post.content)
end end
def test_unpublished_posts_are_hidden should "hide unpublished posts" do
published = Dir[File.join(dest_dir, 'publish_test/2008/02/02/*.html')].map {|f| File.basename(f)} published = Dir[File.join(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
end
end end

View File

View File

@ -1,28 +1,24 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
class TestSite < Test::Unit::TestCase class TestSite < Test::Unit::TestCase
def setup context "creating sites" do
@source = File.join(File.dirname(__FILE__), *%w[source]) setup do
@source = File.join(File.dirname(__FILE__), 'source')
@s = Site.new(@source, dest_dir) @s = Site.new(@source, dest_dir)
end end
def test_site_init should "read layouts" do
end
def test_read_layouts
@s.read_layouts @s.read_layouts
assert_equal ["default", "simple"].sort, @s.layouts.keys.sort assert_equal ["default", "simple"].sort, @s.layouts.keys.sort
end end
def test_read_posts should "read posts" do
@s.read_posts('') @s.read_posts('')
posts = Dir[File.join(@source, '_posts/*')] posts = Dir[File.join(@source, '_posts/*')]
assert_equal posts.size - 1, @s.posts.size assert_equal posts.size - 1, @s.posts.size
end end
def test_site_payload should "deploy payload" do
clear_dest clear_dest
@s.process @s.process
@ -34,3 +30,4 @@ class TestSite < Test::Unit::TestCase
assert_equal 3, @s.categories['foo'].size assert_equal 3, @s.categories['foo'].size
end end
end end
end

View File

@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
class TestTags < Test::Unit::TestCase class TestTags < Test::Unit::TestCase
context "tagging" do
def setup setup do
@content = <<CONTENT @content = <<CONTENT
--- ---
layout: post layout: post
@ -19,7 +19,7 @@ puts "bye"
CONTENT CONTENT
end end
def test_markdown_with_pygments_line_handling should "render markdown with pygments line handling" do
Jekyll.pygments = true Jekyll.pygments = true
Jekyll.content_type = :markdown Jekyll.content_type = :markdown
@ -27,5 +27,5 @@ CONTENT
result = Jekyll.markdown_proc.call(result) result = Jekyll.markdown_proc.call(result)
assert_no_match(/markdown\-html\-error/,result) assert_no_match(/markdown\-html\-error/,result)
end end
end
end end