Dan Dirks committed 1acadfa

Creates new zombie-world-mock.

In order to test acceptance without actually interacting with our world,
the world needed to be mocked out. The way this is done is a little
strange, but it is overriding the require cache so that we can control
what is returned by require('zombie-world'). It will still return the
production code, but it also has a mock tied to it. This mock allows for
overriding individual methods within the world so that we can control
what they do.

Also adds dependency on sinon, as that is our mocking library.

  • Participants
  • Parent commits 4e72b78

Comments (0)

Files changed (3)

File package.json

   "devDependencies" : {
     "coffee-script": ">=1.5.0",
-    "mocha": "latest"
+    "mocha": "latest",
+    "sinon": "latest"
   "engines": {
     "node": ">=0.6",

File test/mocks/

 class ZombieBrowserMock
   constructor: ->
-    console.log('do something...')
 require.cache[require.resolve('zombie')] =

File test/mocks/

+#this file is incredibly messy... should probably figure out a better way of handling this...
+#require our mock library
+sinon = require('sinon')
+#replace the default zombie used in files with a mocked version
+#find the path used to require zombie-world in production code
+worldPath = require.resolve('../../lib/worlds/zombie-world')
+#delete the cached version of this file
+delete require.cache[worldPath]
+#load in the real production world
+realWorld = require(worldPath).World
+mock = null
+#replace the cached version of the production world with our mocked version
+require.cache[worldPath] =
+  exports:
+    World: (callback) ->
+      #call the production code
+ @, =>
+        #create a mock for the production code and put it in module.exports
+        mock = sinon.mock(@)
+        #call our callback
+        callback()
+#expose the mock to the rest of the world to read
+Object.defineProperty module.exports, 'mock',
+  get: ->
+    return mock