Skip to content

Commit

Permalink
more indentation/display cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Mar 21, 2011
1 parent 37edeaf commit 72fab54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/shindo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def tests(description, tags = [], &block)
@afters.push([])

@description = nil
@inline = false
description ||= 'Shindo.tests'
description = "[bold]#{description}[normal]"
unless tags.empty?
Expand All @@ -72,16 +73,21 @@ def tests(description, tags = [], &block)
if block_given?
begin
display_description(description)
Formatador.indent { instance_eval(&block) }
# HACK: increase indent
indent = Thread.current[:formatador].instance_variable_get(:@indent)
Thread.current[:formatador].instance_variable_set(:@indent, indent + 1)
instance_eval(&block)
rescue Shindo::Pending
display_pending(description)
# HACK: remove indent since above doesn't
indent = Thread.current[:formatador].instance_variable_get(:@indent)
Thread.current[:formatador].instance_variable_set(:@indent, indent - 1)
rescue => error
display_error(error)
ensure
# HACK: decrease indent
indent = Thread.current[:formatador].instance_variable_get(:@indent)
Thread.current[:formatador].instance_variable_set(:@indent, indent - 1)
end
else
@inline = true
display_description(description)
end
else
Expand Down
25 changes: 21 additions & 4 deletions lib/shindo/verbose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class Tests
private

def display_description(description)
Formatador.display_line(description)
unless @inline
Formatador.display_line(description)
else
Formatador.display(description)
print ' '
end
end

def display_error(error)
Expand All @@ -18,17 +23,29 @@ def display_error(error)

def display_failure(description)
Thread.current[:totals][:failed] += 1
Formatador.display_line("[red]- #{description}[/]")
unless @inline
Formatador.display_line("[red]- #{description}[/]")
else
print Formatador.parse("[red]- #{description}[/]\n")
end
end

def display_pending(description)
Thread.current[:totals][:pending] += 1
Formatador.display_line("[yellow]# #{description}[/]")
unless @inline
Formatador.display_line("[yellow]# #{description}[/]")
else
print Formatador.parse("[yellow]# #{description}[/]\n")
end
end

def display_success(description)
Thread.current[:totals][:succeeded] += 1
Formatador.display_line("[green]+ #{description}[/]")
unless @inline
Formatador.display_line("[green]+ #{description}[/]")
else
print Formatador.parse("[green]+ #{description}[/]\n")
end
end

end
Expand Down

0 comments on commit 72fab54

Please sign in to comment.