From 39c6c5975bedf6e1610f7328a088acda9ab3406a Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Mon, 15 Mar 2010 17:02:54 -0700 Subject: get scenarios running again - open Runner.html in a browser to run them --- test/scenario/StepsTest.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/scenario/StepsTest.js (limited to 'test/scenario') diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js new file mode 100644 index 00000000..9d64d0a9 --- /dev/null +++ b/test/scenario/StepsTest.js @@ -0,0 +1,7 @@ +StepsTest = TestCase("StepsTest"); + +StepsTest.prototype.testGivenDataset=function(){ + var self = {frame:{}, dataset:[]}; + angular.test.GIVEN.dataset.call(self); + assertEquals('$DATASET:{"dataset":[]}', self.frame.name); +}; -- cgit v1.2.3 From c9aba8b442adce496f0600c88764f7ffcc166879 Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Tue, 16 Mar 2010 14:48:11 -0700 Subject: make xhr just a method --- test/scenario/StepsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/scenario') diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js index 9d64d0a9..32ef637d 100644 --- a/test/scenario/StepsTest.js +++ b/test/scenario/StepsTest.js @@ -2,6 +2,6 @@ StepsTest = TestCase("StepsTest"); StepsTest.prototype.testGivenDataset=function(){ var self = {frame:{}, dataset:[]}; - angular.test.GIVEN.dataset.call(self); + angular.scenario.GIVEN.dataset.call(self); assertEquals('$DATASET:{"dataset":[]}', self.frame.name); }; -- cgit v1.2.3 From 5215e2095cfd42a0363eb02eded34e03fa2b0cd3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 20 May 2010 15:55:41 -0700 Subject: basic end to end runner --- test/scenario/RunnerSpec.js | 105 ++++++++++++++++++++++++++++++++++++++++++++ test/scenario/StepsTest.js | 7 --- 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 test/scenario/RunnerSpec.js delete mode 100644 test/scenario/StepsTest.js (limited to 'test/scenario') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js new file mode 100644 index 00000000..bd7c0599 --- /dev/null +++ b/test/scenario/RunnerSpec.js @@ -0,0 +1,105 @@ +describe('Runner', function(){ + var scenario, runner, log, Describe, It, $scenario; + + function logger(text) { + return function(){log += text;}; + } + + beforeEach(function(){ + log = ''; + scenario = {}; + runner = new angular.scenario.Runner(scenario); + Describe = scenario.describe; + It = scenario.it; + $scenario = scenario.$scenario; + }); + + describe('describe', function(){ + it('should consume the describe functions', function(){ + Describe('describe name', logger('body')); + + expect(log).toEqual('body'); + }); + + describe('it', function(){ + it('should consume it', function(){ + Describe('describe name', function(){ + It('should text', logger('body')); + }); + expect(log).toEqual('body'); + var spec = $scenario.specs['describe name: it should text']; + expect(spec.steps).toEqual([]); + expect(spec.name).toEqual('describe name: it should text'); + }); + }); + }); + + describe('steps building', function(){ + it('should queue steps', function(){ + function step(){}; + Describe('name', function(){ + It('should', function(){ + $scenario.addStep('stepname', step); + }); + }); + expect($scenario.specs['name: it should'].steps).toEqual([{name:'stepname', fn:step}]); + }); + }); + + describe('execution', function(){ + it('should execute the queued steps', function(){ + var next, firstThis, secondThis, doneThis, spec; + $scenario.specs['spec'] = { + steps: [ + {name:'step1', fn: function(done) { + next = done; + log += 'first;'; + firstThis = this; + }}, + {name:'step2', fn:function(done){ + next = done; + log += 'second;'; + secondThis = this; + }} + ] + }; + + spec = $scenario.execute('spec', function(done){ + log += 'done;'; + doneThis = this; + }); + expect(log).toEqual('first;'); + next(); + expect(log).toEqual('first;second;'); + next(); + expect(log).toEqual('first;second;done;'); + expect(spec).not.toEqual(window); + expect(spec).toEqual(firstThis); + expect(spec).toEqual(secondThis); + expect(spec).toEqual(doneThis); + + expect(spec.result.failed).toEqual(false); + expect(spec.result.finished).toEqual(true); + expect(spec.result.error).toBeUndefined(); + expect(spec.result.passed).toEqual(true); + }); + + it('should handle exceptions in a step', function(){ + $scenario.specs['spec'] = { + steps: [ + {name:'error', fn:function(done) { + throw "MyError"; + }} + ] + }; + + var spec = $scenario.execute('spec'); + + expect(spec.result.passed).toEqual(false); + expect(spec.result.failed).toEqual(true); + expect(spec.result.finished).toEqual(true); + expect(spec.result.error).toEqual("MyError"); + }); + }); + +}); \ No newline at end of file diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js deleted file mode 100644 index 32ef637d..00000000 --- a/test/scenario/StepsTest.js +++ /dev/null @@ -1,7 +0,0 @@ -StepsTest = TestCase("StepsTest"); - -StepsTest.prototype.testGivenDataset=function(){ - var self = {frame:{}, dataset:[]}; - angular.scenario.GIVEN.dataset.call(self); - assertEquals('$DATASET:{"dataset":[]}', self.frame.name); -}; -- cgit v1.2.3 From e3368e12a6207706d8a08b18f9958db3b86ca4e5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 20 May 2010 16:55:47 -0700 Subject: semi working state --- test/scenario/RunnerSpec.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/scenario') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index bd7c0599..2883ab7c 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -31,6 +31,9 @@ describe('Runner', function(){ expect(spec.steps).toEqual([]); expect(spec.name).toEqual('describe name: it should text'); }); + + it('should camplain on duplicate it', angular.noop); + }); }); -- cgit v1.2.3 From f6c67e28c94033edf6a16eb6508de54679cb49db Mon Sep 17 00:00:00 2001 From: Andres Ornelas Mesta Date: Mon, 24 May 2010 13:54:32 -0700 Subject: happy --- test/scenario/RunnerSpec.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'test/scenario') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 2883ab7c..702e1ab5 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -1,14 +1,18 @@ describe('Runner', function(){ - var scenario, runner, log, Describe, It, $scenario; + var scenario, runner, log, Describe, It, $scenario, body; function logger(text) { - return function(){log += text;}; + return function(done){ + log += text; + (done||noop)(); + }; } beforeEach(function(){ log = ''; scenario = {}; - runner = new angular.scenario.Runner(scenario); + body = _jQuery('
'); + runner = new angular.scenario.Runner(scenario, _jQuery); Describe = scenario.describe; It = scenario.it; $scenario = scenario.$scenario; @@ -105,4 +109,28 @@ describe('Runner', function(){ }); }); + describe('run', function(){ + var next; + it('should execute all specs', function(){ + Describe('d1', function(){ + It('it1', function(){ $scenario.addStep('s1', logger('s1,')); }); + It('it2', function(){ + $scenario.addStep('s2', logger('s2,')); + $scenario.addStep('s2.2', function(done){ next = done; }); + }); + }); + Describe('d2', function(){ + It('it3', function(){ $scenario.addStep('s3', logger('s3,')); }); + It('it4', function(){ $scenario.addStep('s4', logger('s4,')); }); + }); + + $scenario.run(body); + + expect(log).toEqual('s1,s2,'); + next(); + expect(log).toEqual('s1,s2,s3,s4,'); + + }); + }); + }); \ No newline at end of file -- cgit v1.2.3 From 3fab5d9879272b9f991a67c8135754f00c055834 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Mon, 24 May 2010 15:25:30 -0700 Subject: added error handling on scenario definition --- test/scenario/RunnerSpec.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/scenario') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 702e1ab5..35d74f51 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -37,7 +37,23 @@ describe('Runner', function(){ }); it('should camplain on duplicate it', angular.noop); - + it('should create a failing step if there is a javascript error', function(){ + var spec; + Describe('D1', function(){ + It('I1', function(){ + spec = $scenario.currentSpec; + throw {message: 'blah'}; + }); + }); + var step = spec.steps[0]; + expect(step.name).toEqual('blah'); + try { + step.fn(); + fail(); + } catch (e) { + expect(e.message).toEqual('blah'); + }; + }); }); }); -- cgit v1.2.3 From 55c0767f16e60e77e9d1b4d46698ddbf343ed8b1 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Mon, 24 May 2010 17:48:17 -0700 Subject: added dsl tests and select method --- test/scenario/DSLSpec.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/scenario/DSLSpec.js (limited to 'test/scenario') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js new file mode 100644 index 00000000..3c16876d --- /dev/null +++ b/test/scenario/DSLSpec.js @@ -0,0 +1,40 @@ +describe("DSL", function() { + + var lastStep, executeStep, lastDocument; + + beforeEach(function() { + lastStep = null; + $scenario = { + addStep: function(name, stepFunction) { + lastStep = { name:name, fn: stepFunction}; + } + }; + executeStep = function(step, html, callback) { + lastDocument =_jQuery('