diff options
author | Rémy Coutable <remy@rymai.me> | 2017-11-22 16:33:10 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-11-22 16:33:10 +0000 |
commit | c4de6ec496fd9556ac6cdacbeeb008c833ce9bf1 (patch) | |
tree | 68f7ffb3f7187baaaec40d87c0cf7df65c7a5ea4 /spec/support | |
parent | e72804ed0a73f8807ca58881645f0c95c70de9c9 (diff) | |
parent | db1925f917b30571e0e9d4de63417db90dc693d7 (diff) | |
download | gitlab-ce-c4de6ec496fd9556ac6cdacbeeb008c833ce9bf1.tar.gz |
Merge branch 'improve-extra-queries-output' into 'master'
Improve output for extra queries in specs
See merge request gitlab-org/gitlab-ce!15537
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/query_recorder.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/support/query_recorder.rb b/spec/support/query_recorder.rb index cd67b517ea0..369775db462 100644 --- a/spec/support/query_recorder.rb +++ b/spec/support/query_recorder.rb @@ -76,10 +76,17 @@ RSpec::Matchers.define :exceed_query_limit do |expected| @recorder.count end + def count_queries(queries) + queries.each_with_object(Hash.new(0)) { |query, counts| counts[query] += 1 } + end + def log_message if expected.is_a?(ActiveRecord::QueryRecorder) - extra_queries = (expected.log - @recorder.log).join("\n\n") - "Extra queries: \n\n #{extra_queries}" + counts = count_queries(expected.log) + extra_queries = @recorder.log.reject { |query| counts[query] -= 1 unless counts[query].zero? } + extra_queries_display = count_queries(extra_queries).map { |query, count| "[#{count}] #{query}" } + + (['Extra queries:'] + extra_queries_display).join("\n\n") else @recorder.log_message end |