cloudhead/vows — Issue #197: Tests in vows should not share state
Author: joeandaverde
Created: 2012-02-22 20:18:41+00:00
State: open

When starting with vows I wrote tests that build on parent topics. However, I noticed that all of my tests shared state. The shared state was unexpected. After reviewing the documentation on Vows I realized this was intentional because of the statement, "topics are only run once". My proposal is that topics are re-run for each test in order to facilitate BDD. Here's an example of a few tests I expected to work.

````
vows.describe('User (models/user)').addBatch(
'When creating a user model':
topic: () ->
new User()

'and a brand new credential is added':
topic: () ->
user.setCredential 'twitter', 1865
user

'it should add the credential': (user) ->
assert.equal user.attributes.credentials.length, 1
assert.equal user.attributes.credentials[0].provider, 'twitter'
assert.equal user.attributes.credentials[0].id, 1865

'and the same credential is added again with a different id':
topic: (user) ->
user.setCredential 'twitter', 1234
user

'it should override the existing value': (user) ->
assert.equal user.attributes.credentials.length, 1
assert.equal user.attributes.credentials[0].provider, 'twitter'
assert.equal user.attributes.credentials[0].id, 1234

'and the same credential is added with different casing':
topic: (user) ->
user.setCredential 'Twitter', 1234
user

'it should override the existing value': (user) ->
assert.equal user.attributes.credentials.length, 1
assert.equal user.attributes.credentials[0].provider, 'twitter'
assert.equal user.attributes.credentials[0].id, 1234

'and a completely different credential is added':
topic: (user) ->
user.setCredential 'github', 100
user

'it should be appended to the credentials': (user) ->
assert.equal user.attributes.credentials.length, 2
assert.equal user.attributes.credentials[1].provider, 'github'
````