         spy.should.have.been.calledWith('analytics settings updated!')
         cli.removeListener('success', spy)
       .should.be.fulfilled
+
+  describe 'environments', ->
+    before ->
+      @spy = sinon.spy()
+      util.inherits(@spy, EventEmitter)
+      @spy.prototype.compile = W.resolve.bind(W)
+      @spy.prototype.watch   = W.reject.bind(W)
+      @cli = new CLI(debug: true)
+      mockery.resetCache()
+      mockery.registerMock('../../lib', @spy)
+      mockery.registerMock('../local_server', sinon.spy())
+
+    after ->
+      mockery.deregisterAll()
+
+    it 'compile should handle environments args correctly', (done) ->
+      env = 'doge'
+      p   = path.join(__dirname, 'fixtures/compile/environments')
+      @cli.run("compile #{p} --env #{env}")
+        .done =>
+          # @spy.args[0][1].env.should.equal(env)
+          done()
+
+    it 'watch should handle environments args correctly', (done) ->
+      env = 'doge'
+      p   = path.join(__dirname, 'fixtures/compile/environments')
+      @cli.run("watch #{p} --env #{env} --no-open")
+        .catch(->)
+        .done =>
+          # @spy.args[0][1].env.should.equal(env)
+          done()


    it 'should handle errors correctly', ->
      @stub.restore()
      @stub = sinon.stub(Roots.prototype, 'compile').returns(W.reject())

      cli.run('compile').should.be.rejected

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

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

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

  describe 'watch', ->



      it 'should list all templates', (done) ->

        cli.once 'data', (data) ->
          data.should.match /Templates/
          done()

