mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Set up declarative test
This commit is contained in:
parent
e90db07fc0
commit
a23f85b251
2 changed files with 17 additions and 22 deletions
|
@ -2,33 +2,19 @@
|
|||
require 'test_helper'
|
||||
|
||||
class FiltersTest < MiniTest::Unit::TestCase
|
||||
|
||||
def render(text, options = {}, &block)
|
||||
scope = options.delete(:scope) || Object.new
|
||||
locals = options.delete(:locals) || {}
|
||||
Haml::Engine.new(text, options).to_html(scope, locals, &block)
|
||||
end
|
||||
|
||||
TESTS = {
|
||||
:sass => ["sass/plugin", /width: 100;/, ":sass\n p\n width: 100"],
|
||||
:scss => ["sass/plugin", /width: 100;/, ":scss\n $width: 100;\n p {\n width: $width;\n }"],
|
||||
:less => ["less", /width: 100;/, ":less\n @width: 100;\n p {\n width: @width;\n }"],
|
||||
:coffeescript => ["coffee_script", /var foo;/, ":coffeescript\n foo = 'bar'"],
|
||||
:maruku => ["maruku", /h1/, ":maruku\n # foo"],
|
||||
}
|
||||
|
||||
TESTS.each do |key, value|
|
||||
library, pattern, haml = value
|
||||
|
||||
define_method("test_#{key}_filter") do
|
||||
begin
|
||||
Haml::Util.silence_warnings do
|
||||
require library
|
||||
end
|
||||
assert_match(pattern, render(haml))
|
||||
rescue LoadError
|
||||
warn "Could not load #{key} filter's dependencies"
|
||||
end
|
||||
test "modules including Haml::Filters::Base are registered as filters" do
|
||||
begin
|
||||
refute Haml::Filters.defined.has_key? "bar"
|
||||
Module.new {def self.name; "Foo::Bar"; end; include Haml::Filters::Base}
|
||||
assert Haml::Filters.defined.has_key? "bar"
|
||||
ensure
|
||||
Haml::Filters.defined.delete "bar"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,10 +25,19 @@ require 'fileutils'
|
|||
require 'haml'
|
||||
require 'haml/template'
|
||||
|
||||
Haml::Template.options[:ugly] = false
|
||||
Haml::Template.options[:ugly] = false
|
||||
Haml::Template.options[:format] = :xhtml
|
||||
|
||||
module Declarative
|
||||
def test(name, &block)
|
||||
define_method("test #{name}", &block)
|
||||
end
|
||||
end
|
||||
|
||||
class MiniTest::Unit::TestCase
|
||||
|
||||
extend Declarative
|
||||
|
||||
def assert_warning(message)
|
||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||
yield
|
||||
|
|
Loading…
Add table
Reference in a new issue