don't modify test.statement; delete test.data when done

This commit is contained in:
rolux 2012-06-12 15:31:46 +02:00
parent b9c74fe895
commit 6db715ab87

View file

@ -799,24 +799,26 @@ Ox.test = function(argument, callback) {
item.tests && item.tests.some(function(test) { item.tests && item.tests.some(function(test) {
return test.expected; return test.expected;
}) && item.tests.forEach(function(test) { }) && item.tests.forEach(function(test) {
var actual, isAsync = regexp.test(test.statement); var actual, statement = test.statement,
isAsync = regexp.test(statement);
if (isAsync) { if (isAsync) {
// Add a pending test // Add a pending test
Ox.test.data[id].tests[test.statement] = { Ox.test.data[id].tests[test.statement] = {
expected: test.expected,
name: item.name, name: item.name,
section: item.section section: item.section
}; };
// Patch the test statement // Patch the test statement
test.statement = test.statement.replace( statement = statement.replace(
regexp, regexp,
"$1'" + test.statement.replace(/'/g, "\\'") + "', " "$1'" + statement.replace(/'/g, "\\'") + "', "
); );
} }
if (test.expected || test.statement.match(/Ox\.test\./)) { if (test.expected || statement.match(/Ox\.test\./)) {
// Eval the statement, unless it's a script tag that doesn't // Eval the statement, unless it's a script tag that doesn't
// add a property to Ox.test // add a property to Ox.test
Ox.Log('TEST', test.statement); Ox.Log('TEST', statement);
actual = eval(test.statement); actual = eval(statement);
} }
if (!isAsync && test.expected) { if (!isAsync && test.expected) {
Ox.test.data[id].results.push({ Ox.test.data[id].results.push({
@ -824,7 +826,7 @@ Ox.test = function(argument, callback) {
expected: test.expected, expected: test.expected,
name: item.name, name: item.name,
section: item.section, section: item.section,
statement: test.statement, statement: statement,
passed: Ox.isEqual( passed: Ox.isEqual(
actual, eval('(' + test.expected + ')') actual, eval('(' + test.expected + ')')
) )
@ -835,6 +837,7 @@ Ox.test = function(argument, callback) {
Ox.test.data[id].done = true; Ox.test.data[id].done = true;
if (Ox.isEmpty(Ox.test.data[id].tests)) { if (Ox.isEmpty(Ox.test.data[id].tests)) {
callback(Ox.test.data[id].results); callback(Ox.test.data[id].results);
delete Ox.test.data[id];
} }
} }
if (arguments.length == 2) { if (arguments.length == 2) {
@ -865,13 +868,13 @@ Ox.test = function(argument, callback) {
}); });
Ox.test.data[id].results.push(Ox.extend(test, { Ox.test.data[id].results.push(Ox.extend(test, {
actual: result, actual: result,
expected: expected,
statement: statement, statement: statement,
passed: Ox.isEqual(result, expected) passed: Ox.isEqual(result, expected)
})); }));
delete Ox.test.data[id].tests[statement]; delete Ox.test.data[id].tests[statement];
if (Ox.test.data[id].done && Ox.isEmpty(Ox.test.data[id].tests)) { if (Ox.test.data[id].done && Ox.isEmpty(Ox.test.data[id].tests)) {
Ox.test.data[id].callback(Ox.test.data[id].results); Ox.test.data[id].callback(Ox.test.data[id].results);
delete Ox.test.data[id];
} }
} }
}; };