Convert haml-spec into rspec
This commit is contained in:
parent
b28ab924a7
commit
1658f91b3f
2
Rakefile
2
Rakefile
|
@ -20,7 +20,7 @@ end
|
||||||
namespace :haml do
|
namespace :haml do
|
||||||
desc 'Run Haml Spec'
|
desc 'Run Haml Spec'
|
||||||
task :spec do
|
task :spec do
|
||||||
system('cd haml-spec && rake spec')
|
system('bundle exec rspec --pattern spec/haml-spec/**{,/\*/\*\*\}/\*_spec.rb')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
$:.unshift File.expand_path('../../../lib', __FILE__)
|
$:.unshift File.expand_path('../../lib', __FILE__)
|
||||||
|
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
require "minitest/autorun"
|
require "minitest/autorun"
|
||||||
|
|
|
@ -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
Loading…
Reference in New Issue