Convert haml-spec into rspec

This commit is contained in:
Takashi Kokubun 2015-03-23 00:32:40 +09:00
parent b28ab924a7
commit 1658f91b3f
4 changed files with 1113 additions and 2 deletions

View File

@ -20,7 +20,7 @@ end
namespace :haml do
desc 'Run Haml Spec'
task :spec do
system('cd haml-spec && rake spec')
system('bundle exec rspec --pattern spec/haml-spec/**{,/\*/\*\*\}/\*_spec.rb')
end
end

View File

@ -1,4 +1,4 @@
$:.unshift File.expand_path('../../../lib', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require "rubygems"
require "minitest/autorun"

41
spec/haml-spec/Rakefile Normal file
View File

@ -0,0 +1,41 @@
$:.unshift File.expand_path('../../../lib', __FILE__)
require 'json'
desc 'Convert tests.json into rspec tests'
task :convert do
tests = []
contexts = JSON.parse(File.read(File.expand_path('../../../haml-spec/tests.json', __FILE__)))
contexts.each do |context|
context[1].each_with_index do |(name, test), index|
tests << {
name: "#{name} (#{context[0]})",
html: test['html'],
haml: test['haml'],
locals: test['locals'],
config: test['config'],
}
end
end
spec = "describe 'haml-spec' do\n"
spec += tests.map { |test|
options = Hash[(test[:config] || {}).map {|x, y| [x.to_sym, y]}]
spec = " specify %q{#{test[:name]}} do\n"
spec += " html = %q{#{test[:html]}}\n"
spec += " haml = %q{#{test[:haml]}}\n"
spec += " locals = Hash[#{test[:locals] || {}}.map {|x, y| [x.to_sym, y]}]\n"
spec += " options = #{options}\n"
spec += " options[:format] = '#{options[:format]}'\n" if options.key?(:format)
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"
}.join("\n")
spec += "end\n"
File.write('ruby_haml_spec.rb', spec)
end
task default: :convert

File diff suppressed because it is too large Load Diff