Skip to content

Commit

Permalink
Add Haml::TestCase
Browse files Browse the repository at this point in the history
Fix Minitest base class warnings by creating a Haml::TestCase base
class that inherits from the latest Minitest base class available.

Background:

ActiveSupport 4.1 depends on mintiest 5.x, which uses Minitest::Test as
the base test class.

ActiveSupport 4.0 depends on mintiest 4.x, which uses
MiniTest::Unit::TestCase as the base class.

Rails 3.2 uses Test::Unit::TestCase defined by stdlib. There is no gem
dependency on minitest in Rails 3.2, nor is there a gem dependency on
test-unit.
  • Loading branch information
teeparham committed May 20, 2014
1 parent 315e1cd commit 5017d33
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/engine_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
require 'test_helper'

class EngineTest < MiniTest::Unit::TestCase
class EngineTest < Haml::TestCase
# A map of erroneous Haml documents to the error messages they should produce.
# The error messages may be arrays;
# if so, the second element should be the line number that should be reported for the error.
Expand Down
16 changes: 8 additions & 8 deletions test/filters_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class FiltersTest < MiniTest::Unit::TestCase
class FiltersTest < Haml::TestCase
test "should be registered as filters when including Haml::Filters::Base" do
begin
refute Haml::Filters.defined.has_key? "bar"
Expand Down Expand Up @@ -116,7 +116,7 @@ def evaluate(scope, locals, &block)

end

class ErbFilterTest < MiniTest::Unit::TestCase
class ErbFilterTest < Haml::TestCase
test "multiline expressions should work" do
html = "foobarbaz\n"
haml = %Q{:erb\n <%= "foo" +\n "bar" +\n "baz" %>}
Expand All @@ -137,7 +137,7 @@ class ErbFilterTest < MiniTest::Unit::TestCase

end

class JavascriptFilterTest < MiniTest::Unit::TestCase
class JavascriptFilterTest < Haml::TestCase
test "should interpolate" do
scope = Object.new.instance_eval {foo = "bar"; nil if foo; binding}
haml = ":javascript\n \#{foo}"
Expand Down Expand Up @@ -183,7 +183,7 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase
end
end

class CSSFilterTest < MiniTest::Unit::TestCase
class CSSFilterTest < Haml::TestCase
test "should wrap output in CDATA and a CSS tag when output is XHTML" do
html = "<style type='text/css'>\n /*<![CDATA[*/\n foo\n /*]]>*/\n</style>\n"
haml = ":css\n foo"
Expand Down Expand Up @@ -222,23 +222,23 @@ class CSSFilterTest < MiniTest::Unit::TestCase
end
end

class CDATAFilterTest < MiniTest::Unit::TestCase
class CDATAFilterTest < Haml::TestCase
test "should wrap output in CDATA tag" do
html = "<![CDATA[\n foo\n]]>\n"
haml = ":cdata\n foo"
assert_equal(html, render(haml))
end
end

class EscapedFilterTest < MiniTest::Unit::TestCase
class EscapedFilterTest < Haml::TestCase
test "should escape ampersands" do
html = "&amp;\n"
haml = ":escaped\n &"
assert_equal(html, render(haml))
end
end

class RubyFilterTest < MiniTest::Unit::TestCase
class RubyFilterTest < Haml::TestCase
test "can write to haml_io" do
haml = ":ruby\n haml_io.puts 'hello'\n"
html = "hello\n"
Expand All @@ -256,4 +256,4 @@ class RubyFilterTest < MiniTest::Unit::TestCase
html = "7\n"
assert_equal(html, render(haml))
end
end
end
2 changes: 1 addition & 1 deletion test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FormModel
end


class HelperTest < MiniTest::Unit::TestCase
class HelperTest < Haml::TestCase
Post = Struct.new('Post', :body, :error_field, :errors)
class PostErrors
def on(name)
Expand Down
4 changes: 2 additions & 2 deletions test/parser_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'test_helper'

module Haml
class ParserTest < MiniTest::Unit::TestCase
class ParserTest < Haml::TestCase

test "should raise error for 'else' at wrong indent level" do
begin
Expand Down Expand Up @@ -124,4 +124,4 @@ def parse(haml, options = nil)
parser.parse
end
end
end
end
2 changes: 1 addition & 1 deletion test/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def controller_path
end
end

class TemplateTest < MiniTest::Unit::TestCase
class TemplateTest < Haml::TestCase
TEMPLATE_PATH = File.join(File.dirname(__FILE__), "templates")
TEMPLATES = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful
Expand Down
9 changes: 7 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ class TestApp < Rails::Application
Haml::Template.options[:ugly] = false
Haml::Template.options[:format] = :xhtml

BASE_TEST_CLASS = if defined?(Minitest::Test)
Minitest::Test
else
MiniTest::Unit::TestCase
end

module Declarative
def test(name, &block)
define_method("test #{name}", &block)
end
end

class MiniTest::Unit::TestCase

class Haml::TestCase < BASE_TEST_CLASS
extend Declarative

def render(text, options = {}, base = nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion test/util_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class UtilTest < MiniTest::Unit::TestCase
class UtilTest < Haml::TestCase
include Haml::Util

def test_powerset
Expand Down

0 comments on commit 5017d33

Please sign in to comment.