Skip to content

Commit

Permalink
multiple test cases for same endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferry Lauda Halwa committed Aug 26, 2015
1 parent 393a37f commit b6c79e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down
13 changes: 12 additions & 1 deletion lib/test-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6c79e1

Please sign in to comment.