diff --git a/ee/spec/support/elastic_query_name_inspector.rb b/ee/spec/support/elastic_query_name_inspector.rb index ef599d9a6a65b3f1711af7c2a5f9f1adb98e5c09..82f31762363cfd7874eaa420fca1721cea8b5b25 100644 --- a/ee/spec/support/elastic_query_name_inspector.rb +++ b/ee/spec/support/elastic_query_name_inspector.rb @@ -12,11 +12,17 @@ def inspect(query) @names += query.deep_find_all("_name") end - def has_named_query?(*expected_names) + def query_with?(expected_names:, unexpected_names:) + has_named_query?(expected_names) && excludes_named_query?(unexpected_names) + end + + private + + def has_named_query?(expected_names) @names.superset?(expected_names.to_set) end - def excludes_named_query?(*unexpected_names) + def excludes_named_query?(unexpected_names) unexpected_names.all? { |name| @names.exclude?(name) } end end diff --git a/ee/spec/support/helpers/elasticsearch_helpers.rb b/ee/spec/support/helpers/elasticsearch_helpers.rb index 14065ecc5517a620afb17e5e522dd8fce85c3ad7..4769428645a49110b2c69711bb2dd966be4d6739 100644 --- a/ee/spec/support/helpers/elasticsearch_helpers.rb +++ b/ee/spec/support/helpers/elasticsearch_helpers.rb @@ -14,8 +14,7 @@ def assert_named_queries(*expected_names, without: []) inspector = ElasticQueryNameInspector.new inspector.inspect(query) - inspector.has_named_query?(*expected_names) - inspector.excludes_named_query?(*without) + inspector.query_with?(expected_names: expected_names, unexpected_names: without) rescue ::JSON::ParserError false end