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.
-
#definition ⇒ String
readonly
A readable string of the matcher and any expected values.
-
#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.
Instance Method Summary collapse
-
#colored_char ⇒ String
Express the result with one colored char.
-
#colored_string ⇒ String
The colored string representation of the result.
-
#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 |
#definition ⇒ String (readonly)
Returns A readable string of the matcher and any expected values.
13 14 15 |
# File 'lib/expresenter/common.rb', line 13 def definition @definition end |
#error ⇒ Exception? (readonly)
Returns Any possible raised exception.
16 17 18 |
# File 'lib/expresenter/common.rb', line 16 def error @error end |
#expected ⇒ #object_id (readonly)
Returns The expected value.
19 20 21 |
# File 'lib/expresenter/common.rb', line 19 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.
23 24 25 |
# File 'lib/expresenter/common.rb', line 23 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 |
Instance Method Details
#colored_char ⇒ String
Express the result with one colored char.
87 88 89 |
# File 'lib/expresenter/common.rb', line 87 def colored_char color(char) end |
#colored_string ⇒ String
The colored string representation of the result.
94 95 96 |
# File 'lib/expresenter/common.rb', line 94 def colored_string color(to_bold_s) 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}, " \ "definition: #{definition.inspect}, " \ "error: #{error.inspect}, " \ "expected: #{expected.inspect}, " \ "got: #{got.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.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/expresenter/common.rb', line 72 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.
108 109 110 111 112 113 114 |
# File 'lib/expresenter/common.rb', line 108 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
The representation of the result.
101 102 103 |
# File 'lib/expresenter/common.rb', line 101 def to_s "#{titre}: #{summary}." end |