Skip to content
Browse files

add markdown, rdoc and textile nesting tests

  • Loading branch information...
1 parent 1725633 commit a9d89d28a515d68cd7c6db91dca49bbae7e21b05 @rkh rkh committed Apr 15, 2011
Showing with 97 additions and 5 deletions.
  1. +7 −0 test/helper.rb
  2. +30 −5 test/markdown_test.rb
  3. +30 −0 test/rdoc_test.rb
  4. +30 −0 test/textile_test.rb
View
7 test/helper.rb
@@ -65,6 +65,11 @@ def assert_body(value)
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 @@ def method_missing(name, *args, &block)
else
super
end
+ rescue Rack::Test::Error
+ super
end
# Also check response since we delegate there.
View
35 test/markdown_test.rb
@@ -9,11 +9,6 @@ def markdown_app(&block)
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 @@ def setup
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. <P>SPARTA</P>!', 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<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= markdown :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
# Will generate RDiscountTest, KramdownTest, etc.
View
30 test/rdoc_test.rb
@@ -28,6 +28,36 @@ def rdoc_app(&block)
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.<P>SPARTA</P>!', 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<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= rdoc :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
rescue LoadError
View
30 test/textile_test.rb
@@ -28,6 +28,36 @@ def textile_app(&block)
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. <P>SPARTA</P>!', 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<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= textile :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
rescue LoadError

0 comments on commit a9d89d2

Please sign in to comment.
Something went wrong with that request. Please try again.