#1520 ospec: report duplicate test names

This commit is contained in:
Leo Horie 2017-01-08 13:05:27 -05:00
parent 3bac29bf78
commit 9ad16858a5
9 changed files with 16 additions and 61 deletions

View file

@ -4,7 +4,7 @@
Noiseless testing framework
Version: 1.2.2
Version: 1.2.3
License: MIT
## About

View file

@ -4,6 +4,7 @@ module.exports = new function init() {
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object"
function o(subject, predicate) {
subject = unique(subject, predicate)
ctx[subject] = predicate
if (predicate === undefined) return new Assert(subject)
}
@ -14,6 +15,7 @@ module.exports = new function init() {
o.new = init
o.spec = function(subject, predicate) {
var parent = ctx
subject = unique(subject, predicate)
ctx = ctx[subject] = {}
predicate()
ctx = parent
@ -110,6 +112,13 @@ module.exports = new function init() {
}
}
}
function unique(subject, predicate) {
if (ctx.hasOwnProperty(subject) && predicate) {
console.warn("A test named `" + subject + "` was already defined")
subject = subject + "*"
}
return subject
}
function hook(name) {
return function(predicate) {
if (ctx[name]) throw new Error("This hook should be defined outside of a loop or inside a nested test group:\n" + predicate)

View file

@ -1,6 +1,6 @@
{
"name": "ospec",
"version": "1.2.2",
"version": "1.2.3",
"description": "Noiseless testing framework",
"main": "ospec.js",
"directories": {