Class: Lookout::Difference::Object
- Defined in:
- lib/lookout-3.0/difference/object.rb
Overview
Difference reports between Objects. This is the base difference report class and should be subclassed if something more specific fits the bill. The actual result and expected value are assumed to differ and you’ll surely get confused if they don’t. Determining if the objects differ is up to the caller.
Direct Known Subclasses
Array, Exception, Hash, Lookout::Actual::Method, Lookout::Output, Module, Range, Regexp, String, Symbol
Instance Attribute Summary collapse
-
#actual ⇒ ::Object
readonly
The actual result.
-
#expected ⇒ ::Object
readonly
The expected value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #diff ⇒ Enumerable<String>
- #hash ⇒ Object
-
#initialize(actual, expected) ⇒ Object
constructor
Initializes a difference report between the ACTUAL result and the EXPECTED value.
- #message ⇒ ::String
- #to_s ⇒ ::String
Constructor Details
#initialize(actual, expected) ⇒ Object
Initializes a difference report between the ACTUAL result and the EXPECTED value.
13 |
# File 'lib/lookout-3.0/difference/object.rb', line 13 def initialize(actual, expected) @actual, @expected = actual, expected end |
Instance Attribute Details
#actual ⇒ ::Object (readonly)
Returns The actual result.
58 59 60 |
# File 'lib/lookout-3.0/difference/object.rb', line 58 def actual @actual end |
#expected ⇒ ::Object (readonly)
Returns The expected value.
61 62 63 |
# File 'lib/lookout-3.0/difference/object.rb', line 61 def expected @expected end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 52 |
# File 'lib/lookout-3.0/difference/object.rb', line 49 def ==(other) self.class == other.class and == other. and diff.to_s == other.diff.to_s end |
#diff ⇒ Enumerable<String>
26 |
# File 'lib/lookout-3.0/difference/object.rb', line 26 def diff; [] end |
#hash ⇒ Object
55 |
# File 'lib/lookout-3.0/difference/object.rb', line 55 def hash; @hash ||= [, diff.to_s].hash end |
#message ⇒ ::String
19 |
# File 'lib/lookout-3.0/difference/object.rb', line 19 def ; [inspect_actual, symbol, inspect_expected].join('') end |
#to_s ⇒ ::String
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lookout-3.0/difference/object.rb', line 31 def to_s begin m = rescue => e raise if self.class == Lookout::Difference::Object rescue true return '%s (cannot generate more specific failure message: %s)' % [Lookout::Difference::Object.new(actual, expected)., e] end begin d = diff.to_a.join("\n") rescue => e d = '(cannot diff expected value and actual result: %s)' % e end d.empty? ? m : [m, d].join(d.include?("\n") ? "\n" : ': ') end |