Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-12 21:08:38 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-12 21:08:38 +0300
commitaed0a60015f542db07f971fe321bd52207f632a4 (patch)
treef2a8ba4cf78799af1aff3ee49013afe791925bbb /spec/support/matchers
parent0024c2f44455cf5ace9235a7efa195c12a1d72d2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/make_queries.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/support/matchers/make_queries.rb b/spec/support/matchers/make_queries.rb
new file mode 100644
index 00000000000..19c69240a40
--- /dev/null
+++ b/spec/support/matchers/make_queries.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+RSpec::Matchers.define :make_queries do |expected_count = nil|
+ supports_block_expectations
+
+ match do |block|
+ @recorder = ActiveRecord::QueryRecorder.new(&block)
+ @counter = @recorder.count
+ if expected_count
+ @counter == expected_count
+ else
+ @counter > 0
+ end
+ end
+
+ failure_message do |_|
+ if expected_count
+ "expected to make #{expected_count} queries but made #{@counter} queries"
+ else
+ "expected to make queries but did not make any"
+ end
+ end
+
+ failure_message_when_negated do |_|
+ if expected_count
+ "expected not to make #{expected_count} queries but received #{@counter} queries"
+ else
+ "expected not to make queries but received #{@counter} queries"
+ end
+ end
+end