Class: Ccp::Utils::TestFailed::Differ

Inherits:
Struct
  • Object
show all
Defined in:
lib/ccp/utils/test_failed.rb,
lib/ccp/utils/test_failed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aObject

Returns the value of attribute a

Returns:

  • (Object)

    the current value of a



4
5
6
# File 'lib/ccp/utils/test_failed.rb', line 4

def a
  @a
end

#bObject

Returns the value of attribute b

Returns:

  • (Object)

    the current value of b



4
5
6
# File 'lib/ccp/utils/test_failed.rb', line 4

def b
  @b
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/ccp/utils/test_failed.rb', line 4

def path
  @path
end

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ccp/utils/test_failed.rb', line 6

def execute
  unless a.class == b.class
    failed("%s expected [%s], but got [%s]" % [path, a.class, b.class])
  end

  if a.class == Array
    max = [a.size, b.size].max
    (0...max).each do |i|
      Differ.new(a[i], b[i], "#{path}[#{i}]").execute
    end
    return true
  end

  if a.class == Hash
    (a.keys | b.keys).each do |key|
      Differ.new(a[key], b[key], "#{path}[#{key}]").execute
    end
    return true
  end

  unless a == b
    failed("%s expected %s, but got %s" % [path, a.inspect, b.inspect])
  end
end