From eda51730614df1a3a5d5abec5d629a37d81affec Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Sun, 3 Jun 2012 22:26:14 -0700 Subject: [PATCH] Remove Ruby dependency --- Rakefile | 38 ++++++++++++----------- test/helper.rb | 48 ---------------------------- test/integration.rb | 76 --------------------------------------------- test/unit.rb | 7 ----- 4 files changed, 20 insertions(+), 149 deletions(-) delete mode 100644 test/helper.rb delete mode 100644 test/integration.rb delete mode 100644 test/unit.rb diff --git a/Rakefile b/Rakefile index 7240f8b..0a62cb4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,18 +1,28 @@ require 'rake' require 'rake/clean' -task :default => 'test:integration' +task :default => :test -namespace :test do - desc "Run all integration tests" - task :integration do - require File.expand_path('../test/integration', __FILE__) - end +ROOT = File.expand_path('..', __FILE__) +MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js')) - desc "Run all unit tests" - task :unit do - require File.expand_path('../test/unit', __FILE__) - end +def mustache_version + match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/) + match[1] +end + +def minified_file + ENV['FILE'] || 'mustache.min.js' +end + +desc "Run all tests, requires vows (see http://vowsjs.org)" +task :test do + sh "vows test/*_test.js" +end + +desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)" +task :minify do + sh "uglifyjs mustache.js > #{minified_file}" end # Creates a task that uses the various template wrappers to make a wrapped @@ -52,11 +62,3 @@ templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" templated_build "RequireJS" templated_build "qooxdoo" - -task :minify do - # npm install uglify-js - mmjs = "mustache.min.js" - `echo "/*! Version: 0.5.1-dev */" > #{mmjs}` - `uglifyjs mustache.js >> #{mmjs}` - puts "Created #{mmjs}" -end diff --git a/test/helper.rb b/test/helper.rb deleted file mode 100644 index baadb94..0000000 --- a/test/helper.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test/unit' - -module Mustache - extend self - - ROOT = File.expand_path('../..', __FILE__) - TEST = File.join(ROOT, 'test') - TEST_FILES = File.join(TEST, '_files') - - MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js')) - - TESTS = Dir.glob(File.join(TEST_FILES, '*.js')).map do |name| - File.basename name, '.js' - end - - NODE_PATH = `which node`.strip - JS_PATH = `which js`.strip - JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" - RHINO_JAR = "org.mozilla.javascript.tools.shell.Main" - - def javascript_engines - %w[v8 spidermonkey javascriptcore rhino] - end - - def available_javascript_engines - javascript_engines.select {|engine| send("has_#{engine}?") } - end - - def has_any_engines? - available_javascript_engines.any? - end - - def has_v8? - File.exist?(NODE_PATH) - end - - def has_spidermonkey? - File.exist?(JS_PATH) - end - - def has_javascriptcore? - File.exist?(JSC_PATH) - end - - def has_rhino? - `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/ - end -end diff --git a/test/integration.rb b/test/integration.rb deleted file mode 100644 index d3d482d..0000000 --- a/test/integration.rb +++ /dev/null @@ -1,76 +0,0 @@ -require File.expand_path('../helper', __FILE__) -require 'fileutils' -require 'json' - -module Mustache - class Test < Test::Unit::TestCase - - def self.run_tests_for(engine) - TESTS.each do |test| - define_method("test_#{engine}_#{test}") do - template, view, partial, expect = load_test(test) - - assert_equal expect, run_js(engine, <<-JS).chomp - try { - #{boilerplate_for(engine)} - var template = #{template.to_json}; - var view = #{view}; - var partials = {partial: #{partial.to_json}}; - print(Mustache.render(template, view, partials)); - } catch(e) { - print('ERROR: ' + e.message); - } - JS - end - end - end - - unless Mustache.has_any_engines? - abort "ERROR: Please install node, SpiderMonkey, JavaScriptCore or Rhino" - end - - run_tests_for :v8 if Mustache.has_v8? - run_tests_for :spidermonkey if Mustache.has_spidermonkey? - run_tests_for :javascriptcore if Mustache.has_javascriptcore? - run_tests_for :rhino if Mustache.has_rhino? - - private - - def load_test(name) - template_file = File.join(TEST_FILES, "#{name}.mustache") - view_file = File.join(TEST_FILES, "#{name}.js") - partial_file = File.join(TEST_FILES, "#{name}.partial") - expect_file = File.join(TEST_FILES, "#{name}.txt") - - [template_file, view_file, partial_file, expect_file].map do |file| - File.exist?(file) ? File.read(file) : "" - end - end - - def runner_file - "runner.js" - end - - def run_js(engine, js) - cmd = case engine - when :v8 then NODE_PATH - when :spidermonkey then JS_PATH - when :javascriptcore then JSC_PATH - when :rhino then "java #{RHINO_JAR}" - end - - File.open(runner_file, 'w') {|file| file.write(js) } - - `#{cmd} #{runner_file}` - ensure - FileUtils.rm_r(runner_file) - end - - def boilerplate_for(engine) - boilerplate = MUSTACHE_JS - boilerplate += "\nvar print = console.log;" if engine == :v8 - boilerplate - end - - end -end diff --git a/test/unit.rb b/test/unit.rb deleted file mode 100644 index eb473bd..0000000 --- a/test/unit.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.expand_path('../helper', __FILE__) - -if Mustache.has_v8? - exec "vows #{Mustache::TEST}/*_test.js" -else - abort "ERROR: Please install node" -end