Class: Lookout::Difference::Object

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual, expected) ⇒ Object

Initializes a difference report between the ACTUAL result and the EXPECTED value.

Parameters:



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.

Returns:



58
59
60
# File 'lib/lookout-3.0/difference/object.rb', line 58

def actual
  @actual
end

#expected::Object (readonly)

Returns The expected value.

Returns:



61
62
63
# File 'lib/lookout-3.0/difference/object.rb', line 61

def expected
  @expected
end

Instance Method Details

#==(other) ⇒ Object

Returns True if the receiver’s class, #message, and #diff equal those of OTHER.

Returns:

  • True if the receiver’s class, #message, and #diff equal those of OTHER



49
50
51
52
# File 'lib/lookout-3.0/difference/object.rb', line 49

def ==(other)
  self.class == other.class and
    message == other.message and diff.to_s == other.diff.to_s
end

#diffEnumerable<String>

Note:

The Enumerable returned by this specific implementation is empty. Subclasses may provide more detailed information for their specific types.

Returns An Enumerable over the formatted operations that would have to be applied to #actual to get #expected.

Returns:

  • (Enumerable<String>)

    An Enumerable over the formatted operations that would have to be applied to #actual to get #expected



26
# File 'lib/lookout-3.0/difference/object.rb', line 26

def diff; [] end

#hashObject

Returns a hash value based on #message and #diff.

Returns:



55
# File 'lib/lookout-3.0/difference/object.rb', line 55

def hash; @hash ||= [message, diff.to_s].hash end

#message::String

Note:

Subclasses may override this method to provide more specific messages for their specific types.

Returns The concatenation of #inspect_actual, #symbol, and #inspect_expected, explaining how #actual differs from #expected.

Returns:

  • (::String)

    The concatenation of #inspect_actual, #symbol, and #inspect_expected, explaining how #actual differs from #expected



19
# File 'lib/lookout-3.0/difference/object.rb', line 19

def message; [inspect_actual, symbol, inspect_expected].join('') end

#to_s::String

Note:

This method should not be overridden by subclasses, as it goes to some lengths to safely return a String for display.

Returns The concatenation of #message and #diff.

Returns:



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 = message
  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).message, 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