Skip to content

Commit

Permalink
converting from (test/unit + shoulda) to minitest/spec, and removing …
Browse files Browse the repository at this point in the history
…RR from some tests. whap!
  • Loading branch information
flavorjones committed Apr 15, 2010
1 parent 4f2e966 commit 1caa65a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 131 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Hoe.spec 'mcbean' do

extra_deps << ["loofah", ">= 0.4.7"]
extra_deps << ["rdiscount", ">= 1.3.4"]
extra_dev_deps << ["shoulda", ">= 2.10"]
extra_dev_deps << ["rr", ">= 0.10.4"]
extra_dev_deps << ["minitest", ">= 1.6.0"]
end

task :redocs => :fix_css
Expand Down
5 changes: 2 additions & 3 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require "test/unit"
require "minitest/autorun"
require "mcbean"
require "shoulda"
require "rr"

class Test::Unit::TestCase
class MiniTest::Spec
include RR::Adapters::TestUnit
end
202 changes: 99 additions & 103 deletions test/test_markdown.rb
Original file line number Diff line number Diff line change
@@ -1,132 +1,118 @@
require File.dirname(__FILE__) + "/helper"

class TestMcBeanMarkdown < Test::Unit::TestCase
context McBean::Markdownify do
context "#to_markdown" do
should "add whitespace around block elements" do
assert_markdown "before<div>inner</div>after", "before\ninner\nafter", false
end
describe McBean::Markdownify do
describe "#to_markdown" do
it "add whitespace around block elements" do
assert_markdown "before<div>inner</div>after", "before\ninner\nafter", false
end

should "convert h1 tag" do
assert_markdown "<h1>Foo</h1>", "\nFoo\n==========\n"
end
it "convert h1 tag" do
assert_markdown "<h1>Foo</h1>", "\nFoo\n==========\n"
end

should "convert h2 tag" do
assert_markdown "<h2>Foo</h2>", "\nFoo\n----------\n"
end
it "convert h2 tag" do
assert_markdown "<h2>Foo</h2>", "\nFoo\n----------\n"
end

should "convert h3 tag" do
assert_markdown "<h3>Foo</h3>", "\n### Foo ###\n"
end
it "convert h3 tag" do
assert_markdown "<h3>Foo</h3>", "\n### Foo ###\n"
end

should "convert h4 tag" do
assert_markdown "<h4>Foo</h4>", "\n#### Foo ####\n"
end
it "convert h4 tag" do
assert_markdown "<h4>Foo</h4>", "\n#### Foo ####\n"
end

should "convert blockquote tag" do
assert_markdown "<blockquote><p>Hello\nGoodbye</p></blockquote>",
"> Hello\n> Goodbye\n"
end
it "convert blockquote tag" do
assert_markdown "<blockquote><p>Hello\nGoodbye</p></blockquote>",
"> Hello\n> Goodbye\n"
end

# should "convert nested blockquote tag" do
# assert_markdown(
# "<blockquote><p>Hello</p>\n\n<blockquote><p>Nested</p></blockquote>\n\n<p>Goodbye</p></blockquote>",
# <<-EOM
# > Hello
# >
# > > Nested
# >
# > Goodbye
# EOM
# )
# end

should "convert unordered list" do
assert_markdown "<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n",
"\n* one\n* two\n* three\n"
end
# it "convert nested blockquote tag" do
# assert_markdown(
# "<blockquote><p>Hello</p>\n\n<blockquote><p>Nested</p></blockquote>\n\n<p>Goodbye</p></blockquote>",
# <<-EOM
# > Hello
# >
# > > Nested
# >
# > Goodbye
# EOM
# )
# end

it "convert unordered list" do
assert_markdown "<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n",
"\n* one\n* two\n* three\n"
end

should "convert ordered list" do
assert_markdown "<ol>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ol>\n",
"\n1. one\n2. two\n3. three\n"
end
it "convert ordered list" do
assert_markdown "<ol>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ol>\n",
"\n1. one\n2. two\n3. three\n"
end

should "ignore empty unordered list items" do
assert_markdown "<ul>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ul>\n",
"\n* one\n* three\n",
false
end
it "ignore empty unordered list items" do
assert_markdown "<ul>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ul>\n",
"\n* one\n* three\n",
false
end

should "ignore empty ordered list items" do
assert_markdown "<ol>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ol>\n",
"\n1. one\n3. three\n",
false
end
it "ignore empty ordered list items" do
assert_markdown "<ol>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ol>\n",
"\n1. one\n3. three\n",
false
end

should "convert code blocks" do
assert_markdown "<pre><code>This is a code block\ncontinued\n</code></pre>",
"\n This is a code block\n continued\n\n"
end
it "convert code blocks" do
assert_markdown "<pre><code>This is a code block\ncontinued\n</code></pre>",
"\n This is a code block\n continued\n\n"
end

should "convert <br> tags to newlines" do
assert_markdown "<div>hello<br>there</div>",
"\nhello\nthere\n",
false
assert_markdown "<div>hello<br />there</div>",
"\nhello\nthere\n",
false
it "convert <br> tags to newlines" do
assert_markdown "<div>hello<br>there</div>",
"\nhello\nthere\n",
false
assert_markdown "<div>hello<br />there</div>",
"\nhello\nthere\n",
false
end

describe "anchors" do
it "convert <a> tags" do
assert_markdown "<p>Yes, magic helmet. And <a href=\"http://sample.com/\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample](http://sample.com/).\n"
end

context "anchors" do
should "convert <a> tags" do
assert_markdown "<p>Yes, magic helmet. And <a href=\"http://sample.com/\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample](http://sample.com/).\n"
end
describe "<a> tags without hrefs" do
it "be ignored" do
assert_markdown "<div><a name='link-target'>target title</a></div>",
"\ntarget title\n",
false

context "<a> tags without hrefs" do
should "be ignored" do
assert_markdown "<div><a name='link-target'>target title</a></div>",
"\ntarget title\n",
false
assert_markdown "<div><a id='link-target'>target title</a></div>",
"\ntarget title\n",
false
end
end

assert_markdown "<div><a id='link-target'>target title</a></div>",
"\ntarget title\n",
false
end
describe "<a> tags with titles" do
it "convert fq urls to reference-style" do
assert_markdown2 "<p>Yes, magic helmet. And <a href=\"http://sample.com/\" title=\"Fudd\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: http://sample.com/ \"Fudd\"\n"
end

context "<a> tags with titles" do
should "convert fq urls to reference-style" do
assert_markdown2 "<p>Yes, magic helmet. And <a href=\"http://sample.com/\" title=\"Fudd\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: http://sample.com/ \"Fudd\"\n"
end

should "convert relative urls to reference-style" do
assert_markdown2 "<p>Yes, magic helmet. And <a href=\"/home\" title=\"Fudd\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: /home \"Fudd\"\n"
end

should "convert multiple to appear in order at the end of the document" do
assert_markdown2 "<p>See <a href=\"/prefs\" title=\"Prefs\">Prefs</a> and <a href=\"/home\" title=\"Home\">Home</a>.</p>",
"\nSee [Prefs][1] and [Home][2].\n\n[1]: /prefs \"Prefs\"\n[2]: /home \"Home\"\n"
end
it "convert relative urls to reference-style" do
assert_markdown2 "<p>Yes, magic helmet. And <a href=\"/home\" title=\"Fudd\">I'll give you a sample</a>.</p>",
"\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: /home \"Fudd\"\n"
end
end
end
end

context McBean::Markdownify::Antidote do
context "given that RDiscount is already pretty well tested" do
context "let's limit ourselves to a token test case" do
should "convert markdown into html" do
assert_equal "<h1>hello</h1>\n", McBean.markdown("hello\n=====\n").to_html
it "convert multiple to appear in order at the end of the document" do
assert_markdown2 "<p>See <a href=\"/prefs\" title=\"Prefs\">Prefs</a> and <a href=\"/home\" title=\"Home\">Home</a>.</p>",
"\nSee [Prefs][1] and [Home][2].\n\n[1]: /prefs \"Prefs\"\n[2]: /home \"Home\"\n"
end
end
end
end

private

def assert_markdown html, markdown, roundtrip=true
assert_equal(html, McBean::Markdownify::Antidote.new(markdown).to_html.chomp, "markdown roundtrip failed") if roundtrip
assert_equal(markdown, McBean.fragment(html).to_markdown, "fragment transformation failed")
Expand All @@ -142,3 +128,13 @@ def assert_markdown2 html, markdown, roundtrip=true
McBean.document("<div>#{html}</div>").to_markdown, "document transformation failed")
end
end

describe McBean::Markdownify::Antidote do
describe "given that RDiscount is already pretty well tested" do
describe "let's limit ourselves to a token test case" do
it "convert markdown into html" do
assert_equal "<h1>hello</h1>\n", McBean.markdown("hello\n=====\n").to_html
end
end
end
end
44 changes: 20 additions & 24 deletions test/test_mcbean.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
require File.dirname(__FILE__) + "/helper"

class TestMcBean < Test::Unit::TestCase
context "class name" do
should "set McBean and Mcbean to be the same thing" do
describe McBean do
describe "class name" do
it "sets McBean and Mcbean to be the same thing" do
assert McBean == Mcbean
end
end

context "cleanup" do
should "prune unsafe tags" do
describe "cleanup" do
it "prunes unsafe tags" do
result = McBean.fragment("<div>OK</div><script>BAD</script>").to_markdown
assert_match( /OK/, result)
assert_no_match( /BAD/, result)
result.must_match /OK/
result.wont_match /BAD/
end
end

context "parsing" do
context "McBean.fragment" do
should "call Loofah.fragment" do
html = "<h1>hello</h1>\n"
mock.proxy(Loofah).fragment(html).once
McBean.fragment html
describe "parsing" do
describe "McBean.fragment" do
it "sets .html to be a Loofah fragment" do
McBean.fragment("<h1>hello</h1>\n").html.must_be_instance_of Loofah::HTML::DocumentFragment
end
end

context "McBean.document" do
should "call Loofah.document" do
html = "<h1>hello</h1>\n"
mock.proxy(Loofah).document(html).once
McBean.document html
describe "McBean.document" do
it "sets .html to be a Loofah document" do
McBean.document("<h1>hello</h1>\n").html.must_be_instance_of Loofah::HTML::Document
end
end

context "McBean.markdown" do
context "passed a string" do
should "create a Markdownify::Antidote" do
describe "McBean.markdown" do
describe "passed a string" do
it "creates a Markdownify::Antidote" do
mock.proxy(McBean::Markdownify::Antidote).new(anything).once
assert_equal "<h1>hello</h1>\n", McBean.markdown("hello\n=====\n").to_html
McBean.markdown("hello\n=====\n").to_html.must_equal "<h1>hello</h1>\n"
end
end

context "passed an IO" do
should "create a Markdownify::Antidote" do
describe "passed an IO" do
it "creates a Markdownify::Antidote" do
io = StringIO.new "hello\n=====\n"
mock.proxy(McBean::Markdownify::Antidote).new(anything).once
mock.proxy(io).read.once
Expand Down

0 comments on commit 1caa65a

Please sign in to comment.