From c52e8ef5c3606bdc134f449feb1056ff68f3bf24 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Mislav=20Marohni=C4=87?= <mislav.marohnic@gmail.com>
Date: Thu, 28 Aug 2008 16:29:13 +0200
Subject: [PATCH] BlueCloth vs. RedCloth: change Markdown filter to only use BlueCloth. Remove tests that rely on 'redcloth' or Textile output.
 This is necessary because the new RedCloth doesn't support Markdown anymore, renders Textile with different whitespace setting, and it's generally a bad practice to rely on output of 3rd party libraries that have their own tests.

---
 lib/haml/filters.rb              |   10 ++-----
 test/haml/engine_test.rb         |   48 ++++++++-----------------------------
 test/haml/results/filters.xhtml  |   17 -------------
 test/haml/templates/filters.haml |   23 ------------------
 4 files changed, 14 insertions(+), 84 deletions(-)

diff --git a/lib/haml/filters.rb b/lib/haml/filters.rb
index cb82a71..131c13b 100644
--- a/lib/haml/filters.rb
+++ b/lib/haml/filters.rb
@@ -120,7 +120,7 @@ RUBY
           @required = @lazy_requires[-1]
           require @required
         rescue LoadError => e
-          classname = self.class.to_s.gsub(/\w+::/, '')
+          classname = self.name.match(/\w+$/)[0]
 
           if @lazy_requires.size == 1
             raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
@@ -245,14 +245,10 @@ END
     # Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
     module Markdown
       include Base
-      lazy_require 'bluecloth', 'redcloth'
+      lazy_require 'bluecloth'
 
       def render(text)
-        if @required == 'bluecloth'
-          ::BlueCloth.new(text).to_html
-        else
-          ::RedCloth.new(text).to_html(:markdown)
-        end
+        ::BlueCloth.new(text).to_html
       end
     end
   end
diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb
index f7430f7..5413b6b 100644
--- a/test/haml/engine_test.rb
+++ b/test/haml/engine_test.rb
@@ -445,17 +445,11 @@ SOURCE
       alias_method :gem_original_require_without_bluecloth, :gem_original_require
       alias_method :gem_original_require, :gem_original_require_with_bluecloth
     end
-
-    begin
-      assert_equal("<h1>Foo</h1>\t<p>- a\n- b</p>\n",
-                   Haml::Engine.new(":markdown\n  Foo\n  ===\n  - a\n  - b").to_html)
-    rescue Haml::Error => e
-      if e.message == "Can't run Markdown filter; required 'bluecloth' or 'redcloth', but none were found"
-        puts "\nCouldn't require 'bluecloth' or 'redcloth'; skipping a test."
-      else
-        raise e
-      end
-    end
+    
+    e = assert_raise(Haml::Error) {
+      Haml::Engine.new(":markdown\n  Foo").to_html
+    }
+    assert_equal "Can't run Markdown filter; required file 'bluecloth' not found", e.message
 
     Kernel.module_eval do
       alias_method :gem_original_require, :gem_original_require_without_bluecloth
@@ -472,38 +466,18 @@ SOURCE
       alias_method :gem_original_require, :gem_original_require_with_redcloth
     end
 
-    begin
+    e = assert_raise(Haml::Error) {
       Haml::Engine.new(":redcloth\n  _foo_").to_html
-    rescue Haml::Error
-    else
-      assert(false, "No exception raised!")
-    end
+    }
+    assert_equal "Can't run RedCloth filter; required file 'redcloth' not found", e.message
 
     Kernel.module_eval do
       alias_method :gem_original_require, :gem_original_require_without_redcloth
     end
   end
-
-  def test_no_redcloth_or_bluecloth
-    Kernel.module_eval do
-      def gem_original_require_with_redcloth_and_bluecloth(file)
-        raise LoadError if file == 'redcloth' || file == 'bluecloth'
-        gem_original_require_without_redcloth_and_bluecloth(file)
-      end
-      alias_method :gem_original_require_without_redcloth_and_bluecloth, :gem_original_require
-      alias_method :gem_original_require, :gem_original_require_with_redcloth_and_bluecloth
-    end
-
-    begin
-      Haml::Engine.new(":markdown\n  _foo_").to_html
-    rescue Haml::Error
-    else
-      assert(false, "No exception raised!")
-    end
-
-    Kernel.module_eval do
-      alias_method :gem_original_require, :gem_original_require_without_redcloth_and_bluecloth
-    end    
+  
+  def test_redcloth_gets_run
+    assert_equal "<p><em>foo</em></p>\n", Haml::Engine.new(":redcloth\n  _foo_").to_html
   end
 
   def test_empty_filter
diff --git a/test/haml/results/filters.xhtml b/test/haml/results/filters.xhtml
index 3104401..c82b154 100644
--- a/test/haml/results/filters.xhtml
+++ b/test/haml/results/filters.xhtml
@@ -8,17 +8,6 @@
     font-weight: normal; }
 </style>
 TESTING HAHAHAHA!
-<h1>Foo</h1>
-
-
-	<pre><code>This is preformatted!&#x000A;Look at that!&#x000A;Wowie-zowie!</code></pre>
-
-
-	<p><strong>boldilicious!</strong></p>
-<h1>Yeah</h1>
-
-
-	<p><em>pretty much the same as above</em></p>
 <p>
   <script type='text/javascript'>
     //<![CDATA[
@@ -67,12 +56,6 @@ This
 
 </ul>
 <div class='res'>178</div>
-<p>
-  <p>I like preserved text:</p>
-  
-  
-  	<pre><code>Foo&#x000A;  Bar!&#x000A;Baz</code></pre>
-</p>
 <ul>
 <li>Foo</li>
 <li>Bar</li>
diff --git a/test/haml/templates/filters.haml b/test/haml/templates/filters.haml
index 211d2e5..eaf2ad5 100644
--- a/test/haml/templates/filters.haml
+++ b/test/haml/templates/filters.haml
@@ -15,21 +15,6 @@
   Not
   Print
 
-:redcloth
-  Foo
-  ===
-
-      This is preformatted!
-      Look at that!
-      Wowie-zowie!
-
-  *boldilicious!*
-
-:textile
-  h1. Yeah
-
-  _pretty much the same as above_
-
 %p
   :javascript
     function newline(str) {
@@ -68,14 +53,6 @@
 
 .res= res
 
-%p
-  :textile
-    I like preserved text:
-
-      Foo
-        #{"Bar"}!
-      Baz
-
 :markdown
   *  Foo
   *  Bar
-- 
1.6.0

