diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:10:04 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:10:04 +0000 |
commit | 1bf4fece121298260663c6ca73d39716d3548a03 (patch) | |
tree | 5c82dd2fa63552ecb67fcb034740ec7e8fdba25a /spec/support/matchers | |
parent | 254ec28f5448f6f353cd98f637985de3d1405854 (diff) | |
download | gitlab-ce-1bf4fece121298260663c6ca73d39716d3548a03.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/exceed_query_limit.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/support/matchers/exceed_query_limit.rb b/spec/support/matchers/exceed_query_limit.rb index f38ae44a577..b9630b00038 100644 --- a/spec/support/matchers/exceed_query_limit.rb +++ b/spec/support/matchers/exceed_query_limit.rb @@ -73,6 +73,42 @@ module ExceedQueryLimitHelpers end end +RSpec::Matchers.define :issue_same_number_of_queries_as do + supports_block_expectations + + include ExceedQueryLimitHelpers + + def control + block_arg + end + + def control_recorder + @control_recorder ||= ActiveRecord::QueryRecorder.new(&control) + end + + def expected_count + @expected_count ||= control_recorder.count + end + + def verify_count(&block) + @subject_block = block + + (expected_count - actual_count).abs <= threshold + end + + match do |block| + verify_count(&block) + end + + failure_message_when_negated do |actual| + failure_message + end + + def skip_cached + false + end +end + RSpec::Matchers.define :exceed_all_query_limit do |expected| supports_block_expectations |