aboutsummaryrefslogtreecommitdiffstats
path: root/test/scenario
diff options
context:
space:
mode:
Diffstat (limited to 'test/scenario')
-rw-r--r--test/scenario/DescribeSpec.js10
-rw-r--r--test/scenario/ObjectModelSpec.js257
-rw-r--r--test/scenario/output/HtmlSpec.js5
-rw-r--r--test/scenario/output/jsonSpec.js5
-rw-r--r--test/scenario/output/objectSpec.js5
-rw-r--r--test/scenario/output/xmlSpec.js5
6 files changed, 260 insertions, 27 deletions
diff --git a/test/scenario/DescribeSpec.js b/test/scenario/DescribeSpec.js
index 6fcee731..0322b2d4 100644
--- a/test/scenario/DescribeSpec.js
+++ b/test/scenario/DescribeSpec.js
@@ -107,4 +107,14 @@ describe('angular.scenario.Describe', function() {
var b = new angular.scenario.Describe();
expect(a.id).toNotEqual(b.id);
});
+
+ it('should create uniqueIds for each spec', function() {
+ var d = new angular.scenario.Describe();
+ d.it('fake', function() {});
+ d.it('fake', function() {});
+
+ expect(d.its[0].id).toBeDefined();
+ expect(d.its[1].id).toBeDefined();
+ expect(d.its[0].id).not.toEqual(d.its[1].id);
+ });
});
diff --git a/test/scenario/ObjectModelSpec.js b/test/scenario/ObjectModelSpec.js
index 8b83a52f..cb84b33f 100644
--- a/test/scenario/ObjectModelSpec.js
+++ b/test/scenario/ObjectModelSpec.js
@@ -3,18 +3,36 @@ describe('angular.scenario.ObjectModel', function() {
var runner;
var spec, step;
- beforeEach(function() {
- spec = {
- name: 'test spec',
+ function buildSpec(id, name, definitions) {
+ var spec = {
+ id: id,
+ name: name,
definition: {
- id: 10,
- name: 'describe 1'
+ name: definitions.shift()
}
};
- step = {
- name: 'test step',
- line: function() { return ''; }
+ var currentDef = spec.definition;
+
+ forEach(definitions, function(defName) {
+ currentDef.parent = {
+ name: defName
+ };
+ currentDef = currentDef.parent;
+ });
+
+ return spec;
+ }
+
+ function buildStep(name, line) {
+ return {
+ name: name || 'test step',
+ line: function() { return line || ''; }
};
+ }
+
+ beforeEach(function() {
+ spec = buildSpec(1, 'test spec', ['describe 1']);
+ step = buildStep();
runner = new angular.scenario.testing.MockRunner();
model = new angular.scenario.ObjectModel(runner);
});
@@ -27,23 +45,28 @@ describe('angular.scenario.ObjectModel', function() {
});
it('should add spec and create describe blocks on SpecBegin event', function() {
- runner.emit('SpecBegin', {
- name: 'test spec',
- definition: {
- id: 10,
- name: 'describe 2',
- parent: {
- id: 12,
- name: 'describe 1'
- }
- }
- });
+ runner.emit('SpecBegin', buildSpec(1, 'test spec', ['describe 2', 'describe 1']));
expect(model.value.children['describe 1']).toBeDefined();
expect(model.value.children['describe 1'].children['describe 2']).toBeDefined();
expect(model.value.children['describe 1'].children['describe 2'].specs['test spec']).toBeDefined();
});
+ it('should set fullDefinitionName on SpecBegin event', function() {
+ runner.emit('SpecBegin', buildSpec(1, 'fake spec', ['describe 2']));
+ var spec = model.getSpec(1);
+
+ expect(spec.fullDefinitionName).toBeDefined();
+ expect(spec.fullDefinitionName).toEqual('describe 2');
+ });
+
+ it('should set fullDefinitionName on SpecBegin event (join more names by space)', function() {
+ runner.emit('SpecBegin', buildSpec(1, 'fake spec', ['describe 2', 'describe 1']));
+ var spec = model.getSpec(1);
+
+ expect(spec.fullDefinitionName).toEqual('describe 1 describe 2');
+ });
+
it('should add step to spec on StepBegin', function() {
runner.emit('SpecBegin', spec);
runner.emit('StepBegin', spec, step);
@@ -109,4 +132,200 @@ describe('angular.scenario.ObjectModel', function() {
expect(model.value.children['describe 1'].specs['test spec'].status).toEqual('error');
});
+
+ describe('events', function() {
+ var Spec = angular.scenario.ObjectModel.Spec,
+ Step = angular.scenario.ObjectModel.Step,
+ callback;
+
+ beforeEach(function() {
+ callback = jasmine.createSpy('listener');
+ });
+
+ it('should provide method for registering a listener', function() {
+ expect(model.on).toBeDefined();
+ expect(model.on instanceof Function).toBe(true);
+ });
+
+ it('should forward SpecBegin event', function() {
+ model.on('SpecBegin', callback);
+ runner.emit('SpecBegin', spec);
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward SpecBegin event with ObjectModel.Spec as a param', function() {
+ model.on('SpecBegin', callback);
+ runner.emit('SpecBegin', spec);
+
+ expect(callback.mostRecentCall.args[0] instanceof Spec).toBe(true);
+ expect(callback.mostRecentCall.args[0].name).toEqual(spec.name);
+ });
+
+ it('should forward SpecError event', function() {
+ model.on('SpecError', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('SpecError', spec, {});
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward SpecError event with ObjectModel.Spec and error as a params', function() {
+ var error = {};
+ model.on('SpecError', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('SpecError', spec, error);
+
+ var param = callback.mostRecentCall.args[0];
+ expect(param instanceof Spec).toBe(true);
+ expect(param.name).toEqual(spec.name);
+ expect(param.status).toEqual('error');
+ expect(param.error).toBe(error);
+ });
+
+ it('should forward SpecEnd event', function() {
+ model.on('SpecEnd', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('SpecEnd', spec);
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward SpecEnd event with ObjectModel.Spec as a param', function() {
+ model.on('SpecEnd', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('SpecEnd', spec);
+
+ expect(callback.mostRecentCall.args[0] instanceof Spec).toBe(true);
+ expect(callback.mostRecentCall.args[0].name).toEqual(spec.name);
+ });
+
+ it('should forward StepBegin event', function() {
+ model.on('StepBegin', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward StepBegin event with Spec and Step as params', function() {
+ model.on('StepBegin', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+
+ var params = callback.mostRecentCall.args;
+ expect(params[0] instanceof Spec).toBe(true);
+ expect(params[0].name).toEqual(spec.name);
+ expect(params[1] instanceof Step).toBe(true);
+ });
+
+ it('should forward StepError event', function() {
+ model.on('StepError', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepError', spec, step, {});
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward StepError event with Spec, Step and error as params', function() {
+ var error = {};
+ model.on('StepError', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepError', spec, step, error);
+
+ var params = callback.mostRecentCall.args;
+ expect(params[0] instanceof Spec).toBe(true);
+ expect(params[0].name).toEqual(spec.name);
+ expect(params[1] instanceof Step).toBe(true);
+ expect(params[1].status).toEqual('error');
+ expect(params[2]).toBe(error);
+ });
+
+ it('should forward StepFailure event', function() {
+ model.on('StepFailure', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepFailure', spec, step, {});
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward StepFailure event with Spec, Step and error as params', function() {
+ var error = {};
+ model.on('StepFailure', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepFailure', spec, step, error);
+
+ var params = callback.mostRecentCall.args;
+ expect(params[0] instanceof Spec).toBe(true);
+ expect(params[0].name).toEqual(spec.name);
+ expect(params[1] instanceof Step).toBe(true);
+ expect(params[1].status).toEqual('failure');
+ expect(params[2]).toBe(error);
+ });
+
+ it('should forward StepEnd event', function() {
+ model.on('StepEnd', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepEnd', spec, step);
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should forward StepEnd event with Spec and Step as params', function() {
+ model.on('StepEnd', callback);
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepEnd', spec, step);
+
+ var params = callback.mostRecentCall.args;
+ expect(params[0] instanceof Spec).toBe(true);
+ expect(params[0].name).toEqual(spec.name);
+ expect(params[1] instanceof Step).toBe(true);
+ });
+
+ it('should forward RunnerEnd event', function() {
+ model.on('RunnerEnd', callback);
+ runner.emit('RunnerEnd');
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should set error of first failure', function() {
+ var error = 'first-error',
+ step2 = buildStep();
+
+ model.on('SpecEnd', function(spec) {
+ expect(spec.error).toBeDefined();
+ expect(spec.error).toBe(error);
+ });
+
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepFailure', spec, step, error);
+ runner.emit('StepBegin', spec, step2);
+ runner.emit('StepFailure', spec, step2, 'second-error');
+ runner.emit('SpecEnd', spec);
+ });
+
+ it('should set line number of first failure', function() {
+ var step = buildStep('fake', 'first-line'),
+ step2 = buildStep('fake2', 'second-line');
+
+ model.on('SpecEnd', function(spec) {
+ expect(spec.line).toBeDefined();
+ expect(spec.line).toBe('first-line');
+ });
+
+ runner.emit('SpecBegin', spec);
+ runner.emit('StepBegin', spec, step);
+ runner.emit('StepFailure', spec, step, null);
+ runner.emit('StepBegin', spec, step2);
+ runner.emit('StepFailure', spec, step2, null);
+ runner.emit('SpecEnd', spec);
+ });
+ });
});
diff --git a/test/scenario/output/HtmlSpec.js b/test/scenario/output/HtmlSpec.js
index f973397e..6694bb45 100644
--- a/test/scenario/output/HtmlSpec.js
+++ b/test/scenario/output/HtmlSpec.js
@@ -1,5 +1,5 @@
describe('angular.scenario.output.html', function() {
- var runner, spec, listeners;
+ var runner, model, spec, listeners;
var ui, context;
beforeEach(function() {
@@ -22,8 +22,9 @@ describe('angular.scenario.output.html', function() {
line: function() { return 'unknown:-1'; }
};
runner = new angular.scenario.testing.MockRunner();
+ model = new angular.scenario.ObjectModel(runner);
context = _jQuery("<div></div>");
- ui = angular.scenario.output.html(context, runner);
+ ui = angular.scenario.output.html(context, runner, model);
});
it('should create nested describe context', function() {
diff --git a/test/scenario/output/jsonSpec.js b/test/scenario/output/jsonSpec.js
index afc74a21..2c56b297 100644
--- a/test/scenario/output/jsonSpec.js
+++ b/test/scenario/output/jsonSpec.js
@@ -1,13 +1,14 @@
describe('angular.scenario.output.json', function() {
var output, context;
- var runner, $window;
+ var runner, model, $window;
var spec, step;
beforeEach(function() {
$window = {};
context = _jQuery('<div></div>');
runner = new angular.scenario.testing.MockRunner();
- output = angular.scenario.output.json(context, runner);
+ model = new angular.scenario.ObjectModel(runner);
+ output = angular.scenario.output.json(context, runner, model);
spec = {
name: 'test spec',
definition: {
diff --git a/test/scenario/output/objectSpec.js b/test/scenario/output/objectSpec.js
index 73c3dcf9..9fc2f7d4 100644
--- a/test/scenario/output/objectSpec.js
+++ b/test/scenario/output/objectSpec.js
@@ -1,13 +1,14 @@
describe('angular.scenario.output.object', function() {
var output;
- var runner, $window;
+ var runner, model, $window;
var spec, step;
beforeEach(function() {
$window = {};
runner = new angular.scenario.testing.MockRunner();
+ model = new angular.scenario.ObjectModel(runner);
runner.$window = $window;
- output = angular.scenario.output.object(null, runner);
+ output = angular.scenario.output.object(null, runner, model);
spec = {
name: 'test spec',
definition: {
diff --git a/test/scenario/output/xmlSpec.js b/test/scenario/output/xmlSpec.js
index fbfabcc4..a0e92639 100644
--- a/test/scenario/output/xmlSpec.js
+++ b/test/scenario/output/xmlSpec.js
@@ -1,13 +1,14 @@
describe('angular.scenario.output.json', function() {
var output, context;
- var runner, $window;
+ var runner, model, $window;
var spec, step;
beforeEach(function() {
$window = {};
context = _jQuery('<div></div>');
runner = new angular.scenario.testing.MockRunner();
- output = angular.scenario.output.xml(context, runner);
+ model = new angular.scenario.ObjectModel(runner);
+ output = angular.scenario.output.xml(context, runner, model);
spec = {
name: 'test spec',
definition: {