Module: Spectus::Result::Base

Included in:
Fail, Pass
Defined in:
lib/spectus/result/base.rb

Overview

Result base’s module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actualObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def actual
  @actual
end

#challengeObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def challenge
  @challenge
end

#contextObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def context
  @context
end

#errorObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def error
  @error
end

#expectedObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def expected
  @expected
end

#gotObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def got
  @got
end

#levelObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def level
  @level
end

#subjectObject (readonly)



45
46
47
# File 'lib/spectus/result/base.rb', line 45

def subject
  @subject
end

Instance Method Details

#initialize(message, subject, challenge, context, actual, expected, got, error, level, negate, valid) ⇒ Object

Initialize the result class.

Parameters:

  • message (String)

    It is describing the actual/error value.

  • subject (#object_id)

    The untrusted object to be tested.

  • challenge (Symbol)

    The method to call on the subject.

  • context (Array)

    Parameters of the challenge.

  • actual (#object_id)

    The value that the subject return through its challenge.

  • expected (Array, Hash, Symbol)

    The definition of the expected value.

  • got (#object_id)

    The result of the boolean comparison between the actual value and the expected value.

  • error (#exception, nil)

    Any possible raised exception.

  • level (:High, :Medium, :Low)

    The level of the expectation.

  • negate (Boolean)

    Evaluate to a negative assertion.

  • valid (Boolean)

    Report if the test was true or false.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spectus/result/base.rb', line 24

def initialize(message, subject, challenge, context, actual, expected,
               got, error, level, negate, valid)

  if respond_to?(:exception)
    super(message)
  else
    @message  = message
  end

  @subject    = subject
  @challenge  = challenge
  @context    = context
  @actual     = actual
  @expected   = expected
  @got        = got
  @error      = error
  @level      = level
  @negate     = negate
  @valid      = valid
end

#negate?Boolean

The value of the negate instance variable.

Returns:

  • (Boolean)

    evaluated to a negative assertion or not.



51
52
53
# File 'lib/spectus/result/base.rb', line 51

def negate?
  @negate
end

#to_hSymbol

Report the result.

Returns:

  • (Symbol)

    the properties of the result.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/spectus/result/base.rb', line 66

def to_h
  {
    subject:    subject,
    challenge:  challenge,
    context:    context,
    actual:     actual,
    expected:   expected,
    got:        got,
    error:      error,
    level:      level,
    negate:     negate?,
    valid:      valid?,
    result:     result?
  }
end

#valid?Boolean

The value of the boolean comparison between the actual value and the expected value.

Returns:

  • (Boolean)

    the test was true or false.



59
60
61
# File 'lib/spectus/result/base.rb', line 59

def valid?
  @valid
end