Class: Micronaut::Formatters::BaseTextFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/micronaut/formatters/base_text_formatter.rb

Direct Known Subclasses

DocumentationFormatter, ProgressFormatter

Instance Attribute Summary

Attributes inherited from BaseFormatter

#behaviour, #duration, #example_count, #examples

Instance Method Summary collapse

Methods inherited from BaseFormatter

#add_behaviour, #color_enabled?, #configuration, #example_finished, #failed_examples, #format_backtrace, #initialize, #output, #pending_examples, #profile_examples?, #start, #start_dump, #trace, #trace_override_flag

Constructor Details

This class inherits a constructor from Micronaut::Formatters::BaseFormatter

Instance Method Details

#closeObject



90
91
92
93
94
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 90

def close
  if IO === output && output != $stdout
    output.close 
  end
end

#colorise(s, failure) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 29

def colorise(s, failure)
  if failure.is_a?(Micronaut::Expectations::ExpectationNotMetError)
    red(s)
  else
    magenta(s)
  end
end

#dump_failuresObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 7

def dump_failures
  output.puts
  failed_examples.each_with_index do |failed_example, index|
    exception = failed_example.execution_result[:exception_encountered]
    padding = '    '
    
    output.puts "#{index.next}) #{failed_example}"
    output.puts "#{padding}Failure/Error: #{read_failed_line(exception, failed_example).strip}"
    
    exception.message.split("\n").each do |line|
      output.puts "#{padding}#{colorise(line, exception).strip}"
    end

    format_backtrace(exception.backtrace, failed_example).each do |backtrace_info|
      output.puts grey("#{padding}# #{backtrace_info}")
    end
    
    output.puts 
    output.flush
  end
end

#dump_pendingObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 78

def dump_pending
  unless pending_examples.empty?
    output.puts
    output.puts "Pending:"
    pending_examples.each do |pending_example, message|
      output.puts "  #{pending_example}"
      output.puts grey("   # #{format_caller(pending_example.[:caller])}")
    end
  end
  output.flush
end

#dump_summaryObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 37

def dump_summary
  failure_count = failed_examples.size
  pending_count = pending_examples.size

  output.puts "\nFinished in #{duration} seconds\n"

  summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failures"
  summary << ", #{pending_count} pending" if pending_count > 0  

  if failure_count == 0
    if pending_count > 0
      output.puts yellow(summary)
    else
      output.puts green(summary)
    end
  else
    output.puts red(summary)
  end
  
  # Don't print out profiled info if there are failures, it just clutters the output
  if profile_examples? && failure_count == 0
    sorted_examples = examples.sort_by { |example| example.execution_result[:run_time] }.reverse.first(10)
    output.puts "\nTop #{sorted_examples.size} slowest examples:\n"        
    sorted_examples.each do |example|
      output.puts "  (#{sprintf("%.7f", example.execution_result[:run_time])} seconds) #{example}"
      output.puts grey("   # #{format_caller(example.[:caller])}")
    end
  end
  
  output.flush
end

#format_caller(caller_info) ⇒ Object

def textmate_link_backtrace(path)

file, line = path.split(':')
"txmt://open/?url=file://#{File.expand_path(file)}&line=#{line}"

end



74
75
76
# File 'lib/micronaut/formatters/base_text_formatter.rb', line 74

def format_caller(caller_info)
  caller_info.to_s.split(':in `block').first
end