From 9dc8cbdc9f08f52e6179f1dff1993e1d0436c155 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Sun, 22 May 2011 19:30:57 -0700 Subject: [PATCH 1/2] Adding a submodule reference to the Mustache Spec. --- .gitmodules | 3 +++ ext/spec | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 ext/spec diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..cfec2a7e5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ext/spec"] + path = ext/spec + url = git://github.com/mustache/spec.git diff --git a/ext/spec b/ext/spec new file mode 160000 index 000000000..bf6288ed6 --- /dev/null +++ b/ext/spec @@ -0,0 +1 @@ +Subproject commit bf6288ed6bd0ce8ccea6f1dac070b3d779132c3b From c8e6ebde95e136dd335d8295d7e5bfd48b788c94 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Sun, 22 May 2011 19:57:36 -0700 Subject: [PATCH 2/2] Adding a script to test spec compliance. --- test/compliance_spec.rb | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/compliance_spec.rb diff --git a/test/compliance_spec.rb b/test/compliance_spec.rb new file mode 100644 index 000000000..7d908efc5 --- /dev/null +++ b/test/compliance_spec.rb @@ -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