From 654958150a9278c3749796748421698060126b58 Mon Sep 17 00:00:00 2001 From: Bob Remeika Date: Mon, 27 Jun 2011 23:52:49 -0700 Subject: [PATCH] Added xdescribe --- site/www/src/documents/documentation.html | 16 +++++++++++++ spec/shared/example_group_spec.js | 28 +++++++++++++++++++++++ spec/shared/keyword_spec.js | 7 ++++++ src/example.js | 8 ++++--- src/example_group.js | 17 +++++++++++++- src/keywords.js | 19 ++++++++++++++- 6 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 spec/shared/example_group_spec.js diff --git a/site/www/src/documents/documentation.html b/site/www/src/documents/documentation.html index be354de..f4def51 100644 --- a/site/www/src/documents/documentation.html +++ b/site/www/src/documents/documentation.html @@ -129,6 +129,22 @@

describe (aka group)

+ +

xdescribe (aka group)

+ +

+ Creates a pending group. All groups and examples nested within a pending group will be marked as pending. This can be used to mark an entire set of tests as pending. +

+ +
+xdescribe('example group', function (){
+  it('runs some test', function (){   // This example will be marked as pending and will not run
+    ...
+  });
+});
+
+ +

expect (aka assertion)

diff --git a/spec/shared/example_group_spec.js b/spec/shared/example_group_spec.js new file mode 100644 index 0000000..64a4158 --- /dev/null +++ b/spec/shared/example_group_spec.js @@ -0,0 +1,28 @@ +var footest = foounit.require(':src/foounit'); + +foounit.add(function (kw){ with(kw){ + describe('foounit.ExampleGroup', function (){ + describe('when the pending flag is true', function (){ + it('makes all examples as pending', function (){ + var group = new footest.ExampleGroup('parent', function (){}, true); + + expect(group.isPending()).to(beTrue); + + group.setBefore(function (){ runCount++; }); + group.setAfter(function (){ runCount++; }); + + var example = new footest.Example('test1', function (){}); + group.addExample(example); + expect(example.isPending()).to(beTrue); + + var subgroup = new footest.ExampleGroup('subgroup', function (){}); + group.addGroup(subgroup); + expect(subgroup.isPending()).to(beTrue); + + var subexample = new footest.Example('test2', function (){}); + subgroup.addExample(subexample); + expect(subexample.isPending()).to(beTrue); + }); + }); + }); +}}); diff --git a/spec/shared/keyword_spec.js b/spec/shared/keyword_spec.js index d23d5c0..f4dd828 100644 --- a/spec/shared/keyword_spec.js +++ b/spec/shared/keyword_spec.js @@ -31,6 +31,13 @@ foounit.add(function (kw){ with(kw){ }); }); + describe('xdescribe', function (){ + it('creats a pending group', function (){ + foo = footest.keywords.xdescribe('pending', function (){}); + expect(foo.isPending()).to(beTrue); + }); + }); + describe('matchers', function (){ it('mixes them into the keywords', function (){ var called = false; diff --git a/src/example.js b/src/example.js index 422348d..9a54f82 100644 --- a/src/example.js +++ b/src/example.js @@ -201,9 +201,7 @@ foounit.mixin(foounit.Example.prototype, { this._descriptions = descriptions; } - , getBefores: function (){ - return this._befores; - } + , getBefores: function (){ return this._befores; } , setAfters: function (afters){ this._afters = afters; @@ -216,4 +214,8 @@ foounit.mixin(foounit.Example.prototype, { , getTest: function (){ return this._test; } + + , setStatus: function (code){ + this._status = code; + } }); diff --git a/src/example_group.js b/src/example_group.js index 5012738..38d04b0 100644 --- a/src/example_group.js +++ b/src/example_group.js @@ -1,6 +1,7 @@ -foounit.ExampleGroup = function (description, builder){ +foounit.ExampleGroup = function (description, builder, pending){ this._description = description; this._builder = builder; + this._pending = pending; this._before = null; this._after = null; this._examples = []; @@ -17,10 +18,16 @@ foounit.mixin(foounit.ExampleGroup.prototype, { } , addExample: function (example){ + if (this.isPending()){ + example.setStatus(foounit.Example.prototype.PENDING); + } this._examples.push(example); } , addGroup: function (group){ + if (this.isPending()){ + group.setPending(true); + } this._groups.push(group); } @@ -47,4 +54,12 @@ foounit.mixin(foounit.ExampleGroup.prototype, { , getDescription: function (){ return this._description; } + + , isPending: function (){ + return this._pending; + } + + , setPending: function (bool){ + this._pending = bool; + } }); diff --git a/src/keywords.js b/src/keywords.js index 3ac21cf..b697acd 100644 --- a/src/keywords.js +++ b/src/keywords.js @@ -41,7 +41,6 @@ foounit.addKeyword('after', function (func){ group.setAfter(func); }); - /** * Defines a group in the BuildContext */ @@ -57,6 +56,24 @@ foounit.addKeyword('describe', function (description, builder){ context.setCurrentGroup(parentGroup); }); +/* + * Defines a pending group in the BuildContext. + * All examples and nested groups within this group will + * be marked as pending. + */ +foounit.addKeyword('xdescribe', function (description, builder){ + var context = foounit.getBuildContext() + , parentGroup = context.getCurrentGroup() + , group = new foounit.ExampleGroup(description, builder, true); + + parentGroup.addGroup(group); + + context.setCurrentGroup(group); + group.build(); + context.setCurrentGroup(parentGroup); + return group; +}); + /** * Creates a foounit.Expectation */