Skip to content

Enable RSpecRails/InferredSpecType and drop redundant spec types - #2846

Draft
mroderick wants to merge 1 commit into
masterfrom
chore/rubocop-inferred-spec-type
Draft

Enable RSpecRails/InferredSpecType and drop redundant spec types#2846
mroderick wants to merge 1 commit into
masterfrom
chore/rubocop-inferred-spec-type

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Enables the RuboCop cop that flags spec type metadata RSpec already infers from the file path, so redundant type: :model-style tags never need manual review again.

  • Enable RSpecRails/InferredSpecType (it ships pending) and register components: component in its Inferences, since ViewComponent specs are outside the rspec-rails defaults
  • Autocorrect the 56 offenses it found across 56 spec files (removal of the redundant type: pair from RSpec.describe)

Details:

Why this is safe here

The cop assumes config.infer_spec_type_from_file_location! is enabled, which this repo does in spec/rails_helper.rb - including the custom spec/components mapping registered before inference runs, and config.include ViewComponent::TestHelpers, type: :component, which keys off the inferred type. Removing the explicit tag therefore changes nothing at runtime. The full suite passes (1308 examples, 0 failures) and RuboCop is clean with the cop enabled.

Motivation: reviewer feedback on #2844 pointed out redundant type: :component metadata; this makes the linter catch it permanently.

With config.infer_spec_type_from_file_location! (plus the custom
spec/components mapping in rails_helper.rb), explicit type metadata on
example groups duplicates what RSpec already infers from the file path.
Enable RSpecRails/InferredSpecType so RuboCop flags and autofixes it,
register components: component in Inferences since ViewComponent specs
are not part of the rspec-rails defaults, and autocorrect the 56
offenses it found. No behavioural change; full suite green.
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