Module: Expresenter::Common
Overview
Common collection of methods.
Constant Summary collapse
- SPACE =
White space.
" "
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 ⇒ Symbol
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.
-
#inspect ⇒ String
A string containing a human-readable representation of the result.
-
#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.
Instance Attribute Details
#actual ⇒ #object_id (readonly)
Returned value by the challenged subject.
10 11 12 |
# File 'lib/expresenter/common.rb', line 10 def actual @actual end |
#error ⇒ Exception? (readonly)
Returns Any possible raised exception.
13 14 15 |
# File 'lib/expresenter/common.rb', line 13 def error @error end |
#expected ⇒ #object_id (readonly)
Returns The expected value.
16 17 18 |
# File 'lib/expresenter/common.rb', line 16 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.
20 21 22 |
# File 'lib/expresenter/common.rb', line 20 def got @got end |
#level ⇒ :MUST, ... (readonly)
Returns The requirement level of the expectation.
26 27 28 |
# File 'lib/expresenter/common.rb', line 26 def level @level end |
#matcher ⇒ Symbol (readonly)
Returns The matcher.
23 24 25 |
# File 'lib/expresenter/common.rb', line 23 def matcher @matcher end |
Instance Method Details
#colored_char ⇒ String
Express the result with one colored char.
94 95 96 |
# File 'lib/expresenter/common.rb', line 94 def colored_char color(char) end |
#colored_string ⇒ String
The colored string representation of the result.
101 102 103 |
# File 'lib/expresenter/common.rb', line 101 def colored_string color(to_bold_s) end |
#definition ⇒ String
The readable definition.
72 73 74 |
# File 'lib/expresenter/common.rb', line 72 def definition [matcher.to_s.tr("_", " "), expected&.inspect].compact.join(SPACE) end |
#error? ⇒ Boolean
The state of error.
45 46 47 |
# File 'lib/expresenter/common.rb', line 45 def error? !error.nil? end |
#inspect ⇒ String
A string containing a human-readable representation of the result.
59 60 61 62 63 64 65 66 67 |
# File 'lib/expresenter/common.rb', line 59 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}" \ end |
#negate? ⇒ Boolean
The value of the negate instance variable.
38 39 40 |
# File 'lib/expresenter/common.rb', line 38 def negate? @negate end |
#passed? ⇒ Boolean
Did the test pass?
31 32 33 |
# File 'lib/expresenter/common.rb', line 31 def passed? !failed? end |
#success? ⇒ Boolean
The state of success.
52 53 54 |
# File 'lib/expresenter/common.rb', line 52 def success? got.equal?(true) end |
#summary ⇒ String
The summary of the result.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/expresenter/common.rb', line 79 def summary if error? error. elsif actual.is_a?(::Exception) actual. elsif actual == expected ["expected", negation, "to", definition].compact.join(SPACE) else ["expected", actual.inspect, negation, "to", definition].compact.join(SPACE) end end |
#titre ⇒ String
Titre for the result.
115 116 117 118 119 120 121 |
# File 'lib/expresenter/common.rb', line 115 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
The representation of the result.
108 109 110 |
# File 'lib/expresenter/common.rb', line 108 def to_s "#{titre}: #{summary}." end |