 
   describe 'serialize()', () ->
 
-    before (done) ->
+    before () ->
       @testFunc = (arg) -> "Hello #{arg}!"
       @serializedTestFunc = funcster.serialize(@testFunc)
-      done()
-
-    it 'should wrap a function in an object', (done) ->
+
+    it 'should wrap a function in an object', () ->
       _.keys(@serializedTestFunc).should.eql [ '__js_function' ]
-      done()
-
-    it 'should serialize the function to a string', (done) ->
+
+    it 'should serialize the function to a string', () ->
       @serializedTestFunc.__js_function.should.eql @testFunc.toString()
-      done()
-
-    it 'should allow for custom serialization markers', (done) ->
+
+    it 'should allow for custom serialization markers', () ->
       serialzed = funcster.serialize(@testFunc, 'CUSTOM_MARKER')
       _.keys(serialzed).should.eql [ 'CUSTOM_MARKER' ]
-      done()
 
   describe 'deepSerialize()', () ->
 
-    before (done) ->
+    before () ->
       @original =
         arr: [
           (arg) -> "Hello #{arg}!"

          ]
          z: 'just a string!'
      @serialized = funcster.deepSerialize(@original)
      done()

    it 'should serialize deeply nested functions', (done) ->
      @serialized.arr[0].__js_function.should.eql @original.arr[0].toString()
      @serialized.arr[3].__js_function.should.eql @original.arr[3].toString()
      @serialized.arr[4].foobar.__js_function.should.eql @original.arr[4].foobar.toString()
      @serialized.obj.a[0].b.c.__js_function.should.eql @original.obj.a[0].b.c.toString()
      done()

    it 'should retain non-function values', (done) ->
      @serialized.arr[1].should.eql 'hello!'
      @serialized.arr[2].should.eql 1
      @serialized.arr[4].foo.should.eql 'bar'
      @serialized.obj.z.should.eql 'just a string!'
      done()

  describe '_deepSelectSerializations()', () ->

    before (done) ->
      @selected = funcster._deepSelectSerializations(@serialized)
      done()

    it 'should collect all serialized functions', (done) ->
      @selected.length.should.eql 4
      done()

    it 'should set paths correctly', (done) ->
      @selected[0].path.should.eql [ 'arr', '0' ]
      @selected[1].path.should.eql [ 'arr', '3' ]
      @selected[2].path.should.eql [ 'arr', '4', 'foobar' ]
      @selected[3].path.should.eql [ 'obj', 'a', '0', 'b', 'c' ]
      done()

  describe '_generateModuleScript()', () ->

    it 'should encode functions into a text script', (done) ->
      functions =
        'func_a': 'function(arg) { return arg; }'
        'func_b': 'function(arg) { return [ arg ]; }'

      script = funcster._generateModuleScript(functions)
      script.should.eql 'module.exports=(function(global,module,exports){return{func_a: function(arg) { return arg; },func_b: function(arg) { return [ arg ]; }};})();'

      done()

  describe '_generateModule()', () ->

    it 'should export objects', (done) ->
      func = (arg) -> "Hello #{arg}!"
      script = "module.exports = { foo: #{func.toString()} }"
      moduleObj = funcster._generateModule(script)
      (moduleObj?).should.eql true
      (moduleObj.foo?).should.eql true
      moduleObj.foo('world').should.eql 'Hello world!'
      done()

    it 'should not include typical node.js globals by default', (done) ->
      objects = [ 'process', 'require', 'setTimeout', 'clearTimeout',
        'setInterval', 'clearInterval', 'console', 'Buffer', '__filename',
        '__dirname' ]
      functions = []

      moduleObj.String(new String).should.eql true
      moduleObj.Function(() ->).should.eql true
      moduleObj.Date(new Date).should.eql true

  describe 'deepDeserialize()', () ->

    before () ->
      @original =
        arr: [
          (arg) -> "Hello #{arg}!"
