1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/spec/haml-spec/Rakefile

51 lines
1.6 KiB
Text
Raw Normal View History

2015-03-23 00:32:40 +09:00
$:.unshift File.expand_path('../../../lib', __FILE__)
require 'json'
desc 'Convert tests.json into rspec tests'
task :convert do
2015-03-27 13:14:20 +09:00
spec = "describe 'haml-spec' do\n"
spec += " def assert_render(html, haml, locals, options)\n"
spec += " engine = Hamlit::Template.new(options) { haml }\n"
spec += " result = engine.render(Object.new, locals)\n"
spec += " expect(result.strip).to eq(html)\n"
spec += " end\n\n"
2015-03-23 00:32:40 +09:00
contexts = JSON.parse(File.read(File.expand_path('../../../haml-spec/tests.json', __FILE__)))
2015-03-23 00:42:05 +09:00
contexts.each_with_index do |context, index|
spec += "\n" if index != 0
spec += " context \"#{context[0]}\" do\n"
tests = []
context[1].each do |name, test|
2015-03-23 00:32:40 +09:00
tests << {
2015-03-23 00:42:05 +09:00
name: name,
2015-03-23 00:32:40 +09:00
html: test['html'],
haml: test['haml'],
locals: test['locals'],
config: test['config'],
}
end
2015-03-23 00:42:05 +09:00
spec += tests.map { |test|
2015-03-27 13:14:20 +09:00
locals = Hash[(test[:locals] || {}).map {|x, y| [x.to_sym, y]}]
2015-03-23 00:42:05 +09:00
options = Hash[(test[:config] || {}).map {|x, y| [x.to_sym, y]}]
2015-03-27 13:14:20 +09:00
options[:format] = options[:format].to_sym if options[:format]
2015-03-23 00:42:05 +09:00
spec = " specify \"#{test[:name]}\" do\n"
2015-03-27 13:14:20 +09:00
spec += " html = %q{#{test[:html]}}\n"
spec += " haml = %q{#{test[:haml]}}\n"
spec += " locals = #{locals}\n"
spec += " options = #{options}\n"
spec += " assert_render(html, haml, locals, options)\n"
2015-03-23 00:42:05 +09:00
spec += " end\n"
}.join("\n")
2015-03-23 00:32:40 +09:00
spec += " end\n"
2015-03-23 00:42:05 +09:00
end
2015-03-23 00:32:40 +09:00
spec += "end\n"
File.write('ruby_haml_spec.rb', spec)
end
task default: :convert