Skip to content

RuboCop mechanical cleanup: Lint, Capybara, RSpec, Naming - #2767

Merged
mroderick merged 11 commits into
masterfrom
fix/rubocop-mechanical-cleanup
Jul 30, 2026
Merged

RuboCop mechanical cleanup: Lint, Capybara, RSpec, Naming#2767
mroderick merged 11 commits into
masterfrom
fix/rubocop-mechanical-cleanup

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Problem

.rubocop_todo.yml carried 188 offenses. The first batch — the mechanical, low-risk cops across Lint, Capybara, RSpec, and Naming — can be cleared without behavior change, one commit per rule.

Changes

11 commits, each fixing one RuboCop rule and removing its .rubocop_todo.yml entry:

  • Lint/AssignmentInCondition — extract assignment out of the condition in ApplicationController#redirect_back and Feedback.submit_feedback.
  • Lint/UnderscorePrefixedVariableName — drop the unused _ prefix on member_no_rsvp in group_spec.
  • Lint/MissingSuper — call super in EventCardComponent#initialize.
  • Lint/ConstantDefinitionInBlock — hoist SetupChecker out of the namespace :setup block to the top of setup.rake.
  • Capybara/RSpec/NegationMatcherAfterVisit — add a positive assertion (current path / page element) before negation matchers so the page has settled before asserting absence.
  • Capybara/RSpec/VisibilityMatchervisible: true to visible: :visible in chapters_sidebar_component_spec.
  • RSpec/AnyInstance — stub Services::MailingList.new with an instance_double in member/details_controller_spec (the codebase's established pattern).
  • RSpec/MultipleExpectations — wrap "shows all details" scenarios in aggregate_failures.
  • RSpec/ExampleLength — extract the event form-fill into fill_in_mandatory_event_fields.
  • Naming/AccessorMethodName — rename set_* writer methods to assign_* across their callers.
  • Naming/MethodName — rename has_existing_RSVP_on to existing_rsvp_on? (snake_case predicate).

Deliberately not in this PR

These need judgment or config decisions, not mechanical edits:

  • Lint/Debuggerpage.save_screenshot in spec_helper is a legitimate CI failure-screenshot capture. Whitelisting it means overriding the Capybara DebuggerMethods group, which is brittle across RuboCop versions. Worth a focused config PR.
  • Naming/PredicatePrefixis_logged_in? would rename to logged_in?, which already exists as a different boolean method (the before-action calls it). Same collision risk for the policy is_admin_or_organiser? / is_chapter_organiser? predicates, which are referenced across many controllers and policies. Needs a dedicated rename PR with caller updates and collision resolution.
  • RSpec/AnyInstance in spec/support/helpers/login_helpers.rb — the app-wide allow_any_instance_of(ApplicationController) login stub used by feature and controller specs. Replacing it touches the test login mechanism for the whole suite.

These remain in .rubocop_todo.yml.

Verification

  • bundle exec rubocop — 360 files, no offenses.
  • bundle exec parallel_rspec spec/ -n 3 — 1166 examples, 0 failures.

Result

188 to 167 offenses in .rubocop_todo.yml.

mroderick added 11 commits July 30, 2026 15:25
… model

Extract assignment out of the condition in `redirect_back` and
`Feedback.submit_feedback` so the intent is unambiguous.
Defining the class inside the `namespace :setup` block triggered
Lint/ConstantDefinitionInBlock. Hoist it to the top of the file so
it is a top-level constant.
Capybara/RSpec/NegationMatcherAfterVisit flags `have_no_*` called
right after `visit`, because negation matchers return immediately
before the page has reached its expected state. Add a positive
assertion (current_path or page element) first so the negation only
runs once the page has settled.

Also switch `visible: true` to `visible: :visible` in
chapters_sidebar_component_spec (Capybara/RSpec/VisibilityMatcher).
Replace allow_any_instance_of with the codebase's established
pattern of stubbing Services::MailingList.new to return an
instance_double. login_helpers is left for a separate refactor.
Wrap the "shows all details" style scenarios in aggregate_failures
so they report every mismatch in one run instead of aborting on the
first, resolving RSpec/MultipleExpectations.
The mandatory-fields scenario exceeded the example length limit.
Pull the repeated form-fill block into fill_in_mandatory_event_fields
so the scenario stays focused on assertions.
Naming/AccessorMethodName flags set_-prefixed methods that take an
argument. These set associated records rather than a single attribute,
so rename to assign_organisers, assign_chapters, assign_host,
assign_coaches across their callers.
The method name mixed uppercase (RSVP) and a has_ predicate prefix.
Rename to existing_rsvp_on? to satisfy Naming/MethodName and use
the conventional predicate suffix.
Renaming has_existing_RSVP_on to existing_rsvp_on? in the
MethodName commit also resolved its PredicatePrefix offense, so
member.rb no longer needs excluding. The remaining has_/is_
predicates are left for a dedicated refactor (is_logged_in? collides
with the existing logged_in? boolean).
@mroderick
mroderick marked this pull request as ready for review July 30, 2026 13:49
@mroderick
mroderick merged commit 106b7b1 into master Jul 30, 2026
9 checks passed
@mroderick
mroderick deleted the fix/rubocop-mechanical-cleanup branch July 30, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant