Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

Commit

Permalink
Add the ability to report duplicate IDs
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
JohanLorenzo committed May 25, 2015
1 parent 45cda10 commit fefa198
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/model/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ function Testcase(id, instructions, state, bug, userStory, variables) {
if (Testcase._isOptionalFieldDefined(variables)) {
this.variables = variables;
}

Testcase.alreadyDefinedIds.push(this.id);
}

Testcase.alreadyDefinedIds = [];

Testcase.isValidState = function(candidate) {
return VALID_STATES.indexOf(candidate) !== -1;
};
Expand All @@ -32,6 +36,8 @@ Testcase._sanitizeId = function(candidate) {
} finally {
if (!/^[A-Za-z_.]+$/.test(candidate)) {
errorHandler.add(new Error('"' + candidate + '" should contains only letters, dots, and underscores'));
} else if (Testcase.alreadyDefinedIds.indexOf(candidate) > -1) {
errorHandler.add(new Error('The id "' + candidate + '" is already used'));
}
return candidate;
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/model/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Testcase parser', function () {

beforeEach(function() {
object = {};
Testcase.alreadyDefinedIds.length = 0;
});

it('should accept all attributes', function() {
Expand Down Expand Up @@ -71,6 +72,11 @@ describe('Testcase parser', function () {
var testcase = new Testcase('id', 'instructions');
assert.isUndefined(testcase.variables);
});

it('should push the id to the array of already defined Ids', function() {
new Testcase('newId', 'instructions');
assert.include(Testcase.alreadyDefinedIds, 'newId');
});
});

describe('isValidState()', function() {
Expand Down Expand Up @@ -113,6 +119,12 @@ describe('Testcase parser', function () {
Testcase._sanitizeId('fxos test');
sinon.assert.calledWith(addMock, new Error('"fxos test" should contains only letters, dots, and underscores'));
});

it('should add an error if the id is already defined', function() {
new Testcase('dupeId', 'instructions');
Testcase._sanitizeId('dupeId');
sinon.assert.calledWith(addMock, new Error('The ID "newId" is already used'));
});
});

describe('_sanitizeString()', function() {
Expand Down

0 comments on commit fefa198

Please sign in to comment.