all repos — markup @ 5d5bc19e633ac22886f5afe86f59871a3ab882ba

The code we use to render README.your_favorite_markup

test/markup_test.rb (view raw)

 1$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
 2
 3require 'github/markup'
 4require 'test/unit'
 5
 6class MarkupTest < Test::Unit::TestCase
 7  Dir['test/markups/README.*'].each do |readme|
 8    next if readme =~ /html$/
 9    markup = readme.split('/').last.gsub(/^README\./, '')
10
11    define_method "test_#{markup}" do
12      source = File.read(readme)
13
14      expected_file = "#{readme}.html"
15      expected = File.read(expected_file)
16      actual = GitHub::Markup.render(readme, File.read(readme))
17
18      if source != expected
19        assert(source != actual, "#{markup} did not render anything")
20      end
21
22      diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f|
23        f.write actual
24        f.close_write
25        f.read
26      end
27
28      assert expected == actual, <<message
29#{File.basename expected_file}'s contents don't match command output:
30#{diff}
31message
32    end
33  end
34
35  def test_knows_what_it_can_and_cannot_render
36    assert_equal false, GitHub::Markup.can_render?('README.html')
37    assert_equal true, GitHub::Markup.can_render?('README.markdown')
38    assert_equal false, GitHub::Markup.can_render?('README.cmd')
39  end
40
41  def test_fails_gracefully_on_missing_commands
42    GitHub::Markup.command(:i_made_it_up, /mde/)
43    text = 'hi there'
44    assert GitHub::Markup.can_render?('README.mde')
45    actual = GitHub::Markup.render('README.mde', text)
46    assert_equal text, actual
47  end
48
49  def test_fails_gracefully_on_missing_env_commands
50    GitHub::Markup.command('/usr/bin/env totally_fake', /tf/)
51    text = 'hey mang'
52    assert GitHub::Markup.can_render?('README.tf')
53    actual = GitHub::Markup.render('README.tf', text)
54    assert_equal text, actual
55  end
56end