Module: BetterOutput

Included in:
Bacon
Defined in:
lib/output/better_output.rb

Instance Method Summary collapse

Instance Method Details

#handle_requirement(description) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/output/better_output.rb', line 14

def handle_requirement(description)
  print "#{spaces} ~ #{description}"
  timing = []
  error_type, err = yield(timing)
  
  # goto beginning of line
  print "\e[G\e[K"
  
  case error_type
  when ""
    before_duration = (timing[0] * 1000).to_i
    test_duration = (timing[1] * 1000).to_i
    total = (timing.inject(:+) * 1000 ).to_i
    
    puts "#{spaces} #{Color.green}#{Color.reset} #{description} [#{total} ms (#{before_duration} + #{test_duration})]"
    
  when :failed
    puts "#{spaces} #{Color.red}#{Color.reset} #{description}"
  
  when :error
    # ❍ ☻
    puts "#{spaces} #{Color.red}#{description}#{Color.reset} [#{err.class}]"
    
  end
  
end

#handle_specification(name) ⇒ Object



8
9
10
11
12
# File 'lib/output/better_output.rb', line 8

def handle_specification(name)
  puts "\n#{spaces()}#{Color.underscore}#{name}#{Color.reset}"
  yield
  puts if Counter[:context_depth] == 1
end

#handle_summary(elapsed_time) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/output/better_output.rb', line 41

def handle_summary(elapsed_time)
  print ErrorLog  if Backtraces
  if elapsed_time < 1
    puts "Execution time: #{elapsed_time * 1000} ms"
  else
    puts "Execution time: #{human_duration(elapsed_time)}"
  end
  puts "%d specifications (%d requirements), %d failures, %d errors" %
    Counter.values_at(:specifications, :requirements, :failed, :errors)
end

#spaces(str = " ") ⇒ Object



52
53
54
# File 'lib/output/better_output.rb', line 52

def spaces(str = " ")
  str * 2 * (Counter[:context_depth] - 1)
end