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('
' + html + '
'); + var specThis = { + testWindow: window, + testDocument: lastDocument + }; + step.fn.call(specThis, callback || noop); + }; + }); + + describe("input", function() { + + var input = angular.scenario.dsl.input; + it('should enter', function() { + input('name').enter('John'); + expect(lastStep.name).toEqual("Set input text of 'name' to 'John'"); + executeStep(lastStep, ''); + expect(lastDocument.find('input').val()).toEqual('John'); + }); + + it('should select', function() { + input('gender').select('female'); + expect(lastStep.name).toEqual("Select radio 'gender' to 'female'"); + executeStep(lastStep, '' + + ''); + expect(lastDocument.find(':radio:checked').val()).toEqual('female'); + }); + }); +}); \ No newline at end of file -- cgit v1.2.3 From 4fec828cf6ce896452945c1dd8aa2db61e2bc746 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Tue, 25 May 2010 09:52:52 -0700 Subject: appended lastDocument to the document.body --- test/scenario/DSLSpec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/scenario') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 3c16876d..bed1f008 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -11,6 +11,7 @@ describe("DSL", function() { }; executeStep = function(step, html, callback) { lastDocument =_jQuery('
' + html + '
'); + _jQuery(document.body).append(lastDocument); var specThis = { testWindow: window, testDocument: lastDocument @@ -32,8 +33,10 @@ describe("DSL", function() { it('should select', function() { input('gender').select('female'); expect(lastStep.name).toEqual("Select radio 'gender' to 'female'"); - executeStep(lastStep, '' + + executeStep(lastStep, + '' + ''); + expect(lastDocument.find(':radio:checked').length).toEqual(1); expect(lastDocument.find(':radio:checked').val()).toEqual('female'); }); }); -- cgit v1.2.3 From fe03ea0d1f8814817bee5a35d745db16858eb490 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 12:35:40 -0700 Subject: add repeater DSL and fix typo --- test/scenario/DSLSpec.js | 14 +++++++++++++- test/scenario/RunnerSpec.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'test/scenario') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index bed1f008..0cce7b75 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -40,4 +40,16 @@ describe("DSL", function() { expect(lastDocument.find(':radio:checked').val()).toEqual('female'); }); }); -}); \ No newline at end of file + + describe('expect', function() { + var dslExpect = angular.scenario.dsl.expect; + describe('repeater', function() { + it('should check the count of repeated elements', function() { + dslExpect.repeater('.repeater-row').count.toEqual(2); + expect(lastStep.name).toEqual("Expect to see 2 items repeated with selector '.repeater-row'"); + var html = "
a
b
"; + executeStep(lastStep, html); + }); + }); + }); +}); diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 35d74f51..030bdc06 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -36,7 +36,7 @@ describe('Runner', function(){ expect(spec.name).toEqual('describe name: it should text'); }); - it('should camplain on duplicate it', angular.noop); + it('should complain on duplicate it', angular.noop); it('should create a failing step if there is a javascript error', function(){ var spec; Describe('D1', function(){ -- cgit v1.2.3 From f6a405c283ba1f2e0037e0bedb52e5cee618d4ff Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 13:30:54 -0700 Subject: change repeater count expectation wording --- test/scenario/DSLSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/scenario') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 0cce7b75..5aac9752 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -46,7 +46,7 @@ describe("DSL", function() { describe('repeater', function() { it('should check the count of repeated elements', function() { dslExpect.repeater('.repeater-row').count.toEqual(2); - expect(lastStep.name).toEqual("Expect to see 2 items repeated with selector '.repeater-row'"); + expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'"); var html = "
a
b
"; executeStep(lastStep, html); }); -- cgit v1.2.3 From 85fac4d78c131771d7fdd46d6ccd44bae92419cd Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 14:12:54 -0700 Subject: add beforeEach and afterEach to scenario DSL --- test/scenario/RunnerSpec.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'test/scenario') 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('
'); 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(){ -- cgit v1.2.3