Class: Moto::Reporting::RunStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/reporting/run_status.rb

Overview

Value object holding information about whole ‘run’ of tests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunStatus



31
32
33
34
35
36
37
# File 'lib/reporting/run_status.rb', line 31

def initialize
  @tests_all      = []
  @tests_passed   = []
  @tests_skipped  = []
  @tests_failed   = []
  @tests_error    = []
end

Instance Attribute Details

#durationObject (readonly)

Run’s duration



29
30
31
# File 'lib/reporting/run_status.rb', line 29

def duration
  @duration
end

#tests_allObject (readonly)

Array of all statuses [Moto::Test:Status] from current run



8
9
10
# File 'lib/reporting/run_status.rb', line 8

def tests_all
  @tests_all
end

#tests_errorObject (readonly)

Array of [Moto::Test:Status] with @results.last.code == [Moto::Test::Result::ERROR]



20
21
22
# File 'lib/reporting/run_status.rb', line 20

def tests_error
  @tests_error
end

#tests_failedObject (readonly)

Array of [Moto::Test:Status] with @results.last.code == [Moto::Test::Result::FAILURE]



17
18
19
# File 'lib/reporting/run_status.rb', line 17

def tests_failed
  @tests_failed
end

#tests_passedObject (readonly)

Array of [Moto::Test:Status] with @results.last.code == [Moto::Test::Result::PASSED]



11
12
13
# File 'lib/reporting/run_status.rb', line 11

def tests_passed
  @tests_passed
end

#tests_skippedObject (readonly)

Array of [Moto::Test:Status] with @results.last.code == [Moto::Test::Result::SKIPPED]



14
15
16
# File 'lib/reporting/run_status.rb', line 14

def tests_skipped
  @tests_skipped
end

#time_endObject (readonly)

Time of run’s end



26
27
28
# File 'lib/reporting/run_status.rb', line 26

def time_end
  @time_end
end

#time_startObject (readonly)

Time of run’s start



23
24
25
# File 'lib/reporting/run_status.rb', line 23

def time_start
  @time_start
end

Instance Method Details

#add_test_status(test_status) ⇒ Object

Adds single test’s status to the collection which describes whole run



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/reporting/run_status.rb', line 65

def add_test_status(test_status)

  # Separate collections are kept and data is doubled in order to avoid
  # calling Array.collect in getter for each type of results

  case test_status.results.last.code
    when Moto::Test::Result::PASSED
      @tests_passed << test_status
    when Moto::Test::Result::SKIPPED
      @tests_skipped << test_status
    when Moto::Test::Result::FAILURE
      @tests_failed << test_status
    when Moto::Test::Result::ERROR
      @tests_error << test_status
    else
      raise 'Incorrect value of field: "code" in [Moto::Test::Status]'
  end

  @tests_all << test_status
end

#bitmapObject

Inform about presence o errors/failures/skipped tests in current test run as a bitmap errors present: 0b100 & status_as_bitmap fails present: 0b010 & status_as_bitmap skips present: 0b001 & status_as_bitmap all passed: status_as_bitmap == 0



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/reporting/run_status.rb', line 103

def bitmap
  status = 0

  if tests_error.length > 0
    status += 0b100
  end

  if tests_failed.length > 0
    status += 0b010
  end

  if tests_skipped.length > 0
    status += 0b001
  end

  status
end

#finalize_runObject



43
44
45
46
# File 'lib/reporting/run_status.rb', line 43

def finalize_run
  @time_end = Time.now.to_f
  @duration = @time_end - @time_start
end

#initialize_runObject



39
40
41
# File 'lib/reporting/run_status.rb', line 39

def initialize_run
  @time_start = Time.now.to_f
end

#resultString

Summarized result of whole run



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/reporting/run_status.rb', line 50

def result

  if @tests_error.length > 0
    return Moto::Test::Result::ERROR
  elsif @tests_failed.length > 0
    return Moto::Test::Result::FAILURE
  elsif tests_all.length == @tests_skipped.length
    return Moto::Test::Result::SKIPPED
  end

  Moto::Test::Result::PASSED
end

#to_sString

Overwritten definition of to string.



88
89
90
91
92
93
94
95
# File 'lib/reporting/run_status.rb', line 88

def to_s
  case result
    when Moto::Test::Result::PASSED   then return 'PASSED'
    when Moto::Test::Result::FAILURE  then return 'FAILED'
    when Moto::Test::Result::ERROR    then return 'ERROR'
    when Moto::Test::Result::SKIPPED  then return 'SKIPPED'
  end
end