diff options
author | kpdecker <kpdecker@gmail.com> | 2013-06-01 23:45:43 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-06-01 23:45:43 -0500 |
commit | adda0569e0ec3fc363af9efbb23f5304c6d80fe2 (patch) | |
tree | 9952d7aed77f8710a53731bb98340d5468c9e931 /spec/env/common.js | |
parent | d13ae310d36a27fcbc333570f9b7ae9c7e641392 (diff) | |
download | handlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.zip handlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.tar.gz handlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.tar.bz2 |
Refactor qunit unit tests
Allows for testing node, browser, and precompiled modes in the node
tests. Also reorganizes the qunit spec file to provide better
organization.
Diffstat (limited to 'spec/env/common.js')
-rw-r--r-- | spec/env/common.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/env/common.js b/spec/env/common.js new file mode 100644 index 0000000..53ddd61 --- /dev/null +++ b/spec/env/common.js @@ -0,0 +1,28 @@ +global.should = require('should'); + +global.shouldCompileTo = function(string, hashOrArray, expected, message) { + shouldCompileToWithPartials(string, hashOrArray, false, expected, message); +}; + +global.shouldCompileToWithPartials = function(string, hashOrArray, partials, expected, message) { + var result = compileWithPartials(string, hashOrArray, partials); + result.should.equal(expected, "'" + expected + "' should === '" + result + "': " + message); +}; + +global.compileWithPartials = function(string, hashOrArray, partials) { + var template = CompilerContext[partials ? 'compileWithPartial' : 'compile'](string), ary; + if(Object.prototype.toString.call(hashOrArray) === "[object Array]") { + ary = []; + ary.push(hashOrArray[0]); + ary.push({ helpers: hashOrArray[1], partials: hashOrArray[2] }); + } else { + ary = [hashOrArray]; + } + + return template.apply(this, ary); +}; + + +global.equals = global.equal = function(a, b, msg) { + a.should.equal(b, msg || ''); +}; |