From 01c11dff9175252ae0ddb438d405f67811755d59 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 26 Mar 2024 11:32:44 +0100 Subject: [PATCH] DEV: Silence the output of migration specs (#26365) (plus fix the typo in the filename) --- ...ove_to_groups_migrations_generator_spec.rb | 44 ++++++++++++------- ...etting_rename_migrations_generator_spec.rb | 20 +++++++-- ..._category_setting_approval_values_spec.rb} | 24 ++++++---- 3 files changed, 58 insertions(+), 30 deletions(-) rename spec/migrations/{uppdate_category_setting_approval_values_spec.rb => update_category_setting_approval_values_spec.rb} (68%) diff --git a/spec/generator/site_setting_move_to_groups_migrations_generator_spec.rb b/spec/generator/site_setting_move_to_groups_migrations_generator_spec.rb index f564a1bc072..bcdadf52fee 100644 --- a/spec/generator/site_setting_move_to_groups_migrations_generator_spec.rb +++ b/spec/generator/site_setting_move_to_groups_migrations_generator_spec.rb @@ -7,13 +7,15 @@ RSpec.describe SiteSettingMoveToGroupsMigrationGenerator, type: :generator do it "generates the correct migration for TrustLevelSetting" do freeze_time DateTime.parse("2010-01-01 12:00") - described_class.start( - %w[min_trust_level_to_allow_invite allow_invite_groups], - destination_root: "#{Rails.root}/tmp", - ) + silence_stdout do + described_class.start( + %w[min_trust_level_to_allow_invite allow_invite_groups], + destination_root: "#{Rails.root}/tmp", + ) + end + file_path = "#{Rails.root}/tmp/db/migrate/20100101120000_fill_allow_invite_groups_based_on_deprecated_setting.rb" - expected_content = <<~EXPECTED_CONTENT # frozen_string_literal: true @@ -49,13 +51,15 @@ RSpec.describe SiteSettingMoveToGroupsMigrationGenerator, type: :generator do it "generates the correct migration for TrustLevelAndStaffSetting" do freeze_time DateTime.parse("2010-01-01 12:00") - described_class.start( - %w[min_trust_level_to_allow_invite_tl_and_staff allow_invite_groups], - destination_root: "#{Rails.root}/tmp", - ) + silence_stdout do + described_class.start( + %w[min_trust_level_to_allow_invite_tl_and_staff allow_invite_groups], + destination_root: "#{Rails.root}/tmp", + ) + end + file_path = "#{Rails.root}/tmp/db/migrate/20100101120000_fill_allow_invite_groups_based_on_deprecated_setting.rb" - expected_content = <<~EXPECTED_CONTENT # frozen_string_literal: true @@ -105,18 +109,24 @@ RSpec.describe SiteSettingMoveToGroupsMigrationGenerator, type: :generator do end it "raises an error when old name is incorrect" do - expect { described_class.start(%w[wrong_name allow_invite_groups]) }.to raise_error( - ArgumentError, - ) + silence_stdout do + expect { described_class.start(%w[wrong_name allow_invite_groups]) }.to raise_error( + ArgumentError, + ) + end end it "raises an error when new name is incorrect" do - expect { described_class.start(%w[min_trust_level_to_allow_invite wrong_name]) }.to raise_error( - ArgumentError, - ) + silence_stdout do + expect { + described_class.start(%w[min_trust_level_to_allow_invite wrong_name]) + }.to raise_error(ArgumentError) + end end it "raises an error when old setting is incorrect type" do - expect { described_class.start(%w[title allow_invite_groups]) }.to raise_error(ArgumentError) + silence_stdout do + expect { described_class.start(%w[title allow_invite_groups]) }.to raise_error(ArgumentError) + end end end diff --git a/spec/generator/site_setting_rename_migrations_generator_spec.rb b/spec/generator/site_setting_rename_migrations_generator_spec.rb index 1af9ba127ef..e6cd3eb40b0 100644 --- a/spec/generator/site_setting_rename_migrations_generator_spec.rb +++ b/spec/generator/site_setting_rename_migrations_generator_spec.rb @@ -6,9 +6,15 @@ require "generators/site_setting_rename_migration/site_setting_rename_migration_ RSpec.describe SiteSettingRenameMigrationGenerator, type: :generator do it "generates the correct migration" do freeze_time DateTime.parse("2010-01-01 12:00") - described_class.start(%w[site_description contact_email], destination_root: "#{Rails.root}/tmp") - file_path = "#{Rails.root}/tmp/db/migrate/20100101120000_rename_site_description_setting.rb" + silence_stdout do + described_class.start( + %w[site_description contact_email], + destination_root: "#{Rails.root}/tmp", + ) + end + + file_path = "#{Rails.root}/tmp/db/migrate/20100101120000_rename_site_description_setting.rb" expected_content = <<~EXPECTED_CONTENT # frozen_string_literal: true @@ -28,10 +34,16 @@ RSpec.describe SiteSettingRenameMigrationGenerator, type: :generator do end it "raises an error when old name is incorrect" do - expect { described_class.start(%w[wrong_name contact_email]) }.to raise_error(ArgumentError) + silence_stdout do + expect { described_class.start(%w[wrong_name contact_email]) }.to raise_error(ArgumentError) + end end it "raises an error when new name is incorrect" do - expect { described_class.start(%w[site_description wrong_name]) }.to raise_error(ArgumentError) + silence_stdout do + expect { described_class.start(%w[site_description wrong_name]) }.to raise_error( + ArgumentError, + ) + end end end diff --git a/spec/migrations/uppdate_category_setting_approval_values_spec.rb b/spec/migrations/update_category_setting_approval_values_spec.rb similarity index 68% rename from spec/migrations/uppdate_category_setting_approval_values_spec.rb rename to spec/migrations/update_category_setting_approval_values_spec.rb index 4a1af1a7408..37b972dc876 100644 --- a/spec/migrations/uppdate_category_setting_approval_values_spec.rb +++ b/spec/migrations/update_category_setting_approval_values_spec.rb @@ -10,9 +10,11 @@ RSpec.describe UpdateCategorySettingApprovalValues do end it "backfills with false (new default)" do - expect { described_class.new.up }.to change { category.reload.require_topic_approval }.from( - nil, - ).to(false) + silence_stdout do + expect { described_class.new.up }.to change { + category.reload.require_topic_approval + }.from(nil).to(false) + end end end @@ -29,9 +31,11 @@ RSpec.describe UpdateCategorySettingApprovalValues do let(:category) { Fabricate(:category) } it "backfills with the custom field value" do - expect { described_class.new.up }.to change { category.reload.category_setting }.from( - nil, - ).to(have_attributes(require_topic_approval: true)) + silence_stdout do + expect { described_class.new.up }.to change { category.reload.category_setting }.from( + nil, + ).to(have_attributes(require_topic_approval: true)) + end end end @@ -45,9 +49,11 @@ RSpec.describe UpdateCategorySettingApprovalValues do end it "backfills with the custom field value" do - expect { described_class.new.up }.to change { - category.category_setting.reload.require_topic_approval - }.from(false).to(true) + silence_stdout do + expect { described_class.new.up }.to change { + category.category_setting.reload.require_topic_approval + }.from(false).to(true) + end end end end