all repos — markup @ b7cabb1c81ea30035dd63a508a67a949c1846f4c

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).rstrip
16      actual = GitHub::Markup.render(readme, File.read(readme)).rstrip
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    assert_equal true, GitHub::Markup.can_render?('README.litcoffee')
40  end
41
42  def test_fails_gracefully_on_missing_commands
43    GitHub::Markup.command(:i_made_it_up, /mde/)
44    text = 'hi there'
45    assert GitHub::Markup.can_render?('README.mde')
46    actual = GitHub::Markup.render('README.mde', text)
47    assert_equal text, actual
48  end
49
50  def test_fails_gracefully_on_missing_env_commands
51    GitHub::Markup.command('/usr/bin/env totally_fake', /tf/)
52    text = 'hey mang'
53    assert GitHub::Markup.can_render?('README.tf')
54    actual = GitHub::Markup.render('README.tf', text)
55    assert_equal text, actual
56  end
57end