       indent = indent + "    " while level--
 
       if test.failed == false
-        console.log indent + test.name.green
+        line = indent + test.name.green
       else if test.failed == true
-        console.log indent + "#{test.name} - subtest/s failed".red
-      else if test.failed.name == "AssertionError"
-        console.log indent + "#{test.name} - #{test.failed}".red
+        line = indent + "#{test.name} - subtest failures".red
+      else if test.failed.constructor == String || test.failed.name == "AssertionError"
+        line = indent + "#{test.name} - #{test.failed}".red
       else
-        console.log indent + "#{test.name} - #{test.failed}".yellow
+        line = indent + "#{test.name} - #{test.failed}".yellow
+      console.log(line)
+    console.log()
 
-
-
-  collect_output: (array=[]) ->
-    array.push
-      level: @level
-      name: @name
-      failed: @failed
+  collect: (array=[]) ->
+    array.push(@)
     for context in @children
-      context.collect_output(array)
-
-
+      context.collect(array)
 
   test: (description, fn) ->
     context = new Context(description, @)

colors = require "colors"
EventEmitter = require("events").EventEmitter

module.exports = Testify =
  test: (name, fn) ->
    if fn
      context = new Context(name)
      Testify.count++
      context.emitter.once "done", ->
        Testify.count--
        context.report()
        if Testify.count == 0
          Testify.emitter.emit("done")
      fn(context)
    else
      process.once "exit", ->
        console.log "Unimplemented: #{name}".cyan
  count: 0
  emitter: new EventEmitter()
  once: (args...) ->
    Testify.emitter.once(args...)

process.on "exit", ->
  if Testify.count != 0
    console.log "Not all tests ran".yellow

class Context
  constructor: (@name, @parent) ->
    if @parent
      @level = @parent.level + 1
    else
      @level = 0

    @failed = false
    @children = []

    @emitter = new EventEmitter

  report: ->
    console.log()
    top_level =
      name: "Passed: #{@name}"
      level: @level
      failed: @failed
    if top_level.failed
      top_level.name = "Failed: #{@name}"
    result = [top_level]

    for context in @children
      context.collect_output(result)

    for test in result
      level = test.level


  async: (fn) ->
    Testify.count++
    @emitter.once "done", ->
      Testify.count--

    try
      fn(@)
    catch error
