   afterEach (done) ->
     return process.nextTick done if cleanup.length is 0
 
-    client.s3.deleteObjects Delete: Objects: cleanup, (err) ->
+    upload.s3.deleteObjects Delete: Objects: cleanup, (err) ->
       throw err if err
       cleanup = []
       done()

        dest = 'images_test/Wm/PH/f3/I0'
        opts = {}

        image = new Upload.Image src, dest, opts, client

      describe 'constructor', ->
        it 'should set default values', ->

      , /Bucket name can not be undefined/

    it 'should set default values if not provided', ->
      upload = new Upload 'myBucket'

      assert upload.s3 instanceof require('aws-sdk').S3
      assert upload.versions instanceof Array
      assert.equal upload.awsBucketPath, ''
      assert.equal upload.awsBucketUrl, undefined
      assert.equal upload.awsBucketAcl, 'privat'
      assert.equal upload.resizeQuality, 70
      assert.equal upload.keepOriginal, true
      assert.equal upload.returnExif, false
      assert.equal upload.tmpDir, '/tmp/'
      assert.equal upload.tmpPrefix, 'gm-'

    it 'should override default values'

  describe '#_getRandomPath()', ->
    it 'should return a new random path', ->
      path = upload._getRandomPath()
      assert(/^images_test\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}$/.test(path))

  describe '#_uploadPathIsAvailable()', ->
    it 'should return true for avaiable path', (done) ->
      upload.s3.listObjects = (opts, cb) -> process.nextTick -> cb null, Contents: []
      upload._uploadPathIsAvailable 'some/path/', (err, path, isAvaiable) ->
        assert.ifError err
        assert.equal isAvaiable, true
        done()

    it 'should return false for unavaiable path', (done) ->
      upload.s3.listObjects = (opts, cb) -> process.nextTick -> cb null, Contents: [opts.Prefix]
      upload._uploadPathIsAvailable 'some/path/', (err, path, isAvaiable) ->
        assert.ifError err
        assert.equal isAvaiable, false
        done()

  describe '#_uploadGeneratePath()', ->
    it 'should return an error if path is taken', (done) ->
      upload._uploadPathIsAvailable = (path, cb) -> process.nextTick -> cb null, path, false
      upload._uploadGeneratePath (err, path) ->
        assert /Path '[^']+' not avaiable!/.test err
        done()

    it 'should return an avaiable path', (done) ->
      upload._uploadPathIsAvailable = (path, cb) -> process.nextTick -> cb null, path, true
      upload._uploadGeneratePath (err, path) ->
        assert.ifError err
        assert /^images_test\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}$/.test(path)
        done()
