Permalink
Browse files

Implemented after callback.

  • Loading branch information...
1 parent e374b49 commit f803f2203c45c15849de3ce87d9ffd2e530eecb6 @btakita btakita committed Apr 28, 2008
Showing with 44 additions and 6 deletions.
  1. +15 −3 lib/screw.behaviors.js
  2. +9 −0 lib/screw.builder.js
  3. +20 −3 spec/screwunit_spec.js
View
@@ -19,6 +19,10 @@ $(Screw).bind('loaded', function() {
$(this).fn('parent').fn('run_befores');
$(this).children('.befores').find('.before').fn('run');
},
+ run_afters: function() {
+ $(this).fn('parent').fn('run_afters');
+ $(this).children('.afters').find('.after').fn('run');
+ },
enqueue: function() {
$(this).children('.its').children('.it').fn('enqueue');
$(this).children('.describes').children('.describe').fn('enqueue');
@@ -36,9 +40,13 @@ $(Screw).bind('loaded', function() {
},
run: function() {
try {
- $(this)
- .fn('parent').fn('run_befores');
- $(this).data('screwunit.run')();
+ try {
+ $(this)
+ .fn('parent').fn('run_befores');
+ $(this).data('screwunit.run')();
+ } finally {
+ $(this).fn('parent').fn('run_afters');
+ }
$(this).trigger('passed');
} catch(e) {
$(this).trigger('failed', [e]);
@@ -62,6 +70,10 @@ $(Screw).bind('loaded', function() {
run: function() { $(this).data('screwunit.run')() }
});
+ $('.after').fn({
+ run: function() { $(this).data('screwunit.run')() }
+ });
+
$('.status').text('Running...');
var to_run = unescape(location.search.slice(1)) || 'body > .describes > .describe';
$(to_run)
View
@@ -35,6 +35,7 @@ var Screw = {
.append('<ol class="befores">')
.append('<ul class="its">')
.append('<ul class="describes">')
+ .append('<ol class="afters">')
this.context.push(describe);
fn.call();
@@ -60,6 +61,14 @@ var Screw = {
this.context[this.context.length-1]
.find('.befores')
.append(before);
+ },
+ after: function(fn) {
+ var after = $('<li class="after">')
+ .data('screwunit.run', fn);
+
+ this.context[this.context.length-1]
+ .find('.afters')
+ .append(after);
}
},
Matchers: {
View
@@ -20,20 +20,37 @@ Screw.Unit(function() {
});
describe('#run', function() {
- describe("A describe with a before block", function() {
+ describe("A describe with a before and after block", function() {
var before_invoked = false;
+ var after_invoked = false;
before(function() {
- before_invoked = true;
+ try {
+ expect(before_invoked).to(equal, false);
+ } finally {
+ before_invoked = true;
+ after_invoked = false;
+ }
+ });
+ after(function() {
+ try {
+ expect(after_invoked).to(equal, false);
+ } finally {
+ before_invoked = false;
+ after_invoked = true;
+ }
});
it("invokes the before prior to an it", function() {
expect(before_invoked).to(equal, true);
- before_invoked = false;
});
it("invokes the before prior to each it", function() {
expect(before_invoked).to(equal, true);
});
+
+ it("invokes the after post an it", function() {
+ expect(after_invoked).to(equal, false);
+ });
});
describe("A describe with two before blocks", function() {

0 comments on commit f803f22

Please sign in to comment.