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:
Diffstat (limited to 'spec/support/matchers/exceed_redis_call_limit.rb')
-rw-r--r--spec/support/matchers/exceed_redis_call_limit.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/support/matchers/exceed_redis_call_limit.rb b/spec/support/matchers/exceed_redis_call_limit.rb
new file mode 100644
index 00000000000..2b1e1ebad23
--- /dev/null
+++ b/spec/support/matchers/exceed_redis_call_limit.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module ExceedRedisCallLimitHelpers
+ def build_recorder(block)
+ return block if block.is_a?(RedisCommands::Recorder)
+
+ RedisCommands::Recorder.new(&block)
+ end
+
+ def verify_count(expected, block)
+ @actual = build_recorder(block).count
+
+ @actual > expected
+ end
+
+ def verify_commands_count(command, expected, block)
+ @actual = build_recorder(block).by_command(command).count
+
+ @actual > expected
+ end
+end
+
+RSpec::Matchers.define :exceed_redis_calls_limit do |expected|
+ supports_block_expectations
+
+ include ExceedRedisCallLimitHelpers
+
+ match do |block|
+ verify_count(expected, block)
+ end
+
+ failure_message do
+ "Expected at least #{expected} calls, but got #{actual}"
+ end
+
+ failure_message_when_negated do
+ "Expected a maximum of #{expected} calls, but got #{actual}"
+ end
+end
+
+RSpec::Matchers.define :exceed_redis_command_calls_limit do |command, expected|
+ supports_block_expectations
+
+ include ExceedRedisCallLimitHelpers
+
+ match do |block|
+ verify_commands_count(command, expected, block)
+ end
+
+ failure_message do
+ "Expected at least #{expected} calls to '#{command}', but got #{actual}"
+ end
+
+ failure_message_when_negated do
+ "Expected a maximum of #{expected} calls to '#{command}', but got #{actual}"
+ end
+end