Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adding a script to test spec compliance.
  • Loading branch information
pvande committed May 23, 2011
commit c8e6ebde95e136dd335d8295d7e5bfd48b788c94
53 changes: 53 additions & 0 deletions test/compliance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'rubygems'
require 'yaml'
require 'json'

YAML::add_builtin_type('code') do |_, value|
value['js'].tap do |func|
def func.to_json(_)
"function() { return #{self}; }"
end
end
end

__DIR__ = File.dirname(__FILE__)

testnames = Dir.glob(__DIR__ + '/../ext/spec/specs/[^~]*.yml').map do |name|
File.basename name, '.yml'
end

def load_tests(dir, name)
file = File.join(dir, '..', 'ext', 'spec', 'specs', "#{name}.yml")
return YAML.load_file(file)['tests']
end

describe "Mustache Spec compliance" do
before(:all) do
@mustache = File.read(__DIR__ + "/../mustache.js")
end

testnames.each do |testname|
load_tests(__DIR__, testname).each do |test|
describe test['name'] do
it test['desc'] do
runner = <<-JS
#{@mustache}
print(Mustache.to_html(
#{test['template'].to_json},
#{test['data'].to_json},
#{test['partials'].to_json}
));
JS

# #print appends a newline
run_js(runner).should == test['expected'] + "\n"
end
end
end
end

def run_js(js)
File.open("runner.js", 'w') {|f| f << js}
`js runner.js`
end
end