       userDb.findOne name: "hello"
     .then (res) ->
       assert.equal res.name, "hello"
-
-  test()
+      done()


tmake = require('../lib/tmake')(argv, conf, undefined, db, userDb, settingsDb)

pit = (desc, fn) ->
  it desc, (done) ->
    fn.bind(this)()
    .then -> done()
    .catch (e) -> done(e)

faker = timeout: -> true

_tests = {}
we = (desc, fn) -> _tests[desc] = fn

test = -> _.each _tests, (v, k) ->
  if v.test then pit k, v.test
  else pit k, v

run = -> _.each _tests, (v, k) ->
  if v.run then v.run()
  else
    (v.thaw || v).bind(faker)()

describe 'tmake', ->
  sh.mkdir '-p', argv.runDir

  we 'can fetch a git repo',
    test: ->
      @timeout 5000
      tmake.execute conf, [ "fetch" ]

  we 'can fetch from the project db', ->
    db.update
      name: "hello"
    ,

      db.findOne name: "hello"
    .then (res) ->
      assert.equal res.something, "nice"
      done()

  it 'can configure a build', (done) ->
    tmake.execute conf, [ 'configure' ]
    .then (res) ->
      db.findOne name: "hello"
    .then (dep) ->
      assert.ok dep.cache.configured
      done()

  it 'can build using ninja', (done) ->
    tmake.execute conf, [ 'build' ]
    .then (res) ->
      db.findOne name: "hello"
    .then (dep) ->
      assert.ok dep.cache.built
      done()

  it 'can push to the user local db', (done) ->
    @timeout 5000
    db.findOne name: "hello"
    .then (dep) ->
