19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/squcumber-postgres/support/output.rb', line 19
def format_error(expected_data, actual_result)
expectation_count = (expected_data.rows.count rescue nil) || 0
if expectation_count == 0
table_headings = actual_result[0].keys
else
table_headings = expected_data.hashes[0].keys
end
print_data = Hash[table_headings.map { |key| [key, key.length] }]
actual_result.each do |row|
row.each do |key, value|
print_data[key] = value.length if (value.to_s.length > print_data[key].to_i)
end
end
error = '| ' + table_headings.map { |k| k.ljust(print_data[k], ' ') }.join(' | ') + " |\n"
error << actual_result.map do |row|
'| ' + table_headings.map { |k| (row[k] || '').ljust(print_data[k], ' ') }.join(' | ') + ' |'
end.join("\n") + "\n"
error
end
|