diff --git a/README.md b/README.md index 1b176f1..f9126c7 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,17 @@ hooks.after('GET /machines -> 200', function(test, done) { console.log(machine.name); done(); }); + +hooks.before('GET /machines -> 200 second test case', function(test, done) { + test.request.query = {color: 'red'}; + done(); +}); + +hooks.after('GET /machines -> 200' second test case, function(test, done) { + machine = test.response.body[0]; + console.log(machine.name); + done(); +}); ``` Write a hookfile in **CoffeeScript**: diff --git a/lib/test-runner.coffee b/lib/test-runner.coffee index 9733883..e158b30 100644 --- a/lib/test-runner.coffee +++ b/lib/test-runner.coffee @@ -61,7 +61,18 @@ class TestRunner test.request.server = server _.extend(test.request.headers, options.header) - addTestToMocha test, hooks + regex = new RegExp('^' + test.name, 'i') + found = false + _.each _.keys(hooks.beforeHooks), (key) -> + if regex.test(key) + newTest = _.clone(test) + newTest.name = key + addTestToMocha newTest, hooks + found = true + return + + if !found + addTestToMocha test, hooks done() , callback , # Run mocha