Class: Dragnet::VerificationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/dragnet/verification_result.rb

Overview

Holds the verification result of a Manual Test Record

Constant Summary collapse

VALID_STATUSES =
%i[passed skipped failed].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, reason: nil) ⇒ VerificationResult

Creates a new instance of the class.

Parameters:

  • status (Symbol)

    The status

  • reason (String) (defaults to: nil)


17
18
19
20
# File 'lib/dragnet/verification_result.rb', line 17

def initialize(status:, reason: nil)
  self.status = status
  @reason = reason
end

Instance Attribute Details

#finished_atObject

Returns the value of attribute finished_at.



12
13
14
# File 'lib/dragnet/verification_result.rb', line 12

def finished_at
  @finished_at
end

#reasonObject (readonly)

Returns the value of attribute reason.



12
13
14
# File 'lib/dragnet/verification_result.rb', line 12

def reason
  @reason
end

#started_atObject

Returns the value of attribute started_at.



12
13
14
# File 'lib/dragnet/verification_result.rb', line 12

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



12
13
14
# File 'lib/dragnet/verification_result.rb', line 12

def status
  @status
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dragnet/verification_result.rb', line 30

def failed?
  status == :failed
end

#log_messageString

Returns A string representation of the receiver that can be used to log the result of a verification.

Returns:

  • (String)

    A string representation of the receiver that can be used to log the result of a verification.



93
94
95
96
97
98
99
100
101
# File 'lib/dragnet/verification_result.rb', line 93

def log_message
  if passed?
    '✔ PASSED '.colorize(:light_green)
  elsif skipped?
    "#{'⚠ SKIPPED'.colorize(:light_yellow)} #{reason}"
  else
    "#{'✘ FAILED '.colorize(:light_red)} #{reason || 'Unknown reason'}"
  end
end

#passed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dragnet/verification_result.rb', line 22

def passed?
  status == :passed
end

#runtimeFloat?

Returns The runtime calculated from the started_at and finished_at attributes, if any of them is missing nil is returned instead.

Returns:

  • (Float, nil)

    The runtime calculated from the started_at and finished_at attributes, if any of them is missing nil is returned instead.



78
79
80
81
82
# File 'lib/dragnet/verification_result.rb', line 78

def runtime
  runtime!
rescue Dragnet::Errors::MissingTimestampAttributeError
  nil
end

#runtime!Float

Returns The runtime calculated from the started_at and finished_at timestamp attributes.

Returns:

  • (Float)

    The runtime calculated from the started_at and finished_at timestamp attributes.

Raises:

  • (TypeError)

    If either of these attributes is nil



87
88
89
# File 'lib/dragnet/verification_result.rb', line 87

def runtime!
  @runtime ||= calculate_runtime
end

#skipped?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dragnet/verification_result.rb', line 26

def skipped?
  status == :skipped
end