Class: Minitest::Hyper::Reporter::HashFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/hyper/reporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter) ⇒ HashFormatter

Returns a new instance of HashFormatter.



34
35
36
# File 'lib/minitest/hyper/reporter.rb', line 34

def initialize(reporter)
  @reporter = reporter
end

Class Method Details

.as_hash(reporter) ⇒ Object



30
31
32
# File 'lib/minitest/hyper/reporter.rb', line 30

def self.as_hash(reporter)
  self.new(reporter).to_h
end

Instance Method Details

#reporterObject



38
39
40
# File 'lib/minitest/hyper/reporter.rb', line 38

def reporter
  @reporter
end

#result_class(result) ⇒ Object



86
87
88
# File 'lib/minitest/hyper/reporter.rb', line 86

def result_class(result)
  result_code(result).to_s
end

#result_code(result) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/minitest/hyper/reporter.rb', line 73

def result_code(result)
  case result.failure
  when Skip
    :skip
  when UnexpectedError
    :error
  when Assertion
    :fail
  else
    :pass
  end
end

#result_data(results) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/minitest/hyper/reporter.rb', line 56

def result_data(results)
  collection = []
  results.each do |result|
    collection << {
      name: result.name,
      code: result_code(result),
      class: result_class(result),
      outcome: result_string(result),
      time: result.time,
      assertions: result.assertions,
      location: result.location,
      failure: result.failure
    }
  end
  collection
end

#result_string(result) ⇒ Object



90
91
92
# File 'lib/minitest/hyper/reporter.rb', line 90

def result_string(result)
  result_code(result).to_s.capitalize
end

#to_hObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/minitest/hyper/reporter.rb', line 42

def to_h
  {
    count: reporter.count,
    assertions: reporter.assertions,
    start_time: reporter.start_time,
    total_time: reporter.total_time,
    failures: reporter.failures,
    errors: reporter.errors,
    skips: reporter.skips,
    results: result_data(reporter.all_results),
    non_passing: result_data(reporter.results)
  }
end