class Shindo::Tests

def test(description, tags = [], &block)

def test(description, tags = [], &block)
  tags = [*tags]
  @tag_stack.push(tags)
  taggings = ''
  unless tags.empty?
    taggings = " (#{tags.join(', ')})"
  end
  # if the test includes +tags and discludes -tags, evaluate it
  if (@if_tagged.empty? || !(@if_tagged & @tag_stack.flatten).empty?) &&
      (@unless_tagged.empty? || (@unless_tagged & @tag_stack.flatten).empty?)
    if block_given?
      begin
        for before in @befores.flatten.compact
          before.call
        end
        @annals.start
        success = instance_eval(&block)
        @annals.stop
        for after in @afters.flatten.compact
          after.call
        end
      rescue => error
        @annals.stop
        success = false
        file, line, method = error.backtrace.first.split(':')
        if method
          method << "in #{method[4...-1]} " # get method from "in `foo'"
        else
          method = ''
        end
        method << "! #{error.message} (#{error.class})"
        @annals.unshift(:file => file, :line => line.to_i, :method => method)
        @formatador.display_line("[red]#{error.message} (#{error.class})[/]")
      end
      @success = @success && success
      if success
        @formatador.display_line("[green]+ #{description}#{taggings}[/]")
      else
        @formatador.display_line("[red]- #{description}#{taggings}[/]")
        if STDOUT.tty?
          prompt(description, &block)
        end
      end
    else
      @formatador.display_line("[yellow]* #{description}#{taggings}[/]")
    end
  else
    @formatador.display_line("_ #{description}#{taggings}")
  end
  @tag_stack.pop
end