             expect(func()).toEqual(42);
 
 # start testing misc.coffee
+
+describe 'console.debug', =>
+    before =>
+        @debug_orig = global.DEBUG
+
+    after =>
+        global.DEBUG = @debug_orig
+
+    beforeEach =>
+        # console.debug is re-routed to console.log !
+        @console_log_stub = sinon.stub(global.console, "log")
+
+    afterEach =>
+        @console_log_stub.restore()
+
+    it 'does not debug when the global DEBUG flag is false', =>
+        global.DEBUG = false
+        console.debug("test 1")
+        @console_log_stub.notCalled.should.be.true()
+
+    it 'does log a debug message when the global DEBUG flag is true', =>
+        global.DEBUG = true
+        console.debug("test 2")
+        @console_log_stub.calledOnce.should.be.true()
+        @console_log_stub.getCall(0).args[0].should.be.eql "test 2"
+
 
 describe 'startswith', ->
     startswith = misc.startswith


            co[2].ref[0].should.be.eql d
            co[2].ref[1].should.be.eql r

describe "trunc", ->
    t = misc.trunc

        callback.getCall(1).args[0].should.eql "xyz"

    describe "sinon's stubs", ->
    # also see the test for console.debug /w the console.log stub below
        it "are working for withArgs", ->
            func = sinon.stub()
            func.withArgs(42).returns(1)
