Skip to content
Browse files

Added global describe so global before and after callbacks can be def…

…ined.
  • Loading branch information...
1 parent 38aaef4 commit d829a743a337ab7f16b1c9cda0873fa5ace9f035 @btakita btakita committed
Showing with 46 additions and 15 deletions.
  1. +5 −2 lib/screw.behaviors.js
  2. +13 −9 lib/screw.builder.js
  3. +28 −4 spec/screwunit_spec.js
View
7 lib/screw.behaviors.js
@@ -29,8 +29,11 @@ $(Screw).bind('loaded', function() {
},
selector: function() {
var parent_selector = $(this).fn('parent').fn('selector');
- return (parent_selector ? parent_selector : 'body')
- + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
+ if(parent_selector) {
+ return parent_selector + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
+ } else {
+ return 'body';
+ }
}
});
View
22 lib/screw.builder.js
@@ -4,16 +4,20 @@ var Screw = {
var suite = new Function("matchers", "specifications",
"with (specifications) { with (matchers) { " + contents + " } }"
);
-
- if(!Screw.first_suite_loaded) {
+
+ if(!Screw.global_suite_added) {
$(function() {
- Screw.Specifications.context.push(
- $('body')
- .append($('<h3 class="status">'))
- .append($('<ul class="describes">'))
- );
+ var body = $('body');
+ $('body')
+ .addClass('describe')
+ .append($('<h3 class="status">'))
+ .append('<ol class="befores">')
+ .append('<ul class="its">')
+ .append('<ul class="describes">')
+ .append('<ol class="afters">')
+ Screw.Specifications.context.push(body);
})
- Screw.first_suite_loaded = true;
+ Screw.global_suite_added = true
}
Screw.last_suite = suite;
@@ -24,7 +28,7 @@ var Screw = {
}
})
},
- first_suite_loaded: false,
+ global_suite_added: false,
last_suite: null,
Specifications: {
context: [],
View
32 spec/screwunit_spec.js
@@ -1,4 +1,24 @@
Screw.Unit(function() {
+ var global_before_invoked = false;
+ var global_after_invoked = false;
+ before(function() {
+ try {
+ expect(global_before_invoked).to(equal, false);
+ } finally {
+ global_before_invoked = true;
+ global_after_invoked = false;
+ }
+ });
+
+ after(function() {
+ try {
+ expect(global_after_invoked).to(equal, false);
+ } finally {
+ global_before_invoked = false;
+ global_after_invoked = true;
+ }
+ });
+
describe('Screw.Unit', function() {
describe("Matchers", function() {
describe("#equal", function() {
@@ -130,17 +150,21 @@ Screw.Unit(function() {
}
});
- it("invokes the before prior to an it", function() {
- expect(before_invoked).to(equal, true);
+ it("invokes the global before prior to an it", function() {
+ expect(global_before_invoked).to(equal, true);
});
- it("invokes the before prior to each it", function() {
+ it("invokes the before prior to an it", function() {
expect(before_invoked).to(equal, true);
});
- it("invokes the after post an it", function() {
+ it("invokes the after callback after an it", function() {
expect(after_invoked).to(equal, false);
});
+
+ it("invokes the global after callback after an it", function() {
+ expect(global_after_invoked).to(equal, false);
+ });
});
describe("A describe with two before blocks", function() {

0 comments on commit d829a74

Please sign in to comment.
Something went wrong with that request. Please try again.