Skip to content

Commit 519ca7b

Browse files
committed
[Test Runner] Adds suport for split_key, from user_profile tests
1 parent 2898084 commit 519ca7b

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
@@ -189,10 +189,24 @@ def compare_pairs(expected_pairs, response, test)
189189

190190
def compare_hash(expected_pairs, actual_hash, test)
191191
expected_pairs.each do |expected_key, expected_value|
192-
# Find the value to compare in the response
193-
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
194-
# Sometimes the expected *key* is a cached value from a previous request.
195-
test.get_cached_value(k)
192+
# TODO: Refactor! split_key
193+
if (match = expected_key.match(/(^\$[a-z]+)/))
194+
keys = expected_key.split('.')
195+
keys.delete(match[1])
196+
dynamic_key = test.cached_values[match[1].gsub('$', '')]
197+
value = dynamic_key.dig(*keys)
198+
199+
if expected_pairs.values.first.is_a?(String) && expected_pairs.values.first.match?(/^\$/)
200+
return test.cached_values[expected_pairs.values.first.gsub('$','')] == value
201+
else
202+
return expected_pairs.values.first == value
203+
end
204+
205+
else
206+
split_key = TestFile::Test.split_and_parse_key(expected_key).collect do |k|
207+
# Sometimes the expected *key* is a cached value from a previous request.
208+
test.get_cached_value(k)
209+
end
196210
end
197211
# We now accept 'nested.keys' so let's try the previous implementation and if that doesn't
198212
# work, try with the nested key, otherwise, raise exception.

0 commit comments

Comments
 (0)