     .done()
 
   it 'should download file from remote server', (done) ->
-    @helpers.getFile @_sftp, FILE_REMOTE, FILE_LOCAL_DOWNLOAD
-    .then ->
-      expect(fs.existsSync(FILE_LOCAL_DOWNLOAD)).toBe true
-      done()
+    fs.makeDirectory(FOLDER_LOCAL)
+    .then => @helpers.getFile @_sftp, FILE_REMOTE, FILE_LOCAL_DOWNLOAD
+    .then -> fs.exists(FILE_LOCAL_DOWNLOAD)
+    .then -> fs.removeTree(FOLDER_LOCAL)
+    .then -> done()
     .fail (error) -> done(error)
     .done()
 

  it 'should download all files from remote server', (done) ->
    fileRemoteA = "#{FOLDER_REMOTE}/testA.txt"
    fileRemoteB = "#{FOLDER_REMOTE}/testB.txt"
    @helpers.putFile @_sftp, FILE_LOCAL, fileRemoteA
    .then => @helpers.putFile @_sftp, FILE_LOCAL, fileRemoteB
    .then => @helpers.downloadAllFiles @_sftp, FOLDER_LOCAL, FOLDER_REMOTE
    .then ->
      expect(fs.existsSync("#{FOLDER_LOCAL}/testA.txt")).toBe true
      expect(fs.existsSync("#{FOLDER_LOCAL}/testB.txt")).toBe true
      done()
    .fail (error) -> done(error)
    .done()

Q = require 'q'
fs = require 'q-io/fs'
_ = require 'underscore'
Connection = require 'ssh2'
SftpConfig = require('../../config').config.sftp
