rails_generators/javascript_test/templates/assets/jsunittest.js in newjs-1.4.1 vs rails_generators/javascript_test/templates/assets/jsunittest.js in newjs-1.5.0
- old
+ new
@@ -1,6 +1,6 @@
-/* Jsunittest, version 0.6.3
+/* Jsunittest, version 0.7.2
* (c) 2008 Dr Nic Williams
*
* Jsunittest is freely distributable under
* the terms of an MIT-style license.
* For details, see the web site: http://jsunittest.rubyforge.org
@@ -197,11 +197,11 @@
if (typeof replacement == "function") return replacement;
var template = new Template(replacement);
return function(match) { return template.evaluate(match) };
};
-JsUnitTest.Version = '0.6.3';
+JsUnitTest.Version = '0.7.2';
JsUnitTest.Template = function(template, pattern) {
this.template = template; //template.toString();
this.pattern = pattern || JsUnitTest.Template.Pattern;
};
@@ -439,11 +439,11 @@
// and act accordingly.
data: options.data || ""
};
// Create the request object
- var xml = new XMLHttpRequest();
+ var xml = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
// Open the asynchronous POST request
xml.open(options.type, options.url, true);
// We're going to wait for a request for 5 seconds, before giving up
@@ -527,11 +527,11 @@
// Return the response data (either an XML Document or a text string)
return data;
}
-}
+};
JsUnitTest.Unit.Assertions = {
buildMessage: function(message, template) {
var args = JsUnitTest.arrayfromargs(arguments).slice(2);
return (message ? message + '\n' : '') +
new JsUnitTest.Unit.MessageTemplate(template).evaluate(args);
@@ -673,11 +673,20 @@
assertNoMatch: function(expected, actual, message) {
message = this.buildMessage(message || 'assertNoMatch', 'regex <?> matched <?>', expected, actual);
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
},
+ assertHasClass: function(element, klass, message) {
+ element = JsUnitTest.$(element);
+ message = this.buildMessage(message || 'assertHasClass', '? doesn\'t have class <?>.', element, klass);
+ this.assertBlock(message, function() {
+ return !!element.className.match(new RegExp(klass))
+ });
+ },
+
assertHidden: function(element, message) {
+ element = JsUnitTest.$(element);
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
},
assertInstanceOf: function(expected, actual, message) {
@@ -820,29 +829,33 @@
JsUnitTest.Unit.Runner.prototype.getResult = function() {
var results = {
tests: this.tests.length,
assertions: 0,
failures: 0,
- errors: 0
+ errors: 0,
+ warnings: 0
};
for (var i=0; i < this.tests.length; i++) {
var test = this.tests[i];
results.assertions += test.assertions;
results.failures += test.failures;
results.errors += test.errors;
+ results.warnings += test.warnings;
};
return results;
};
JsUnitTest.Unit.Runner.prototype.postResults = function() {
if (this.options.resultsURL) {
// new Ajax.Request(this.options.resultsURL,
// { method: 'get', parameters: this.getResult(), asynchronous: false });
var results = this.getResult();
var url = this.options.resultsURL + "?";
+ url += "tests="+ this.tests.length + "&";
url += "assertions="+ results.assertions + "&";
+ url += "warnings=" + results.warnings + "&";
url += "failures=" + results.failures + "&";
url += "errors=" + results.errors;
JsUnitTest.ajax({
url: url,
type: 'GET'
@@ -877,11 +890,11 @@
this.postResults();
this.logger.summary(this.summary());
};
JsUnitTest.Unit.Runner.prototype.summary = function() {
- return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors').evaluate(this.getResult());
+ return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings').evaluate(this.getResult());
};
JsUnitTest.Unit.Testcase = function(name, test, setup, teardown) {
this.name = name;
this.test = test || function() {};
this.setup = setup || function() {};
@@ -893,18 +906,20 @@
for (method in JsUnitTest.Unit.Assertions) {
JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
}
-JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
-JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
-JsUnitTest.Unit.Testcase.prototype.assertions = 0;
-JsUnitTest.Unit.Testcase.prototype.failures = 0;
-JsUnitTest.Unit.Testcase.prototype.errors = 0;
-// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
+JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
+JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
+JsUnitTest.Unit.Testcase.prototype.assertions = 0;
+JsUnitTest.Unit.Testcase.prototype.failures = 0;
+JsUnitTest.Unit.Testcase.prototype.errors = 0;
+JsUnitTest.Unit.Testcase.prototype.warnings = 0;
JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
+// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
+
JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
this.isWaiting = true;
this.test = nextPart;
this.timeToWait = time;
};
@@ -926,11 +941,11 @@
this.error(e, this);
}
};
JsUnitTest.Unit.Testcase.prototype.summary = function() {
- var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
+ var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings\n';
return new JsUnitTest.Template(msg).evaluate(this) +
this.messages.join("\n");
};
JsUnitTest.Unit.Testcase.prototype.pass = function() {
@@ -946,10 +961,22 @@
line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
}
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
};
+JsUnitTest.Unit.Testcase.prototype.warning = function(message) {
+ this.warnings++;
+ var line = "";
+ try {
+ throw new Error("stack");
+ } catch(e){
+ line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
+ }
+ this.messages.push("Warning: " + message + (line ? " Line #" + line : ""));
+};
+JsUnitTest.Unit.Testcase.prototype.warn = JsUnitTest.Unit.Testcase.prototype.warning;
+
JsUnitTest.Unit.Testcase.prototype.info = function(message) {
this.messages.push("Info: " + message);
};
JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
@@ -959,9 +986,10 @@
};
JsUnitTest.Unit.Testcase.prototype.status = function() {
if (this.failures > 0) return 'failed';
if (this.errors > 0) return 'error';
+ if (this.warnings > 0) return 'warning';
return 'passed';
};
JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
var startAt = new Date();
\ No newline at end of file