why won't redis commands work from within my mocha test for coffee script files?

class ThingWithRedis
  constructor: (@config) ->
    @redis = require('redis').createClient()

  push: (key, object) ->
    @redis.set(key, object)
  fetch: (key, amount) ->
    @redis.get key, (err, replies) ->
      console.log "|#{replies}|"

module.exports = ThingWithRedis

#if you uncomment these lines and run this file, redis works

#twr = new ThingWithRedis('some config value')
#twr.push('key1', 'hello2')
#twr.fetch('key1', 1)
#twr.redis.quit()

but from the test:

ThingWithRedis = require '../thing_with_redis'

assert = require('assert')

describe 'ThingWithRedis', ->
  it 'should return the state pushed on', ->

    twr = new ThingWithRedis('config')
    twr.push('key1', 'hello1')
    twr.fetch('key1', 1)

    assert.equal(1, 1)

you never see 'hello1' be printed.

but when I run coffee thing_with_redis.coffee directly with the bottom lines un-commented you do see 'hello2' printed.

it's when I run:

mocha --compilers coffee:coffee-script

redis seems to just stop working. Any ideas?

i gave up on mocha and moved to jasmine with this article:

http://braddickason.com/jasmine-and-nodejs-testing/

It is possible that the Redis connection has not yet been established. Try waiting for the 'ready' event before running your tests.

describe 'ThingWithRedis', ->
  it 'should return the state pushed on', ->

    twr = new ThingWithRedis('config')
    twr.redis.on 'ready', ->
      twr.push('key1', 'hello1')
      twr.fetch('key1', 1)

It is important to note that node_redis adds commands called before the 'ready' event to a queue and then processes them when the connection is established. It is possible that mocha is exiting before redis is 'ready'.

https://github.com/mranney/node_redis#ready