Permalink
Browse files

Add after callbacks

  • Loading branch information...
1 parent ed10945 commit 745d382d9329c23feaf5ed5a59141bb2f6e4d81b @joshuaclayton committed Jun 6, 2010
Showing with 27 additions and 2 deletions.
  1. +1 −0 README.markdown
  2. +4 −1 specit.js
  3. +22 −1 specit.tests.js
View
@@ -57,6 +57,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
## Other supported features
* Before callbacks
+* After callbacks
## What's it do?
View
@@ -33,8 +33,9 @@
describe: function(description, body) {
this.currentTests = [];
this.currentBefore = function() {};
+ this.currentAfter = function() {};
body();
- module(description, {setup: this.currentBefore});
+ module(description, {setup: this.currentBefore, teardown: this.currentAfter});
$.each(this.currentTests, function(i, currentTest) { currentTest(); });
},
it: function(description, body) {
@@ -44,6 +45,7 @@
currentTests.push(function() { asyncTest(description, body); });
},
before: function(callback) { this.currentBefore = callback; },
+ after: function(callback) { this.currentAfter = callback; },
expectations: function(current) {
var expect = function(expectation, args) {
var args = $.makeArray(args);
@@ -206,4 +208,5 @@
window.it = SpecIt.it;
window.asyncIt = SpecIt.asyncIt;
window.before = SpecIt.before;
+ window.after = SpecIt.after;
})();
View
@@ -159,7 +159,7 @@ describe("SpecIt", function() {
});
});
-var john, beforeCallbackTest, afterCallbackTest;
+var john, beforeCallbackTest;
describe("SpecIt with a before callback", function() {
var jane = {name: "Jane"};
@@ -210,3 +210,24 @@ describe("SpecIt with a different before callback", function() {
equals(typeof jane, "undefined");
});
});
+
+describe("SpecIt with an after callback", function() {
+ var changedFromAfterCallback = "unchanged";
+
+ after(function() {
+ changedFromAfterCallback = "changed";
+ });
+
+ it("should not call after callback until after a test is run", function() {
+ equals(changedFromAfterCallback, "unchanged");
+ });
+
+ it("should call the after callback the first test is run", function() {
+ equals(changedFromAfterCallback, "changed");
+ changedFromAfterCallback = "bogus";
+ });
+
+ it("should call the after callback after each test is run", function() {
+ equals(changedFromAfterCallback, "changed");
+ });
+});

0 comments on commit 745d382

Please sign in to comment.