test/unit/string_extensions_test.rb in stringex-2.0.11 vs test/unit/string_extensions_test.rb in stringex-2.1.0

- old
+ new

@@ -5,10 +5,20 @@ if RUBY_VERSION.to_f < 1.9 $KCODE = "U" end +# Try loading RedCloth but it's okay if it's not there +begin + gem 'RedCloth' +rescue LoadError + puts + puts ">> Could not load RedCloth. String#to_html was not tested." + puts ">> Please gem install RedCloth if you'd like to use this functionality." + puts +end + class StringExtensionsTest < Test::Unit::TestCase def setup Stringex::Localization.reset! end @@ -76,12 +86,10 @@ "1000-dollars", "«zut alors»" => "zut-alors", "Rabbits aren't real" => "rabbits-arent-real", - "R" => - "r", "R$ isn't R" => "reais-isnt-r" }.each do |html, plain| assert_equal plain, html.to_url end @@ -259,9 +267,32 @@ String.class_eval do remove_method :to_ascii def to_ascii old_to_ascii + end + end + end + + if defined?(RedCloth) + def test_to_html + { + "h1. A Solution" => "<h1>A Solution</h1>", + "I hated wrapping textilize around a string.\n\nIt always felt dirty." => + "<p>I hated wrapping textilize around a string.</p>\n<p>It always felt dirty.</p>", + "I think _this_ is awesome" => "<p>I think <em>this</em> is awesome</p>", + "Um... _*really*_, man" => "<p>Um&#8230; <em><strong>really</strong></em>, man</p>" + }.each do |plain, html| + assert_equal html, plain.to_html + end + end + + def test_to_html_lite + { + "I have no pee on me" => "I have no pee on me", + "But I _do_ get Textile!" => "But I <em>do</em> get Textile!" + }.each do |plain, html| + assert_equal html, plain.to_html(:lite) end end end end