Skip to content

Commit

Permalink
Fix RSpec/ContextWording cop (#24739)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed May 4, 2023
1 parent cf18cc2 commit 710745e
Show file tree
Hide file tree
Showing 105 changed files with 559 additions and 668 deletions.
109 changes: 0 additions & 109 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,115 +328,6 @@ RSpec/AnyInstance:
- 'spec/workers/activitypub/delivery_worker_spec.rb'
- 'spec/workers/web/push_notification_worker_spec.rb'

# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/config/initializers/rack_attack_spec.rb'
- 'spec/controllers/accounts_controller_spec.rb'
- 'spec/controllers/activitypub/collections_controller_spec.rb'
- 'spec/controllers/activitypub/inboxes_controller_spec.rb'
- 'spec/controllers/admin/domain_blocks_controller_spec.rb'
- 'spec/controllers/admin/reports/actions_controller_spec.rb'
- 'spec/controllers/admin/statuses_controller_spec.rb'
- 'spec/controllers/api/v1/accounts/relationships_controller_spec.rb'
- 'spec/controllers/api/v1/accounts_controller_spec.rb'
- 'spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb'
- 'spec/controllers/api/v1/emails/confirmations_controller_spec.rb'
- 'spec/controllers/api/v1/instances/activity_controller_spec.rb'
- 'spec/controllers/api/v1/instances/peers_controller_spec.rb'
- 'spec/controllers/api/v1/media_controller_spec.rb'
- 'spec/controllers/api/v2/filters_controller_spec.rb'
- 'spec/controllers/application_controller_spec.rb'
- 'spec/controllers/auth/registrations_controller_spec.rb'
- 'spec/controllers/auth/sessions_controller_spec.rb'
- 'spec/controllers/concerns/cache_concern_spec.rb'
- 'spec/controllers/concerns/challengable_concern_spec.rb'
- 'spec/controllers/concerns/localized_spec.rb'
- 'spec/controllers/concerns/rate_limit_headers_spec.rb'
- 'spec/controllers/instance_actors_controller_spec.rb'
- 'spec/controllers/settings/applications_controller_spec.rb'
- 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb'
- 'spec/controllers/statuses_controller_spec.rb'
- 'spec/helpers/admin/account_moderation_notes_helper_spec.rb'
- 'spec/helpers/jsonld_helper_spec.rb'
- 'spec/helpers/routing_helper_spec.rb'
- 'spec/lib/activitypub/activity/accept_spec.rb'
- 'spec/lib/activitypub/activity/announce_spec.rb'
- 'spec/lib/activitypub/activity/create_spec.rb'
- 'spec/lib/activitypub/activity/follow_spec.rb'
- 'spec/lib/activitypub/activity/reject_spec.rb'
- 'spec/lib/emoji_formatter_spec.rb'
- 'spec/lib/entity_cache_spec.rb'
- 'spec/lib/feed_manager_spec.rb'
- 'spec/lib/html_aware_formatter_spec.rb'
- 'spec/lib/link_details_extractor_spec.rb'
- 'spec/lib/ostatus/tag_manager_spec.rb'
- 'spec/lib/scope_transformer_spec.rb'
- 'spec/lib/status_cache_hydrator_spec.rb'
- 'spec/lib/status_reach_finder_spec.rb'
- 'spec/lib/text_formatter_spec.rb'
- 'spec/models/account/field_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/admin/account_action_spec.rb'
- 'spec/models/concerns/account_interactions_spec.rb'
- 'spec/models/concerns/remotable_spec.rb'
- 'spec/models/custom_emoji_filter_spec.rb'
- 'spec/models/custom_emoji_spec.rb'
- 'spec/models/email_domain_block_spec.rb'
- 'spec/models/media_attachment_spec.rb'
- 'spec/models/notification_spec.rb'
- 'spec/models/remote_follow_spec.rb'
- 'spec/models/report_spec.rb'
- 'spec/models/session_activation_spec.rb'
- 'spec/models/setting_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/models/web/push_subscription_spec.rb'
- 'spec/policies/account_moderation_note_policy_spec.rb'
- 'spec/policies/account_policy_spec.rb'
- 'spec/policies/backup_policy_spec.rb'
- 'spec/policies/custom_emoji_policy_spec.rb'
- 'spec/policies/domain_block_policy_spec.rb'
- 'spec/policies/email_domain_block_policy_spec.rb'
- 'spec/policies/instance_policy_spec.rb'
- 'spec/policies/invite_policy_spec.rb'
- 'spec/policies/relay_policy_spec.rb'
- 'spec/policies/report_note_policy_spec.rb'
- 'spec/policies/report_policy_spec.rb'
- 'spec/policies/settings_policy_spec.rb'
- 'spec/policies/tag_policy_spec.rb'
- 'spec/policies/user_policy_spec.rb'
- 'spec/presenters/account_relationships_presenter_spec.rb'
- 'spec/presenters/status_relationships_presenter_spec.rb'
- 'spec/services/account_search_service_spec.rb'
- 'spec/services/account_statuses_cleanup_service_spec.rb'
- 'spec/services/activitypub/fetch_remote_status_service_spec.rb'
- 'spec/services/activitypub/process_account_service_spec.rb'
- 'spec/services/activitypub/process_status_update_service_spec.rb'
- 'spec/services/fetch_link_card_service_spec.rb'
- 'spec/services/fetch_oembed_service_spec.rb'
- 'spec/services/fetch_remote_status_service_spec.rb'
- 'spec/services/follow_service_spec.rb'
- 'spec/services/import_service_spec.rb'
- 'spec/services/notify_service_spec.rb'
- 'spec/services/process_mentions_service_spec.rb'
- 'spec/services/reblog_service_spec.rb'
- 'spec/services/report_service_spec.rb'
- 'spec/services/resolve_account_service_spec.rb'
- 'spec/services/resolve_url_service_spec.rb'
- 'spec/services/search_service_spec.rb'
- 'spec/services/unallow_domain_service_spec.rb'
- 'spec/services/verify_link_service_spec.rb'
- 'spec/validators/disallowed_hashtags_validator_spec.rb'
- 'spec/validators/email_mx_validator_spec.rb'
- 'spec/validators/follow_limit_validator_spec.rb'
- 'spec/validators/poll_validator_spec.rb'
- 'spec/validators/status_pin_validator_spec.rb'
- 'spec/validators/unreserved_username_validator_spec.rb'
- 'spec/validators/url_validator_spec.rb'
- 'spec/workers/move_worker_spec.rb'
- 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
Expand Down
16 changes: 8 additions & 8 deletions spec/config/initializers/rack_attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,36 @@ def app
let(:remote_ip) { '1.2.3.5' }

describe 'throttle excessive sign-up requests by IP address' do
context 'through the website' do
context 'when accessed through the website' do
let(:limit) { 25 }
let(:period) { 5.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }

context 'for exact path' do
context 'with exact path' do
let(:path) { '/auth' }

it_behaves_like 'throttled endpoint'
end

context 'for path with format' do
context 'with path with format' do
let(:path) { '/auth.html' }

it_behaves_like 'throttled endpoint'
end
end

context 'through the API' do
context 'when accessed through the API' do
let(:limit) { 5 }
let(:period) { 30.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }

context 'for exact path' do
context 'with exact path' do
let(:path) { '/api/v1/accounts' }

it_behaves_like 'throttled endpoint'
end

context 'for path with format' do
context 'with path with format' do
let(:path) { '/api/v1/accounts.json' }

it 'returns http not found' do
Expand All @@ -91,13 +91,13 @@ def app
let(:period) { 5.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }

context 'for exact path' do
context 'with exact path' do
let(:path) { '/auth/sign_in' }

it_behaves_like 'throttled endpoint'
end

context 'for path with format' do
context 'with path with format' do
let(:path) { '/auth/sign_in.html' }

it_behaves_like 'throttled endpoint'
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
end
end

context 'as HTML' do
context 'with HTML' do
let(:format) { 'html' }

it_behaves_like 'preliminary checks'
Expand Down Expand Up @@ -140,7 +140,7 @@
end
end

context 'as JSON' do
context 'with JSON' do
let(:authorized_fetch_mode) { false }
let(:format) { 'json' }

Expand Down Expand Up @@ -193,7 +193,7 @@
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end

context 'in authorized fetch mode' do
context 'with authorized fetch mode' do
let(:authorized_fetch_mode) { true }

it 'returns http unauthorized' do
Expand Down Expand Up @@ -251,7 +251,7 @@
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end

context 'in authorized fetch mode' do
context 'with authorized fetch mode' do
let(:authorized_fetch_mode) { true }

it 'returns http success' do
Expand All @@ -278,7 +278,7 @@
end
end

context 'as RSS' do
context 'with RSS' do
let(:format) { 'rss' }

it_behaves_like 'preliminary checks'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
end
end

context 'in authorized fetch mode' do
context 'with authorized fetch mode' do
before do
allow(controller).to receive(:authorized_fetch_mode?).and_return(true)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/activitypub/inboxes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
expect(response).to have_http_status(202)
end

context 'for a specific account' do
context 'with a specific account' do
subject(:response) { post :create, params: { account_username: account.username }, body: '{}' }

let(:account) { Fabricate(:account) }
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/domain_blocks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
BlockDomainService.new.call(domain_block)
end

context 'downgrading a domain suspension to silence' do
context 'when downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' }

Expand All @@ -100,7 +100,7 @@
end
end

context 'upgrading a domain silence to suspend' do
context 'when upgrading a domain silence to suspend' do
let(:original_severity) { 'silence' }
let(:new_severity) { 'suspend' }

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/reports/actions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@
end
end

context 'action as submit button' do
context 'with Action as submit button' do
subject { post :create, params: common_params.merge({ action => '' }) }

it_behaves_like 'all action types'
end

context 'action as submit button' do
context 'with Action as submit button' do
subject { post :create, params: common_params.merge({ moderation_action: action }) }

it_behaves_like 'all action types'
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
end
end

context 'filtering by media' do
context 'when filtering by media' do
before do
get :index, params: { account_id: account.id, media: '1' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
lewis.follow!(user.account)
end

context 'provided only one ID' do
context 'when provided only one ID' do
before do
get :index, params: { id: simon.id }
end
Expand All @@ -39,7 +39,7 @@
end
end

context 'provided multiple IDs' do
context 'when provided multiple IDs' do
before do
get :index, params: { id: [simon.id, lewis.id] }
end
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/api/v1/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
post :create, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement }
end

context 'given truthy agreement' do
context 'when given truthy agreement' do
let(:agreement) { 'true' }

it 'returns http success' do
Expand All @@ -48,7 +48,7 @@
end
end

context 'given no agreement' do
context 'when given no agreement' do
it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)
end
Expand Down Expand Up @@ -121,7 +121,7 @@
end
end

context 'modifying follow options' do
context 'when modifying follow options' do
let(:locked) { false }

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
BlockDomainService.new.call(domain_block)
end

context 'downgrading a domain suspension to silence' do
context 'when downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' }

Expand All @@ -101,7 +101,7 @@
end
end

context 'upgrading a domain silence to suspend' do
context 'when upgrading a domain silence to suspend' do
let(:original_severity) { 'silence' }
let(:new_severity) { 'suspend' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
allow(controller).to receive(:doorkeeper_token) { token }
end

context 'from a random app' do
context 'when from a random app' do
it 'returns http forbidden' do
post :create
expect(response).to have_http_status(403)
end
end

context 'from an app that created the account' do
context 'when from an app that created the account' do
before do
user.update(created_by_application: token.application)
end
Expand All @@ -35,7 +35,7 @@
expect(response).to have_http_status(403)
end

context 'but user changed e-mail and has not confirmed it' do
context 'with user changed e-mail and has not confirmed it' do
before do
user.update(email: 'foo@bar.com')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
expect(response).to have_http_status(200)
end

context '!Setting.activity_api_enabled' do
context 'with !Setting.activity_api_enabled' do
it 'returns 404' do
Setting.activity_api_enabled = false

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/instances/peers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
expect(response).to have_http_status(200)
end

context '!Setting.peers_api_enabled' do
context 'with !Setting.peers_api_enabled' do
it 'returns 404' do
Setting.peers_api_enabled = false

Expand Down

0 comments on commit 710745e

Please sign in to comment.