diff options
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/background_migrations_matchers.rb | 19 | ||||
-rw-r--r-- | spec/support/matchers/graphql_matchers.rb | 9 | ||||
-rw-r--r-- | spec/support/matchers/make_queries.rb | 31 |
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 |