Enable RSpecRails/InferredSpecType and drop redundant spec types - #2846
Draft
mroderick wants to merge 1 commit into
Draft
Enable RSpecRails/InferredSpecType and drop redundant spec types#2846mroderick wants to merge 1 commit into
mroderick wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.components: componentin its Inferences, since ViewComponent specs are outside the rspec-rails defaultstype:pair fromRSpec.describe)Details:
Why this is safe here
The cop assumes
config.infer_spec_type_from_file_location!is enabled, which this repo does inspec/rails_helper.rb- including the customspec/componentsmapping registered before inference runs, andconfig.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: :componentmetadata; this makes the linter catch it permanently.