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()
しかし、テストから:
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)
「hello1」が表示されることはありません。
しかし、コーヒーのthing_with_redis.coffeeをコメントなしで直接実行すると、「hello2」が表示されます。
それは私が実行したときです:
mocha --compilers coffee:coffee-script
redis が機能しなくなったようです。何か案は?