From 0f2c16ac4b6a26a6394f80af6e2cd9338dfffde0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 26 May 2023 03:41:12 -0400 Subject: [PATCH] Fix RSpec/NoExpectationExample cop (#25103) --- .rubocop_todo.yml | 7 ------ .../auth/registrations_controller_spec.rb | 23 ++++++++++++++++--- spec/services/precompute_feed_service_spec.rb | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5711b3d4f..3383a6b28 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -528,13 +528,6 @@ RSpec/MultipleMemoizedHelpers: RSpec/NestedGroups: Max: 6 -# Configuration parameters: AllowedPatterns. -# AllowedPatterns: ^expect_, ^assert_ -RSpec/NoExpectationExample: - Exclude: - - 'spec/controllers/auth/registrations_controller_spec.rb' - - 'spec/services/precompute_feed_service_spec.rb' - RSpec/PendingWithoutReason: Exclude: - 'spec/models/account_spec.rb' diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index a80273635..b52d7c6ce 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -244,9 +244,26 @@ RSpec.describe Auth::RegistrationsController do end end - it 'does nothing if user already exists' do - Fabricate(:account, username: 'test') - subject + context 'with an already taken username' do + subject do + Setting.registrations_mode = 'open' + post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } } + end + + before do + Fabricate(:account, username: 'test') + end + + it 'responds with an error message about the username' do + subject + + expect(response).to have_http_status(:success) + expect(username_error_text).to eq(I18n.t('errors.messages.taken')) + end + + def username_error_text + Nokogiri::Slop(response.body).css('.user_account_username .error').text + end end include_examples 'checks for enabled registrations', :create diff --git a/spec/services/precompute_feed_service_spec.rb b/spec/services/precompute_feed_service_spec.rb index 86ab59b29..18ba00244 100644 --- a/spec/services/precompute_feed_service_spec.rb +++ b/spec/services/precompute_feed_service_spec.rb @@ -19,7 +19,7 @@ RSpec.describe PrecomputeFeedService, type: :service do it 'does not raise an error even if it could not find any status' do account = Fabricate(:account) - subject.call(account) + expect { subject.call(account) }.to_not raise_error end it 'filters statuses' do