 spectacular.subject = (name, block) ->
   notInsideIt 'subject'
   [name, block] = [block, name] if typeof name is 'function'
-
   currentExampleGroup.ownSubjectBlock = block
   spectacular.given name, block if name?
 

  @getter 'subject', -> @subjectBlock?.call(this)

  pending: ->
    if @promise?.pending
      @promise.resolve()
      @result.state = 'pending'

  skip: ->
    if @promise?.pending
      @promise.reject new Error 'Skipped'
      @result.state = 'skipped'

  resolve: ->
    if @promise?.pending
      if @result.hasFailures()
        @promise.reject()
        @result.state = 'failure'
      else
        @promise.resolve()
        @result.state = 'success'

  reject: (reason) ->
    if @promise?.pending
      @promise.reject reason
      @result.state = 'failure'

  run: ->
    @promise = new spectacular.Promise
    afterPromise = new spectacular.Promise

    @result = new spectacular.ExampleResult this
    @runBefore => @executeBlock()
    @promise.then => @runAfter => afterPromise.resolve()
    @promise.fail (reason) => @runAfter => afterPromise.reject reason

    afterPromise

  runBefore: (callback) ->
    befores = @beforeHooks
    next = =>
      if befores.length is 0
        callback()
      else


  runAfter: (callback) ->
    afters = @afterHooks
    next = (err) =>
      return callback err if err?
      if afters.length is 0
        callback()
      else
