"use strict";

var TEMP_DIR = "./.tmp",
    
    expect = require( "chai" ).expect,
    
    Q = require( "q" ),
    path = require( "path" ),
    fs = require( "fs" ),
    rimraf = require( "rimraf" ),
    cpy = require( "cpy" );


describe( "grunt-meta-excel", function(){
    
    before( function( done ){
        prepareTestFiles( function(){
            done();
        } )
    } );
    
//    after( function(){
//        rimraf.sync( TEMP_DIR );
//    } );
    
    it( "test", function( done ){
        setInterval( done, 1000 );
    } );
} );


function prepareTestFiles( done ){
    if( fs.existsSync( TEMP_DIR ) ){
        rimraf.sync( TEMP_DIR );
    }

    fs.mkdir( TEMP_DIR, function( err ){

        Q.all(
            ( function(){
                var deferred = Q.defer();
                cpy( ["**/*"], path.resolve( TEMP_DIR, "htdocs_replace" ), { cwd: "./sample/htdocs" }, function( err ){
                    deferred.resolve( err );
                } );
                return deferred.promise;
            } )(),

            ( function(){
                var deferred = Q.defer();
                cpy( ["__boilerplate.html"], path.resolve( TEMP_DIR, "htdocs_generate" ), { cwd: "./sample/htdocs" }, function( err ){
                    deferred.resolve( err );
                } );
                return deferred.promise;
            } )()
        )
            .then( function(){ done(); } );
    } );
}

@@ -328,16 +328,23 @@
 stFiles(
+).then(
  functio
@@ -351,40 +351,21 @@
 n()%7B
-%0A            done();%0A       
+ done();
  %7D )
+;
 %0A   
@@ -375,18 +375,16 @@
 );%0A    %0A
-//
     afte
@@ -399,13 +399,17 @@
 ion(
+ done 
 )%7B%0A
-//
     
@@ -417,34 +417,56 @@
    r
-imraf.sync( TEMP_DIR
+emoveTestFiles().then( function()%7B done(); %7D
  );%0A
-//
     
@@ -569,22 +569,21 @@
 unction 
-p
 re
-par
+mov
 eTestFil
@@ -585,24 +585,49 @@
 stFiles(
- done )%7B
+)%7B%0A    var deferred = Q.defer();%0A
 %0A    if(
@@ -674,13 +674,8 @@
 mraf
-.sync
 ( TE
@@ -680,24 +680,72 @@
 TEMP_DIR
+, function()%7B%0A            deferred.resolve( true
  );%0A    
 %7D%0A%0A    f
@@ -740,11 +740,232 @@
     
+   
-%7D%0A%0A
+ %7D );%0A    %7D%0A    else %7B%0A        deferred.resolve( true );%0A    %7D%0A    %0A    return deferred.promise;%0A%7D%0A%0Afunction prepareTestFiles()%7B%0A    var deferred = Q.defer();%0A    %0A    removeTestFiles()%0A        .then( function()%7B%0A        
     
@@ -1002,16 +1002,24 @@
 err )%7B%0A%0A
+        
         
@@ -1029,32 +1029,40 @@
 ll(%0A            
+      
+  
 ( function()%7B%0A  
@@ -1051,32 +1051,40 @@
   ( function()%7B%0A
+        
                 
@@ -1101,32 +1101,40 @@
 ed = Q.defer();%0A
+        
                 
@@ -1249,32 +1249,40 @@
                 
+        
 deferred.resolve
@@ -1298,32 +1298,40 @@
                 
+        
 %7D );%0A           
@@ -1327,32 +1327,40 @@
                 
+    
+    
 return deferred.
@@ -1376,24 +1376,32 @@
             
+        
 %7D )(),%0A%0A    
@@ -1400,32 +1400,40 @@
 ),%0A%0A            
+       
+ 
 ( function()%7B%0A  
@@ -1422,32 +1422,40 @@
   ( function()%7B%0A
+        
                 
@@ -1472,32 +1472,40 @@
 ed = Q.defer();%0A
+        
                 
@@ -1635,32 +1635,40 @@
                 
+  
+      
 deferred.resolve
@@ -1684,37 +1684,50 @@
                 
-%7D );%0A
+        %7D );%0A     
                 
@@ -1718,32 +1718,35 @@
                 
+   
 return deferred.
@@ -1770,14 +1770,30 @@
     
-%7D )()%0A
+        %7D )()%0A        
     
@@ -1802,32 +1802,40 @@
   )%0A            
+        
 .then( function(
@@ -1830,36 +1830,54 @@
 n( function()%7B d
-one(
+eferred.resolve( true 
 ); %7D );%0A    %7D );
@@ -1872,15 +1872,62 @@
  );%0A    
+ 
-%7D )
+   %7D );%0A    %7D );%0A    %0A    return deferred.promise
 ;%0A%7D%0A

テスト追加の準備。テスト用ファイルの配置処理を実装。