Skip to content

Commit 8ec8f8e

Browse files
committed
[Test Runner] Adds suport for split_key, from user_profile tests
1 parent 232051b commit 8ec8f8e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

elasticsearch-api/api-spec-testing/rspec_matchers.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,24 @@ def compare_pairs(expected_pairs, response, test)
198198

199199
def compare_hash(expected_pairs, actual_hash, test)
200200
expected_pairs.each do |expected_key, expected_value|
201-
# Find the value to compare in the response
202-
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
203-
# Sometimes the expected *key* is a cached value from a previous request.
204-
test.get_cached_value(k)
201+
# TODO: Refactor! split_key
202+
if (match = expected_key.match(/(^\$[a-z]+)/))
203+
keys = expected_key.split('.')
204+
keys.delete(match[1])
205+
dynamic_key = test.cached_values[match[1].gsub('$', '')]
206+
value = dynamic_key.dig(*keys)
207+
208+
if expected_pairs.values.first.is_a?(String) && expected_pairs.values.first.match?(/^\$/)
209+
return test.cached_values[expected_pairs.values.first.gsub('$','')] == value
210+
else
211+
return expected_pairs.values.first == value
212+
end
213+
214+
else
215+
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
216+
# Sometimes the expected *key* is a cached value from a previous request.
217+
test.get_cached_value(k)
218+
end
205219
end
206220
# We now accept 'nested.keys' so let's try the previous implementation and if that doesn't
207221
# work, try with the nested key, otherwise, raise exception.

0 commit comments

Comments
 (0)