From a9d89d28a515d68cd7c6db91dca49bbae7e21b05 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 15 Apr 2011 11:14:23 +0200 Subject: [PATCH] add markdown, rdoc and textile nesting tests --- test/helper.rb | 7 +++++++ test/markdown_test.rb | 35 ++++++++++++++++++++++++++++++----- test/rdoc_test.rb | 30 ++++++++++++++++++++++++++++++ test/textile_test.rb | 30 ++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 99ec8245..fb6a4388 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -65,6 +65,11 @@ class Test::Unit::TestCase assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "") end + def assert_like(a,b) + pattern = /\s*\n\s*| id=['"][^"']*["']/ + assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "") + end + def assert_include(str, substr) assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}" end @@ -76,6 +81,8 @@ class Test::Unit::TestCase else super end + rescue Rack::Test::Error + super end # Also check response since we delegate there. diff --git a/test/markdown_test.rb b/test/markdown_test.rb index 4553601a..0223fa0e 100644 --- a/test/markdown_test.rb +++ b/test/markdown_test.rb @@ -9,11 +9,6 @@ MarkdownTest = proc do get '/' end - def assert_like(a,b) - pattern = /\s*\n\s*| id=['"][^"']*["']/ - assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "") - end - def setup Tilt.prefer engine, 'markdown', 'mkd', 'md' super @@ -41,6 +36,36 @@ MarkdownTest = proc do mock_app { get('/') { markdown :no_such_template } } assert_raise(Errno::ENOENT) { get('/') } end + + it "renders with inline layouts" do + mock_app do + layout { 'THIS. IS. #{yield.upcase}!' } + get('/') { markdown 'Sparta', :layout_engine => :str } + end + get '/' + assert ok? + assert_like 'THIS. IS.

SPARTA

!', body + end + + it "renders with file layouts" do + markdown_app { markdown 'Hello World', :layout => :layout2, :layout_engine => :erb } + assert ok? + assert_body "ERB Layout!\n

Hello World

" + end + + it "can be used in a nested fashion for partials and whatnot" do + mock_app do + template(:inner) { "hi" } + template(:outer) { "<%= markdown :inner %>" } + get '/' do + erb :outer + end + end + + get '/' + assert ok? + assert_like '

hi

', body + end end # Will generate RDiscountTest, KramdownTest, etc. diff --git a/test/rdoc_test.rb b/test/rdoc_test.rb index 7407b0e7..243a8b7e 100644 --- a/test/rdoc_test.rb +++ b/test/rdoc_test.rb @@ -28,6 +28,36 @@ class RdocTest < Test::Unit::TestCase mock_app { get('/') { rdoc :no_such_template } } assert_raise(Errno::ENOENT) { get('/') } end + + it "renders with inline layouts" do + mock_app do + layout { 'THIS. IS. #{yield.upcase}!' } + get('/') { rdoc 'Sparta', :layout_engine => :str } + end + get '/' + assert ok? + assert_like 'THIS. IS.

SPARTA

!', body + end + + it "renders with file layouts" do + rdoc_app { rdoc 'Hello World', :layout => :layout2, :layout_engine => :erb } + assert ok? + assert_body "ERB Layout!\n

Hello World

" + end + + it "can be used in a nested fashion for partials and whatnot" do + mock_app do + template(:inner) { "hi" } + template(:outer) { "<%= rdoc :inner %>" } + get '/' do + erb :outer + end + end + + get '/' + assert ok? + assert_like '

hi

', body + end end rescue LoadError diff --git a/test/textile_test.rb b/test/textile_test.rb index f9535b43..8d54ce09 100644 --- a/test/textile_test.rb +++ b/test/textile_test.rb @@ -28,6 +28,36 @@ class TextileTest < Test::Unit::TestCase mock_app { get('/') { textile :no_such_template } } assert_raise(Errno::ENOENT) { get('/') } end + + it "renders with inline layouts" do + mock_app do + layout { 'THIS. IS. #{yield.upcase}!' } + get('/') { textile 'Sparta', :layout_engine => :str } + end + get '/' + assert ok? + assert_like 'THIS. IS.

SPARTA

!', body + end + + it "renders with file layouts" do + textile_app { textile 'Hello World', :layout => :layout2, :layout_engine => :erb } + assert ok? + assert_body "ERB Layout!\n

Hello World

" + end + + it "can be used in a nested fashion for partials and whatnot" do + mock_app do + template(:inner) { "hi" } + template(:outer) { "<%= textile :inner %>" } + get '/' do + erb :outer + end + end + + get '/' + assert ok? + assert_like '

hi

', body + end end rescue LoadError