Module: Expresenter::Base
Overview
Common collection of methods for Result’s classes.
Instance Attribute Summary collapse
-
#actual ⇒ #object_id
readonly
Returned value by the challenged subject.
-
#error ⇒ Exception?
readonly
Any possible raised exception.
-
#expected ⇒ #object_id
readonly
The expected value.
-
#got ⇒ #object_id
readonly
The result of the boolean comparison between the actual value and the expected value through the matcher.
-
#level ⇒ :MUST, ...
readonly
The requirement level of the expectation.
-
#matcher ⇒ #object_id
readonly
The matcher.
Instance Method Summary collapse
-
#colored_char ⇒ String
Express the result with one colored char.
-
#colored_string ⇒ String
The colored string representation of the result.
-
#definition ⇒ String
The readable definition.
-
#error? ⇒ Boolean
The state of error.
-
#initialize(actual:, error:, expected:, got:, negate:, valid:, matcher:, level:) ⇒ Object
Common initialize method.
-
#inspect ⇒ String
A string containing a human-readable representation of the result.
-
#maybe_negate ⇒ String
The negation, if any.
-
#negate? ⇒ Boolean
The value of the negate instance variable.
-
#passed? ⇒ Boolean
Did the test pass?.
-
#success? ⇒ Boolean
The state of success.
-
#summary ⇒ String
The summary of the result.
-
#titre ⇒ String
Titre for the result.
-
#to_s ⇒ String
The representation of the result.
-
#valid? ⇒ Boolean
The value of the boolean comparison between the actual value and the expected value.
Instance Attribute Details
#actual ⇒ #object_id (readonly)
Returned value by the challenged subject.
7 8 9 |
# File 'lib/expresenter/base.rb', line 7 def actual @actual end |
#error ⇒ Exception? (readonly)
Returns Any possible raised exception.
10 11 12 |
# File 'lib/expresenter/base.rb', line 10 def error @error end |
#expected ⇒ #object_id (readonly)
Returns The expected value.
13 14 15 |
# File 'lib/expresenter/base.rb', line 13 def expected @expected end |
#got ⇒ #object_id (readonly)
Returns The result of the boolean comparison between the actual value and the expected value through the matcher.
17 18 19 |
# File 'lib/expresenter/base.rb', line 17 def got @got end |
#level ⇒ :MUST, ... (readonly)
Returns The requirement level of the expectation.
23 24 25 |
# File 'lib/expresenter/base.rb', line 23 def level @level end |
#matcher ⇒ #object_id (readonly)
Returns The matcher.
20 21 22 |
# File 'lib/expresenter/base.rb', line 20 def matcher @matcher end |
Instance Method Details
#colored_char ⇒ String
Express the result with one colored char.
133 134 135 |
# File 'lib/expresenter/base.rb', line 133 def colored_char color(char) end |
#colored_string ⇒ String
The colored string representation of the result.
140 141 142 |
# File 'lib/expresenter/base.rb', line 140 def colored_string color(to_s) end |
#definition ⇒ String
The readable definition.
104 105 106 |
# File 'lib/expresenter/base.rb', line 104 def definition [matcher, expected&.inspect].compact.join(" ") end |
#error? ⇒ Boolean
The state of error.
68 69 70 |
# File 'lib/expresenter/base.rb', line 68 def error? !error.nil? end |
#initialize(actual:, error:, expected:, got:, negate:, valid:, matcher:, level:) ⇒ Object
Common initialize method.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/expresenter/base.rb', line 36 def initialize(actual:, error:, expected:, got:, negate:, valid:, matcher:, level:) @actual = actual @error = error @expected = expected @got = got @negate = negate @valid = valid @matcher = matcher @level = level super(to_s) if failed? end |
#inspect ⇒ String
A string containing a human-readable representation of the result.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/expresenter/base.rb', line 90 def inspect "#{self.class}(actual: #{actual.inspect}, " \ "error: #{error.inspect}, " \ "expected: #{expected.inspect}, " \ "got: #{got.inspect}, " \ "matcher: #{matcher.inspect}, " \ "negate: #{negate?.inspect}, " \ "level: #{level.inspect}, " \ "valid: #{valid?.inspect})" \ end |
#maybe_negate ⇒ String
The negation, if any.
111 112 113 |
# File 'lib/expresenter/base.rb', line 111 def maybe_negate negate? ? " not" : "" end |
#negate? ⇒ Boolean
The value of the negate instance variable.
61 62 63 |
# File 'lib/expresenter/base.rb', line 61 def negate? @negate end |
#passed? ⇒ Boolean
Did the test pass?
54 55 56 |
# File 'lib/expresenter/base.rb', line 54 def passed? !failed? end |
#success? ⇒ Boolean
The state of success.
75 76 77 |
# File 'lib/expresenter/base.rb', line 75 def success? got.equal?(true) end |
#summary ⇒ String
The summary of the result.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/expresenter/base.rb', line 118 def summary if error? error. elsif actual.is_a?(::Exception) actual. elsif actual == expected "expected#{maybe_negate} to #{definition}" else "expected #{actual.inspect}#{maybe_negate} to #{definition}" end end |
#titre ⇒ String
Titre for the result.
154 155 156 157 158 159 160 |
# File 'lib/expresenter/base.rb', line 154 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
The representation of the result.
147 148 149 |
# File 'lib/expresenter/base.rb', line 147 def to_s "#{titre}: #{summary}." end |
#valid? ⇒ Boolean
The value of the boolean comparison between the actual value and the expected value.
83 84 85 |
# File 'lib/expresenter/base.rb', line 83 def valid? @valid end |