mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
test all mardown engines if available
This commit is contained in:
parent
b3e82c5293
commit
4b8aaef0b4
2 changed files with 32 additions and 9 deletions
3
Gemfile
3
Gemfile
|
@ -34,9 +34,12 @@ gem 'slim', :group => 'slim'
|
||||||
gem 'RedCloth', :group => 'redcloth'
|
gem 'RedCloth', :group => 'redcloth'
|
||||||
gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
|
gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
|
||||||
gem 'rdoc', :group => 'rdoc'
|
gem 'rdoc', :group => 'rdoc'
|
||||||
|
gem 'kramdown', :group => 'kramdown'
|
||||||
|
gem 'maruku', :group => 'maruku'
|
||||||
|
|
||||||
platforms :ruby do
|
platforms :ruby do
|
||||||
gem 'rdiscount', :group => 'rdiscount'
|
gem 'rdiscount', :group => 'rdiscount'
|
||||||
|
gem 'bluecloth', :group => 'bluecloth'
|
||||||
end
|
end
|
||||||
|
|
||||||
platforms :ruby_18, :jruby do
|
platforms :ruby_18, :jruby do
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
require File.dirname(__FILE__) + '/helper'
|
require File.dirname(__FILE__) + '/helper'
|
||||||
|
|
||||||
begin
|
MarkdownTest = proc do
|
||||||
fail LoadError, "rdiscount not available" if defined? JRuby
|
|
||||||
require 'rdiscount'
|
|
||||||
|
|
||||||
class MarkdownTest < Test::Unit::TestCase
|
|
||||||
def markdown_app(&block)
|
def markdown_app(&block)
|
||||||
mock_app do
|
mock_app do
|
||||||
set :views, File.dirname(__FILE__) + '/views'
|
set :views, File.dirname(__FILE__) + '/views'
|
||||||
|
@ -13,16 +9,32 @@ class MarkdownTest < Test::Unit::TestCase
|
||||||
get '/'
|
get '/'
|
||||||
end
|
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
|
it 'renders inline markdown strings' do
|
||||||
markdown_app { markdown '# Hiya' }
|
markdown_app { markdown '# Hiya' }
|
||||||
assert ok?
|
assert ok?
|
||||||
assert_equal "<h1>Hiya</h1>\n", body
|
assert_like "<h1>Hiya</h1>\n", body
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders .markdown files in views path' do
|
it 'renders .markdown files in views path' do
|
||||||
markdown_app { markdown :hello }
|
markdown_app { markdown :hello }
|
||||||
assert ok?
|
assert ok?
|
||||||
assert_equal "<h1>Hello From Markdown</h1>\n", body
|
assert_like "<h1>Hello From Markdown</h1>", body
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises error if template not found" do
|
it "raises error if template not found" do
|
||||||
|
@ -31,6 +43,14 @@ class MarkdownTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError
|
# Will generate RDiscountTest, KramdownTest, etc.
|
||||||
warn "#{$!.to_s}: skipping markdown tests"
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue