summaryrefslogtreecommitdiff
path: root/spec/support/matchers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support/matchers
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/background_migrations_matchers.rb19
-rw-r--r--spec/support/matchers/graphql_matchers.rb9
-rw-r--r--spec/support/matchers/make_queries.rb31
3 files changed, 41 insertions, 18 deletions
diff --git a/spec/support/matchers/background_migrations_matchers.rb b/spec/support/matchers/background_migrations_matchers.rb
index 1057639beec..b471323dd72 100644
--- a/spec/support/matchers/background_migrations_matchers.rb
+++ b/spec/support/matchers/background_migrations_matchers.rb
@@ -67,17 +67,6 @@ end
RSpec::Matchers.define :have_scheduled_batched_migration do |table_name: nil, column_name: nil, job_arguments: [], **attributes|
define_method :matches? do |migration|
- # Default arguments passed by BatchedMigrationWrapper (values don't matter here)
- expect(migration).to be_background_migration_with_arguments([
- _start_id = 1,
- _stop_id = 2,
- table_name,
- column_name,
- _sub_batch_size = 10,
- _pause_ms = 100,
- *job_arguments
- ])
-
batched_migrations =
Gitlab::Database::BackgroundMigration::BatchedMigration
.for_configuration(migration, table_name, column_name, job_arguments)
@@ -94,3 +83,11 @@ RSpec::Matchers.define :have_scheduled_batched_migration do |table_name: nil, co
expect(batched_migrations.count).to be(0)
end
end
+
+RSpec::Matchers.define :be_finalize_background_migration_of do |migration|
+ define_method :matches? do |klass|
+ expect_next_instance_of(klass) do |instance|
+ expect(instance).to receive(:finalize_background_migration).with(migration)
+ end
+ end
+end
diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb
index 3ba88c3ae71..e6d820104be 100644
--- a/spec/support/matchers/graphql_matchers.rb
+++ b/spec/support/matchers/graphql_matchers.rb
@@ -211,18 +211,13 @@ end
RSpec::Matchers.define :have_graphql_resolver do |expected|
match do |field|
- case expected
- when Method
- expect(field.type_class.resolve_proc).to eq(expected)
- else
- expect(field.type_class.resolver).to eq(expected)
- end
+ expect(field.resolver).to eq(expected)
end
end
RSpec::Matchers.define :have_graphql_extension do |expected|
match do |field|
- expect(field.type_class.extensions).to include(expected)
+ expect(field.extensions).to include(expected)
end
end
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