Module: Expresenter::Common
Overview
Common collection of methods.
Constant Summary collapse
- 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.
-
#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.
9 10 11 |
# File 'lib/expresenter/common.rb', line 9 def actual @actual end |
#error ⇒ Exception? (readonly)
Returns Any possible raised exception.
12 13 14 |
# File 'lib/expresenter/common.rb', line 12 def error @error end |
#expected ⇒ #object_id (readonly)
Returns The expected value.
15 16 17 |
# File 'lib/expresenter/common.rb', line 15 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.
19 20 21 |
# File 'lib/expresenter/common.rb', line 19 def got @got end |
#level ⇒ :MUST, ... (readonly)
Returns The requirement level of the expectation.
25 26 27 |
# File 'lib/expresenter/common.rb', line 25 def level @level end |
#matcher ⇒ Symbol (readonly)
Returns The matcher.
22 23 24 |
# File 'lib/expresenter/common.rb', line 22 def matcher @matcher end |
Instance Method Details
#colored_char ⇒ String
Express the result with one colored char.
102 103 104 |
# File 'lib/expresenter/common.rb', line 102 def colored_char color(char) end |
#colored_string ⇒ String
The colored string representation of the result.
109 110 111 |
# File 'lib/expresenter/common.rb', line 109 def colored_string color(to_bold_s) end |
#definition ⇒ String
The readable definition.
80 81 82 |
# File 'lib/expresenter/common.rb', line 80 def definition [matcher.to_s.tr("_", " "), expected&.inspect].compact.join(SPACE) end |
#error? ⇒ Boolean
The state of error.
44 45 46 |
# File 'lib/expresenter/common.rb', line 44 def error? !error.nil? end |
#inspect ⇒ String
A string containing a human-readable representation of the result.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/expresenter/common.rb', line 66 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 |
#negate? ⇒ Boolean
The value of the negate instance variable.
37 38 39 |
# File 'lib/expresenter/common.rb', line 37 def negate? @negate end |
#passed? ⇒ Boolean
Did the test pass?
30 31 32 |
# File 'lib/expresenter/common.rb', line 30 def passed? !failed? end |
#success? ⇒ Boolean
The state of success.
51 52 53 |
# File 'lib/expresenter/common.rb', line 51 def success? got.equal?(true) end |
#summary ⇒ String
The summary of the result.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/expresenter/common.rb', line 87 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.
123 124 125 126 127 128 129 |
# File 'lib/expresenter/common.rb', line 123 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
The representation of the result.
116 117 118 |
# File 'lib/expresenter/common.rb', line 116 def to_s "#{titre}: #{summary}." end |
#valid? ⇒ Boolean
The value of the boolean comparison between the actual value and the expected value.
59 60 61 |
# File 'lib/expresenter/common.rb', line 59 def valid? @valid end |