Class: HooplaSalesforce::TextReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/hoopla_salesforce/text_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ TextReporter

Returns a new instance of TextReporter.



7
8
9
# File 'lib/hoopla_salesforce/text_reporter.rb', line 7

def initialize(result)
  @result = result
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/hoopla_salesforce/text_reporter.rb', line 5

def result
  @result
end

Instance Method Details

#end_colorObject



19
20
21
# File 'lib/hoopla_salesforce/text_reporter.rb', line 19

def end_color
  "\e[0m"
end

#greenObject



11
12
13
# File 'lib/hoopla_salesforce/text_reporter.rb', line 11

def green
  "\e[32m"
end

#redObject



15
16
17
# File 'lib/hoopla_salesforce/text_reporter.rb', line 15

def red
  "\e[31m"
end

#reportObject



29
30
31
32
33
34
35
36
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hoopla_salesforce/text_reporter.rb', line 29

def report
  indent            = "  "
  updated_files     = []
  problems          = []
  test_failures     = []
  coverage_warnings = []

  sanitize(result[:messages]).each do |message|
    if message[:success]
      status = " "
      status = "U" if message[:changed]
      status = "D" if message[:deleted]
      status = "A" if message[:created]

      updated_files << "#{green}#{indent}#{status} #{message[:file_name]}#{end_color}"
    end 

    if message[:problem]
      problem = "#{red}#{indent}#{message[:file_name]}:#{message[:line_number]} (column #{message[:column_number]})\n" 
      problem += "#{indent*2}#{message[:problem]}#{end_color}"
      problems << problem
    end
  end

  if ENV['FULL_OUTPUT']
    pp result
  else
    puts "(Run with FULL_OUTPUT=true to show full deploy output)"
  end

  puts
  puts "Updated files:"
  puts updated_files.uniq.join("\n")
  puts

  puts "Test results:"
  test_result = result[:run_test_result]
  failures    = test_result[:num_failures].to_i
  passes      = test_result[:num_tests_run].to_i - failures
  passes      = 0 if passes < 0
  print "#{indent}Passes: #{green}#{passes}#{end_color} "
  print "Failures: #{red}#{failures}#{end_color} "
  puts  "Duration: #{test_result[:total_time]}"
  puts

  # :failures is only an array if we have more than 1. Fun...
  sanitize(test_result[:failures]).each do |failure|
    message = "#{indent}#{red}#{failure[:name]}.#{failure[:method_name]}: #{failure[:message]}\n"
    message += failure[:stack_trace].split("\n").map{ |l| indent * 2 + l }.join("\n") if failure[:stack_trace]
    message += end_color
    test_failures << message
  end

  if !test_failures.empty?
    puts "Test failures:"
    puts test_failures.join("\n")
    puts
  end

  sanitize(test_result[:code_coverage_warnings]).each do |warning|
    coverage_warnings << "#{indent}#{warning[:name]}: #{warning[:message]}"
  end
  
  if !coverage_warnings.empty?
    puts "Coverage warnings:"
    puts coverage_warnings.join("\n")
    puts
  end

  if !problems.empty?
    puts "Problems:"
    puts problems.join("\n")
    puts
  end

  return problems.empty?
end

#sanitize(data) ⇒ Object



23
24
25
26
27
# File 'lib/hoopla_salesforce/text_reporter.rb', line 23

def sanitize(data)
  return data if data.is_a? Array
  return [data] if data
  []
end