From b06284c572d69bb6de0460c6823fa7812fd54208 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 7 Nov 2023 04:10:36 -0500 Subject: [PATCH] Fix `RSpec/HookArgument` cop (#27747) --- .rubocop_todo.yml | 14 -------------- .../api/v1/streaming_controller_spec.rb | 6 +++--- .../well_known/webfinger_controller_spec.rb | 2 +- spec/helpers/instance_helper_spec.rb | 2 +- spec/models/user_spec.rb | 12 ++++++------ spec/rails_helper.rb | 4 ++-- .../activitypub/note_serializer_spec.rb | 2 +- .../activitypub/update_poll_serializer_spec.rb | 2 +- spec/services/import_service_spec.rb | 2 +- 9 files changed, 16 insertions(+), 30 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6409181601..e55fd698f2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -94,20 +94,6 @@ RSpec/AnyInstance: RSpec/ExampleLength: Max: 22 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, each, example -RSpec/HookArgument: - Exclude: - - 'spec/controllers/api/v1/streaming_controller_spec.rb' - - 'spec/controllers/well_known/webfinger_controller_spec.rb' - - 'spec/helpers/instance_helper_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/rails_helper.rb' - - 'spec/serializers/activitypub/note_serializer_spec.rb' - - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - - 'spec/services/import_service_spec.rb' - # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: diff --git a/spec/controllers/api/v1/streaming_controller_spec.rb b/spec/controllers/api/v1/streaming_controller_spec.rb index 7014ed9b2b..06639a13fd 100644 --- a/spec/controllers/api/v1/streaming_controller_spec.rb +++ b/spec/controllers/api/v1/streaming_controller_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' describe Api::V1::StreamingController do - around(:each) do |example| + around do |example| before = Rails.configuration.x.streaming_api_base_url Rails.configuration.x.streaming_api_base_url = Rails.configuration.x.web_domain example.run Rails.configuration.x.streaming_api_base_url = before end - before(:each) do + before do request.headers.merge! Host: Rails.configuration.x.web_domain end @@ -24,7 +24,7 @@ describe Api::V1::StreamingController do end context 'with streaming api on different host' do - before(:each) do + before do Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}" @streaming_host = URI.parse(Rails.configuration.x.streaming_api_base_url).host end diff --git a/spec/controllers/well_known/webfinger_controller_spec.rb b/spec/controllers/well_known/webfinger_controller_spec.rb index 20770a7211..6610f4d138 100644 --- a/spec/controllers/well_known/webfinger_controller_spec.rb +++ b/spec/controllers/well_known/webfinger_controller_spec.rb @@ -16,7 +16,7 @@ describe WellKnown::WebfingerController do let(:alice) { Fabricate(:account, username: 'alice') } let(:resource) { nil } - around(:each) do |example| + around do |example| tmp = Rails.configuration.x.alternate_domains Rails.configuration.x.alternate_domains = alternate_domains example.run diff --git a/spec/helpers/instance_helper_spec.rb b/spec/helpers/instance_helper_spec.rb index c2e26dbed3..cdbce56598 100644 --- a/spec/helpers/instance_helper_spec.rb +++ b/spec/helpers/instance_helper_spec.rb @@ -18,7 +18,7 @@ describe InstanceHelper do end describe 'site_hostname' do - around(:each) do |example| + around do |example| before = Rails.configuration.x.local_domain example.run Rails.configuration.x.local_domain = before diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 92ce87e369..faf7fabf1e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -102,7 +102,7 @@ RSpec.describe User do end describe 'blacklist' do - around(:each) do |example| + around do |example| old_blacklist = Rails.configuration.x.email_blacklist Rails.configuration.x.email_domains_blacklist = 'mvrht.com' @@ -169,7 +169,7 @@ RSpec.describe User do let(:user) { Fabricate(:user, confirmed_at: nil, unconfirmed_email: new_email) } context 'when the user is already approved' do - around(:example) do |example| + around do |example| registrations_mode = Setting.registrations_mode Setting.registrations_mode = 'approved' @@ -193,7 +193,7 @@ RSpec.describe User do end context 'when the user does not require explicit approval' do - around(:example) do |example| + around do |example| registrations_mode = Setting.registrations_mode Setting.registrations_mode = 'open' @@ -213,7 +213,7 @@ RSpec.describe User do end context 'when the user requires explicit approval but is not approved' do - around(:example) do |example| + around do |example| registrations_mode = Setting.registrations_mode Setting.registrations_mode = 'approved' @@ -237,7 +237,7 @@ RSpec.describe User do describe '#approve!' do subject { user.approve! } - around(:example) do |example| + around do |example| registrations_mode = Setting.registrations_mode Setting.registrations_mode = 'approved' @@ -338,7 +338,7 @@ RSpec.describe User do end describe 'whitelist' do - around(:each) do |example| + around do |example| old_whitelist = Rails.configuration.x.email_domains_whitelist Rails.configuration.x.email_domains_whitelist = 'mastodon.space' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 8d9677f6ce..c2ef3e3159 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -142,13 +142,13 @@ RSpec.configure do |config| search_data_manager.remove_indexes end - config.before(:each) do |example| + config.before do |example| unless example.metadata[:paperclip_processing] allow_any_instance_of(Paperclip::Attachment).to receive(:post_process).and_return(true) # rubocop:disable RSpec/AnyInstance end end - config.after :each do + config.after do Rails.cache.clear redis.del(redis.keys) end diff --git a/spec/serializers/activitypub/note_serializer_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb index 31ee31f132..311a4573d9 100644 --- a/spec/serializers/activitypub/note_serializer_spec.rb +++ b/spec/serializers/activitypub/note_serializer_spec.rb @@ -14,7 +14,7 @@ describe ActivityPub::NoteSerializer do let!(:reply_by_account_third) { Fabricate(:status, account: account, thread: parent, visibility: :public) } let!(:reply_by_account_visibility_direct) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } - before(:each) do + before do @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter) end diff --git a/spec/serializers/activitypub/update_poll_serializer_spec.rb b/spec/serializers/activitypub/update_poll_serializer_spec.rb index 14c24c70cc..9a13fdd576 100644 --- a/spec/serializers/activitypub/update_poll_serializer_spec.rb +++ b/spec/serializers/activitypub/update_poll_serializer_spec.rb @@ -9,7 +9,7 @@ describe ActivityPub::UpdatePollSerializer do let(:poll) { Fabricate(:poll, account: account) } let!(:status) { Fabricate(:status, account: account, poll: poll) } - before(:each) do + before do @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: described_class, adapter: ActivityPub::Adapter) end diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index 1904ac8dc9..e12bbc1a78 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -208,7 +208,7 @@ RSpec.describe ImportService, type: :service do let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') } let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) } - around(:each) do |example| + around do |example| local_before = Rails.configuration.x.local_domain web_before = Rails.configuration.x.web_domain Rails.configuration.x.local_domain = 'local.com'