Module: Expresenter::Common
Overview
Common collection of methods.
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.
-
#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/common.rb', line 7 def actual @actual end |
#error ⇒ Exception? (readonly)
Returns Any possible raised exception.
10 11 12 |
# File 'lib/expresenter/common.rb', line 10 def error @error end |
#expected ⇒ #object_id (readonly)
Returns The expected value.
13 14 15 |
# File 'lib/expresenter/common.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/common.rb', line 17 def got @got end |
#level ⇒ :MUST, ... (readonly)
Returns The requirement level of the expectation.
23 24 25 |
# File 'lib/expresenter/common.rb', line 23 def level @level end |
#matcher ⇒ #object_id (readonly)
Returns The matcher.
20 21 22 |
# File 'lib/expresenter/common.rb', line 20 def matcher @matcher end |
Instance Method Details
#colored_char ⇒ String
Express the result with one colored char.
107 108 109 |
# File 'lib/expresenter/common.rb', line 107 def colored_char color(char) end |
#colored_string ⇒ String
The colored string representation of the result.
114 115 116 |
# File 'lib/expresenter/common.rb', line 114 def colored_string color(to_s) end |
#definition ⇒ String
The readable definition.
78 79 80 |
# File 'lib/expresenter/common.rb', line 78 def definition [matcher, expected&.inspect].compact.join(" ") end |
#error? ⇒ Boolean
The state of error.
42 43 44 |
# File 'lib/expresenter/common.rb', line 42 def error? !error.nil? end |
#inspect ⇒ String
A string containing a human-readable representation of the result.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/expresenter/common.rb', line 64 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.
85 86 87 |
# File 'lib/expresenter/common.rb', line 85 def maybe_negate negate? ? " not" : "" end |
#negate? ⇒ Boolean
The value of the negate instance variable.
35 36 37 |
# File 'lib/expresenter/common.rb', line 35 def negate? @negate end |
#passed? ⇒ Boolean
Did the test pass?
28 29 30 |
# File 'lib/expresenter/common.rb', line 28 def passed? !failed? end |
#success? ⇒ Boolean
The state of success.
49 50 51 |
# File 'lib/expresenter/common.rb', line 49 def success? got.equal?(true) end |
#summary ⇒ String
The summary of the result.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/expresenter/common.rb', line 92 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.
128 129 130 131 132 133 134 |
# File 'lib/expresenter/common.rb', line 128 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
The representation of the result.
121 122 123 |
# File 'lib/expresenter/common.rb', line 121 def to_s "#{titre}: #{summary}." end |
#valid? ⇒ Boolean
The value of the boolean comparison between the actual value and the expected value.
57 58 59 |
# File 'lib/expresenter/common.rb', line 57 def valid? @valid end |