Просмотр исходного кода

stubbed _() for tests, and basic i18n test

tags/0.4.0
Ben Cherry 15 лет назад
Родитель
Сommit
6a9da0581a
1 измененных файлов: 34 добавлений и 8 удалений
  1. +34
    -8
      test/mustache_spec.rb

+ 34
- 8
test/mustache_spec.rb Просмотреть файл

@@ -24,12 +24,23 @@ end


describe "mustache" do describe "mustache" do
before(:all) do before(:all) do
@mustache = File.read(__DIR__ + "/../mustache.js")
mustache = File.read(__DIR__ + "/../mustache.js")
stubbed_gettext = <<-JS
// Stubbed gettext translation method for {{_i}}{{/i}} tags in Mustache.
function _(text) {
return text;
}
JS

@boilerplate = <<-JS
#{mustache}
#{stubbed_gettext}
JS
end end


it "should return the same when invoked multiple times" do it "should return the same when invoked multiple times" do
js = <<-JS js = <<-JS
#{@mustache}
#{@boilerplate}
Mustache.to_html("x") Mustache.to_html("x")
print(Mustache.to_html("x")); print(Mustache.to_html("x"));
JS JS
@@ -39,7 +50,7 @@ describe "mustache" do


it "should clear the context after each run" do it "should clear the context after each run" do
js = <<-JS js = <<-JS
#{@mustache}
#{@boilerplate}
Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{x: 1}]}) Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{x: 1}]})
try { try {
print(Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{}]})); print(Mustache.to_html("{{#list}}{{x}}{{/list}}", {list: [{}]}));
@@ -52,7 +63,7 @@ describe "mustache" do


it "should not double-render" do it "should not double-render" do
js = <<-JS js = <<-JS
#{@mustache}
#{@boilerplate}
var template = "{{#foo}}{{bar}}{{/foo}}"; var template = "{{#foo}}{{bar}}{{/foo}}";
var ctx = { var ctx = {
foo: true, foo: true,
@@ -66,6 +77,21 @@ describe "mustache" do
run_js(js).strip.should == "{{win}}" run_js(js).strip.should == "{{win}}"
end end


it "should work with i18n" do
js = <<-JS
#{@boilerplate}

var template = "{{_i}}foo {{bar}}{{/i}}";
var ctx = {
bar: "BAR"
};

print(Mustache.to_html(template, ctx));
JS

run_js(js).strip.should == "foo BAR"
end

non_partials.each do |testname| non_partials.each do |testname|
describe testname do describe testname do
it "should generate the correct html" do it "should generate the correct html" do
@@ -74,7 +100,7 @@ describe "mustache" do


runner = <<-JS runner = <<-JS
try { try {
#{@mustache}
#{@boilerplate}
#{view} #{view}
var template = #{template}; var template = #{template};
var result = Mustache.to_html(template, #{testname}); var result = Mustache.to_html(template, #{testname});
@@ -92,7 +118,7 @@ describe "mustache" do


runner = <<-JS runner = <<-JS
try { try {
#{@mustache}
#{@boilerplate}
#{view} #{view}
var chunks = []; var chunks = [];
var sendFun = function(chunk) { var sendFun = function(chunk) {
@@ -122,7 +148,7 @@ describe "mustache" do


runner = <<-JS runner = <<-JS
try { try {
#{@mustache}
#{@boilerplate}
#{view} #{view}
var template = #{template}; var template = #{template};
var partials = {"partial": #{partial}}; var partials = {"partial": #{partial}};
@@ -142,7 +168,7 @@ describe "mustache" do


runner = <<-JS runner = <<-JS
try { try {
#{@mustache}
#{@boilerplate}
#{view}; #{view};
var template = #{template}; var template = #{template};
var partials = {"partial": #{partial}}; var partials = {"partial": #{partial}};


Загрузка…
Отмена
Сохранить