Skip to content

Commit

Permalink
Execute all setup, teardown and test methods in a scope local to the …
Browse files Browse the repository at this point in the history
…test. You can now place "this." in front

of all of your test variables to make them local to the test, if you don't want to pollute the global scope.
  • Loading branch information
Phil Crosby committed Aug 26, 2010
1 parent 1244642 commit 0fcb9f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions shoulda.js
Expand Up @@ -202,16 +202,18 @@ var Tests = {

Tests.testsRun++;
var failureMessage = null;
// This is the scope which all references "this" in the setup and test methods will resolve to.
var testScope = {};

try {
for (var i = 0; i < contexts.length; i++) {
if (contexts[i].setupMethod)
contexts[i].setupMethod.methodBody();
contexts[i].setupMethod.methodBody.apply(testScope);
}
testMethod.methodBody();
testMethod.methodBody.apply(testScope);
for (var i = 0; i < contexts.length; i++) {
if (contexts[i].tearDownMethod)
contexts[i].tearDownMethod.methodBody();
contexts[i].tearDownMethod.methodBody.apply(testScope);
}
} catch(exception) {
failureMessage = exception.toString();
Expand Down

0 comments on commit 0fcb9f1

Please sign in to comment.