Class: Xcode::Test::Formatters::StdoutFormatter

Inherits:
Object
  • Object
show all
Includes:
Xcode::TerminalOutput
Defined in:
lib/xcode/test/formatters/stdout_formatter.rb

Constant Summary

Constants included from Xcode::TerminalOutput

Xcode::TerminalOutput::LEVELS

Instance Method Summary collapse

Methods included from Xcode::TerminalOutput

#color_output=, #color_output?, #format_lhs, included, #log_level, log_level=, #print, #print_input, #print_output, #print_system, #print_task, #puts, terminal_supports_colors?

Constructor Details

#initialize(options = {}) ⇒ StdoutFormatter

Returns a new instance of StdoutFormatter.



7
8
9
10
11
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 7

def initialize(options = {})
  @errors = []
  @test_count = 0
  options.each { |k,v| self.send("#{k}=", v) }
end

Instance Method Details

#after(report) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 17

def after(report)
  level = @errors.count>0 ? :error : :info
  if @errors.count>0
    print_task :test, "The following failures occured:", :warning 
    @errors.each do |e|
      print_task :test, "[#{e.suite.name} #{e.name}]", :error
      e.errors.each do |error|
        print_task :test, "  #{error[:message]}", :error
        print_task :test, "    at #{error[:location]}", :error
        if error[:data].count>0
          print_task :test, "\n   Test Output:", :error
          print_task :test, "   > #{error[:data].join("   > ")}\n\n", :error
        end
      end       
      
      # if there is left over data in the test report, show that
      if e.data.count>0
        print_task :test, "\n  There was this trailing output after the above failures", :error
        print_task :test, "   > #{e.data.join("   > ")}\n\n", :error
      end
    end
  end
  
  print_task :test, "Finished in #{report.duration} seconds", :info
  print_task :test, "#{@test_count} tests, #{@errors.count} failures", report.failed? ? :error : :info
end

#after_suite(suite) ⇒ Object



48
49
50
51
52
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 48

def after_suite(suite)
  color = (suite.total_passed_tests == suite.tests.count) ? :info : :error
  #print_task :test, "#{suite.total_passed_tests}/#{suite.tests.count}", color
  puts " [#{suite.total_passed_tests}/#{suite.tests.count}]", color
end

#after_test(test) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 58

def after_test(test)
  @test_count += 1
  if test.passed?
    print ".", :green
  elsif test.failed?
    print "F", :red
    @errors << test 
  end                    
end

#before(report) ⇒ Object



13
14
15
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 13

def before(report)
  print_task :test, "Begin tests", :info
end

#before_suite(suite) ⇒ Object



44
45
46
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 44

def before_suite(suite)
  print_task :test, "#{suite.name}: ", :info, false
end

#before_test(test) ⇒ Object



54
55
56
# File 'lib/xcode/test/formatters/stdout_formatter.rb', line 54

def before_test(test)
  # puts "[#{test.suite.name} #{test.name}] << BEGIN"
end