diff options
| -rw-r--r-- | src/scenario/Runner.js | 15 | ||||
| -rw-r--r-- | test/scenario/RunnerSpec.js | 40 |
2 files changed, 52 insertions, 3 deletions
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js index da6e2c39..8e0cc909 100644 --- a/src/scenario/Runner.js +++ b/src/scenario/Runner.js @@ -8,23 +8,34 @@ angular.scenario.Runner = function(scope, jQuery){ var specs = this.specs = {}; var path = []; - this.scope.describe = function describe(name, body){ + this.scope.describe = function(name, body){ path.push(name); body(); path.pop(); }; - this.scope.it = function it(name, body) { + var beforeEach = noop; + var afterEach = noop; + this.scope.beforeEach = function(body) { + beforeEach = body; + }; + this.scope.afterEach = function(body) { + afterEach = body; + }; + this.scope.it = function(name, body) { var specName = path.join(' ') + ': it ' + name; self.currentSpec = specs[specName] = { name: specName, steps:[] }; try { + beforeEach(); body(); } catch(err) { self.addStep(err.message || 'ERROR', function(){ throw err; }); + } finally { + afterEach(); } self.currentSpec = null; }; diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 030bdc06..ca6e8eb2 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -14,6 +14,8 @@ describe('Runner', function(){ body = _jQuery('<div></div>'); runner = new angular.scenario.Runner(scenario, _jQuery); Describe = scenario.describe; + BeforeEach = scenario.beforeEach; + AfterEach = scenario.afterEach; It = scenario.it; $scenario = scenario.$scenario; }); @@ -36,7 +38,10 @@ describe('Runner', function(){ expect(spec.name).toEqual('describe name: it should text'); }); - it('should complain on duplicate it', angular.noop); + it('should complain on duplicate it', function() { + // WRITE ME!!!! + }); + it('should create a failing step if there is a javascript error', function(){ var spec; Describe('D1', function(){ @@ -55,6 +60,39 @@ describe('Runner', function(){ }; }); }); + + describe('beforeEach', function() { + it('should execute beforeEach before every it', function() { + Describe('describe name', function(){ + BeforeEach(logger('before;')); + It('should text', logger('body;')); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('before;body;before;body2;'); + }); + }); + describe('afterEach', function() { + it('should execute afterEach after every it', function() { + Describe('describe name', function(){ + AfterEach(logger('after;')); + It('should text', logger('body;')); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('body;after;body2;after;'); + }); + + it('should always execute afterEach after every it', function() { + Describe('describe name', function(){ + AfterEach(logger('after;')); + It('should text', function() { + log = 'body;'; + throw "MyError"; + }); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('body;after;body2;after;'); + }); + }); }); describe('steps building', function(){ |
