Permalink
Browse files

update formatador usage

  • Loading branch information...
1 parent 005c0e1 commit f56ea1489c01d8ada20a37493031bbf5dc70f0df @geemus geemus committed Nov 18, 2010
Showing with 46 additions and 51 deletions.
  1. +17 −18 lib/shindo.rb
  2. +9 −12 lib/shindo/bin.rb
  3. +11 −12 lib/shindo/taciturn.rb
  4. +9 −9 lib/shindo/verbose.rb
View
@@ -20,7 +20,6 @@ def initialize(description, tags = [], &block)
@befores = []
@description_stack = []
@tag_stack = []
- Thread.current[:formatador] = Formatador.new
Thread.current[:reload] = false
Thread.current[:tags] ||= []
Thread.current[:totals] ||= { :failed => 0, :pending => 0, :skipped => 0, :succeeded => 0 }
@@ -34,7 +33,7 @@ def initialize(description, tags = [], &block)
@unless_tagged << tag[1..-1]
end
end
- Thread.current[:formatador].display_line
+ Formatador.display_line
tests(description, tags, &block)
end
@@ -75,7 +74,7 @@ def tests(description, tags = [], &block)
if block_given?
begin
display_description(description)
- Thread.current[:formatador].indent { instance_eval(&block) }
+ Formatador.indent { instance_eval(&block) }
rescue => error
display_error(error)
end
@@ -145,8 +144,8 @@ def assert(type, expectation, description, &block)
"expected => #{expectation.inspect}",
"returned => #{value.inspect}"
]
- Thread.current[:formatador].indent do
- Thread.current[:formatador].display_lines([*@message].map {|message| "[red]#{message}[/]"})
+ Formatador.indent do
+ Formatador.display_lines([*@message].map {|message| "[red]#{message}[/]"})
end
@message = nil
end
@@ -162,11 +161,11 @@ def assert(type, expectation, description, &block)
def prompt(description, &block)
return if Thread.main[:exit] || Thread.current[:reload]
- Thread.current[:formatador].display("Action? [c,e,i,q,r,t,?]? ")
+ Formatador.display("Action? [c,e,i,q,r,t,?]? ")
choice = STDIN.gets.strip
continue = false
- Thread.current[:formatador].display_line
- Thread.current[:formatador].indent do
+ Formatador.display_line
+ Formatador.indent do
case choice
when 'c', 'continue'
continue = true
@@ -176,12 +175,12 @@ def prompt(description, &block)
if value.nil?
value = 'nil'
end
- Thread.current[:formatador].display_line(value)
+ Formatador.display_line(value)
rescue => error
display_error(error)
end
when 'i', 'interactive', 'irb'
- Thread.current[:formatador].display_line('Starting interactive session...')
+ Formatador.display_line('Starting interactive session...')
if @irb.nil?
require 'irb'
ARGV.clear # Avoid passing args to IRB
@@ -191,7 +190,7 @@ def prompt(description, &block)
IRB.conf[:PROMPT][:SHINDO] = {}
end
for key, value in IRB.conf[:PROMPT][:SIMPLE]
- IRB.conf[:PROMPT][:SHINDO][key] = "#{Thread.current[:formatador].indentation}#{value}"
+ IRB.conf[:PROMPT][:SHINDO][key] = "#{Formatador.indentation}#{value}"
end
@irb.context.prompt_mode = :SHINDO
@irb.context.workspace = IRB::WorkSpace.new(@gestalt.bindings.last)
@@ -200,19 +199,19 @@ def prompt(description, &block)
rescue SystemExit
end
when 'q', 'quit', 'exit'
- Thread.current[:formatador].display_line("Exiting...")
+ Formatador.display_line("Exiting...")
Thread.main[:exit] = true
when 'r', 'reload'
- Thread.current[:formatador].display_line("Reloading...")
+ Formatador.display_line("Reloading...")
Thread.current[:reload] = true
when 't', 'backtrace', 'trace'
if @gestalt.calls.empty?
- Thread.current[:formatador].display_line("[red]No methods were called, so no backtrace was captured.[/]")
+ Formatador.display_line("[red]No methods were called, so no backtrace was captured.[/]")
else
@gestalt.display_calls
end
when '?', 'help'
- Thread.current[:formatador].display_lines([
+ Formatador.display_lines([
'c - ignore this error and continue',
'i - interactive mode',
'q - quit Shindo',
@@ -221,12 +220,12 @@ def prompt(description, &block)
'? - display help'
])
else
- Thread.current[:formatador].display_line("[red]#{choice} is not a valid choice, please try again.[/]")
+ Formatador.display_line("[red]#{choice} is not a valid choice, please try again.[/]")
end
- Thread.current[:formatador].display_line
+ Formatador.display_line
end
unless continue || Thread.main[:exit]
- Thread.current[:formatador].display_line("[red]- #{description}[/]")
+ Formatador.display_line("[red]- #{description}[/]")
prompt(description, &block)
end
end
View
@@ -1,12 +1,11 @@
require File.join(File.dirname(__FILE__), '..', 'shindo')
@interrupt = lambda do
- formatador = Thread.current[:formatador] || Formatador
unless Thread.main[:exit]
- formatador.display_line('Gracefully Exiting... (ctrl-c to force)')
+ Formatador.display_line('Gracefully Exiting... (ctrl-c to force)')
Thread.main[:exit] = true
else
- formatador.display_line('Exiting...')
+ Formatador.display_line('Exiting...')
Thread.exit
end
end
@@ -66,15 +65,13 @@ def run_in_thread(helpers, tests, thread_locals)
@totals ||= { :failed => 0, :pending => 0, :succeeded => 0 }
@success = @totals[:failed] == 0
-lines = []
-lines << "[red]#{@totals[:failed]} failed[/]," if @totals[:failed] > 0
-lines << "[yellow]#{@totals[:pending]} pending[/]," if @totals[:pending] > 0
-lines << "[green]#{@totals[:succeeded]} succeeded[/]"
-lines = lines[0...-2].join(', ') << ' and ' << lines[-1] if lines.length > 3
-lines << "in [bold]#{Time.now - @started_at}[/] seconds"
-Formatador.display_line
-Formatador.display_line(lines.join(' '))
-Formatador.display_line
+status = []
+status << "[red]#{@totals[:failed]} failed[/]," if @totals[:failed] > 0
+status << "[yellow]#{@totals[:pending]} pending[/]," if @totals[:pending] > 0
+status << "[green]#{@totals[:succeeded]} succeeded[/]"
+status = status[0...-2].join(', ') << ' and ' << status[-1] if status.length > 3
+status << "in [bold]#{Time.now - @started_at}[/] seconds"
+Formatador.display_lines(['', status.join(' '), ''])
if @success
Kernel.exit(0)
@@ -4,10 +4,10 @@ class Tests
private
def display_description_stack
- return if @description_stack.empty?
- Thread.current[:formatador].indent do
- Thread.current[:formatador].display_line(@description_stack.pop)
- display_description_stack
+ Formatador.indent do
+ @description_stack.length.times do
+ Formatador.display_line(@description_stack.pop)
+ end
end
end
@@ -20,22 +20,21 @@ def display_description(description)
end
def display_error(error)
+ Formatador.display_lines(['', Thread.current[:file]])
display_description_stack
- Thread.current[:formatador].indent do
- Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
- unless error.backtrace.empty?
- Thread.current[:formatador].indent do
- Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
- end
+ Formatador.display_line("[red]#{error.message} (#{error.class})[/]")
+ unless error.backtrace.empty?
+ Formatador.indent do
+ Formatador.display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
end
end
end
def display_failure(description)
Thread.current[:totals][:failed] += 1
- Thread.current[:formatador].display_line
+ Formatador.display_lines(['', Thread.current[:file]])
display_description_stack
- Thread.current[:formatador].display_line("[red]- #{description}[/]")
+ Formatador.display_line("[red]- #{description}[/]")
end
def display_pending(description)
View
@@ -4,40 +4,40 @@ class Tests
private
def display_description(description)
- Thread.current[:formatador].display_line(description)
+ Formatador.display_line(description)
end
def display_error(error)
- Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
+ Formatador.display_line("[red]#{error.message} (#{error.class})[/]")
unless error.backtrace.empty?
- Thread.current[:formatador].indent do
- Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
+ Formatador.indent do
+ Formatador.display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
end
end
end
def display_failure(description)
Thread.current[:totals][:failed] += 1
- Thread.current[:formatador].display_line("[red]- #{description}[/]")
+ Formatador.display_line("[red]- #{description}[/]")
end
def display_pending(description)
Thread.current[:totals][:pending] += 1
- Thread.current[:formatador].display_line("[yellow]# #{description}[/]")
+ Formatador.display_line("[yellow]# #{description}[/]")
end
def display_success(description)
Thread.current[:totals][:succeeded] += 1
- Thread.current[:formatador].display_line("[green]+ #{description}[/]")
+ Formatador.display_line("[green]+ #{description}[/]")
end
def raises?(expectation, &block)
- @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
+ @gestalt = Gestalt.new({'formatador' => Formatador})
[value = @gestalt.run(&block), value.is_a?(expectation)]
end
def returns?(expectation, &block)
- @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
+ @gestalt = Gestalt.new({'formatador' => Formatador})
[value = @gestalt.run(&block), value == expectation]
end

0 comments on commit f56ea14

Please sign in to comment.