 CLI          = require '../lib/cli'
 pkg          = require('../package.json')
 EventEmitter = require('events').EventEmitter
+util         = require 'util'
 
 cli = new CLI(debug: true)
 test_tpl_path = 'https://github.com/jenius/sprout-test-template.git'
 
 describe 'cli', ->
 
-  before -> mockery.enable(warnOnUnregistered: false)
+  before -> mockery.enable(warnOnUnregistered: false, useCleanCache: true)
   after -> mockery.disable()
 
   it 'should throw if no arguments are provided', ->


    it 'should error when trying to compile invalid code'

    describe 'watch environments', ->
      before ->
        @spy = sinon.spy(global, 'Roots')
        mockery.registerMock('../../lib', Roots)

      after ->
        @spy.restore()
        mockery.deregisterAll()

      it 'watch should handle environments args correctly', (done) ->
        env = 'doge'
        p   = path.join(__dirname, 'fixtures/compile/environments')
        cli.run("watch #{p} --env #{env}")
          .done =>
            @spy.args[0][1].env.should.equal(env)
            done()

  describe 'clean', ->

    it 'should remove the output folder', (done) ->

    cli.run("compile #{broken_ext_path}")

  it 'should correctly log other thrown errors', (done) ->
    mockery.resetCache()
    stub = sinon.stub(Roots.prototype, 'compile').returns([])
    mockery.registerMock('../../lib', Roots)

    cb = (err) ->
      err.toString().should.equal("TypeError: Object  has no method 'then'")
