mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Prepare haml-spec for both pretty and ugly
This commit is contained in:
parent
b89c57eca6
commit
522ed5699c
3 changed files with 28 additions and 24 deletions
2
Rakefile
2
Rakefile
|
@ -6,7 +6,7 @@ task default: :test
|
||||||
Rake::TestTask.new do |t|
|
Rake::TestTask.new do |t|
|
||||||
t.libs << 'lib' << 'test'
|
t.libs << 'lib' << 'test'
|
||||||
files = Dir['test/*_test.rb']
|
files = Dir['test/*_test.rb']
|
||||||
files << 'test/haml-spec/hamlit_test.rb'
|
files << 'test/haml-spec/*_test.rb'
|
||||||
t.ruby_opts = %w[-rtest_helper]
|
t.ruby_opts = %w[-rtest_helper]
|
||||||
t.test_files = files
|
t.test_files = files
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
|
27
test/haml-spec/haml_spec_test.rb
Normal file
27
test/haml-spec/haml_spec_test.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
require 'rubygems'
|
||||||
|
require 'minitest/autorun'
|
||||||
|
require 'json'
|
||||||
|
require 'haml'
|
||||||
|
require 'hamlit'
|
||||||
|
|
||||||
|
class HamlTest < MiniTest::Test
|
||||||
|
contexts = JSON.parse(File.read(File.dirname(__FILE__) + '/tests.json'))
|
||||||
|
|
||||||
|
contexts.each do |context|
|
||||||
|
context[1].each do |name, test|
|
||||||
|
[{ ugly: true }].each do |base_options|
|
||||||
|
define_method("test_#{base_options[:ugly] ? 'ugly' : 'pretty'}_spec: #{name} (#{context[0]})") do
|
||||||
|
haml = test['haml']
|
||||||
|
locals = Hash[(test['locals'] || {}).map {|x, y| [x.to_sym, y]}]
|
||||||
|
options = Hash[(test['config'] || {}).map {|x, y| [x.to_sym, y]}]
|
||||||
|
options[:format] = options[:format].to_sym if options.key?(:format)
|
||||||
|
options = base_options.merge(options)
|
||||||
|
haml_result = Haml::Engine.new(haml, options).render(Object.new, locals)
|
||||||
|
hamlit_result = Hamlit::HamlEngine.new(haml, options).render(Object.new, locals)
|
||||||
|
|
||||||
|
assert_equal haml_result, hamlit_result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,23 +0,0 @@
|
||||||
require "rubygems"
|
|
||||||
require "minitest/autorun"
|
|
||||||
require "json"
|
|
||||||
require "hamlit"
|
|
||||||
|
|
||||||
class HamlTest < MiniTest::Unit::TestCase
|
|
||||||
contexts = JSON.parse(File.read(File.dirname(__FILE__) + "/tests.json"))
|
|
||||||
contexts.each do |context|
|
|
||||||
context[1].each do |name, test|
|
|
||||||
define_method("test_spec: #{name} (#{context[0]})") do
|
|
||||||
html = test["html"]
|
|
||||||
haml = test["haml"]
|
|
||||||
locals = Hash[(test["locals"] || {}).map {|x, y| [x.to_sym, y]}]
|
|
||||||
options = Hash[(test["config"] || {}).map {|x, y| [x.to_sym, y]}]
|
|
||||||
options[:format] = options[:format].to_sym if options.key?(:format)
|
|
||||||
engine = Hamlit::HamlEngine.new(haml, options)
|
|
||||||
result = engine.render(Object.new, locals)
|
|
||||||
|
|
||||||
assert_equal html, result.strip
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Reference in a new issue