Skip to content

Commit 2e6117a

Browse files
author
Stefanie Grunwald
authored
Merge pull request #19 from moertel/fix-unknown-columns-silent-error
Raise error for unknown column names
2 parents 5c94ee6 + 9b3f297 commit 2e6117a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/squcumber-postgres/step_definitions/common_steps.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
expected = data.hashes || []
114114
expected = convert_mock_values(expected) if placeholder
115115

116+
sanity_check_result(actual, expected)
117+
116118
expected.each_with_index do |hash, i|
117119
raise("Does not start with expected result, got:\n#{format_error(data, actual)}") unless actual[i].all? do |key, value|
118120
values_match(value, hash[key]) # actual,expected
@@ -125,10 +127,12 @@
125127
expected = data.hashes || []
126128
expected = convert_mock_values(expected) if placeholder
127129

130+
sanity_check_result(actual, expected)
131+
128132
expected.each do |hash|
129133
raise("Result is not included, got:\n#{format_error(data, actual)}") unless actual.any? do |row|
130134
row.all? do |key, value|
131-
values_match(value, hash[key]) # actual,expected
135+
values_match(value, hash[key]) # actual, expected
132136
end
133137
end
134138
end
@@ -139,6 +143,8 @@
139143
expected = data.hashes || []
140144
expected = convert_mock_values(expected) if placeholder
141145

146+
sanity_check_result(actual, expected)
147+
142148
expected.each do |hash|
143149
raise("Result is included, got:\n#{format_error(data, actual)}") if actual.any? do |row|
144150
row.all? do |key, value|
@@ -153,6 +159,8 @@
153159
expected = data.hashes || []
154160
expected = convert_mock_values(expected) if placeholder
155161

162+
sanity_check_result(actual, expected)
163+
156164
raise("Does not match exactly, got:\n#{format_error(data, actual)}") if actual.length != expected.length
157165

158166
actual.each_with_index do |row, i|

lib/squcumber-postgres/support/matchers.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
module MatcherHelpers
2+
def sanity_check_result(actual, expected)
3+
raise("The returned result is empty") if actual.empty?
4+
raise("No data provided for comparison") if expected.empty?
5+
6+
expected[0].keys.each do |expected_key|
7+
unless actual[0].keys.include?(expected_key)
8+
raise("Column name '#{expected_key}' does not exist in result.\nAvailable column names are #{actual[0].keys.join(', ')}")
9+
end
10+
end
11+
end
12+
213
def values_match(actual, expected)
314
if expected.eql?('today')
415
actual.match(/#{Regexp.quote(Date.today.to_s)}/)

0 commit comments

Comments
 (0)