Class: Speq::Outcome
- Inherits:
-
Object
- Object
- Speq::Outcome
- 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
-
#values ⇒ Object
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #error? ⇒ Boolean
- #error_count ⇒ Object
- #fail? ⇒ Boolean
- #fail_count ⇒ Object
-
#initialize(values) ⇒ Outcome
constructor
A new instance of Outcome.
- #pass? ⇒ Boolean
- #pass_count ⇒ Object
- #report ⇒ Object
- #to_s ⇒ Object
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
#values ⇒ Object
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 |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/speq/values.rb', line 43 def ==(other) other.values == values end |
#error? ⇒ Boolean
55 56 57 |
# File 'lib/speq/values.rb', line 55 def error? error_count.positive? end |
#error_count ⇒ Object
39 40 41 |
# File 'lib/speq/values.rb', line 39 def error_count values[2] end |
#fail? ⇒ Boolean
51 52 53 |
# File 'lib/speq/values.rb', line 51 def fail? !pass? && !error? end |
#fail_count ⇒ Object
35 36 37 |
# File 'lib/speq/values.rb', line 35 def fail_count values[1] end |
#pass? ⇒ Boolean
47 48 49 |
# File 'lib/speq/values.rb', line 47 def pass? fail_count.zero? && error_count.zero? end |
#pass_count ⇒ Object
31 32 33 |
# File 'lib/speq/values.rb', line 31 def pass_count values[0] end |
#report ⇒ Object
54 55 56 |
# File 'lib/speq/string_fmt.rb', line 54 def report "pass: #{pass_count}, fail: #{fail_count}, errors: #{error_count}" end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/speq/string_fmt.rb', line 58 def to_s pass? ? '✔'.green : 'x'.red end |