Skip to content

Commit 95e7573

Browse files
committed
[Test Runner] Rspec matcher - handle is_true with split_key
1 parent fb83f53 commit 95e7573

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
# Validate that a field is `true`.
4343
RSpec::Matchers.define :match_true_field do |field, test|
4444
match do |response|
45+
# TODO: Refactor! split_key for is_true
46+
if (match = field.match(/(^\$[a-z]+)/))
47+
keys = field.split('.')
48+
keys.delete(match[1])
49+
dynamic_key = test.cached_values[match[1].gsub('$', '')]
50+
return !!dynamic_key.dig(*keys)
51+
end
52+
4553
# Handle is_true: ''
4654
return !!response if field == ''
4755

0 commit comments

Comments
 (0)