/*global expect, Square, execSync, sinon, beforeEach, afterEach */
describe('[square] watch API', function () {
  'use strict';

  /**
   * The location of our testing fixtures.
   *
   * @type {String}
   */
  var path = require('path')
    , fixtures = path.join(process.env.PWD, 'test/fixtures')
    , expected = path.join(process.env.PWD, 'test/expected')
    , Watch = require('../lib/watch.js')
    , Square= require('../lib/square.js')
    , canihaz = require('canihaz')('square');

  /**
   * Async helpers.
   */
  var async = require('async');

  /**
   * Simple dummy function that is used for testing.
   *
   * @api private
   */
  function noop() { console.log(/* dummy function*/); }

  it('exposes constructor', function () {
    expect(Watch).to.be.a('function');
  });

  it('Watcher has watch, refresher, defer and live methods, encapsulates square', function (done) {
    var square = new Square({ 'disable log transport': true });
    square.parse(fixtures +'/read/adeptable.json');

    square.on('idle', function () {
      expect(watcher).to.be.a('object');
      expect(watcher).to.have.property('watch');
      expect(watcher).to.have.property('refresher');
      expect(watcher).to.have.property('live');
      expect(watcher).to.have.property('defer');
      expect(watcher).to.have.property('init');
      expect(watcher).to.have.property('silent');
      expect(watcher.watch).to.be.a('function');
      expect(watcher.refresher).to.be.a('function');
      expect(watcher.live).to.be.a('function');
      expect(watcher.defer).to.be.a('function');
      expect(watcher.init).to.be.a('function');
      expect(watcher.silent).to.be.a('boolean');
      done();
    });

    var watcher = new Watch(square, 8888, true);
  });

  describe('@construction', function () {
    var square, watcher;

    beforeEach(function () {
      square = new Square({ 'disable log transport': true });
      square.parse(fixtures +'/read/adeptable.json');
    });

    it('attach Square instance as property', function (done) {
      square.on('idle', function () {
        expect(watcher).to.have.property('square');
        expect(watcher.square).to.be.a('object');
        expect(watcher.square).to.be.instanceof(Square);
        done();
      });

      watcher = new Watch(square, 8888, true);
    });

    it('register event listener to trigger on build', function () {
      var build = sinon.spy(square, 'on');
      watcher = new Watch(square, 8888, true);
      expect(build).to.be.calledOnce;
      expect(build).to.be.calledWith('build');
      build.restore();
    });

    it('asynchronously loads required modules for watch', function () {
      var parallel = sinon.spy(async, 'parallel');
      watcher = new Watch(square, 8888, true);
      expect(parallel).to.be.calledOnce;
      parallel.restore();
    });
  });

  describe('#watch', function () {
    it('calls square#files to get a list of files from the bundle');
    it('constructs fs.notify and supply a list of files');
    it('will emit idle to start the spinner');
    it('will register event listeners on the notifier');
    it('will remove `node_modules` from the list of files');
    it('will remove `.`directories from the list of files');
    it('will remove output files from the list of files');
    it('adds additional files as configured by extensions in package.json');
    it('calls the #refresher on detected file changes');
  });

  describe('#refresher', function () {
    it('will log an error if watching fails');
    it('will emit processing to stop the spinner');
    it('will log an empty line and notice of changed files');
    it('calls square#refresh to reinitialize a build');
  });

  describe('#live', function () {
    it('gets the static content of reload.js');
    it('lazy loads socket.IO through canihaz');
    it('will try to find the local IP of the network to connect to');
    it('log additional information on how to use browser reloading');
    it('exposes the eventemitter as promise');
  });
});



@@ -865,36 +865,32 @@
 are', function (
-done
 ) %7B%0A    var squa
@@ -1002,42 +1002,53 @@
     
-square.on('idle', function () %7B%0A  
+var watcher = new Watch(square, 8888, true);%0A
     
@@ -1078,26 +1078,24 @@
 ('object');%0A
-  
     expect(w
@@ -1125,34 +1125,32 @@
 y('watch');%0A    
-  
 expect(watcher).
@@ -1176,26 +1176,24 @@
 efresher');%0A
-  
     expect(w
@@ -1222,34 +1222,32 @@
 ty('live');%0A    
-  
 expect(watcher).
@@ -1269,34 +1269,32 @@
 y('defer');%0A    
-  
 expect(watcher).
@@ -1315,34 +1315,32 @@
 ty('init');%0A    
- 
- 
 expect(watcher).
@@ -1363,34 +1363,32 @@
 ('silent');%0A    
-  
 expect(watcher.w
@@ -1410,34 +1410,32 @@
 function');%0A    
- 
- 
 expect(watcher.r
@@ -1461,34 +1461,32 @@
 function');%0A    
-  
 expect(watcher.l
@@ -1503,34 +1503,32 @@
 .a('function');%0A
-  
     expect(watch
@@ -1554,34 +1554,32 @@
 function');%0A    
-  
 expect(watcher.i
@@ -1600,26 +1600,24 @@
 function');%0A
-  
     expect(w
@@ -1655,80 +1655,8 @@
 ');%0A
-      done();%0A    %7D);%0A%0A    var watcher = new Watch(square, 8888, true);%0A
   %7D)
@@ -1935,20 +1935,16 @@
 nction (
-done
 ) %7B%0A    
@@ -1949,48 +1949,55 @@
     
-square.on('idle', function () %7B%0A 
+watcher = new Watch(square, 8888, true);%0A
       
- 
 expe
@@ -2034,34 +2034,32 @@
 square');%0A      
-  
 expect(watcher.s
@@ -2086,26 +2086,24 @@
 ct');%0A      
- 
- 
 expect(watch
@@ -2143,82 +2143,8 @@
 e);%0A
-        done();%0A      %7D);%0A%0A      watcher = new Watch(square, 8888, true);%0A
     

remove pointless async tests