test/gfm_test.rb in github-markdown-0.5.3 vs test/gfm_test.rb in github-markdown-0.5.4
- old
+ new
@@ -14,10 +14,37 @@
assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_html,
Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
end
class GFMBasicTest < Test::Unit::TestCase
+ Dir['test/fixtures/*.md'].each do |md_file|
+ markup = md_file.split('/').last.gsub(/\.md/, '')
+
+ define_method "test_#{markup}" do
+ source = File.read(md_file)
+
+ expected_file = "test/fixtures/#{markup}.html"
+ expected = File.read(expected_file).rstrip
+ actual = GitHub::Markdown.render(source).rstrip
+
+ if source != expected
+ assert(source != actual, "#{markup} did not render anything")
+ end
+
+ diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f|
+ f.write actual
+ f.close_write
+ f.read
+ end
+
+ assert expected == actual, <<message
+#{File.basename expected_file}'s contents don't match command output:
+#{diff}
+message
+ end
+ end
+
def test_that_render_works
GitHub::Markdown.to_html("Hello **world**!", :gfm)
end
def test_that_code_blocks_work
@@ -48,10 +75,10 @@
html = GitHub::Markdown.render(markdown)
parsed = Nokogiri::HTML::DocumentFragment.parse(html)
items.inject(parsed) do |node, expected_item|
- child = node.at('.//ul/li')
+ child = node.xpath('.//ul/li')
child_item = child.children.detect{|e| e.text?}.text.strip
assert_equal expected_item, child_item
node = child
end
end