Permalink
Browse files

test all mardown engines if available

  • Loading branch information...
1 parent b3e82c5 commit 4b8aaef0b435e4bd1e3ef4d2eee0d84e38333e9d @rkh rkh committed Apr 15, 2011
Showing with 32 additions and 9 deletions.
  1. +3 −0 Gemfile
  2. +29 −9 test/markdown_test.rb
View
@@ -34,9 +34,12 @@ gem 'slim', :group => 'slim'
gem 'RedCloth', :group => 'redcloth'
gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
gem 'rdoc', :group => 'rdoc'
+gem 'kramdown', :group => 'kramdown'
+gem 'maruku', :group => 'maruku'
platforms :ruby do
gem 'rdiscount', :group => 'rdiscount'
+ gem 'bluecloth', :group => 'bluecloth'
end
platforms :ruby_18, :jruby do
View
@@ -1,10 +1,6 @@
require File.dirname(__FILE__) + '/helper'
-begin
-fail LoadError, "rdiscount not available" if defined? JRuby
-require 'rdiscount'
-
-class MarkdownTest < Test::Unit::TestCase
+MarkdownTest = proc do
def markdown_app(&block)
mock_app do
set :views, File.dirname(__FILE__) + '/views'
@@ -13,16 +9,32 @@ 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
+ end
+
+ it 'uses the correct engine' do
+ assert_equal engine, Tilt[:md]
+ assert_equal engine, Tilt[:mkd]
+ assert_equal engine, Tilt[:markdown]
+ end
+
it 'renders inline markdown strings' do
markdown_app { markdown '# Hiya' }
assert ok?
- assert_equal "<h1>Hiya</h1>\n", body
+ assert_like "<h1>Hiya</h1>\n", body
end
it 'renders .markdown files in views path' do
markdown_app { markdown :hello }
assert ok?
- assert_equal "<h1>Hello From Markdown</h1>\n", body
+ assert_like "<h1>Hello From Markdown</h1>", body
end
it "raises error if template not found" do
@@ -31,6 +43,14 @@ def markdown_app(&block)
end
end
-rescue LoadError
- warn "#{$!.to_s}: skipping markdown tests"
+# Will generate RDiscountTest, KramdownTest, etc.
+Tilt.mappings['md'].each do |t|
+ begin
+ t.new { "" }
+ klass = Class.new(Test::Unit::TestCase) { define_method(:engine) { t }}
+ klass.class_eval(&MarkdownTest)
+ Object.const_set t.name[/[^:]+(?=Template$)/] << "Test", klass
+ rescue LoadError
+ warn "#{$!}: skipping markdown tests with #{t}"
+ end
end

0 comments on commit 4b8aaef

Please sign in to comment.