Class: Lookout::Equalities::Hash

Inherits:
Object show all
Defined in:
lib/lookout/equalities/hash.rb

Instance Method Summary collapse

Methods inherited from Object

#message

Instance Method Details

#diff(expected, actual) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/lookout/equalities/hash.rb', line 11

def diff(expected, actual)
  return if expected.size == 1 or not Hash === actual
  Lookout::Diff::Formats::Hash.
    new(Lookout::Diff::Operations.
          new(Lookout::Diff::Algorithms::Difflib.
                new(array(actual), array(expected)))).to_a.join("\n")
end

#equal?(expected, actual) ⇒ Boolean

Returns:



6
7
8
9
# File 'lib/lookout/equalities/hash.rb', line 6

def equal?(expected, actual)
  return false unless Hash === actual and expected.size == actual.size
  expected.all?{ |k, v| Lookout::Equality.equal? v, actual[k] }
end