選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

60 行
1.4KB

  1. require 'rubygems'
  2. require 'json'
  3. __DIR__ = File.dirname(__FILE__)
  4. testnames = Dir.glob(__DIR__ + '/../examples/*.js').map do |name|
  5. File.basename name, '.js'
  6. end
  7. describe "mustache" do
  8. before(:all) do
  9. @mustache = File.read(__DIR__ + "/../mustache.js")
  10. end
  11. # it "should clear the context after each run" do
  12. # js = <<-JS
  13. # #{@mustache}
  14. # Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{x: 1}]})
  15. # try {
  16. # print(Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{}]}));
  17. # } catch(e) {
  18. # print('ERROR: ' + e);
  19. # }
  20. # JS
  21. # run_js(js).should == "ERROR: Can't find x in [object Object]\n"
  22. # end
  23. testnames.each do |testname|
  24. describe testname do
  25. it "should generate the correct html" do
  26. view = File.read(__DIR__ + "/../examples/#{testname}.js")
  27. template = File.read(__DIR__ + "/../examples/#{testname}.html").to_json
  28. expect = File.read(__DIR__ + "/../examples/#{testname}.txt")
  29. runner = <<-JS
  30. try {
  31. #{@mustache}
  32. #{view}
  33. var template = #{template};
  34. var result = Mustache.to_html(template, #{testname});
  35. print(result);
  36. } catch(e) {
  37. print('ERROR: ' + e.message);
  38. }
  39. JS
  40. run_js(runner).should == expect
  41. end
  42. end
  43. end
  44. def run_js(js)
  45. File.open("runner.js", 'w') {|f| f << js}
  46. `js runner.js`
  47. end
  48. end