diff options
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/be_boolean.rb | 10 | ||||
-rw-r--r-- | spec/support/matchers/exceed_query_limit.rb | 29 |
2 files changed, 39 insertions, 0 deletions
diff --git a/spec/support/matchers/be_boolean.rb b/spec/support/matchers/be_boolean.rb new file mode 100644 index 00000000000..b8c2c385504 --- /dev/null +++ b/spec/support/matchers/be_boolean.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Assert that this value is a boolean, i.e. true or false +# +# ``` +# expect(value).to be_boolean +# ``` +RSpec::Matchers.define :be_boolean do + match { |value| value.in? [true, false] } +end diff --git a/spec/support/matchers/exceed_query_limit.rb b/spec/support/matchers/exceed_query_limit.rb index a5a017828b3..4b08c13945c 100644 --- a/spec/support/matchers/exceed_query_limit.rb +++ b/spec/support/matchers/exceed_query_limit.rb @@ -380,3 +380,32 @@ RSpec::Matchers.define :exceed_query_limit do |expected| failure_message end end + +RSpec::Matchers.define :match_query_count do |expected| + supports_block_expectations + + include ExceedQueryLimitHelpers + + def verify_count(&block) + @subject_block = block + actual_count == maximum + end + + def failure_message + threshold_message = threshold > 0 ? " (+#{threshold})" : '' + counts = "#{expected_count}#{threshold_message}" + "Expected exactly #{counts} queries, got #{actual_count}:\n\n#{log_message}" + end + + def skip_cached + false + end + + match do |block| + verify_count(&block) + end + + failure_message_when_negated do |actual| + failure_message + end +end |