visionmedia/mocha — Issue #227: pass args in done()
Author: johnnywengluu
Created: 2012-01-20 20:27:42+00:00
State: open

Instead of declaring global variables why not just pass the variables in done() (similar to how Async and Vows works).

Eg instead of this:

describe '#resetDatabase()', ->

response = null

beforeEach (done) ->
db.resetDatabase ->
query = """
START indexedNode = node:groups(name = "Organizations")
RETURN indexedNode.name
"""

dbHttp.cypher {url, query}, (err, res) ->
if err is null
response = res
done null

it 'should create an indexed node', (done) ->

response.data[0][0].should.equal "Organizations"
done()

We do like this:

describe '#resetDatabase()', ->

beforeEach (done) ->
db.resetDatabase ->
query = """
START indexedNode = node:groups(name = "Organizations")
RETURN indexedNode.name
"""

dbHttp.cypher {url, query}, (err, res) ->
if err is null then done null, res

it 'should create an indexed node', (res, done) ->

res.data[0][0].should.equal "Organizations"
done()

This could be written like:

describe '#resetDatabase()', ->

beforeEach (done) ->
db.resetDatabase ->
query = """
START indexedNode = node:groups(name = "Organizations")
RETURN indexedNode.name
"""

dbHttp.cypher {url, query}, done

it 'should create an indexed node', (res, done) ->

res.data[0][0].should.equal "Organizations"
done()

In this way we don't need to declare global variables and it makes much more sense.