Class: Speq::Outcome

Inherits:
Object
  • Object
show all
Defined in:
lib/speq/values.rb,
lib/speq/string_fmt.rb

Overview

Encodes the outcome of a group or individual test

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Outcome

Returns a new instance of Outcome.



27
28
29
# File 'lib/speq/values.rb', line 27

def initialize(values)
  @values = values
end

Instance Attribute Details

#valuesObject

Returns the value of attribute values.



26
27
28
# File 'lib/speq/values.rb', line 26

def values
  @values
end

Class Method Details

.aggregate(outcomes) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/speq/values.rb', line 18

def self.aggregate(outcomes)
  Outcome.new(
    [outcomes.map(&:pass?).count(true),
     outcomes.map(&:fail?).count(true),
     outcomes.map(&:error?).count(true)]
  )
end

.errorObject



6
7
8
# File 'lib/speq/values.rb', line 6

def self.error
  Outcome.new([0, 0, 1])
end

.failObject



14
15
16
# File 'lib/speq/values.rb', line 14

def self.fail
  Outcome.new([0, 1, 0])
end

.passObject



10
11
12
# File 'lib/speq/values.rb', line 10

def self.pass
  Outcome.new([1, 0, 0])
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/speq/values.rb', line 43

def ==(other)
  other.values == values
end

#error?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/speq/values.rb', line 55

def error?
  error_count.positive?
end

#error_countObject



39
40
41
# File 'lib/speq/values.rb', line 39

def error_count
  values[2]
end

#fail?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/speq/values.rb', line 51

def fail?
  !pass? && !error?
end

#fail_countObject



35
36
37
# File 'lib/speq/values.rb', line 35

def fail_count
  values[1]
end

#pass?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/speq/values.rb', line 47

def pass?
  fail_count.zero? && error_count.zero?
end

#pass_countObject



31
32
33
# File 'lib/speq/values.rb', line 31

def pass_count
  values[0]
end

#reportObject



54
55
56
# File 'lib/speq/string_fmt.rb', line 54

def report
  "pass: #{pass_count}, fail: #{fail_count}, errors: #{error_count}"
end

#to_sObject



58
59
60
# File 'lib/speq/string_fmt.rb', line 58

def to_s
  pass? ? ''.green : 'x'.red
end