all repos — markup @ bf7155e8ccd681171681e8b467f8836bc6e86c7a

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      expected_file = "#{readme}.html"
13      expected = File.read(expected_file)
14      actual = GitHub::Markup.render(readme, File.read(readme))
15
16      diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f|
17        f.write actual
18        f.close_write
19        f.read
20      end
21
22      assert expected == actual, <<message
23#{File.basename expected_file}'s contents don't match command output:
24#{diff}
25message
26    end
27  end
28
29  def test_knows_what_it_can_and_cannot_render
30    assert_equal false, GitHub::Markup.can_render?('README.html')
31    assert_equal true, GitHub::Markup.can_render?('README.markdown')
32    assert_equal false, GitHub::Markup.can_render?('README.cmd')
33  end
34
35  def test_fails_gracefully_on_missing_commands
36    GitHub::Markup.command(:i_made_it_up, /mde/)
37    text = 'hi there'
38    assert GitHub::Markup.can_render?('README.mde')
39    actual = GitHub::Markup.render('README.mde', text)
40    assert_equal text, actual
41  end
42
43  def test_fails_gracefully_on_missing_env_commands
44    GitHub::Markup.command('/usr/bin/env totally_fake', /tf/)
45    text = 'hey mang'
46    assert GitHub::Markup.can_render?('README.tf')
47    actual = GitHub::Markup.render('README.tf', text)
48    assert_equal text, actual
49  end
50end